Skip to content

Commit

Permalink
Merge pull request #17 from dado3212/Auto-highlight
Browse files Browse the repository at this point in the history
v1.4.1 - Add in listener for enter key
  • Loading branch information
dado3212 authored Apr 30, 2018
2 parents 7e37a2c + 3657bc2 commit 21e059e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions SpacesRenamer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
hiddenPopover.close()

nameChangeWindow.makeKeyAndOrderFront(nil)
nameChangeWindow.selectCurrent()
NSApp.activate(ignoringOtherApps: true)
}
}
Expand Down
1 change: 1 addition & 0 deletions SpacesRenamer/DesktopSnippet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DesktopSnippet: NSView {
@IBOutlet var label: NSTextField!
@IBOutlet var textField: NSTextField!
@IBOutlet var monitorImage: NSImageView!
var isCurrent: Bool = false

class func instanceFromNib() -> DesktopSnippet {
var topLevelObjects : NSArray?
Expand Down
2 changes: 1 addition & 1 deletion SpacesRenamer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>1.4.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down
8 changes: 8 additions & 0 deletions SpacesRenamer/NameChangeWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class NameChangeWindow: NSWindow {
super.keyDown(with: event)
}

func selectCurrent() {
DispatchQueue.main.async {
if let viewController = self.contentViewController as? ViewController {
viewController.selectCurrent()
}
}
}

func refresh() {
DispatchQueue.main.async {
if let appDelegate = NSApplication.shared.delegate as? AppDelegate, let button = appDelegate.statusItem.button {
Expand Down
22 changes: 21 additions & 1 deletion SpacesRenamer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class ViewController: NSViewController {

let snippet = DesktopSnippet.instanceFromNib()
if (uuid == currentSpace) {
snippet.monitorImage.image = NSImage(named: NSImage.Name("MonitorSelected") )
snippet.monitorImage.image = NSImage(named: NSImage.Name("MonitorSelected"))
snippet.isCurrent = true
}

snippet.label.stringValue = "\(i)"
Expand Down Expand Up @@ -141,6 +142,17 @@ class ViewController: NSViewController {
textField.stringValue = newName as! String
}
}

selectCurrent()
}

func selectCurrent() {
for snippet in snippets {
if snippet.isCurrent {
snippet.textField.becomeFirstResponder()
break
}
}
}

override func viewWillAppear() {
Expand Down Expand Up @@ -180,6 +192,14 @@ extension ViewController: NSTextFieldDelegate {
appDelegate.closeNameChangeWindow(sender: nil)
}
}

func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
if commandSelector == #selector(NSResponder.insertNewline(_:)) {
self.pressChangeName(textView)
return true
}
return false
}
}

extension ViewController {
Expand Down
Binary file modified build/spaces-renamer.zip
Binary file not shown.
Binary file not shown.

0 comments on commit 21e059e

Please sign in to comment.