ClientMgr // Enable batch deletion.
This commit is contained in:
parent
be3ccb52f4
commit
fda532a799
|
@ -17,6 +17,7 @@ class ctlClientListMgr: NSWindowController, NSTableViewDelegate, NSTableViewData
|
||||||
super.windowDidLoad()
|
super.windowDidLoad()
|
||||||
localize()
|
localize()
|
||||||
tblClients.delegate = self
|
tblClients.delegate = self
|
||||||
|
tblClients.allowsMultipleSelection = true
|
||||||
tblClients.dataSource = self
|
tblClients.dataSource = self
|
||||||
tblClients.reloadData()
|
tblClients.reloadData()
|
||||||
}
|
}
|
||||||
|
@ -132,18 +133,24 @@ extension ctlClientListMgr {
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func btnRemoveClientClicked(_: Any) {
|
@IBAction func btnRemoveClientClicked(_: Any) {
|
||||||
if tblClients.selectedRow >= mgrPrefs.clientsIMKTextInputIncapable.count { return }
|
guard let minIndexSelected = tblClients.selectedRowIndexes.min() else { return }
|
||||||
if tblClients.selectedRow < 0 { return }
|
if minIndexSelected >= mgrPrefs.clientsIMKTextInputIncapable.count { return }
|
||||||
let isLastRow: Bool = {
|
if minIndexSelected < 0 { return }
|
||||||
|
var isLastRow = false
|
||||||
|
tblClients.selectedRowIndexes.sorted().reversed().forEach { index in
|
||||||
|
isLastRow = {
|
||||||
if mgrPrefs.clientsIMKTextInputIncapable.count < 2 { return false }
|
if mgrPrefs.clientsIMKTextInputIncapable.count < 2 { return false }
|
||||||
return tblClients.selectedRow == mgrPrefs.clientsIMKTextInputIncapable.count - 1
|
return minIndexSelected == mgrPrefs.clientsIMKTextInputIncapable.count - 1
|
||||||
}()
|
}()
|
||||||
mgrPrefs.clientsIMKTextInputIncapable.remove(at: tblClients.selectedRow)
|
if index < mgrPrefs.clientsIMKTextInputIncapable.count {
|
||||||
|
mgrPrefs.clientsIMKTextInputIncapable.remove(at: index)
|
||||||
|
}
|
||||||
|
}
|
||||||
if isLastRow {
|
if isLastRow {
|
||||||
tblClients.selectRowIndexes(.init(arrayLiteral: tblClients.selectedRow - 1), byExtendingSelection: false)
|
tblClients.selectRowIndexes(.init(arrayLiteral: minIndexSelected - 1), byExtendingSelection: false)
|
||||||
}
|
}
|
||||||
tblClients.reloadData()
|
tblClients.reloadData()
|
||||||
btnRemoveClient.isEnabled = (0..<mgrPrefs.clientsIMKTextInputIncapable.count).contains(tblClients.selectedRow)
|
btnRemoveClient.isEnabled = (0..<mgrPrefs.clientsIMKTextInputIncapable.count).contains(minIndexSelected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(_: NSTableView, objectValueFor _: NSTableColumn?, row: Int) -> Any? {
|
func tableView(_: NSTableView, objectValueFor _: NSTableColumn?, row: Int) -> Any? {
|
||||||
|
|
Loading…
Reference in New Issue