diff --git a/VimR/AppDelegate.swift b/VimR/AppDelegate.swift index b64c607f..0e36b002 100644 --- a/VimR/AppDelegate.swift +++ b/VimR/AppDelegate.swift @@ -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 { diff --git a/VimR/AppearancePrefPane.swift b/VimR/AppearancePrefPane.swift index a22e70fa..4b343c18 100644 --- a/VimR/AppearancePrefPane.swift +++ b/VimR/AppearancePrefPane.swift @@ -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)) diff --git a/VimR/Base.lproj/MainMenu.xib b/VimR/Base.lproj/MainMenu.xib index 2179c888..3e9f2c26 100644 --- a/VimR/Base.lproj/MainMenu.xib +++ b/VimR/Base.lproj/MainMenu.xib @@ -12,11 +12,7 @@ - - - - - + @@ -31,7 +27,11 @@ - + + + + + @@ -687,26 +687,5 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/VimR/PrefWindowComponent.swift b/VimR/PrefWindowComponent.swift index 1c9c86f2..3017814d 100644 --- a/VimR/PrefWindowComponent.swift +++ b/VimR/PrefWindowComponent.swift @@ -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) } }