Make further progress on rename sheet.
This commit is contained in:
parent
fbaacbc47f
commit
01729378f3
@ -10,6 +10,7 @@
|
||||
<outlet property="newTitleTextField" destination="OYZ-cW-H2x" id="QBo-lj-NGi"/>
|
||||
<outlet property="renameButton" destination="RI3-Rg-htY" id="PMM-jS-psV"/>
|
||||
<outlet property="renamePrompt" destination="Sh3-Yd-lqa" id="wd5-4I-pYl"/>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="eYQ-Qy-Z2g"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
@ -50,7 +51,13 @@
|
||||
<buttonCell key="cell" type="push" title="Rename" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="gcS-uM-zjx">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
DQ
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="rename:" target="-1" id="ba5-O4-rNJ"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vuB-kU-1EJ">
|
||||
<rect key="frame" x="232" y="13" width="89" height="32"/>
|
||||
@ -61,6 +68,9 @@
|
||||
Gw
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="cancel:" target="-1" id="4sS-Ja-Gev"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
|
@ -63,6 +63,24 @@ extension MainWindowController {
|
||||
|
||||
@objc func renameFromContextualMenu(_ sender: Any?) {
|
||||
|
||||
guard let window = window, let menuItem = sender as? NSMenuItem, let object = menuItem.representedObject as? DisplayNameProvider, object is Feed || object is Folder else {
|
||||
return
|
||||
}
|
||||
|
||||
renameWindowController = RenameWindowController(originalTitle: object.nameForDisplay) { (newTitle) in
|
||||
guard let newTitle = newTitle else {
|
||||
return
|
||||
}
|
||||
if let feed = object as? Feed {
|
||||
feed.editedName = newTitle
|
||||
}
|
||||
else if let folder = object as? Folder {
|
||||
folder.name = newTitle
|
||||
}
|
||||
self.renameWindowController = nil
|
||||
}
|
||||
|
||||
renameWindowController!.runSheetOnWindow(window)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
return false
|
||||
}
|
||||
|
||||
var renameWindowController: RenameWindowController?
|
||||
|
||||
// MARK: NSWindowController
|
||||
|
||||
private let windowAutosaveName = NSWindow.FrameAutosaveName(rawValue: kWindowFrameKey)
|
||||
|
@ -15,18 +15,52 @@ final class RenameWindowController: NSWindowController {
|
||||
@IBOutlet var renameButton: NSButton!
|
||||
|
||||
private var originalTitle: String!
|
||||
private var hostWindow: NSWindow!
|
||||
private var callback: ((String?) -> Void)?
|
||||
|
||||
convenience init(originalTitle: String) {
|
||||
convenience init(originalTitle: String, callback: @escaping ((String?) -> Void)) {
|
||||
|
||||
self.init(windowNibName: NSNib.Name(rawValue: "RenameSheet"))
|
||||
self.originalTitle = originalTitle
|
||||
self.callback = callback
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
|
||||
newTitleTextField.stringValue = originalTitle
|
||||
|
||||
let prompt = NSLocalizedString("Rename %@ to:", comment: "Rename sheet")
|
||||
let localizedPrompt = NSString.localizedStringWithFormat(prompt as NSString, originalTitle)
|
||||
renamePrompt.stringValue = localizedPrompt as String
|
||||
|
||||
updateUI()
|
||||
}
|
||||
|
||||
func runSheetOnWindow(_ w: NSWindow) {
|
||||
|
||||
guard let window = window else {
|
||||
return
|
||||
}
|
||||
|
||||
hostWindow = w
|
||||
hostWindow.beginSheet(window) { (returnCode: NSApplication.ModalResponse) -> Void in
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Actions
|
||||
|
||||
@IBAction func cancel(_ sender: AnyObject) {
|
||||
|
||||
callback?(nil)
|
||||
hostWindow!.endSheet(window!, returnCode: .cancel)
|
||||
}
|
||||
|
||||
@IBAction func rename(_ sender: AnyObject) {
|
||||
|
||||
callback?(newTitleTextField.stringValue)
|
||||
hostWindow!.endSheet(window!, returnCode: .OK)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension RenameWindowController: NSTextFieldDelegate {
|
||||
|
Loading…
x
Reference in New Issue
Block a user