GUI command picker for toolbox menu
This commit is contained in:
1 parent
ecc7a79a8c
commit
9104a7b7b9
4 files changed
+75
-64
No files matched your search
@@ -1595,29 +1595,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Add / Duplicate" : {
|
|
||||||
"extractionState" : "manual",
|
|
||||||
"localizations" : {
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "新增/复制"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "新增/複製"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-HK" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "新增/複製"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Add Host" : {
|
"Add Host" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@objc public class ToolboxViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate {
|
@objc public class ToolboxViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate, WidgetPickerViewControllerDelegate {
|
||||||
|
|
||||||
@objc weak var specialEntryDelegate: ToolboxSpecialEntryDelegate?
|
@objc weak var specialEntryDelegate: ToolboxSpecialEntryDelegate?
|
||||||
public let tableView = UITableView()
|
public let tableView = UITableView()
|
||||||
@@ -124,7 +124,7 @@ import UIKit
|
|||||||
|
|
||||||
tableView.separatorInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
tableView.separatorInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
||||||
// Configure buttons
|
// Configure buttons
|
||||||
addButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Add / Duplicate"), for: .normal)
|
addButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Add"), for: .normal)
|
||||||
deleteButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Delete"), for: .normal)
|
deleteButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Delete"), for: .normal)
|
||||||
editButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Edit"), for: .normal)
|
editButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Edit"), for: .normal)
|
||||||
exitButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Exit"), for: .normal)
|
exitButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Exit"), for: .normal)
|
||||||
@@ -258,48 +258,73 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func addButtonTapped() {
|
@available(iOS 13.0, *)
|
||||||
|
public func widgetPickerViewController(_ controller: WidgetPickerViewController, didCreateWidget payload: NSDictionary) {
|
||||||
|
createEntry(cmdString: payload["cmdString"] as? String, alias: payload["buttonLabel"] as? String)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createEntry(cmdString: String?, alias: String?){
|
||||||
|
|
||||||
|
let cmdString = cmdString ?? ""
|
||||||
|
let alias = alias ?? cmdString
|
||||||
let previouslySelectedIndexPath = tableView.indexPathForSelectedRow //memorize selected indexpath
|
let previouslySelectedIndexPath = tableView.indexPathForSelectedRow //memorize selected indexpath
|
||||||
let alert = UIAlertController(title: SwiftLocalizationHelper.localizedString(forKey: "New Command"), message: SwiftLocalizationHelper.localizedString(forKey: "Enter a new command and alias"), preferredStyle: .alert)
|
|
||||||
alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey:"Command") }
|
|
||||||
alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey: "Alias (optional)") }
|
|
||||||
alert.textFields?[0].keyboardType = .asciiCapable
|
|
||||||
alert.textFields?[0].autocorrectionType = .no
|
|
||||||
alert.textFields?[0].spellCheckingType = .no
|
|
||||||
alert.textFields?[1].keyboardType = .default
|
|
||||||
alert.textFields?[1].autocorrectionType = .no
|
|
||||||
alert.textFields?[1].spellCheckingType = .no
|
|
||||||
|
|
||||||
let submitAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Add"), style: .default) { [unowned alert] _ in
|
let newCommand = RemoteCommand(cmdString: cmdString, alias: alias)
|
||||||
let keyboardCmdString = alert.textFields?[0].text ?? ""
|
let addCommandSuceeded = CommandManager.shared.addCommand(newCommand)
|
||||||
let alias = alert.textFields?[1].text ?? keyboardCmdString
|
//self.reloadTableView() // don't know why but this reload has to be called from the CommandManager, it doesn't work here.
|
||||||
let newCommand = RemoteCommand(cmdString: keyboardCmdString, alias: alias)
|
|
||||||
let addCommandSuceeded = CommandManager.shared.addCommand(newCommand)
|
|
||||||
//self.reloadTableView() // don't know why but this reload has to be called from the CommandManager, it doesn't work here.
|
|
||||||
|
|
||||||
//if previouslySelectedIndexPath == nil { return }
|
//if previouslySelectedIndexPath == nil { return }
|
||||||
if addCommandSuceeded {
|
if addCommandSuceeded {
|
||||||
let lastRow = self.tableView.numberOfRows(inSection: 0) - 1 //for now there's only 1 section for the tableview, just use setion 0
|
let lastRow = self.tableView.numberOfRows(inSection: 0) - 1 //for now there's only 1 section for the tableview, just use setion 0
|
||||||
let newEntryIndexPath = IndexPath(row: lastRow, section: 0)
|
let newEntryIndexPath = IndexPath(row: lastRow, section: 0)
|
||||||
self.tableView.selectRow(at: newEntryIndexPath, animated: true, scrollPosition: .middle) // shift the highlight to the newly added entry
|
self.tableView.selectRow(at: newEntryIndexPath, animated: true, scrollPosition: .middle) // shift the highlight to the newly added entry
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.tableView.selectRow(at: previouslySelectedIndexPath, animated: true, scrollPosition: .middle) // keep the highlight on the previous entry if failed to add command
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
let cancelAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey:"Cancel"), style: .cancel)
|
self.tableView.selectRow(at: previouslySelectedIndexPath, animated: true, scrollPosition: .middle) // keep the highlight on the previous entry if failed to add command
|
||||||
alert.addAction(submitAction)
|
|
||||||
alert.addAction(cancelAction)
|
|
||||||
|
|
||||||
if let selectedIndexPath = self.tableView.indexPathForSelectedRow {
|
|
||||||
if isSpecialEntrySelected() {return}
|
|
||||||
let selectedCommand = CommandManager.shared.getAllCommands()[selectedIndexPath.row-specialEntries.count]
|
|
||||||
alert.textFields?[0].text = selectedCommand.cmdString // load selected keyboard cmd string
|
|
||||||
//alert.textFields?[1].text = selectedCommand.alias // leave the alias input field empty
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.present(alert, animated: true)
|
@objc private func addButtonTapped() {
|
||||||
|
if #available(iOS 13.0, *) {
|
||||||
|
let pickerViewController = WidgetPickerViewController()
|
||||||
|
pickerViewController.delegate = (self as WidgetPickerViewControllerDelegate)
|
||||||
|
pickerViewController.keyboardPickerMode = .shortcutPicker
|
||||||
|
pickerViewController.shortcutPickerNeedAlias = true
|
||||||
|
pickerViewController.tabIdentifiers = ["keyboard"]
|
||||||
|
pickerViewController.initialTabIdentifier = "keyboard"
|
||||||
|
let nav = UINavigationController(rootViewController: pickerViewController)
|
||||||
|
nav.modalPresentationStyle = .overFullScreen
|
||||||
|
self.present(nav, animated: true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
let alert = UIAlertController(title: SwiftLocalizationHelper.localizedString(forKey: "New Command"), message: SwiftLocalizationHelper.localizedString(forKey: "Enter a new command and alias"), preferredStyle: .alert)
|
||||||
|
alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey:"Command") }
|
||||||
|
alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey: "Alias (optional)") }
|
||||||
|
alert.textFields?[0].keyboardType = .asciiCapable
|
||||||
|
alert.textFields?[0].autocorrectionType = .no
|
||||||
|
alert.textFields?[0].spellCheckingType = .no
|
||||||
|
alert.textFields?[1].keyboardType = .default
|
||||||
|
alert.textFields?[1].autocorrectionType = .no
|
||||||
|
alert.textFields?[1].spellCheckingType = .no
|
||||||
|
|
||||||
|
let submitAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Add"), style: .default) { [unowned alert] _ in
|
||||||
|
self.createEntry(cmdString: alert.textFields?[0].text ?? "", alias: alert.textFields?[1].text)
|
||||||
|
}
|
||||||
|
|
||||||
|
let cancelAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey:"Cancel"), style: .cancel)
|
||||||
|
alert.addAction(submitAction)
|
||||||
|
alert.addAction(cancelAction)
|
||||||
|
|
||||||
|
if let selectedIndexPath = self.tableView.indexPathForSelectedRow {
|
||||||
|
if isSpecialEntrySelected() {return}
|
||||||
|
let selectedCommand = CommandManager.shared.getAllCommands()[selectedIndexPath.row-specialEntries.count]
|
||||||
|
alert.textFields?[0].text = selectedCommand.cmdString // load selected keyboard cmd string
|
||||||
|
//alert.textFields?[1].text = selectedCommand.alias // leave the alias input field empty
|
||||||
|
}
|
||||||
|
|
||||||
|
self.present(alert, animated: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -302,6 +302,7 @@ struct WidgetPickerView: View {
|
|||||||
private let availableTabs: [WidgetPickerTab]
|
private let availableTabs: [WidgetPickerTab]
|
||||||
private let preferredInitialTab: WidgetPickerTab?
|
private let preferredInitialTab: WidgetPickerTab?
|
||||||
private let keyboardPickerMode: VirtualKeyboardMode
|
private let keyboardPickerMode: VirtualKeyboardMode
|
||||||
|
var shortcutPickerNeedAlias: Bool = false
|
||||||
private let shortcutPickerTipText: String?
|
private let shortcutPickerTipText: String?
|
||||||
private let shortcutIdentifier: String?
|
private let shortcutIdentifier: String?
|
||||||
@ObservedObject private var presentationState: WidgetPickerPresentationState
|
@ObservedObject private var presentationState: WidgetPickerPresentationState
|
||||||
@@ -348,6 +349,7 @@ struct WidgetPickerView: View {
|
|||||||
availableTabs: [WidgetPickerTab] = WidgetPickerTab.allCases,
|
availableTabs: [WidgetPickerTab] = WidgetPickerTab.allCases,
|
||||||
preferredInitialTab: WidgetPickerTab? = nil,
|
preferredInitialTab: WidgetPickerTab? = nil,
|
||||||
keyboardPickerMode: VirtualKeyboardMode = .picker,
|
keyboardPickerMode: VirtualKeyboardMode = .picker,
|
||||||
|
shortcutPickerNeedAlias: Bool = false,
|
||||||
shortcutPickerTipText: String? = nil,
|
shortcutPickerTipText: String? = nil,
|
||||||
shortcutIdentififier: String? = nil,
|
shortcutIdentififier: String? = nil,
|
||||||
presentationState: WidgetPickerPresentationState = WidgetPickerPresentationState(),
|
presentationState: WidgetPickerPresentationState = WidgetPickerPresentationState(),
|
||||||
@@ -363,6 +365,7 @@ struct WidgetPickerView: View {
|
|||||||
self.availableTabs = normalizedTabs
|
self.availableTabs = normalizedTabs
|
||||||
self.preferredInitialTab = resolvedInitialTab
|
self.preferredInitialTab = resolvedInitialTab
|
||||||
self.keyboardPickerMode = keyboardPickerMode
|
self.keyboardPickerMode = keyboardPickerMode
|
||||||
|
self.shortcutPickerNeedAlias = shortcutPickerNeedAlias
|
||||||
self.shortcutPickerTipText = shortcutPickerTipText
|
self.shortcutPickerTipText = shortcutPickerTipText
|
||||||
self.shortcutIdentifier = shortcutIdentififier
|
self.shortcutIdentifier = shortcutIdentififier
|
||||||
self.presentationState = presentationState
|
self.presentationState = presentationState
|
||||||
@@ -1770,6 +1773,7 @@ struct WidgetPickerView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var showsComboModeControl: Bool {
|
private var showsComboModeControl: Bool {
|
||||||
|
if isShortcutPickerMode { return false }
|
||||||
guard targetWidgetKind == .button else { return false }
|
guard targetWidgetKind == .button else { return false }
|
||||||
if let selectedFunctionalButtonOption {
|
if let selectedFunctionalButtonOption {
|
||||||
return selectedFunctionalButtonOption.allowsSkillCombo || selectedFunctionalButtonOption.allowsShortcutCombo
|
return selectedFunctionalButtonOption.allowsSkillCombo || selectedFunctionalButtonOption.allowsShortcutCombo
|
||||||
@@ -1778,14 +1782,17 @@ struct WidgetPickerView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var showsShapeControl: Bool {
|
private var showsShapeControl: Bool {
|
||||||
targetWidgetKind == .button
|
if isShortcutPickerMode { return false }
|
||||||
|
return targetWidgetKind == .button
|
||||||
}
|
}
|
||||||
|
|
||||||
private var showsButtonLabelField: Bool {
|
private var showsButtonLabelField: Bool {
|
||||||
targetWidgetKind == .button
|
if isShortcutPickerMode { return shortcutPickerNeedAlias }
|
||||||
|
return targetWidgetKind == .button
|
||||||
}
|
}
|
||||||
|
|
||||||
private var showsIntervalSlider: Bool {
|
private var showsIntervalSlider: Bool {
|
||||||
|
if isShortcutPickerMode { return false }
|
||||||
guard buttonCommandCount >= 2 else { return false }
|
guard buttonCommandCount >= 2 else { return false }
|
||||||
if let selectedFunctionalButtonOption {
|
if let selectedFunctionalButtonOption {
|
||||||
return selectedFunctionalButtonOption.allowsSkillCombo
|
return selectedFunctionalButtonOption.allowsSkillCombo
|
||||||
@@ -1815,7 +1822,7 @@ struct WidgetPickerView: View {
|
|||||||
|
|
||||||
private var shouldBypassCreateWidgetSheet: Bool {
|
private var shouldBypassCreateWidgetSheet: Bool {
|
||||||
if isShortcutPickerMode {
|
if isShortcutPickerMode {
|
||||||
return true
|
// return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if containsMovementDirectionPad {
|
if containsMovementDirectionPad {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public final class WidgetPickerViewController: UIViewController {
|
|||||||
public var tabIdentifiers: [String] = []
|
public var tabIdentifiers: [String] = []
|
||||||
public var initialTabIdentifier: String?
|
public var initialTabIdentifier: String?
|
||||||
public var keyboardPickerMode: VirtualKeyboardMode = .picker
|
public var keyboardPickerMode: VirtualKeyboardMode = .picker
|
||||||
|
var shortcutPickerNeedAlias: Bool = false
|
||||||
public var shortcutPickerTipText: String?
|
public var shortcutPickerTipText: String?
|
||||||
@objc public var shortcutIdentifier: String?
|
@objc public var shortcutIdentifier: String?
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ public final class WidgetPickerViewController: UIViewController {
|
|||||||
availableTabs: resolvedTabs(),
|
availableTabs: resolvedTabs(),
|
||||||
preferredInitialTab: resolvedInitialTab(),
|
preferredInitialTab: resolvedInitialTab(),
|
||||||
keyboardPickerMode: keyboardPickerMode,
|
keyboardPickerMode: keyboardPickerMode,
|
||||||
|
shortcutPickerNeedAlias: shortcutPickerNeedAlias,
|
||||||
shortcutPickerTipText: shortcutPickerTipText,
|
shortcutPickerTipText: shortcutPickerTipText,
|
||||||
shortcutIdentififier: shortcutIdentifier,
|
shortcutIdentififier: shortcutIdentifier,
|
||||||
presentationState: presentationState,
|
presentationState: presentationState,
|
||||||
|
|||||||
Reference in new issue
Block a user