Skip to content

Commit

Permalink
feat(Core): Support BBEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji4n1ng committed Jul 20, 2019
1 parent 5b72c44 commit ab3a9e3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string>com.microsoft.VSCode</string>
<string>com.github.atom</string>
<string>com.sublimetext.3</string>
<string>com.barebones.bbedit</string>
</array>
</dict>
</plist>
4 changes: 4 additions & 0 deletions OpenInTerminal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
95C6C339227A9EE600F157C4 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95C6C33B227A9EE600F157C4 /* Preferences.storyboard */; };
95C6C340227AA1CB00F157C4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9584EDF4226DEF79003C7EE8 /* Localizable.strings */; };
95C6C341227AA1D000F157C4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9584EDF4226DEF79003C7EE8 /* Localizable.strings */; };
95C6F81C22E37D59001C6374 /* BBEditApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C6F81B22E37D59001C6374 /* BBEditApp.swift */; };
95F5BED5227734E800D505A0 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F5BED4227734E800D505A0 /* PreferencesWindowController.swift */; };
95FC9244228BAD6900F51DF2 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95C6C33B227A9EE600F157C4 /* Preferences.storyboard */; };
CF7258BBE507C21AABDF27E6 /* Pods_OpenInTerminal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1463FD2DA3F2CBDE5C98A8F7 /* Pods_OpenInTerminal.framework */; };
Expand Down Expand Up @@ -181,6 +182,7 @@
9590B6A0226CBC1D00362B93 /* FinderExtensionPreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderExtensionPreferencesViewController.swift; sourceTree = "<group>"; };
95BAA1812279E28D005E1DAC /* AboutPreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutPreferencesViewController.swift; sourceTree = "<group>"; };
95C6C33A227A9EE600F157C4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Preferences.storyboard; sourceTree = "<group>"; };
95C6F81B22E37D59001C6374 /* BBEditApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BBEditApp.swift; sourceTree = "<group>"; };
95F5BED4227734E800D505A0 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
95FC9243228BAAD600F51DF2 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
D0C631DF227F862E002C4AA0 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -391,6 +393,7 @@
9590B698226C6E9600362B93 /* AtomApp.swift */,
9590B69A226C6EA200362B93 /* SublimeApp.swift */,
957B75DE2292358E00E35061 /* VSCodiumApp.swift */,
95C6F81B22E37D59001C6374 /* BBEditApp.swift */,
);
path = Editors;
sourceTree = "<group>";
Expand Down Expand Up @@ -666,6 +669,7 @@
9590B68E226C04E000362B93 /* Defaults.swift in Sources */,
4725253322680EF9003C50DF /* TerminalProtocol.swift in Sources */,
9590B69B226C6EA200362B93 /* SublimeApp.swift in Sources */,
95C6F81C22E37D59001C6374 /* BBEditApp.swift in Sources */,
9590B695226C6E7400362B93 /* EditorManager.swift in Sources */,
4725254122680F5A003C50DF /* Finder.swift in Sources */,
9590B697226C6E8600362B93 /* VSCodeApp.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions OpenInTerminal/OpenInTerminal.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string>com.microsoft.VSCode</string>
<string>com.github.atom</string>
<string>com.sublimetext.3</string>
<string>com.barebones.bbedit</string>
</array>
</dict>
</plist>
27 changes: 19 additions & 8 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="426"/>
<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="143" width="340" height="260"/>
<rect key="frame" x="20" y="146" width="340" height="260"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="YDG-6D-DhJ">
<rect key="frame" x="-2" y="244" width="59" height="16"/>
Expand Down Expand Up @@ -461,52 +461,62 @@
</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="47" width="120" height="88"/>
<rect key="frame" x="20" y="26" width="120" height="112"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ATh-GK-Nb9">
<rect key="frame" x="-2" y="72" width="124" height="16"/>
<rect key="frame" x="-2" y="96" width="124" height="16"/>
<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="48" width="38" height="16"/>
<rect key="frame" x="-2" y="72" width="38" height="16"/>
<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="24" width="86" height="16"/>
<rect key="frame" x="-2" y="48" width="86" height="16"/>
<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="16"/>
<rect key="frame" x="-2" y="24" width="71" height="16"/>
<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>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="paV-cF-WMg">
<rect key="frame" x="-2" y="0.0" width="47" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="BBEdit" id="MLU-yh-FPM">
<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"/>
<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"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
</subviews>
Expand All @@ -521,6 +531,7 @@
<connections>
<outlet property="alacrittyTextField" destination="Mx4-aq-XS9" id="pqV-UT-h1a"/>
<outlet property="atomTextField" destination="JUf-uB-85A" id="Zqd-bB-NKf"/>
<outlet property="bbeditTextField" destination="paV-cF-WMg" id="N13-Uc-oCT"/>
<outlet property="hyperTextField" destination="btg-Vx-4Pl" id="ngx-02-cs4"/>
<outlet property="iTermTabButton" destination="Lmz-5e-p2j" id="Vr0-XJ-pnx"/>
<outlet property="iTermTextField" destination="wVI-dH-WOK" id="oeJ-Rq-h9e"/>
Expand All @@ -536,7 +547,7 @@
</viewController>
<customObject id="mlw-wX-Yfn" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-132" y="1121.5"/>
<point key="canvasLocation" x="-132" y="1123"/>
</scene>
<!--Advanced-->
<scene sceneID="X6j-fK-tNl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FinderExtensionPreferencesViewController: PreferencesViewController {
@IBOutlet weak var atomTextField: NSTextField!
@IBOutlet weak var sublimeTextField: NSTextField!
@IBOutlet weak var vscodiumTextField: NSTextField!
@IBOutlet weak var bbeditTextField: NSTextField!

// MARK: Lifecycle

Expand Down Expand Up @@ -77,7 +78,8 @@ class FinderExtensionPreferencesViewController: PreferencesViewController {
[(.vscode, vscodeTextField),
(.atom, atomTextField),
(.sublime, sublimeTextField),
(.vscodium, vscodiumTextField)]
(.vscodium, vscodiumTextField),
(.bbedit, bbeditTextField)]

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, .vscodium]
[.vscode, .atom, .sublime, .vscodium, .bbedit]

editors.forEach { editor in
let isInstalled = FinderManager.shared.editorIsInstalled(editor)
Expand Down
34 changes: 34 additions & 0 deletions OpenInTerminalCore/Editors/BBEditApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// BBEditApp.swift
// OpenInTerminalCore
//
// Created by Jianing Wang on 2019/7/21.
// Copyright © 2019 Jianing Wang. All rights reserved.
//

import Foundation

final class BBEditApp: Editor {

func open(_ path: String) throws {

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

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

let script = NSAppleScript(source: source)!

var error: NSDictionary?

script.executeAndReturnError(&error)

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

}
7 changes: 7 additions & 0 deletions OpenInTerminalCore/Editors/EditorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum EditorType: String {
case atom = "Atom"
case sublime = "Sublime"
case vscodium = "VSCodium"
case bbedit = "BBEdit"

public var fullName: String {
switch self {
Expand All @@ -25,6 +26,8 @@ public enum EditorType: String {
return "Sublime Text"
case .vscodium:
return "VSCodium"
case .bbedit:
return "BBEdit"
}
}

Expand All @@ -38,6 +41,8 @@ public enum EditorType: String {
return "com.sublimetext.3"
case .vscodium:
return "com.visualstudio.code.oss"
case .bbedit:
return "com.barebones.bbedit"
}
}

Expand All @@ -51,6 +56,8 @@ public enum EditorType: String {
return SublimeApp()
case .vscodium:
return VSCodiumApp()
case .bbedit:
return BBEditApp()
}
}
}
3 changes: 3 additions & 0 deletions OpenInTerminalCore/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum OITError: Error {
case cannotAccessAtom
case cannotAccessSublime
case cannotAccessVSCodium
case cannotAccessBBEdit
case wrongUrl
case cannotSetItermNewOption

Expand Down Expand Up @@ -48,6 +49,8 @@ extension OITError : CustomStringConvertible {
return "Cannot access Sublime, please check permissions."
case .cannotAccessVSCodium:
return "Cannot access VSCodium, please check permissions."
case .cannotAccessBBEdit:
return "Cannot access BBEdit, please check permissions."
case .wrongUrl:
return "Oops, got a wrong url"
case .cannotSetItermNewOption:
Expand Down

0 comments on commit ab3a9e3

Please sign in to comment.