From 8b52dab667556e398eb2b8bb8c1369903db90dfe Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 8 Aug 2024 11:00:18 -0500 Subject: [PATCH] Make duplicate row use the responder chain --- Zavala/AppDelegate.swift | 10 +--------- Zavala/Editor/EditorViewController.swift | 17 +++++++---------- Zavala/MainCoordinator.swift | 8 -------- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Zavala/AppDelegate.swift b/Zavala/AppDelegate.swift index 35bbcb58..0bc4f096 100644 --- a/Zavala/AppDelegate.swift +++ b/Zavala/AppDelegate.swift @@ -98,7 +98,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { modifierFlags: [.shift, .command]) let duplicateRowsCommand = UIKeyCommand(title: .duplicateRowControlLabel, - action: #selector(duplicateRowsCommand(_:)), + action: .duplicateCurrentRows, input: "r", modifierFlags: [.command, .control]) @@ -404,10 +404,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } } - @objc func duplicateRowsCommand(_ sender: Any?) { - mainCoordinator?.duplicateRows() - } - @objc func rowNotesCommand(_ sender: Any?) { if mainCoordinator?.isCreateRowNotesUnavailable ?? true { if mainCoordinator?.isEditingTopic ?? false { @@ -538,10 +534,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { override func validate(_ command: UICommand) { switch command.action { - case #selector(duplicateRowsCommand(_:)): - if mainCoordinator?.isDuplicateRowsUnavailable ?? true { - command.attributes = .disabled - } case #selector(rowNotesCommand(_:)): if mainCoordinator?.isCreateRowNotesUnavailable ?? true { if mainCoordinator?.isEditingTopic ?? false { diff --git a/Zavala/Editor/EditorViewController.swift b/Zavala/Editor/EditorViewController.swift index 0f0c6b01..27ba4dc1 100644 --- a/Zavala/Editor/EditorViewController.swift +++ b/Zavala/Editor/EditorViewController.swift @@ -17,6 +17,7 @@ extension Selector { static let addRowBelow = #selector(EditorViewController.addRowBelow(_:)) static let createRowInside = #selector(EditorViewController.createRowInside(_:)) static let createRowOutside = #selector(EditorViewController.createRowOutside(_:)) + static let duplicateCurrentRows = #selector(EditorViewController.duplicateCurrentRows(_:)) static let deleteCurrentRows = #selector(EditorViewController.deleteCurrentRows(_:)) static let moveCurrentRowsLeft = #selector(EditorViewController.moveCurrentRowsLeft(_:)) static let moveCurrentRowsRight = #selector(EditorViewController.moveCurrentRowsRight(_:)) @@ -117,10 +118,6 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio return true } - var isDuplicateRowsUnavailable: Bool { - return currentRows == nil - } - var isGoBackwardUnavailable: Bool { return delegate?.editorViewControllerIsGoBackUnavailable ?? true } @@ -616,7 +613,7 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio } else { return super.canPerformAction(action, withSender: sender) } - case .addRowAbove, .addRowBelow, .createRowInside, .deleteCurrentRows: + case .addRowAbove, .addRowBelow, .createRowInside, .duplicateCurrentRows, .deleteCurrentRows: return currentRows != nil case .createRowOutside: if let outline, let currentRows, !outline.isCreateRowOutsideUnavailable(rows: currentRows) { @@ -1064,11 +1061,6 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio } - func duplicateCurrentRows() { - guard let rows = currentRows else { return } - duplicateRows(rows) - } - func moveCursorToCurrentRowTopic() { guard let rowShadowTableIndex = currentRows?.last?.shadowTableIndex, let currentRowViewCell = collectionView.cellForItem(at: IndexPath(row: rowShadowTableIndex, section: adjustedRowsSection)) as? EditorRowViewCell else { return } @@ -1273,6 +1265,11 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio createRowOutside(afterRows: rows) } + @objc func duplicateCurrentRows(_ sender: Any?) { + guard let rows = currentRows else { return } + duplicateRows(rows) + } + @objc func deleteCurrentRows(_ sender: Any?) { guard let rows = currentRows else { return } deleteRows(rows) diff --git a/Zavala/MainCoordinator.swift b/Zavala/MainCoordinator.swift index 6ee424d7..58bc2e16 100644 --- a/Zavala/MainCoordinator.swift +++ b/Zavala/MainCoordinator.swift @@ -59,10 +59,6 @@ extension MainCoordinator { return editorViewController?.isNotesFiltered ?? false } - var isDuplicateRowsUnavailable: Bool { - return editorViewController?.isDuplicateRowsUnavailable ?? true - } - var isCreateRowNotesUnavailable: Bool { return editorViewController?.isCreateRowNotesUnavailable ?? true } @@ -123,10 +119,6 @@ extension MainCoordinator { return editorViewController?.isEditingNote ?? false } - func duplicateRows() { - editorViewController?.duplicateCurrentRows() - } - func focusIn() { editorViewController?.focusIn() }