Skip to content

Commit

Permalink
fix(Main): FinderSync Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji4n1ng committed Jul 21, 2019
1 parent 2bd4301 commit f5ce7fa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 187 deletions.
6 changes: 2 additions & 4 deletions OpenInTerminal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -203,7 +202,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4725259022681424003C50DF /* OpenInTerminalCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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 = "";
Expand Down
68 changes: 0 additions & 68 deletions OpenInTerminal/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,53 +110,17 @@ 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)
}

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)
}

Expand All @@ -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
Expand All @@ -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()
Expand Down
10 changes: 0 additions & 10 deletions OpenInTerminal/Notifier/OpenNotifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion OpenInTerminal/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
107 changes: 3 additions & 104 deletions OpenInTerminalFinderExtension/FinderSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Cocoa
import FinderSync
import OpenInTerminalCore

class FinderSync: FIFinderSync {

Expand All @@ -34,20 +33,20 @@ class FinderSync: FIFinderSync {

override var toolbarItemToolTip: String {
return NSLocalizedString("toolbar.item_tooltip",
comment: "打开当前路径到终端")
comment: "Open current directory in Terminal.")
}

override var toolbarItemImage: NSImage {
return NSImage(named: "Icon")!
}

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"),
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down

0 comments on commit f5ce7fa

Please sign in to comment.