Link add shortcut to manager

This commit is contained in:
Davide De Rosa 2019-03-27 20:28:37 +01:00
parent d5b7a1e576
commit e1638d1c73
3 changed files with 28 additions and 2 deletions

View File

@ -61,7 +61,9 @@ class ShortcutsEditViewController: UITableViewController, TableModelHost {
}()
func reloadModel() {
model.set(.shortcut, count: wrappers?.count ?? 0, in: .all)
var rows = [RowType](repeating: .shortcut, count: wrappers?.count ?? 0)
rows.append(.addShortcut)
model.set(rows, in: .all)
}
// MARK: UIViewController
@ -84,6 +86,12 @@ class ShortcutsEditViewController: UITableViewController, TableModelHost {
}
}
}
// MARK: Actions
private func addShortcut() {
perform(segue: StoryboardSegue.Shortcuts.shortcutAddSegueIdentifier)
}
private func handleShortcutsFetchError(_ error: Error?) {
@ -117,6 +125,8 @@ extension ShortcutsEditViewController {
enum RowType {
case shortcut
case addShortcut
}
override func numberOfSections(in tableView: UITableView) -> Int {
@ -138,10 +148,16 @@ extension ShortcutsEditViewController {
guard let wrapper = wrappers?[indexPath.row] else {
break
}
cell.apply(Theme.current)
cell.leftText = wrapper.phrase
cell.rightText = wrapper.intentDescription
case .addShortcut:
cell.applyAction(Theme.current)
cell.leftText = L10n.Shortcuts.Edit.Cells.AddShortcut.caption
cell.accessoryType = .none
cell.isTappable = true
}
cell.apply(Theme.current)
return cell
}
@ -158,6 +174,9 @@ extension ShortcutsEditViewController {
vc.delegate = self
editedIndexPath = indexPath
present(vc, animated: true, completion: nil)
case .addShortcut:
addShortcut()
}
}
}

View File

@ -219,6 +219,7 @@
"shortcuts.edit.title" = "Manage shortcuts";
"shortcuts.edit.sections.all.header" = "Existing shortcuts";
"shortcuts.edit.cells.add_shortcut.caption" = "Add shortcut";
"about.title" = "About";
"about.sections.web.header" = "Web";

View File

@ -754,6 +754,12 @@ public enum L10n {
public enum Edit {
/// Manage shortcuts
public static let title = L10n.tr("Localizable", "shortcuts.edit.title")
public enum Cells {
public enum AddShortcut {
/// Add shortcut
public static let caption = L10n.tr("Localizable", "shortcuts.edit.cells.add_shortcut.caption")
}
}
public enum Sections {
public enum All {
/// Existing shortcuts