mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
GH-213 Use NSTextField to preview editor font
This commit is contained in:
parent
f36b877fd4
commit
3b40fa1f2d
@ -23,6 +23,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
self.mainWindowManager.newMainWindow()
|
||||
}
|
||||
|
||||
@IBAction func showPrefWindow(sender: AnyObject!) {
|
||||
self.prefWindowComponent.show()
|
||||
}
|
||||
|
||||
override init() {
|
||||
self.mainWindowManager = MainWindowManager(prefWindowComponent: self.prefWindowComponent)
|
||||
super.init()
|
||||
@ -33,8 +37,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
// self.window.contentView?.addSubview(testView)
|
||||
// self.window.makeFirstResponder(testView)
|
||||
|
||||
// self.mainWindowManager.newMainWindow()
|
||||
self.prefWindowComponent.show()
|
||||
self.newDocument(self)
|
||||
}
|
||||
|
||||
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
|
||||
|
@ -28,7 +28,7 @@ class AppearancePrefPane: NSView, NSComboBoxDelegate, NSControlTextEditingDelega
|
||||
private let sizes = [9, 10, 11, 12, 13, 14, 16, 18, 24, 36, 48, 64]
|
||||
private let sizeCombo = NSComboBox(forAutoLayout: ())
|
||||
private let fontPopup = NSPopUpButton(frame: CGRect.zero, pullsDown: false)
|
||||
private let previewArea = NSTextField(forAutoLayout: ())
|
||||
private let previewArea = NSTextView(frame: CGRect.zero)
|
||||
|
||||
private var font: NSFont
|
||||
private var fontSize = CGFloat(13)
|
||||
@ -49,8 +49,6 @@ class AppearancePrefPane: NSView, NSComboBoxDelegate, NSControlTextEditingDelega
|
||||
super.init(frame: CGRect.zero)
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.wantsLayer = true
|
||||
self.layer?.backgroundColor = NSColor.yellowColor().CGColor
|
||||
self.addViews()
|
||||
}
|
||||
|
||||
@ -83,16 +81,7 @@ class AppearancePrefPane: NSView, NSComboBoxDelegate, NSControlTextEditingDelega
|
||||
sizeCombo.addItemWithObjectValue(string)
|
||||
}
|
||||
|
||||
let previewArea = self.previewArea
|
||||
previewArea.editable = false
|
||||
previewArea.bezeled = true
|
||||
previewArea.bezelStyle = .SquareBezel
|
||||
previewArea.allowsEditingTextAttributes = false
|
||||
previewArea.drawsBackground = true
|
||||
previewArea.backgroundColor = NSColor.whiteColor()
|
||||
previewArea.lineBreakMode = .ByTruncatingTail
|
||||
previewArea.font = self.font
|
||||
previewArea.stringValue =
|
||||
let exampleText =
|
||||
"abcdefghijklmnopqrstuvwxyz\n" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" +
|
||||
"0123456789\n" +
|
||||
@ -100,10 +89,29 @@ class AppearancePrefPane: NSView, NSComboBoxDelegate, NSControlTextEditingDelega
|
||||
"<- -> => >> << >>= =<< .. \n" +
|
||||
":: -< >- -<< >>- ++ /= =="
|
||||
|
||||
let previewArea = self.previewArea
|
||||
previewArea.editable = true
|
||||
previewArea.maxSize = CGSize(width: CGFloat.max, height: CGFloat.max)
|
||||
previewArea.verticallyResizable = true
|
||||
previewArea.horizontallyResizable = true
|
||||
previewArea.textContainer?.heightTracksTextView = false
|
||||
previewArea.textContainer?.widthTracksTextView = false
|
||||
previewArea.autoresizingMask = [ .ViewWidthSizable, .ViewHeightSizable]
|
||||
previewArea.textContainer?.containerSize = CGSize.init(width: CGFloat.max, height: CGFloat.max)
|
||||
previewArea.layoutManager?.replaceTextStorage(NSTextStorage(string: exampleText))
|
||||
previewArea.font = self.font
|
||||
|
||||
let previewScrollView = NSScrollView(forAutoLayout: ())
|
||||
previewScrollView.hasVerticalScroller = true
|
||||
previewScrollView.hasHorizontalScroller = true
|
||||
previewScrollView.autohidesScrollers = true
|
||||
previewScrollView.borderType = .BezelBorder
|
||||
previewScrollView.documentView = previewArea
|
||||
|
||||
self.addSubview(fontTitle)
|
||||
self.addSubview(fontPopup)
|
||||
self.addSubview(sizeCombo)
|
||||
self.addSubview(previewArea)
|
||||
self.addSubview(previewScrollView)
|
||||
|
||||
fontTitle.autoPinEdgeToSuperviewEdge(.Left, withInset: 18)
|
||||
fontTitle.autoAlignAxis(.Baseline, toSameAxisOfView: fontPopup)
|
||||
@ -115,14 +123,13 @@ class AppearancePrefPane: NSView, NSComboBoxDelegate, NSControlTextEditingDelega
|
||||
sizeCombo.autoSetDimension(.Width, toSize: 75)
|
||||
// If we use .Baseline the combo box is placed one pixel off...
|
||||
sizeCombo.autoAlignAxis(.Horizontal, toSameAxisOfView: fontPopup)
|
||||
sizeCombo.autoPinEdgeToSuperviewEdge(.Right, withInset: 18)
|
||||
sizeCombo.autoPinEdge(.Left, toEdge: .Right, ofView: fontPopup, withOffset: 5)
|
||||
|
||||
previewArea.autoSetDimension(.Height, toSize: 150)
|
||||
previewArea.autoPinEdge(.Top, toEdge: .Bottom, ofView: fontPopup, withOffset: 18)
|
||||
previewArea.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 18)
|
||||
previewArea.autoPinEdge(.Right, toEdge: .Right, ofView: sizeCombo)
|
||||
previewArea.autoPinEdgeToSuperviewEdge(.Left, withInset: 18)
|
||||
previewScrollView.autoSetDimension(.Height, toSize: 200)
|
||||
previewScrollView.autoPinEdge(.Top, toEdge: .Bottom, ofView: fontPopup, withOffset: 18)
|
||||
previewScrollView.autoPinEdgeToSuperviewEdge(.Right, withInset: 18)
|
||||
previewScrollView.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 18)
|
||||
previewScrollView.autoPinEdgeToSuperviewEdge(.Left, withInset: 18)
|
||||
|
||||
fontPopup.selectItemWithTitle(self.fontName)
|
||||
sizeCombo.stringValue = String(Int(self.fontSize))
|
||||
|
@ -12,11 +12,7 @@
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="VimR" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="VimR" customModuleProvider="target"/>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
@ -31,7 +27,11 @@
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
|
||||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
|
||||
<connections>
|
||||
<action selector="showPrefWindow:" target="-1" id="rJ8-BB-CFP"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
|
||||
<menuItem title="Services" id="NMo-om-nkz">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
@ -687,26 +687,5 @@
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<window title="VimR" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="165" height="125"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
|
||||
<view key="contentView" id="EiT-Mj-1SZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="165" height="125"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z3E-Xb-Y41">
|
||||
<rect key="frame" x="18" y="20" width="129" height="85"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Very early release of VimR with NeoVim backend
⌘-N to get started!" id="SJI-z6-rr0">
|
||||
<font key="font" metaFont="systemBold"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="-33.5" y="178.5"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
|
@ -13,6 +13,9 @@ struct PrefData {
|
||||
|
||||
class PrefWindowComponent: NSObject, NSTableViewDataSource, NSTableViewDelegate, Component {
|
||||
|
||||
private static let windowWidth = CGFloat(640)
|
||||
private static let defaultEditorFont = NSFont(name: "Menlo", size: 13)!
|
||||
|
||||
private let windowMask = NSTitledWindowMask
|
||||
| NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
|
||||
|
||||
@ -25,7 +28,7 @@ class PrefWindowComponent: NSObject, NSTableViewDataSource, NSTableViewDelegate,
|
||||
}
|
||||
|
||||
private var data = PrefData(
|
||||
appearance: AppearancePrefData(editorFont: NSFont(name: "Menlo", size: 13)!)
|
||||
appearance: AppearancePrefData(editorFont: PrefWindowComponent.defaultEditorFont)
|
||||
)
|
||||
|
||||
private let window: NSWindow
|
||||
@ -45,11 +48,13 @@ class PrefWindowComponent: NSObject, NSTableViewDataSource, NSTableViewDelegate,
|
||||
]
|
||||
|
||||
self.window = NSWindow(
|
||||
contentRect: CGRect(x: 100, y: 100, width: 640, height: 480),
|
||||
contentRect: CGRect(x: 100, y: 100, width: PrefWindowComponent.windowWidth, height: 300),
|
||||
styleMask: self.windowMask,
|
||||
backing: .Buffered,
|
||||
defer: true
|
||||
)
|
||||
let window = self.window
|
||||
window.minSize = CGSize(width: PrefWindowComponent.windowWidth, height: 240)
|
||||
window.title = "Preferences"
|
||||
window.releasedWhenClosed = false
|
||||
window.center()
|
||||
@ -119,12 +124,11 @@ class PrefWindowComponent: NSObject, NSTableViewDataSource, NSTableViewDelegate,
|
||||
|
||||
let paneScrollView = self.paneScrollView
|
||||
paneScrollView.hasVerticalScroller = true;
|
||||
paneScrollView.hasHorizontalScroller = true;
|
||||
paneScrollView.borderType = .NoBorder;
|
||||
paneScrollView.hasHorizontalScroller = false;
|
||||
paneScrollView.autohidesScrollers = true;
|
||||
paneScrollView.borderType = .NoBorder;
|
||||
paneScrollView.autoresizesSubviews = true;
|
||||
paneScrollView.backgroundColor = NSColor.windowBackgroundColor();
|
||||
paneScrollView.autohidesScrollers = true;
|
||||
|
||||
self.window.contentView?.addSubview(categoryScrollView)
|
||||
self.window.contentView?.addSubview(paneScrollView)
|
||||
@ -139,7 +143,10 @@ class PrefWindowComponent: NSObject, NSTableViewDataSource, NSTableViewDelegate,
|
||||
paneScrollView.autoPinEdgeToSuperviewEdge(.Bottom)
|
||||
paneScrollView.autoPinEdge(.Left, toEdge: .Right, ofView: categoryScrollView)
|
||||
|
||||
self.paneScrollView.documentView = self.panes[0].view
|
||||
let pane = self.panes[0].view
|
||||
self.paneScrollView.documentView = pane
|
||||
pane.autoPinEdgeToSuperviewEdge(.Right)
|
||||
pane.autoPinEdgeToSuperviewEdge(.Left)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user