From f5ce7fa773042fc5af7b2a4cfe7ddd341f19b494 Mon Sep 17 00:00:00 2001 From: Ji4n1ng Date: Sun, 21 Jul 2019 10:53:09 +0800 Subject: [PATCH] fix(Main): FinderSync Menu --- OpenInTerminal.xcodeproj/project.pbxproj | 6 +- OpenInTerminal/AppDelegate.swift | 68 ----------- OpenInTerminal/Notifier/OpenNotifier.swift | 10 -- OpenInTerminal/en.lproj/Localizable.strings | 2 +- .../FinderSync.swift | 107 +----------------- 5 files changed, 6 insertions(+), 187 deletions(-) diff --git a/OpenInTerminal.xcodeproj/project.pbxproj b/OpenInTerminal.xcodeproj/project.pbxproj index efda0c2..ab28be9 100644 --- a/OpenInTerminal.xcodeproj/project.pbxproj +++ b/OpenInTerminal.xcodeproj/project.pbxproj @@ -26,7 +26,6 @@ 47252586226812AB003C50DF /* OpenInTerminalCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4725251122680E87003C50DF /* OpenInTerminalCore.framework */; }; 47252587226812AB003C50DF /* OpenInTerminalCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4725251122680E87003C50DF /* OpenInTerminalCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4725258A226812AB003C50DF /* OpenInTerminalFinderExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 4725254A22680FEB003C50DF /* OpenInTerminalFinderExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - 4725259022681424003C50DF /* OpenInTerminalCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4725251122680E87003C50DF /* OpenInTerminalCore.framework */; }; 950A4E692271EEC8002A9548 /* AlacrittyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A4E682271EEC8002A9548 /* AlacrittyApp.swift */; }; 9511D89522747334008E52B9 /* CoreManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9511D89422747334008E52B9 /* CoreManager.swift */; }; 9511D8AC22749582008E52B9 /* LaunchNotifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9511D8AB22749582008E52B9 /* LaunchNotifier.swift */; }; @@ -203,7 +202,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4725259022681424003C50DF /* OpenInTerminalCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -885,7 +883,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.11; - MARKETING_VERSION = 0.10.3; + MARKETING_VERSION = 2.0.0; PRODUCT_BUNDLE_IDENTIFIER = wang.jianing.OpenInTerminal; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -910,7 +908,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.11; - MARKETING_VERSION = 0.10.3; + MARKETING_VERSION = 2.0.0; PRODUCT_BUNDLE_IDENTIFIER = wang.jianing.OpenInTerminal; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/OpenInTerminal/AppDelegate.swift b/OpenInTerminal/AppDelegate.swift index 6691f88..a316cc9 100644 --- a/OpenInTerminal/AppDelegate.swift +++ b/OpenInTerminal/AppDelegate.swift @@ -110,35 +110,9 @@ extension AppDelegate { OpenNotifier.addObserver(observer: self, selector: #selector(openDefaultTerminal), notification: .openDefaultTerminal) - OpenNotifier.addObserver(observer: self, - selector: #selector(openTerminal), - notification: .openTerminal) - OpenNotifier.addObserver(observer: self, - selector: #selector(openITerm), - notification: .openITerm) - OpenNotifier.addObserver(observer: self, - selector: #selector(openHyper), - notification: .openHyper) - OpenNotifier.addObserver(observer: self, - selector: #selector(openAlacritty), - notification: .openAlacritty) - OpenNotifier.addObserver(observer: self, selector: #selector(openDefaultEditor), notification: .openDefaultEditor) - OpenNotifier.addObserver(observer: self, - selector: #selector(openVSCode), - notification: .openVSCode) - OpenNotifier.addObserver(observer: self, - selector: #selector(openAtom), - notification: .openAtom) - OpenNotifier.addObserver(observer: self, - selector: #selector(openSublime), - notification: .openSublime) - OpenNotifier.addObserver(observer: self, - selector: #selector(openVSCodium), - notification: .openVSCodium) - OpenNotifier.addObserver(observer: self, selector: #selector(copyPathToClipboard), notification: .copyPathToClipboard) @@ -146,17 +120,7 @@ extension AppDelegate { func removeObserver() { OpenNotifier.removeObserver(observer: self, notification: .openDefaultTerminal) - OpenNotifier.removeObserver(observer: self, notification: .openTerminal) - OpenNotifier.removeObserver(observer: self, notification: .openITerm) - OpenNotifier.removeObserver(observer: self, notification: .openHyper) - OpenNotifier.removeObserver(observer: self, notification: .openAlacritty) - OpenNotifier.removeObserver(observer: self, notification: .openDefaultEditor) - OpenNotifier.removeObserver(observer: self, notification: .openVSCode) - OpenNotifier.removeObserver(observer: self, notification: .openAtom) - OpenNotifier.removeObserver(observer: self, notification: .openSublime) - OpenNotifier.removeObserver(observer: self, notification: .openVSCodium) - OpenNotifier.removeObserver(observer: self, notification: .copyPathToClipboard) } @@ -170,22 +134,6 @@ extension AppDelegate { TerminalManager.shared.openTerminal(terminalType) } - @objc func openTerminal() { - TerminalManager.shared.openTerminal(.terminal) - } - - @objc func openITerm() { - TerminalManager.shared.openTerminal(.iTerm) - } - - @objc func openHyper() { - TerminalManager.shared.openTerminal(.hyper) - } - - @objc func openAlacritty() { - TerminalManager.shared.openTerminal(.alacritty) - } - @objc func openDefaultEditor() { guard let editorType = EditorManager.shared.getOrPickDefaultEditor() else { return @@ -194,22 +142,6 @@ extension AppDelegate { EditorManager.shared.openEditor(editorType) } - @objc func openVSCode() { - EditorManager.shared.openEditor(.vscode) - } - - @objc func openAtom() { - EditorManager.shared.openEditor(.atom) - } - - @objc func openSublime() { - EditorManager.shared.openEditor(.sublime) - } - - @objc func openVSCodium() { - EditorManager.shared.openEditor(.vscodium) - } - @objc func copyPathToClipboard() { do { var path = try FinderManager.shared.getFullPathToFrontFinderWindowOrSelectedFile() diff --git a/OpenInTerminal/Notifier/OpenNotifier.swift b/OpenInTerminal/Notifier/OpenNotifier.swift index 9846763..b0edcee 100644 --- a/OpenInTerminal/Notifier/OpenNotifier.swift +++ b/OpenInTerminal/Notifier/OpenNotifier.swift @@ -12,17 +12,7 @@ public class OpenNotifier: Notifier { public enum Notification: String { case openDefaultTerminal - case openTerminal - case openITerm - case openHyper - case openAlacritty - case openDefaultEditor - case openVSCode - case openAtom - case openSublime - case openVSCodium - case copyPathToClipboard } diff --git a/OpenInTerminal/en.lproj/Localizable.strings b/OpenInTerminal/en.lproj/Localizable.strings index 657f23e..2ca5587 100644 --- a/OpenInTerminal/en.lproj/Localizable.strings +++ b/OpenInTerminal/en.lproj/Localizable.strings @@ -29,4 +29,4 @@ "alert.reset_preferences_description" = "⚠️ Note that this will reset all user preferences"; "toolbar.item_name" = "Open in Terminal"; -"toolbar.item_tooltip" = "Open the current directory in the Terminal."; +"toolbar.item_tooltip" = "Open current directory in Terminal."; diff --git a/OpenInTerminalFinderExtension/FinderSync.swift b/OpenInTerminalFinderExtension/FinderSync.swift index 03ad42d..dbb383b 100644 --- a/OpenInTerminalFinderExtension/FinderSync.swift +++ b/OpenInTerminalFinderExtension/FinderSync.swift @@ -8,7 +8,6 @@ import Cocoa import FinderSync -import OpenInTerminalCore class FinderSync: FIFinderSync { @@ -34,7 +33,7 @@ class FinderSync: FIFinderSync { override var toolbarItemToolTip: String { return NSLocalizedString("toolbar.item_tooltip", - comment: "打开当前路径到终端") + comment: "Open current directory in Terminal.") } override var toolbarItemImage: NSImage { @@ -42,12 +41,12 @@ class FinderSync: FIFinderSync { } override func menu(for menuKind: FIMenuKind) -> NSMenu { - // Produce a menu for the extension. + let menu = NSMenu(title: "") switch menuKind { - case .contextualMenuForContainer, .contextualMenuForItems: + case .contextualMenuForContainer, .contextualMenuForItems, .toolbarItemMenu: let openInTerminalItem = NSMenuItem(title: NSLocalizedString("menu.open_with_default_terminal", comment: "Open with default Terminal"), @@ -70,74 +69,6 @@ class FinderSync: FIFinderSync { copyPathItem.image = NSImage(named: "context_menu_icon_path") menu.addItem(copyPathItem) - case .toolbarItemMenu: - - menu.addItem(withTitle: TerminalType.terminal.rawValue, - action: #selector(openTerminal), - keyEquivalent: "") - - if FinderManager.shared.terminalIsInstalled(.iTerm) { - menu.addItem(withTitle: TerminalType.iTerm.rawValue, - action: #selector(openITerm), - keyEquivalent: "") - } - - if FinderManager.shared.terminalIsInstalled(.hyper) { - menu.addItem(withTitle: TerminalType.hyper.rawValue, - action: #selector(openHyper), - keyEquivalent: "") - } - - if FinderManager.shared.terminalIsInstalled(.alacritty) { - menu.addItem(withTitle: TerminalType.alacritty.rawValue, - action: #selector(openAlacritty), - keyEquivalent: "") - } - - let separator = NSMenuItem.separator() - separator.title = "-----------------------" - menu.addItem(separator) - - var hasEditor = false - - if FinderManager.shared.editorIsInstalled(.vscode) { - menu.addItem(withTitle: EditorType.vscode.fullName, - action: #selector(openVSCode), - keyEquivalent: "") - hasEditor = true - } - - if FinderManager.shared.editorIsInstalled(.atom) { - menu.addItem(withTitle: EditorType.atom.fullName, - action: #selector(openAtom), - keyEquivalent: "") - hasEditor = true - } - - if FinderManager.shared.editorIsInstalled(.sublime) { - menu.addItem(withTitle: EditorType.sublime.fullName, - action: #selector(openSublime), - keyEquivalent: "") - hasEditor = true - } - - if FinderManager.shared.editorIsInstalled(.vscodium) { - menu.addItem(withTitle: EditorType.vscodium.fullName, - action: #selector(openVSCodium), - keyEquivalent: "") - hasEditor = true - } - - if hasEditor { - let separator = NSMenuItem.separator() - separator.title = "-----------------------" - menu.addItem(separator) - } - - menu.addItem(withTitle: NSLocalizedString("menu.copy_path_to_clipboard", - comment: "Copy path to Clipboard"), - action: #selector(copyPathToClipboard), - keyEquivalent: "") default: break } @@ -151,42 +82,10 @@ class FinderSync: FIFinderSync { OpenNotifier.postNotification(.openDefaultTerminal) } - @objc func openTerminal() { - OpenNotifier.postNotification(.openTerminal) - } - - @objc func openITerm() { - OpenNotifier.postNotification(.openITerm) - } - - @objc func openHyper() { - OpenNotifier.postNotification(.openHyper) - } - - @objc func openAlacritty() { - OpenNotifier.postNotification(.openAlacritty) - } - @objc func openDefaultEditor() { OpenNotifier.postNotification(.openDefaultEditor) } - @objc func openVSCode() { - OpenNotifier.postNotification(.openVSCode) - } - - @objc func openAtom() { - OpenNotifier.postNotification(.openAtom) - } - - @objc func openSublime() { - OpenNotifier.postNotification(.openSublime) - } - - @objc func openVSCodium() { - OpenNotifier.postNotification(.openVSCodium) - } - @objc func copyPathToClipboard() { OpenNotifier.postNotification(.copyPathToClipboard) }