Skip to content

Commit 29fa39d

Browse files
committed
Standardise changing create menu title
1 parent 42db05b commit 29fa39d

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

Plug-Ins/Dialog Editor/DialogEditorWindowController.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DialogEditorWindowController: AbstractEditor, ResourceEditor {
1212
]
1313

1414
let resource: Resource
15+
let createMenuTitle: String? = "Add Dialog Item"
1516
private let manager: RFEditorManager
1617
@IBOutlet var documentView: DITLDocumentView!
1718
@IBOutlet var tabView: NSTabView!
@@ -150,17 +151,6 @@ class DialogEditorWindowController: AbstractEditor, ResourceEditor {
150151
self.setDocumentEdited(false)
151152
}
152153

153-
154-
func windowDidBecomeKey(_ notification: Notification) {
155-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
156-
createItem?.title = NSLocalizedString("Create New Item", comment: "")
157-
}
158-
159-
func windowDidResignKey(_ notification: Notification) {
160-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
161-
createItem?.title = NSLocalizedString("Create New Resource…", comment: "")
162-
}
163-
164154
override func selectAll(_ sender: Any?) {
165155
itemList.selectAll(sender)
166156
}

Plug-Ins/Menu Editor/MenuEditorWindowController.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MenuEditorWindowController: AbstractEditor, ResourceEditor {
1111

1212
@IBOutlet weak var menuTable: NSTableView!
1313
let resource: Resource
14+
let createMenuTitle: String? = "Add Menu Item"
1415
private let manager: RFEditorManager
1516
private var fieldEditorForMenuPreview: NSTextView!
1617

@@ -249,17 +250,6 @@ class MenuEditorWindowController: AbstractEditor, ResourceEditor {
249250
self.setDocumentEdited(false)
250251
}
251252

252-
253-
func windowDidBecomeKey(_ notification: Notification) {
254-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
255-
createItem?.title = NSLocalizedString("Create New Item", comment: "menu command for adding menu items to MENUs")
256-
}
257-
258-
func windowDidResignKey(_ notification: Notification) {
259-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
260-
createItem?.title = NSLocalizedString("Create New Resource…", comment: "")
261-
}
262-
263253
@IBAction func createNewItem(_ sender: Any?) {
264254
var selRow = menuTable.selectedRow
265255
if selRow == -1 {

RFSupport/AbstractEditor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,18 @@ open class AbstractEditor: NSWindowController, NSWindowDelegate, NSMenuItemValid
9999
return true
100100
}
101101
}
102+
103+
open func windowDidBecomeKey(_ notification: Notification) {
104+
if let createMenuTitle = (self as? ResourceEditor)?.createMenuTitle {
105+
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
106+
createItem?.title = NSLocalizedString(createMenuTitle, comment: "")
107+
}
108+
}
109+
110+
open func windowDidResignKey(_ notification: Notification) {
111+
if (self as? ResourceEditor)?.createMenuTitle != nil {
112+
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
113+
createItem?.title = NSLocalizedString("New Resource…", comment: "")
114+
}
115+
}
102116
}

RFSupport/ResForgePlugin.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ import AppKit
22

33
/// An editor provides a window for editing or viewing resources of the supported types.
44
public protocol ResourceEditor: AbstractEditor {
5-
/// The list of resource types that this plugin supports.
5+
/// The list of resource types that this editor supports.
66
static var supportedTypes: [String] { get }
77

8-
var windowTitle: String { get }
8+
/// The resource that the editor is editing.
99
var resource: Resource { get }
10+
11+
/// The title of the editor's window. Default implementation provided.
12+
var windowTitle: String { get }
13+
14+
/// The title of the "Create" menu item, if the editor implements the `createNewItem()` function.
15+
var createMenuTitle: String? { get }
16+
17+
/// Initialise the editor with the resource to be edited and the editor manager.
18+
/// May return nil if the editor is unable to edit the resource.
1019
init?(resource: Resource, manager: RFEditorManager)
1120

12-
// Implementers should declare these @IBAction
21+
// Implementers should declare these @IBAction (or @obj)
1322
func saveResource(_ sender: Any)
1423
func revertResource(_ sender: Any)
1524
}
1625
public extension ResourceEditor {
17-
var windowTitle: String {
18-
resource.defaultWindowTitle
19-
}
26+
var windowTitle: String { resource.defaultWindowTitle }
27+
var createMenuTitle: String? { nil }
2028
}
2129

2230
/// A preview provider allows the document to display a grid view for a supported resource type.

ResForge/Template Editor/TemplateEditor.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TemplateEditor: AbstractEditor, ResourceEditor {
1111
static let supportedTypes: [String] = []
1212

1313
let resource: Resource
14+
let createMenuTitle: String? = "Insert List Entry"
1415
let manager: RFEditorManager
1516
let template: Resource
1617
private let filter: TemplateFilter.Type?
@@ -169,16 +170,6 @@ class TemplateEditor: AbstractEditor, ResourceEditor {
169170
@IBAction func itemValueUpdated(_ sender: Any) {
170171
edited = .user
171172
}
172-
173-
func windowDidBecomeKey(_ notification: Notification) {
174-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
175-
createItem?.title = NSLocalizedString("Create List Entry", comment: "")
176-
}
177-
178-
func windowDidResignKey(_ notification: Notification) {
179-
let createItem = NSApp.mainMenu?.item(withTag: 3)?.submenu?.item(withTag: 0)
180-
createItem?.title = NSLocalizedString("Create New Resource…", comment: "")
181-
}
182173
}
183174

184175
extension TemplateEditor: NSOutlineViewDelegate, NSOutlineViewDataSource {

0 commit comments

Comments
 (0)