-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FranzCocoa,Editor: add JumptoLine support
- Loading branch information
Showing
6 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Cocoa | ||
|
||
class JumpToLineWindowController: NSWindowController { | ||
@IBOutlet weak var textField: NSTextField! | ||
|
||
weak var delegate: JumpToLineWindowDelegate? | ||
|
||
private let numberFormatter = { | ||
let formatter = NumberFormatter() | ||
formatter.allowsFloats = false | ||
formatter.numberStyle = .none | ||
return formatter | ||
}() | ||
|
||
convenience init() { | ||
self.init(windowNibName: "JumpToLineWindowController") | ||
} | ||
|
||
override func windowDidLoad() { | ||
super.windowDidLoad() | ||
|
||
textField.delegate = self | ||
textField.focusRingType = .none | ||
textField.formatter = numberFormatter | ||
|
||
window?.delegate = self | ||
window?.center() | ||
} | ||
} | ||
|
||
// MARK: - JumpToLineWindowDelegate | ||
protocol JumpToLineWindowDelegate: AnyObject { | ||
func willJumpToLine(_ line: Int) -> Bool | ||
} | ||
|
||
// MARK: - NSTextFieldDelegate | ||
extension JumpToLineWindowController: NSTextFieldDelegate { | ||
func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { | ||
if commandSelector == #selector(cancelOperation(_:)) { | ||
WindowManager.shared.closeJumpToLineWindow() | ||
return true | ||
} else if commandSelector == #selector(insertNewline(_:)) { | ||
guard let delegate else { return false } | ||
if delegate.willJumpToLine(textField.integerValue) { | ||
WindowManager.shared.closeJumpToLineWindow() | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
|
||
// MARK: - NSWindowDelegate | ||
extension JumpToLineWindowController: NSWindowDelegate { | ||
func windowDidResignKey(_ notification: Notification) { | ||
WindowManager.shared.closeJumpToLineWindow() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> | ||
<dependencies> | ||
<deployment identifier="macosx"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="JumpToLineWindowController" customModule="Franz" customModuleProvider="target"> | ||
<connections> | ||
<outlet property="textField" destination="11n-sU-VX3" id="cSc-UC-oyi"/> | ||
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="F0z-JX-Cv5"> | ||
<windowStyleMask key="styleMask" titled="YES" fullSizeContentView="YES"/> | ||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> | ||
<rect key="contentRect" x="196" y="240" width="480" height="48"/> | ||
<rect key="screenRect" x="0.0" y="0.0" width="1728" height="1079"/> | ||
<view key="contentView" id="se5-gp-TjO"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="48"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="11n-sU-VX3"> | ||
<rect key="frame" x="18" y="10" width="444" height="28"/> | ||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" placeholderString="Line Number" id="5J9-hs-OD2"> | ||
<font key="font" metaFont="system" size="24"/> | ||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> | ||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> | ||
</textFieldCell> | ||
</textField> | ||
</subviews> | ||
<constraints> | ||
<constraint firstItem="11n-sU-VX3" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="10" id="8kH-9b-F7O"/> | ||
<constraint firstItem="11n-sU-VX3" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" symbolic="YES" id="EdY-s0-Ug9"/> | ||
<constraint firstAttribute="bottom" secondItem="11n-sU-VX3" secondAttribute="bottom" constant="10" id="Ody-CH-shg"/> | ||
<constraint firstAttribute="trailing" secondItem="11n-sU-VX3" secondAttribute="trailing" constant="20" symbolic="YES" id="TIT-Er-Pnz"/> | ||
</constraints> | ||
</view> | ||
<connections> | ||
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/> | ||
</connections> | ||
<point key="canvasLocation" x="65" y="14"/> | ||
</window> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters