Skip to content

Commit

Permalink
Prevent crash when adding mpv filter with no name
Browse files Browse the repository at this point in the history
Ref #2348.  Changes to NewFilterSheetViewController (in FilterWindowController.swift):
* Add button is disabled until text is entered for name of custom mpv filter
  • Loading branch information
ekstasis committed Mar 23, 2019
1 parent b062373 commit 68f3c08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions iina/Base.lproj/FilterWindowController.xib
Expand Up @@ -211,6 +211,7 @@ Gw
</window>
<viewController id="bda-X5-kCJ" customClass="NewFilterSheetViewController" customModule="IINA" customModuleProvider="target">
<connections>
<outlet property="addButton" destination="THV-Yh-VnK" id="GeO-qk-FbF"/>
<outlet property="filterWindow" destination="-2" id="Pjr-CT-nJA"/>
<outlet property="scrollContentView" destination="ZHP-RK-Ly4" id="NhJ-gL-sPY"/>
<outlet property="tableView" destination="n0t-vk-dME" id="IBk-xT-LkA"/>
Expand Down
17 changes: 16 additions & 1 deletion iina/FilterWindowController.swift
Expand Up @@ -299,7 +299,8 @@ class NewFilterSheetViewController: NSViewController, NSTableViewDelegate, NSTab
@IBOutlet weak var filterWindow: FilterWindowController!
@IBOutlet weak var tableView: NSTableView!
@IBOutlet weak var scrollContentView: NSView!

@IBOutlet weak var addButton: NSButton!

private var currentPreset: FilterPreset?
private var currentBindings: [String: NSControl] = [:]
private var presets: [FilterPreset] = []
Expand Down Expand Up @@ -333,6 +334,11 @@ class NewFilterSheetViewController: NSViewController, NSTableViewDelegate, NSTab
self.scrollContentView.addSubview(self.quickLabel(yPos: maxY, title: preset.localizedParamName(name)))
maxY += 21
let input = self.quickInput(yPos: &maxY, param: param)
// For preventing crash due to adding a filter with no name:
if name == "name", preset.name.starts(with: "custom_"), let textField = input as? NSTextField {
textField.delegate = self
self.addButton.isEnabled = !textField.stringValue.isEmpty
}
self.scrollContentView.addSubview(input)
self.currentBindings[name] = input
}
Expand Down Expand Up @@ -442,3 +448,12 @@ class NewFilterSheetViewController: NSViewController, NSTableViewDelegate, NSTab
}

}

/* For preventing crash due to to adding filter with no name */
extension NewFilterSheetViewController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
if let textField = obj.object as? NSTextField {
self.addButton.isEnabled = !textField.stringValue.isEmpty
}
}
}

0 comments on commit 68f3c08

Please sign in to comment.