Skip to content
Permalink
Browse files

Prevent crash when adding mpv filter with no name

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 68f3c08b3cd302251408f3abfad7de16ab1497d8
Showing with 17 additions and 1 deletion.
  1. +1 −0 iina/Base.lproj/FilterWindowController.xib
  2. +16 −1 iina/FilterWindowController.swift
@@ -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"/>
@@ -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] = []
@@ -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
}
@@ -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.
You can’t perform that action at this time.