Skip to content

Commit

Permalink
feat(Main): support VSCodium
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji4n1ng committed May 20, 2019
1 parent 280c7d1 commit cae5102
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 10 deletions.
4 changes: 4 additions & 0 deletions OpenInTerminal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
9521EDD0226B4BE6008445D1 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9521EDCF226B4BE6008445D1 /* Constants.swift */; };
954EFA932273643C001E101E /* EditorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954EFA922273643C001E101E /* EditorProtocol.swift */; };
9571DA84227E6FFF0076AA64 /* AdvancedPreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9571DA83227E6FFF0076AA64 /* AdvancedPreferencesViewController.swift */; };
957B75DF2292358E00E35061 /* VSCodiumApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957B75DE2292358E00E35061 /* VSCodiumApp.swift */; };
9584EDF2226DEF79003C7EE8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9584EDF4226DEF79003C7EE8 /* Localizable.strings */; };
9590B68E226C04E000362B93 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9590B68D226C04E000362B93 /* Defaults.swift */; };
9590B691226C6DB000362B93 /* TerminalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9590B690226C6DB000362B93 /* TerminalType.swift */; };
Expand Down Expand Up @@ -162,6 +163,7 @@
9557D3D42274A78C00CE34FA /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
9571DA83227E6FFF0076AA64 /* AdvancedPreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedPreferencesViewController.swift; sourceTree = "<group>"; };
9571DA88227E78B00076AA64 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Preferences.strings; sourceTree = "<group>"; };
957B75DE2292358E00E35061 /* VSCodiumApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VSCodiumApp.swift; sourceTree = "<group>"; };
9584EDF3226DEF79003C7EE8 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
9584EDF5226DEFC0003C7EE8 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
9590B68D226C04E000362B93 /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -372,6 +374,7 @@
9590B696226C6E8600362B93 /* VSCodeApp.swift */,
9590B698226C6E9600362B93 /* AtomApp.swift */,
9590B69A226C6EA200362B93 /* SublimeApp.swift */,
957B75DE2292358E00E35061 /* VSCodiumApp.swift */,
);
path = Editors;
sourceTree = "<group>";
Expand Down Expand Up @@ -608,6 +611,7 @@
9590B697226C6E8600362B93 /* VSCodeApp.swift in Sources */,
950A4E692271EEC8002A9548 /* AlacrittyApp.swift in Sources */,
9590B699226C6E9600362B93 /* AtomApp.swift in Sources */,
957B75DF2292358E00E35061 /* VSCodiumApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 8 additions & 0 deletions OpenInTerminal/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ extension AppDelegate {
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),
Expand All @@ -152,6 +155,7 @@ extension AppDelegate {
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 Down Expand Up @@ -202,6 +206,10 @@ extension AppDelegate {
EditorManager.shared.openEditor(.sublime)
}

@objc func openVSCodium() {
EditorManager.shared.openEditor(.vscodium)
}

@objc func copyPathToClipboard() {
do {
var path = try FinderManager.shared.getFullPathToFrontFinderWindowOrSelectedFile()
Expand Down
1 change: 1 addition & 0 deletions OpenInTerminal/Notifier/OpenNotifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class OpenNotifier: Notifier {
case openVSCode
case openAtom
case openSublime
case openVSCodium

case copyPathToClipboard
}
Expand Down
25 changes: 18 additions & 7 deletions OpenInTerminal/PreferencesWindow/Base.lproj/Preferences.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@
<objects>
<viewController title="Toolbar" id="s5W-qL-1Xs" customClass="FinderExtensionPreferencesViewController" customModule="OpenInTerminal" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" focusRingType="none" id="jOR-Px-swx">
<rect key="frame" x="0.0" y="0.0" width="380" height="423"/>
<rect key="frame" x="0.0" y="0.0" width="380" height="439"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="pxi-dF-LO8">
<rect key="frame" x="20" y="117" width="340" height="286"/>
<rect key="frame" x="20" y="133" width="340" height="286"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="YDG-6D-DhJ">
<rect key="frame" x="-2" y="269" width="59" height="17"/>
Expand Down Expand Up @@ -474,42 +474,52 @@
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="e4W-Gy-mcj">
<rect key="frame" x="20" y="42" width="120" height="67"/>
<rect key="frame" x="20" y="33" width="120" height="92"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ATh-GK-Nb9">
<rect key="frame" x="-2" y="50" width="124" height="17"/>
<rect key="frame" x="-2" y="75" width="124" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Visual Studio Code" id="FW0-5J-5aA">
<font key="font" metaFont="systemSemibold" size="13"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JUf-uB-85A">
<rect key="frame" x="-2" y="25" width="38" height="17"/>
<rect key="frame" x="-2" y="50" width="38" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Atom" id="aXu-a5-jQP">
<font key="font" metaFont="systemSemibold" size="13"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zHm-c4-qKu">
<rect key="frame" x="-2" y="0.0" width="86" height="17"/>
<rect key="frame" x="-2" y="25" width="86" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Sublime Text" id="3Xd-Ub-1BR">
<font key="font" metaFont="systemSemibold" size="13"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="I0A-cT-SW1">
<rect key="frame" x="-2" y="0.0" width="71" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="VSCodium" id="SFC-3T-3pr">
<font key="font" metaFont="systemSemibold" size="13"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
Expand All @@ -535,11 +545,12 @@
<outlet property="terminalTextField" destination="YDG-6D-DhJ" id="dsZ-oJ-huh"/>
<outlet property="terminalWindowButton" destination="PO6-Ar-lmN" id="jr6-i6-H0M"/>
<outlet property="vscodeTextField" destination="ATh-GK-Nb9" id="ufo-fn-JoQ"/>
<outlet property="vscodiumTextField" destination="I0A-cT-SW1" id="kgP-h9-rbd"/>
</connections>
</viewController>
<customObject id="mlw-wX-Yfn" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-131.5" y="1121.5"/>
<point key="canvasLocation" x="-132" y="1129.5"/>
</scene>
<!--Advanced-->
<scene sceneID="X6j-fK-tNl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class FinderExtensionPreferencesViewController: PreferencesViewController {
@IBOutlet weak var terminalTabButton: NSButton!
@IBOutlet weak var terminalClearButton: NSButton!


@IBOutlet weak var iTermTextField: NSTextField!
@IBOutlet weak var iTermWindowButton: NSButton!
@IBOutlet weak var iTermTabButton: NSButton!
Expand All @@ -31,6 +30,7 @@ class FinderExtensionPreferencesViewController: PreferencesViewController {
@IBOutlet weak var vscodeTextField: NSTextField!
@IBOutlet weak var atomTextField: NSTextField!
@IBOutlet weak var sublimeTextField: NSTextField!
@IBOutlet weak var vscodiumTextField: NSTextField!

// MARK: Lifecycle

Expand Down Expand Up @@ -77,7 +77,8 @@ class FinderExtensionPreferencesViewController: PreferencesViewController {
let editors: [(EditorType, NSTextField)] =
[(.vscode, vscodeTextField),
(.atom, atomTextField),
(.sublime, sublimeTextField)]
(.sublime, sublimeTextField),
(.vscodium, vscodiumTextField)]

editors.forEach { editor, textField in
let isInstalled = FinderManager.shared.editorIsInstalled(editor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class GeneralPreferencesViewController: PreferencesViewController {
defaultEditorButton.addItem(withTitle: Constants.none)

let editors: [EditorType] =
[.vscode, .atom, .sublime]
[.vscode, .atom, .sublime, .vscodium]

editors.forEach { editor in
let isInstalled = FinderManager.shared.editorIsInstalled(editor)
Expand Down
1 change: 1 addition & 0 deletions OpenInTerminalCore/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Constants {
}

public enum QuickToggleType: String {

case openWithDefaultTerminal
case openWithDefaultEditor
case copyPathToClipboard
Expand Down
7 changes: 7 additions & 0 deletions OpenInTerminalCore/Editors/EditorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum EditorType: String {
case vscode = "VSCode"
case atom = "Atom"
case sublime = "Sublime"
case vscodium = "VSCodium"

public var fullName: String {
switch self {
Expand All @@ -22,6 +23,8 @@ public enum EditorType: String {
return "Atom"
case .sublime:
return "Sublime Text"
case .vscodium:
return "VSCodium"
}
}

Expand All @@ -33,6 +36,8 @@ public enum EditorType: String {
return "com.github.atom"
case .sublime:
return "com.sublimetext.3"
case .vscodium:
return "com.visualstudio.code.oss"
}
}

Expand All @@ -44,6 +49,8 @@ public enum EditorType: String {
return AtomApp()
case .sublime:
return SublimeApp()
case .vscodium:
return VSCodiumApp()
}
}
}
34 changes: 34 additions & 0 deletions OpenInTerminalCore/Editors/VSCodiumApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// VSCodiumApp.swift
// OpenInTerminalCore
//
// Created by Jianing Wang on 2019/5/20.
// Copyright © 2019 Jianing Wang. All rights reserved.
//

import Foundation

final class VSCodiumApp: Editor {

func open(_ path: String) throws {

guard let url = URL(string: path) else {
throw OITError.wrongUrl
}

let source = """
do shell script "open -a VSCodium \(url.path.editorEscaped)"
"""

let script = NSAppleScript(source: source)!

var error: NSDictionary?

script.executeAndReturnError(&error)

if error != nil {
throw OITError.cannotAccessVSCodium
}
}

}
3 changes: 3 additions & 0 deletions OpenInTerminalCore/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum OITError: Error {
case cannotAccessVSCode
case cannotAccessAtom
case cannotAccessSublime
case cannotAccessVSCodium
case wrongUrl

}
Expand All @@ -44,6 +45,8 @@ extension OITError : CustomStringConvertible {
return "Cannot access Atom, please check permissions."
case .cannotAccessSublime:
return "Cannot access Sublime, please check permissions."
case .cannotAccessVSCodium:
return "Cannot access VSCodium, please check permissions."
case .wrongUrl:
return "Oops, got a wrong url"
}
Expand Down
11 changes: 11 additions & 0 deletions OpenInTerminalFinderExtension/FinderSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class FinderSync: FIFinderSync {
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 = "-----------------------"
Expand Down Expand Up @@ -158,6 +165,10 @@ class FinderSync: FIFinderSync {
OpenNotifier.postNotification(.openSublime)
}

@objc func openVSCodium() {
OpenNotifier.postNotification(.openVSCodium)
}

@objc func copyPathToClipboard() {
OpenNotifier.postNotification(.copyPathToClipboard)
}
Expand Down

0 comments on commit cae5102

Please sign in to comment.