From 1bc1764d92b0e522c2adc24936ec0000a3f8a7a5 Mon Sep 17 00:00:00 2001 From: Jianing Wang Date: Sun, 24 May 2020 12:33:49 +0800 Subject: [PATCH] feat(core): support JetBrains apps --- OpenInTerminal.xcodeproj/project.pbxproj | 82 +++++++++++++++---- OpenInTerminal/Constants.swift | 2 +- .../Editors/{ => EditorApps}/AtomApp.swift | 0 .../Editors/{ => EditorApps}/BBEditApp.swift | 0 .../{ => EditorApps}/CotEditorApp.swift | 0 .../EditorApps/JetBrains/AppCodeApp.swift | 34 ++++++++ .../EditorApps/JetBrains/CLionApp.swift | 34 ++++++++ .../EditorApps/JetBrains/GoLandApp.swift | 34 ++++++++ .../JetBrains/InterlliJIDEAApp.swift | 34 ++++++++ .../JetBrains}/PhpStormApp.swift | 2 +- .../EditorApps/JetBrains/PyCharmApp.swift | 34 ++++++++ .../EditorApps/JetBrains/RubyMineApp.swift | 34 ++++++++ .../EditorApps/JetBrains/WebStormApp.swift | 34 ++++++++ .../Editors/{ => EditorApps}/MacVimApp.swift | 0 .../Editors/{ => EditorApps}/SublimeApp.swift | 0 .../{ => EditorApps}/TextEditApp.swift | 0 .../{ => EditorApps}/TextMateApp.swift | 0 .../Editors/{ => EditorApps}/VSCodeApp.swift | 0 .../{ => EditorApps}/VSCodeInsidersApp.swift | 0 .../{ => EditorApps}/VSCodiumApp.swift | 0 .../Editors/EditorManager.swift | 1 + OpenInTerminalCore/Editors/EditorType.swift | 73 ++++++++++++++++- OpenInTerminalCore/FinderManager.swift | 2 +- .../{ => TerminalApps}/AlacrittyApp.swift | 0 .../{ => TerminalApps}/HyperApp.swift | 0 .../{ => TerminalApps}/TerminalApp.swift | 0 .../{ => TerminalApps}/iTermApp.swift | 0 27 files changed, 381 insertions(+), 19 deletions(-) rename OpenInTerminalCore/Editors/{ => EditorApps}/AtomApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/BBEditApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/CotEditorApp.swift (100%) create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/AppCodeApp.swift create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/CLionApp.swift create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/GoLandApp.swift create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/InterlliJIDEAApp.swift rename OpenInTerminalCore/Editors/{ => EditorApps/JetBrains}/PhpStormApp.swift (90%) create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/PyCharmApp.swift create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/RubyMineApp.swift create mode 100644 OpenInTerminalCore/Editors/EditorApps/JetBrains/WebStormApp.swift rename OpenInTerminalCore/Editors/{ => EditorApps}/MacVimApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/SublimeApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/TextEditApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/TextMateApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/VSCodeApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/VSCodeInsidersApp.swift (100%) rename OpenInTerminalCore/Editors/{ => EditorApps}/VSCodiumApp.swift (100%) rename OpenInTerminalCore/Terminals/{ => TerminalApps}/AlacrittyApp.swift (100%) rename OpenInTerminalCore/Terminals/{ => TerminalApps}/HyperApp.swift (100%) rename OpenInTerminalCore/Terminals/{ => TerminalApps}/TerminalApp.swift (100%) rename OpenInTerminalCore/Terminals/{ => TerminalApps}/iTermApp.swift (100%) diff --git a/OpenInTerminal.xcodeproj/project.pbxproj b/OpenInTerminal.xcodeproj/project.pbxproj index 2256dd6..55c4ea9 100644 --- a/OpenInTerminal.xcodeproj/project.pbxproj +++ b/OpenInTerminal.xcodeproj/project.pbxproj @@ -27,6 +27,13 @@ 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, ); }; }; 95030E6E24797B9B0071A985 /* TextEditApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E6D24797B9B0071A985 /* TextEditApp.swift */; }; + 95030E72247A1F3B0071A985 /* PyCharmApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E71247A1F3B0071A985 /* PyCharmApp.swift */; }; + 95030E75247A21570071A985 /* CLionApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E74247A21570071A985 /* CLionApp.swift */; }; + 95030E77247A29860071A985 /* AppCodeApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E76247A29860071A985 /* AppCodeApp.swift */; }; + 95030E79247A2A190071A985 /* GoLandApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E78247A2A190071A985 /* GoLandApp.swift */; }; + 95030E7B247A2A7D0071A985 /* InterlliJIDEAApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E7A247A2A7D0071A985 /* InterlliJIDEAApp.swift */; }; + 95030E7D247A2B2A0071A985 /* RubyMineApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E7C247A2B2A0071A985 /* RubyMineApp.swift */; }; + 95030E80247A2B700071A985 /* WebStormApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95030E7F247A2B700071A985 /* WebStormApp.swift */; }; 950A4E692271EEC8002A9548 /* AlacrittyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A4E682271EEC8002A9548 /* AlacrittyApp.swift */; }; 9511D8AC22749582008E52B9 /* LaunchNotifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9511D8AB22749582008E52B9 /* LaunchNotifier.swift */; }; 95163CD22269979E007C006F /* Notifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95163CD12269979E007C006F /* Notifier.swift */; }; @@ -177,6 +184,13 @@ 4725257F2268112F003C50DF /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7BE6A353376D4C2E8A800E17 /* Pods-OpenInTerminal.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OpenInTerminal.debug.xcconfig"; path = "Target Support Files/Pods-OpenInTerminal/Pods-OpenInTerminal.debug.xcconfig"; sourceTree = ""; }; 95030E6D24797B9B0071A985 /* TextEditApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEditApp.swift; sourceTree = ""; }; + 95030E71247A1F3B0071A985 /* PyCharmApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PyCharmApp.swift; sourceTree = ""; }; + 95030E74247A21570071A985 /* CLionApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLionApp.swift; sourceTree = ""; }; + 95030E76247A29860071A985 /* AppCodeApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCodeApp.swift; sourceTree = ""; }; + 95030E78247A2A190071A985 /* GoLandApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoLandApp.swift; sourceTree = ""; }; + 95030E7A247A2A7D0071A985 /* InterlliJIDEAApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterlliJIDEAApp.swift; sourceTree = ""; }; + 95030E7C247A2B2A0071A985 /* RubyMineApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RubyMineApp.swift; sourceTree = ""; }; + 95030E7F247A2B700071A985 /* WebStormApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebStormApp.swift; sourceTree = ""; }; 950A4E682271EEC8002A9548 /* AlacrittyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlacrittyApp.swift; sourceTree = ""; }; 9511D8AB22749582008E52B9 /* LaunchNotifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchNotifier.swift; sourceTree = ""; }; 95163CD12269979E007C006F /* Notifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifier.swift; sourceTree = ""; }; @@ -314,10 +328,7 @@ 4725253222680EF8003C50DF /* TerminalProtocol.swift */, 9590B690226C6DB000362B93 /* TerminalType.swift */, 4725252E22680EE0003C50DF /* TerminalManager.swift */, - 4725253822680F4B003C50DF /* TerminalApp.swift */, - 4725253A22680F4B003C50DF /* iTermApp.swift */, - 4725253922680F4B003C50DF /* HyperApp.swift */, - 950A4E682271EEC8002A9548 /* AlacrittyApp.swift */, + 95030E70247A1CB20071A985 /* TerminalApps */, ); path = Terminals; sourceTree = ""; @@ -358,6 +369,50 @@ name = Frameworks; sourceTree = ""; }; + 95030E6F247A1C9E0071A985 /* EditorApps */ = { + isa = PBXGroup; + children = ( + 95030E6D24797B9B0071A985 /* TextEditApp.swift */, + 9590B696226C6E8600362B93 /* VSCodeApp.swift */, + 9590B698226C6E9600362B93 /* AtomApp.swift */, + 9590B69A226C6EA200362B93 /* SublimeApp.swift */, + 957B75DE2292358E00E35061 /* VSCodiumApp.swift */, + 95C6F81B22E37D59001C6374 /* BBEditApp.swift */, + 95E7170B22F1370F000E331A /* VSCodeInsidersApp.swift */, + 956BCE0F22F80D6C00310B56 /* TextMateApp.swift */, + 9595D29F23BA0E7F006CBB36 /* CotEditorApp.swift */, + 951FC31223C611E600A51B50 /* MacVimApp.swift */, + 95030E73247A21240071A985 /* JetBrains */, + ); + path = EditorApps; + sourceTree = ""; + }; + 95030E70247A1CB20071A985 /* TerminalApps */ = { + isa = PBXGroup; + children = ( + 4725253822680F4B003C50DF /* TerminalApp.swift */, + 4725253A22680F4B003C50DF /* iTermApp.swift */, + 4725253922680F4B003C50DF /* HyperApp.swift */, + 950A4E682271EEC8002A9548 /* AlacrittyApp.swift */, + ); + path = TerminalApps; + sourceTree = ""; + }; + 95030E73247A21240071A985 /* JetBrains */ = { + isa = PBXGroup; + children = ( + 95030E76247A29860071A985 /* AppCodeApp.swift */, + 95030E74247A21570071A985 /* CLionApp.swift */, + 95030E78247A2A190071A985 /* GoLandApp.swift */, + 95030E7A247A2A7D0071A985 /* InterlliJIDEAApp.swift */, + 95DD629B243B4420003550B3 /* PhpStormApp.swift */, + 95030E71247A1F3B0071A985 /* PyCharmApp.swift */, + 95030E7C247A2B2A0071A985 /* RubyMineApp.swift */, + 95030E7F247A2B700071A985 /* WebStormApp.swift */, + ); + path = JetBrains; + sourceTree = ""; + }; 9511D8AA22748FD6008E52B9 /* Assets */ = { isa = PBXGroup; children = ( @@ -436,17 +491,7 @@ 954EFA922273643C001E101E /* EditorProtocol.swift */, 9590B692226C6DE900362B93 /* EditorType.swift */, 9590B694226C6E7400362B93 /* EditorManager.swift */, - 95030E6D24797B9B0071A985 /* TextEditApp.swift */, - 9590B696226C6E8600362B93 /* VSCodeApp.swift */, - 9590B698226C6E9600362B93 /* AtomApp.swift */, - 9590B69A226C6EA200362B93 /* SublimeApp.swift */, - 957B75DE2292358E00E35061 /* VSCodiumApp.swift */, - 95C6F81B22E37D59001C6374 /* BBEditApp.swift */, - 95E7170B22F1370F000E331A /* VSCodeInsidersApp.swift */, - 956BCE0F22F80D6C00310B56 /* TextMateApp.swift */, - 9595D29F23BA0E7F006CBB36 /* CotEditorApp.swift */, - 951FC31223C611E600A51B50 /* MacVimApp.swift */, - 95DD629B243B4420003550B3 /* PhpStormApp.swift */, + 95030E6F247A1C9E0071A985 /* EditorApps */, ); path = Editors; sourceTree = ""; @@ -727,10 +772,13 @@ 95E7170C22F1370F000E331A /* VSCodeInsidersApp.swift in Sources */, 4725254422680F7C003C50DF /* Log.swift in Sources */, 4725254522680F7C003C50DF /* Error.swift in Sources */, + 95030E75247A21570071A985 /* CLionApp.swift in Sources */, 4725253D22680F4B003C50DF /* iTermApp.swift in Sources */, 4725253522680EFD003C50DF /* FinderManager.swift in Sources */, + 95030E80247A2B700071A985 /* WebStormApp.swift in Sources */, 9590B691226C6DB000362B93 /* TerminalType.swift in Sources */, 95030E6E24797B9B0071A985 /* TextEditApp.swift in Sources */, + 95030E7B247A2A7D0071A985 /* InterlliJIDEAApp.swift in Sources */, 4725253122680EF3003C50DF /* Constants.swift in Sources */, 4725254022680F5A003C50DF /* Terminal.swift in Sources */, 4725253C22680F4B003C50DF /* HyperApp.swift in Sources */, @@ -741,13 +789,17 @@ 4725253322680EF9003C50DF /* TerminalProtocol.swift in Sources */, 9590B69B226C6EA200362B93 /* SublimeApp.swift in Sources */, 95C6F81C22E37D59001C6374 /* BBEditApp.swift in Sources */, + 95030E7D247A2B2A0071A985 /* RubyMineApp.swift in Sources */, 95DFC1242354A2C300941D3A /* DefaultsManager.swift in Sources */, + 95030E79247A2A190071A985 /* GoLandApp.swift in Sources */, 9590B695226C6E7400362B93 /* EditorManager.swift in Sources */, 4725254122680F5A003C50DF /* Finder.swift in Sources */, 9590B697226C6E8600362B93 /* VSCodeApp.swift in Sources */, 951FC31323C611E600A51B50 /* MacVimApp.swift in Sources */, + 95030E72247A1F3B0071A985 /* PyCharmApp.swift in Sources */, 950A4E692271EEC8002A9548 /* AlacrittyApp.swift in Sources */, 9590B699226C6E9600362B93 /* AtomApp.swift in Sources */, + 95030E77247A29860071A985 /* AppCodeApp.swift in Sources */, 957B75DF2292358E00E35061 /* VSCodiumApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/OpenInTerminal/Constants.swift b/OpenInTerminal/Constants.swift index 136d0b7..0910cb1 100644 --- a/OpenInTerminal/Constants.swift +++ b/OpenInTerminal/Constants.swift @@ -29,7 +29,7 @@ struct Constants { /// .terminal, .iTerm, .hyper, .alacritty static let allTerminals: [TerminalType] = [.terminal, .iTerm, .hyper, .alacritty] /// .vscode, .atom, .sublime, .vscodium, .bbedit, .vscodeInsiders, .textMate, .cotEditor, .macVim, .phpStorm - static let allEditors: [EditorType] = [.vscode, .atom, .sublime, .vscodium, .bbedit, .vscodeInsiders, .textMate, .cotEditor, .macVim, .phpStorm] + static let allEditors: [EditorType] = [.textEdit, .vscode, .atom, .sublime, .vscodium, .bbedit, .vscodeInsiders, .textMate, .cotEditor, .macVim, .appCode, .cLion, .goLand, .intelliJIDEA, .phpStorm, .pyCharm, .rubyMine, .webStorm] } extension NSImage { diff --git a/OpenInTerminalCore/Editors/AtomApp.swift b/OpenInTerminalCore/Editors/EditorApps/AtomApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/AtomApp.swift rename to OpenInTerminalCore/Editors/EditorApps/AtomApp.swift diff --git a/OpenInTerminalCore/Editors/BBEditApp.swift b/OpenInTerminalCore/Editors/EditorApps/BBEditApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/BBEditApp.swift rename to OpenInTerminalCore/Editors/EditorApps/BBEditApp.swift diff --git a/OpenInTerminalCore/Editors/CotEditorApp.swift b/OpenInTerminalCore/Editors/EditorApps/CotEditorApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/CotEditorApp.swift rename to OpenInTerminalCore/Editors/EditorApps/CotEditorApp.swift diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/AppCodeApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/AppCodeApp.swift new file mode 100644 index 0000000..8e748d4 --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/AppCodeApp.swift @@ -0,0 +1,34 @@ +// +// AppCodeApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class AppCodeApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a AppCode \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.appCode.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/CLionApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/CLionApp.swift new file mode 100644 index 0000000..42e1134 --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/CLionApp.swift @@ -0,0 +1,34 @@ +// +// CLionApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class CLionApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a CLion \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.cLion.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/GoLandApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/GoLandApp.swift new file mode 100644 index 0000000..703aa2c --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/GoLandApp.swift @@ -0,0 +1,34 @@ +// +// GoLandApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class GoLandApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a GoLand \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.goLand.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/InterlliJIDEAApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/InterlliJIDEAApp.swift new file mode 100644 index 0000000..a5b9d8a --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/InterlliJIDEAApp.swift @@ -0,0 +1,34 @@ +// +// InterlliJIDEAApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class InterlliJIDEAApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a InterlliJ\\\\ IDEA \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.intelliJIDEA.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/PhpStormApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/PhpStormApp.swift similarity index 90% rename from OpenInTerminalCore/Editors/PhpStormApp.swift rename to OpenInTerminalCore/Editors/EditorApps/JetBrains/PhpStormApp.swift index 28b4f14..b27316b 100644 --- a/OpenInTerminalCore/Editors/PhpStormApp.swift +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/PhpStormApp.swift @@ -27,7 +27,7 @@ final class PhpStormApp: Editor { script.executeAndReturnError(&error) if error != nil { - throw OITError.cannotAccessApp(EditorType.macVim.rawValue) + throw OITError.cannotAccessApp(EditorType.phpStorm.rawValue) } } diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/PyCharmApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/PyCharmApp.swift new file mode 100644 index 0000000..40ca6df --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/PyCharmApp.swift @@ -0,0 +1,34 @@ +// +// PyCharmApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class PyCharmApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a PyCharm \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.pyCharm.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/RubyMineApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/RubyMineApp.swift new file mode 100644 index 0000000..ee45160 --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/RubyMineApp.swift @@ -0,0 +1,34 @@ +// +// RubyMineApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class RubyMineApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a RubyMine \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.rubyMine.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/EditorApps/JetBrains/WebStormApp.swift b/OpenInTerminalCore/Editors/EditorApps/JetBrains/WebStormApp.swift new file mode 100644 index 0000000..89a06d6 --- /dev/null +++ b/OpenInTerminalCore/Editors/EditorApps/JetBrains/WebStormApp.swift @@ -0,0 +1,34 @@ +// +// WebStormApp.swift +// OpenInTerminalCore +// +// Created by Jianing Wang on 2020/5/24. +// Copyright © 2020 Jianing Wang. All rights reserved. +// + +import Foundation + +final class WebStormApp: Editor { + + func open(_ path: String) throws { + + guard let url = URL(string: path) else { + throw OITError.wrongUrl + } + + let source = """ + do shell script "open -a WebStorm \(url.path.specialCharEscaped)" + """ + + let script = NSAppleScript(source: source)! + + var error: NSDictionary? + + script.executeAndReturnError(&error) + + if error != nil { + throw OITError.cannotAccessApp(EditorType.webStorm.rawValue) + } + } + +} diff --git a/OpenInTerminalCore/Editors/MacVimApp.swift b/OpenInTerminalCore/Editors/EditorApps/MacVimApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/MacVimApp.swift rename to OpenInTerminalCore/Editors/EditorApps/MacVimApp.swift diff --git a/OpenInTerminalCore/Editors/SublimeApp.swift b/OpenInTerminalCore/Editors/EditorApps/SublimeApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/SublimeApp.swift rename to OpenInTerminalCore/Editors/EditorApps/SublimeApp.swift diff --git a/OpenInTerminalCore/Editors/TextEditApp.swift b/OpenInTerminalCore/Editors/EditorApps/TextEditApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/TextEditApp.swift rename to OpenInTerminalCore/Editors/EditorApps/TextEditApp.swift diff --git a/OpenInTerminalCore/Editors/TextMateApp.swift b/OpenInTerminalCore/Editors/EditorApps/TextMateApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/TextMateApp.swift rename to OpenInTerminalCore/Editors/EditorApps/TextMateApp.swift diff --git a/OpenInTerminalCore/Editors/VSCodeApp.swift b/OpenInTerminalCore/Editors/EditorApps/VSCodeApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/VSCodeApp.swift rename to OpenInTerminalCore/Editors/EditorApps/VSCodeApp.swift diff --git a/OpenInTerminalCore/Editors/VSCodeInsidersApp.swift b/OpenInTerminalCore/Editors/EditorApps/VSCodeInsidersApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/VSCodeInsidersApp.swift rename to OpenInTerminalCore/Editors/EditorApps/VSCodeInsidersApp.swift diff --git a/OpenInTerminalCore/Editors/VSCodiumApp.swift b/OpenInTerminalCore/Editors/EditorApps/VSCodiumApp.swift similarity index 100% rename from OpenInTerminalCore/Editors/VSCodiumApp.swift rename to OpenInTerminalCore/Editors/EditorApps/VSCodiumApp.swift diff --git a/OpenInTerminalCore/Editors/EditorManager.swift b/OpenInTerminalCore/Editors/EditorManager.swift index dd2386f..c96a965 100644 --- a/OpenInTerminalCore/Editors/EditorManager.swift +++ b/OpenInTerminalCore/Editors/EditorManager.swift @@ -47,6 +47,7 @@ public class EditorManager { alert.addButton(withTitle: EditorType.atom.rawValue).refusesFirstResponder = true alert.addButton(withTitle: EditorType.vscode.rawValue).refusesFirstResponder = true + let modalResult = alert.runModal() switch modalResult { diff --git a/OpenInTerminalCore/Editors/EditorType.swift b/OpenInTerminalCore/Editors/EditorType.swift index b3738e7..d4f64c7 100644 --- a/OpenInTerminalCore/Editors/EditorType.swift +++ b/OpenInTerminalCore/Editors/EditorType.swift @@ -20,7 +20,16 @@ public enum EditorType: String { case textMate = "TextMate" case cotEditor = "CotEditor" case macVim = "MacVim" + + // JetBrains + case appCode = "AppCode" + case cLion = "CLion" + case goLand = "GoLand" + case intelliJIDEA = "IntelliJ_IDEA" case phpStorm = "PhpStorm" + case pyCharm = "PyCharm" + case rubyMine = "RubyMine" + case webStorm = "WebStorm" public var fullName: String { switch self { @@ -44,8 +53,23 @@ public enum EditorType: String { return "CotEditor" case .macVim: return "MacVim" + + case .appCode: + return "AppCode" + case .cLion: + return "CLion" + case .goLand: + return "GoLand" + case .intelliJIDEA: + return "IntelliJ IDEA" case .phpStorm: return "PhpStorm" + case .pyCharm: + return "PyCharm" + case .rubyMine: + return "RubyMine" + case .webStorm: + return "WebStorm" } } @@ -71,8 +95,23 @@ public enum EditorType: String { return "" case .macVim: return "" + + case .appCode: + return "com.jetbrains.appcode" + case .cLion: + return "com.jetbrains.clion" + case .goLand: + return "com.jetbrains.goland" + case .intelliJIDEA: + return "com.jetbrains.intellij" case .phpStorm: - return "" + return "com.jetbrains.PhpStorm" + case .pyCharm: + return "com.jetbrains.pycharm" + case .rubyMine: + return "com.jetbrains.rubymine" + case .webStorm: + return "com.jetbrains.webstorm" } } @@ -98,8 +137,23 @@ public enum EditorType: String { return CotEditorApp() case .macVim: return MacVimApp() + + case .appCode: + return AppCodeApp() + case .cLion: + return CLionApp() + case .goLand: + return GoLandApp() + case .intelliJIDEA: + return InterlliJIDEAApp() case .phpStorm: return PhpStormApp() + case .pyCharm: + return PyCharmApp() + case .rubyMine: + return RubyMineApp() + case .webStorm: + return WebStormApp() } } } @@ -108,6 +162,8 @@ public extension EditorType { init?(by fullName: String) { switch fullName { + case "TextEdit": + self = .textEdit case "Visual Studio Code": self = .vscode case "Atom": @@ -126,8 +182,23 @@ public extension EditorType { self = .cotEditor case "MacVim": self = .macVim + + case "AppCode": + self = .appCode + case "CLion": + self = .cLion + case "GoLand": + self = .goLand + case "IntelliJ IDEA": + self = .intelliJIDEA case "PhpStorm": self = .phpStorm + case "PyCharm": + self = .pyCharm + case "RubyMine": + self = .rubyMine + case "WebStorm": + self = .webStorm default: return nil } diff --git a/OpenInTerminalCore/FinderManager.swift b/OpenInTerminalCore/FinderManager.swift index b72c0e1..33b8c93 100644 --- a/OpenInTerminalCore/FinderManager.swift +++ b/OpenInTerminalCore/FinderManager.swift @@ -141,7 +141,7 @@ public class FinderManager { while !searchDirs.isEmpty { // to avoid an infinite loop levelCount += 1 - if levelCount > 15 { + if levelCount > 20 { break } diff --git a/OpenInTerminalCore/Terminals/AlacrittyApp.swift b/OpenInTerminalCore/Terminals/TerminalApps/AlacrittyApp.swift similarity index 100% rename from OpenInTerminalCore/Terminals/AlacrittyApp.swift rename to OpenInTerminalCore/Terminals/TerminalApps/AlacrittyApp.swift diff --git a/OpenInTerminalCore/Terminals/HyperApp.swift b/OpenInTerminalCore/Terminals/TerminalApps/HyperApp.swift similarity index 100% rename from OpenInTerminalCore/Terminals/HyperApp.swift rename to OpenInTerminalCore/Terminals/TerminalApps/HyperApp.swift diff --git a/OpenInTerminalCore/Terminals/TerminalApp.swift b/OpenInTerminalCore/Terminals/TerminalApps/TerminalApp.swift similarity index 100% rename from OpenInTerminalCore/Terminals/TerminalApp.swift rename to OpenInTerminalCore/Terminals/TerminalApps/TerminalApp.swift diff --git a/OpenInTerminalCore/Terminals/iTermApp.swift b/OpenInTerminalCore/Terminals/TerminalApps/iTermApp.swift similarity index 100% rename from OpenInTerminalCore/Terminals/iTermApp.swift rename to OpenInTerminalCore/Terminals/TerminalApps/iTermApp.swift