From f55adf4d1d6d0ce6ff64d75bfdb63cdaa8c75cff Mon Sep 17 00:00:00 2001 From: blakedgordon Date: Sun, 22 Mar 2020 13:41:38 -0700 Subject: [PATCH 1/3] Added ability to change right icon to arrow --- Dozer/Constants.swift | 1 + Dozer/DozerIcons.swift | 33 +++++++++++- Dozer/Other/Info.plist | 2 +- Dozer/ViewControllers/GeneralVC.swift | 11 ++++ Dozer/XIB/General.xib | 74 +++++++++++++++++---------- 5 files changed, 93 insertions(+), 28 deletions(-) diff --git a/Dozer/Constants.swift b/Dozer/Constants.swift index 9ff3487..1d6b582 100644 --- a/Dozer/Constants.swift +++ b/Dozer/Constants.swift @@ -12,6 +12,7 @@ extension Defaults.Keys { static let hideAfterDelayEnabled: Defaults.Key = Key("hideAfterDelayEnabled", default: false) static let hideAfterDelay: Defaults.Key = Key("hideAfterDelay", default: 10) static let noIconMode: Defaults.Key = Key("noIconMode", default: false) + static let rightIconArrow: Defaults.Key = Key("rightIconArrow", default: false) static let removeDozerIconEnabled: Defaults.Key = Key("removeStatusIconEnabled", default: false) static let animationEnabled: Defaults.Key = Key("animationEnabeld", default: false) } diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index 07d802e..f847a82 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -15,7 +15,11 @@ public final class DozerIcons { dozerIcons.append(NormalStatusIcon()) if !hideBothDozerIcons { - dozerIcons.append(NormalStatusIcon()) + let rightIcon = NormalStatusIcon() + if rightIconAsArrow { + rightIcon.statusIcon.image = NSImage(named: (hideStatusBarIconsAtLaunch) ? NSImage.goLeftTemplateName : NSImage.goRightTemplateName) + } + dozerIcons.append(rightIcon) } if enableRemoveDozerIcon { @@ -65,6 +69,10 @@ public final class DozerIcons { didSet { defaults[.noIconMode] = self.hideBothDozerIcons if hideBothDozerIcons { + let leftDozerIcon = get(dozerIcon: .normalLeft) + if rightIconAsArrow { + leftDozerIcon.statusIcon.image = NSImage(named: NSImage.goRightTemplateName) + } let rightDozerIconXPos = get(dozerIcon: .normalRight).xPositionOnScreen dozerIcons.removeAll(where: { $0.xPositionOnScreen == rightDozerIconXPos }) } else { @@ -72,6 +80,19 @@ public final class DozerIcons { } } } + + public var rightIconAsArrow: Bool = defaults[.rightIconArrow] { + didSet { + defaults[.rightIconArrow] = self.rightIconAsArrow + let rightIcon = get(dozerIcon: .normalRight) + if rightIconAsArrow { + let leftIcon = get(dozerIcon: .normalLeft) + rightIcon.statusIcon.image = (leftIcon.isShown) ? NSImage(named: NSImage.goRightTemplateName) : NSImage(named: NSImage.goLeftTemplateName) + } else { + rightIcon.setIcon() + } + } + } public var enableRemoveDozerIcon: Bool = defaults[.removeDozerIconEnabled] { didSet { @@ -91,6 +112,9 @@ public final class DozerIcons { perform(action: .hide, statusIcon: .normalLeft) if defaults[.noIconMode] { perform(action: .hide, statusIcon: .normalRight) + } else if rightIconAsArrow { + let rightIcon = get(dozerIcon: .normalRight) + rightIcon.statusIcon.image = NSImage(named: NSImage.goLeftTemplateName) } didHideStatusBarIcons() } @@ -98,8 +122,15 @@ public final class DozerIcons { public func show() { perform(action: .hide, statusIcon: .remove) perform(action: .show, statusIcon: .normalLeft) + let leftIcon = get(dozerIcon: .normalLeft) + if leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goRightTemplateName)?.name() { + leftIcon.setIcon() + } if defaults[.noIconMode] { perform(action: .show, statusIcon: .normalRight) + } else if rightIconAsArrow { + let rightIcon = get(dozerIcon: .normalRight) + rightIcon.statusIcon.image = NSImage(named: NSImage.goRightTemplateName) } didShowStatusBarIcons() } diff --git a/Dozer/Other/Info.plist b/Dozer/Other/Info.plist index b2bfcdb..d024133 100755 --- a/Dozer/Other/Info.plist +++ b/Dozer/Other/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 4.1.0 CFBundleVersion - 8 + $(CURRENT_PROJECT_VERSION) Fabric APIKey diff --git a/Dozer/ViewControllers/GeneralVC.swift b/Dozer/ViewControllers/GeneralVC.swift index 101a779..b01001d 100644 --- a/Dozer/ViewControllers/GeneralVC.swift +++ b/Dozer/ViewControllers/GeneralVC.swift @@ -25,6 +25,7 @@ final class General: NSViewController, PreferencePane { @IBOutlet private var HideStatusBarIconsAtLaunchCheckbox: NSButton! @IBOutlet private var HideStatusBarIconsAfterDelayCheckbox: NSButton! @IBOutlet private var HideBothDozerIconsCheckbox: NSButton! + @IBOutlet private var VisualizeRightAsArrowCheckbox: NSButton! @IBOutlet private var EnableRemoveDozerIconCheckbox: NSButton! @IBOutlet private var ToggleMenuItemsView: MASShortcutView! @@ -43,6 +44,7 @@ final class General: NSViewController, PreferencePane { HideStatusBarIconsAtLaunchCheckbox.isChecked = defaults[.hideAtLaunchEnabled] HideStatusBarIconsAfterDelayCheckbox.isChecked = defaults[.hideAfterDelayEnabled] HideBothDozerIconsCheckbox.isChecked = defaults[.noIconMode] + VisualizeRightAsArrowCheckbox.isChecked = defaults[.rightIconArrow] EnableRemoveDozerIconCheckbox.isChecked = defaults[.removeDozerIconEnabled] ToggleMenuItemsView.associatedUserDefaultsKey = UserDefaultKeys.Shortcuts.ToggleMenuItems @@ -75,6 +77,15 @@ final class General: NSViewController, PreferencePane { @IBAction private func hideBothDozerIconsClicked(_ sender: NSButton) { DozerIcons.shared.hideBothDozerIcons = HideBothDozerIconsCheckbox.isChecked + if HideBothDozerIconsCheckbox.isChecked { + VisualizeRightAsArrowCheckbox.isChecked = false + DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked + } + VisualizeRightAsArrowCheckbox.isEnabled = !HideBothDozerIconsCheckbox.isChecked + } + + @IBAction private func visualizeRightAsArrowClicked(_ sender: NSButton) { + DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked } @IBAction private func enableRemoveDozerIconClicked(_ sender: NSButton) { diff --git a/Dozer/XIB/General.xib b/Dozer/XIB/General.xib index 5a450b1..8bdfd29 100644 --- a/Dozer/XIB/General.xib +++ b/Dozer/XIB/General.xib @@ -1,7 +1,8 @@ - + - + + @@ -14,16 +15,17 @@ + - + - - - - - - - - - - + @@ -52,7 +45,7 @@ - + @@ -93,8 +86,19 @@ + - + @@ -114,19 +118,19 @@ - + - + - + + + + + + + + + + + + + + + + + + + - + - + From 8a084b963863dfe00ebd3003ca0acfedcaaf5238 Mon Sep 17 00:00:00 2001 From: blakedgordon Date: Wed, 25 Mar 2020 13:31:15 -0700 Subject: [PATCH 2/3] Ensure left icon changes back to dot if they get swapped around --- Dozer/DozerIcons.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dozer/DozerIcons.swift b/Dozer/DozerIcons.swift index f847a82..e65f7c8 100755 --- a/Dozer/DozerIcons.swift +++ b/Dozer/DozerIcons.swift @@ -123,7 +123,8 @@ public final class DozerIcons { perform(action: .hide, statusIcon: .remove) perform(action: .show, statusIcon: .normalLeft) let leftIcon = get(dozerIcon: .normalLeft) - if leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goRightTemplateName)?.name() { + if leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goRightTemplateName)?.name() || + leftIcon.statusIcon.image?.name() == NSImage(named: NSImage.goLeftTemplateName)?.name() { leftIcon.setIcon() } if defaults[.noIconMode] { From b49461609f8f52d738d25d93cccc541b4340d04d Mon Sep 17 00:00:00 2001 From: blakedgordon Date: Wed, 25 Mar 2020 16:01:55 -0700 Subject: [PATCH 3/3] Address bug where Right Icon checkbox could be enabled after app is restarted --- Dozer/AppDelegate.swift | 2 +- Dozer/ViewControllers/GeneralVC.swift | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Dozer/AppDelegate.swift b/Dozer/AppDelegate.swift index 2a994bc..7ab2308 100755 --- a/Dozer/AppDelegate.swift +++ b/Dozer/AppDelegate.swift @@ -18,7 +18,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { Fabric.with([Crashlytics.self]) #endif - MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: UserDefaultKeys.Shortcuts.ToggleMenuItems) { [unowned self] in + MASShortcutBinder.shared()?.bindShortcut(withDefaultsKey: UserDefaultKeys.Shortcuts.ToggleMenuItems) { () in DozerIcons.shared.toggle() } diff --git a/Dozer/ViewControllers/GeneralVC.swift b/Dozer/ViewControllers/GeneralVC.swift index b01001d..ecee915 100644 --- a/Dozer/ViewControllers/GeneralVC.swift +++ b/Dozer/ViewControllers/GeneralVC.swift @@ -46,6 +46,7 @@ final class General: NSViewController, PreferencePane { HideBothDozerIconsCheckbox.isChecked = defaults[.noIconMode] VisualizeRightAsArrowCheckbox.isChecked = defaults[.rightIconArrow] EnableRemoveDozerIconCheckbox.isChecked = defaults[.removeDozerIconEnabled] + configureEnabledRightIconAsArrowCheckbox() ToggleMenuItemsView.associatedUserDefaultsKey = UserDefaultKeys.Shortcuts.ToggleMenuItems view.addSubview(ToggleMenuItemsView) @@ -77,11 +78,7 @@ final class General: NSViewController, PreferencePane { @IBAction private func hideBothDozerIconsClicked(_ sender: NSButton) { DozerIcons.shared.hideBothDozerIcons = HideBothDozerIconsCheckbox.isChecked - if HideBothDozerIconsCheckbox.isChecked { - VisualizeRightAsArrowCheckbox.isChecked = false - DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked - } - VisualizeRightAsArrowCheckbox.isEnabled = !HideBothDozerIconsCheckbox.isChecked + configureEnabledRightIconAsArrowCheckbox() } @IBAction private func visualizeRightAsArrowClicked(_ sender: NSButton) { @@ -91,4 +88,12 @@ final class General: NSViewController, PreferencePane { @IBAction private func enableRemoveDozerIconClicked(_ sender: NSButton) { DozerIcons.shared.enableRemoveDozerIcon = EnableRemoveDozerIconCheckbox.isChecked } + + private func configureEnabledRightIconAsArrowCheckbox() { + if HideBothDozerIconsCheckbox.isChecked { + VisualizeRightAsArrowCheckbox.isChecked = false + DozerIcons.shared.rightIconAsArrow = VisualizeRightAsArrowCheckbox.isChecked + } + VisualizeRightAsArrowCheckbox.isEnabled = !HideBothDozerIconsCheckbox.isChecked + } }