8000 [rem-21]: Add option to disable cmd-scroll by jasonjmcghee · Pull Request #22 · jasonjmcghee/rem · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[rem-21]: Add option to disable cmd-scroll #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rem/SettingsManager.swift
8000
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
// The settings structure
struct AppSettings: Codable {
var saveEverythingCopiedToClipboard: Bool
var enableCmdScrollShortcut: Bool
}

// The settings manager handles saving and loading the settings
Expand All @@ -26,7 +27,7 @@ class SettingsManager: ObservableObject {
self.settings = decodedSettings
} else {
// Default settings
self.settings = AppSettings(saveEverythingCopiedToClipboard: false)
self.settings = AppSettings(saveEverythingCopiedToClipboard: false, enableCmdScrollShortcut: true)
}
}

Expand All @@ -48,6 +49,8 @@ struct SettingsView: View {
Form {
Toggle("Remember everything copied to clipboard", isOn: $settingsManager.settings.saveEverythingCopiedToClipboard)
.onChange(of: settingsManager.settings.saveEverythingCopiedToClipboard) { settingsManager.saveSettings() }
Toggle("Allow opening / closing timeline with CMD + Scroll", isOn: $settingsManager.settings.enableCmdScrollShortcut)
.onChange(of: settingsManager.settings.enableCmdScrollShortcut) { settingsManager.saveSettings() }
}
}
.padding()
Expand Down
13 changes: 11 additions & 2 deletions rem/TimelineView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ struct TimelineView: View {
let overlayView = ImageAnalysisOverlayView()
private let imageAnalyzer = ImageAnalyzer()

var settingsManager: SettingsManager
var onClose: () -> Void // Closure to handle thumbnail click

private var fps: Int32 = 25

init(viewModel: TimelineViewModel, onClose: @escaping () -> Void) {
init(viewModel: TimelineViewModel, settingsManager: SettingsManager, onClose: @escaping () -> Void) {
self.viewModel = viewModel
self.settingsManager = settingsManager
self.>
_frame = State(initialValue: NSScreen.main?.visibleFrame ?? NSRect.zero)
_customHostingView = State(initialValue: nil)
Expand All @@ -30,7 +32,7 @@ struct TimelineView: View {
let index = viewModel.currentFrameIndex
if let image = DatabaseManager.shared.getImage(index: index) {
let nsImage = NSImage(cgImage: image, size: NSSize(width: image.width, height: image.width))
CustomHostingControllerRepresentable(onClose: onClose, image: nsImag 8000 e, analysis: $imageAnalysis, frame: frame)
CustomHostingControllerRepresentable(settingsManager: settingsManager, onClose: onClose, image: nsImage, analysis: $imageAnalysis, frame: frame)
.frame(width: frame.width, height: frame.height)
.ignoresSafeArea(.all)
.onChange(of: viewModel.currentFrameIndex) {
Expand Down Expand Up @@ -169,6 +171,7 @@ class CustomHostingView: NSHostingView<AnyView> {
}

struct CustomHostingControllerRepresentable: NSViewControllerRepresentable {
var settingsManager: SettingsManager
var onClose: () -> Void // Closure to handle thumbnail click
var image: NSImage
@Binding var analysis: ImageAnalysis?
Expand All @@ -177,6 +180,7 @@ struct CustomHostingControllerRepresentable: NSViewControllerRepresentable {
func makeNSViewController(context: Context) -> CustomHostingViewController {
let viewController = CustomHostingViewController()
viewController.>
viewController.settingsManager = settingsManager
viewController.updateImage(image, frame: frame)
return viewController
}
Expand All @@ -185,10 +189,12 @@ struct CustomHostingControllerRepresentable: NSViewControllerRepresentable {
nsViewController.updateImage(image, frame: frame)
nsViewController.updateAnalysis(analysis)
nsViewController.>
nsViewController.settingsManager = settingsManager
}
}

class CustomHostingViewController: NSViewController {
var settingsManager: SettingsManager?
var onClose: (() -> Void)? // Closure to handle thumbnail click
var customHostingView: CustomHostingView?
var interceptingView: CustomInterceptingView?
Expand All @@ -200,6 +206,7 @@ class CustomHostingViewController: NSViewController {
override func loadView() {
let _interceptingView = CustomInterceptingView()
_interceptingView.>
_interceptingView.settingsManager = settingsManager
self.view = _interceptingView // Basic NSView as a container
if customHostingView == nil {
customHostingView = CustomHostingView(image: NSImage(), frame: self.view.bounds)
Expand Down Expand Up @@ -227,6 +234,7 @@ class CustomHostingViewController: NSViewController {
}

class CustomInterceptingView: NSView {
var settingsManager: SettingsManager?
var onClose: (() -> Void)? // Closure to handle thumbnail click
weak var customHostingView: CustomHostingView?

Expand Down Expand Up @@ -258,6 +266,7 @@ class CustomInterceptingView: NSView {
}

override func scrollWheel(with event: NSEvent) {
guard settingsManager?.settings.enableCmdScrollShortcut ?? false else { return }
if event.modifierFlags.contains(.command) && event.scrollingDeltaY > 0 {
self.exit()
}
Expand Down
3 changes: 2 additions & 1 deletion rem/remApp.swift
< 811C input type="hidden" name="path" value="rem/remApp.swift" autocomplete="off" data-targets="deferred-diff-lines.inputs" />
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

private func handleGlobalScrollEvent(_ event: NSEvent) {
guard settingsManager.settings.enableCmdScrollShortcut else { return}
guard event.modifierFlags.contains(.command) else { return }

if event.scrollingDeltaY < 0 && !self.isTimelineOpen() { // Check if scroll up
Expand Down Expand Up @@ -579,7 +580,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

timelineViewWindow?.collectionBehavior = [.fullScreenAuxiliary, .canJoinAllSpaces, .participatesInCycle]
timelineViewWindow?.ignoresMouseEvents = false
timelineView = TimelineView(viewModel: TimelineViewModel(), onClose: {
timelineView = TimelineView(viewModel: TimelineViewModel(), settingsManager: settingsManager, onClose: {
DispatchQueue.main.async { [weak self] in
self?.closeTimelineView()
}
Expand Down
0