Skip to content

Commit

Permalink
Delete code for older, no longer supported OS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Dec 24, 2023
1 parent fced914 commit 2c0394c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 250 deletions.
182 changes: 5 additions & 177 deletions Zavala/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,171 +14,11 @@ var appDelegate: AppDelegate!
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

override var keyCommands: [UIKeyCommand]? {
#if targetEnvironment(macCatalyst)
return nil
#else
if #available(iOS 15.0, *) {
return nil
}

var menuKeyCommands = [UIKeyCommand]()

menuKeyCommands.append(showPreferences)
menuKeyCommands.append(beginDocumentSearchCommand)
menuKeyCommands.append(showOpenQuicklyCommand)

if AccountManager.shared.isSyncAvailable {
menuKeyCommands.append(syncCommand)
}


if !(mainCoordinator?.isOutlineFunctionsUnavailable ?? true) {
menuKeyCommands.append(toggleFilterOnCommand)
menuKeyCommands.append(beginInDocumentSearchCommand)
menuKeyCommands.append(useSelectionForSearchCommand)
menuKeyCommands.append(nextInDocumentSearchCommand)
menuKeyCommands.append(previousInDocumentSearchCommand)
menuKeyCommands.append(printDocsCommand)
menuKeyCommands.append(printListsCommand)
menuKeyCommands.append(outlineGetInfoCommand)
}

menuKeyCommands.append(newOutlineCommand)
menuKeyCommands.append(importOPMLCommand)

if !(mainCoordinator?.isOutlineFunctionsUnavailable ?? true) {
menuKeyCommands.append(exportMarkdownListsCommand)
menuKeyCommands.append(exportOPMLsCommand)
}

menuKeyCommands.append(newWindowCommand)
menuKeyCommands.append(toggleSidebarCommand)

menuKeyCommands.append(deleteCommand)

if !(mainCoordinator?.isGoBackwardOneUnavailable ?? true) {
menuKeyCommands.append(goBackwardOneCommand)
}

if !(mainCoordinator?.isGoForwardOneUnavailable ?? true) {
menuKeyCommands.append(goForwardOneCommand)
}

if !(mainCoordinator?.isInsertImageUnavailable ?? true) {
menuKeyCommands.append(insertImageCommand)
}

if !(mainCoordinator?.isLinkUnavailable ?? true) {
menuKeyCommands.append(linkCommand)
}

if !(mainCoordinator?.isInsertRowUnavailable ?? true) {
menuKeyCommands.append(insertRowCommand)
}

if !(mainCoordinator?.isCreateRowUnavailable ?? true) {
menuKeyCommands.append(createRowCommand)
}

if !(mainCoordinator?.isDuplicateRowsUnavailable ?? true) {
menuKeyCommands.append(duplicateRowsCommand)
}

if !(mainCoordinator?.isCreateRowInsideUnavailable ?? true) {
menuKeyCommands.append(createRowInsideCommand)
}

if !(mainCoordinator?.isCreateRowOutsideUnavailable ?? true) {
menuKeyCommands.append(createRowOutsideCommand)
}

if !(mainCoordinator?.isMoveRowsUpUnavailable ?? true) {
menuKeyCommands.append(moveRowsUpCommand)
}

if !(mainCoordinator?.isMoveRowsDownUnavailable ?? true) {
menuKeyCommands.append(moveRowsDownCommand)
}

if !(mainCoordinator?.isMoveRowsLeftUnavailable ?? true) {
menuKeyCommands.append(moveRowsLeftCommand)
}

if !(mainCoordinator?.isMoveRowsRightUnavailable ?? true) {
menuKeyCommands.append(moveRowsRightCommand)
}

if !(mainCoordinator?.isToggleRowCompleteUnavailable ?? true) {
if mainCoordinator?.isCompleteRowsAvailable ?? false {
menuKeyCommands.append(completeRowsCommand)
} else {
menuKeyCommands.append(uncompleteRowsCommand)
}
}

if !(mainCoordinator?.isCreateRowNotesUnavailable ?? true) {
menuKeyCommands.append(createRowNotesCommand)
}

if !(mainCoordinator?.isDeleteRowNotesUnavailable ?? true) {
menuKeyCommands.append(deleteRowNotesCommand)
}

if !(mainCoordinator?.isSplitRowUnavailable ?? true) {
menuKeyCommands.append(splitRowCommand)
}

if !(mainCoordinator?.isExpandAllInOutlineUnavailable ?? true) {
menuKeyCommands.append(expandAllInOutlineCommand)
}

if !(mainCoordinator?.isCollapseAllInOutlineUnavailable ?? true) {
menuKeyCommands.append(collapseAllInOutlineCommand)
}

if !(mainCoordinator?.isExpandAllUnavailable ?? true) {
menuKeyCommands.append(expandAllCommand)
}

if !(mainCoordinator?.isCollapseAllUnavailable ?? true) {
menuKeyCommands.append(collapseAllCommand)
}

if !(mainCoordinator?.isExpandUnavailable ?? true) {
menuKeyCommands.append(expandCommand)
}

if !(mainCoordinator?.isCollapseUnavailable ?? true) {
menuKeyCommands.append(collapseCommand)
}

if !(mainCoordinator?.isCollapseParentRowUnavailable ?? true) {
menuKeyCommands.append(collapseParentRowCommand)
}

if !(mainCoordinator?.isDeleteCompletedRowsUnavailable ?? true) {
menuKeyCommands.append(deleteCompletedRowsCommand)
}

return menuKeyCommands
#endif
}

let showPreferences: UIKeyCommand = {
let title: String
if #available(iOS 16, *) {
title = AppStringAssets.settingsEllipsisControlLabel
} else {
title = AppStringAssets.preferencesEllipsisControlLabel
}

return UIKeyCommand(title: title,
action: #selector(showPreferences(_:)),
input: ",",
modifierFlags: [.command])

}()
let showPreferences = UIKeyCommand(title: AppStringAssets.settingsEllipsisControlLabel,
action: #selector(showPreferences(_:)),
input: ",",
modifierFlags: [.command])


let syncCommand = UIKeyCommand(title: AppStringAssets.syncControlLabel,
action: #selector(syncCommand(_:)),
Expand Down Expand Up @@ -216,11 +56,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
input: "n",
modifierFlags: [.command])

let toggleSidebarCommand = UIKeyCommand(title: AppStringAssets.togglerSidebarControlLabel,
action: #selector(toggleSidebarCommand(_:)),
input: "s",
modifierFlags: [.control, .command])

let deleteCommand = UIKeyCommand(title: AppStringAssets.deleteControlLabel,
action: #selector(delete),
input: "\u{8}",
Expand Down Expand Up @@ -1101,13 +936,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let toggleFilterOutlineMenu = UIMenu(title: "", options: .displayInline, children: [toggleFilterOnCommand, toggleCompletedFilterCommand, toggleNotesFilterCommand])
builder.insertChild(toggleFilterOutlineMenu, atStartOfMenu: .view)

if #available(macOS 12.0, *) {
// This is included automatically on 12 and up
} else {
let toggleSidebarMenu = UIMenu(title: "", options: .displayInline, children: [toggleSidebarCommand])
builder.insertSibling(toggleSidebarMenu, afterMenu: .toolbar)
}

// Outline Menu
let completeMenu = UIMenu(title: "", options: .displayInline, children: [toggleCompleteRowsCommand, deleteCompletedRowsCommand, createRowNotesCommand, deleteRowNotesCommand])
let moveRowMenu = UIMenu(title: "", options: .displayInline, children: [moveRowsLeftCommand, moveRowsRightCommand, moveRowsUpCommand, moveRowsDownCommand])
Expand Down
8 changes: 2 additions & 6 deletions Zavala/Documents/DocumentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,8 @@ extension DocumentsViewController {
}

private func reconfigureAll() {
if #available(iOS 15, *) {
let indexPaths = (0..<documents.count).map { IndexPath(row: $0, section: 0) }
collectionView.reconfigureItems(at: indexPaths)
} else {
collectionView.reloadItems(at: collectionView.indexPathsForVisibleItems)
}
let indexPaths = (0..<documents.count).map { IndexPath(row: $0, section: 0) }
collectionView.reconfigureItems(at: indexPaths)
}

private func scheduleReconfigureAll() {
Expand Down
39 changes: 15 additions & 24 deletions Zavala/DocumentsActivityItemsConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,21 @@ extension DocumentsActivityItemsConfiguration: UIActivityItemsConfigurationReadi
return nil
}

if #available(iOS 15.0, *) {
switch key {
case .title:
return selectedDocuments[at].title
case .linkPresentationMetadata:
let iconView = UIImageView(image: ZavalaImageAssets.outline)
iconView.backgroundColor = .accentColor
iconView.tintColor = .label
iconView.contentMode = .scaleAspectFit
iconView.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
let metadata = LPLinkMetadata()
metadata.title = selectedDocuments[at].title
metadata.iconProvider = NSItemProvider(object: iconView.asImage())
return metadata
default:
return nil
}
} else {
switch key {
case .title:
return selectedDocuments[at].title
default:
return nil
}
switch key {
case .title:
return selectedDocuments[at].title
case .linkPresentationMetadata:
let iconView = UIImageView(image: ZavalaImageAssets.outline)
iconView.backgroundColor = .accentColor
iconView.tintColor = .label
iconView.contentMode = .scaleAspectFit
iconView.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
let metadata = LPLinkMetadata()
metadata.title = selectedDocuments[at].title
metadata.iconProvider = NSItemProvider(object: iconView.asImage())
return metadata
default:
return nil
}
}

Expand Down
37 changes: 8 additions & 29 deletions Zavala/Editor/EditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,17 @@ class EditorViewController: UIViewController, DocumentsActivityItemsConfiguratio
var keyCommands = [UIKeyCommand]()

let shiftTab = UIKeyCommand(input: "\t", modifierFlags: [.shift], action: #selector(moveCurrentRowsLeft))
if #available(iOS 15.0, *) {
shiftTab.wantsPriorityOverSystemBehavior = true
}
shiftTab.wantsPriorityOverSystemBehavior = true
keyCommands.append(shiftTab)

let tab = UIKeyCommand(action: #selector(moveCurrentRowsRight), input: "\t")
if #available(iOS 15.0, *) {
tab.wantsPriorityOverSystemBehavior = true
}
tab.wantsPriorityOverSystemBehavior = true
keyCommands.append(tab)

// We need to have this here in addition to the AppDelegate, since iOS won't pick it up for some reason
if !isToggleRowCompleteUnavailable {
let commandReturn = UIKeyCommand(input: "\r", modifierFlags: [.command], action: #selector(toggleCompleteRows))
if #available(iOS 15, *) {
commandReturn.wantsPriorityOverSystemBehavior = true
}
commandReturn.wantsPriorityOverSystemBehavior = true
keyCommands.append(commandReturn)
}

Expand Down Expand Up @@ -2281,18 +2275,10 @@ private extension EditorViewController {
}

func layoutEditor(row: Row) {
if #available(iOS 15, *) {
guard let index = row.shadowTableIndex else { return }
let indexPath = IndexPath(row: index, section: adjustedRowsSection)
UIView.performWithoutAnimation {
self.collectionView.reconfigureItems(at: [indexPath])
}
} else {
// This is presumably less effecient than just reconfiguring the item and
// it can trigger layout bugs. For example if the first row of a topic above
// this row is an image, things go to 💩 in a hurry.
collectionView.collectionViewLayout.invalidateLayout()
collectionView.layoutIfNeeded()
guard let index = row.shadowTableIndex else { return }
let indexPath = IndexPath(row: index, section: adjustedRowsSection)
UIView.performWithoutAnimation {
self.collectionView.reconfigureItems(at: [indexPath])
}

makeCursorVisibleIfNecessary()
Expand Down Expand Up @@ -2321,7 +2307,7 @@ private extension EditorViewController {

let hasSectionOtherThanRows = reloads.contains(where: { $0.section != adjustedRowsSection })

if #available(iOS 15, *), !hasSectionOtherThanRows {
if !hasSectionOtherThanRows {
collectionView.reconfigureItems(at: reloads)
} else {
if changes.isReloadsAnimatable {
Expand All @@ -2343,13 +2329,6 @@ private extension EditorViewController {

applyChanges(changes)

if #available(iOS 15, *) {
} else {
if let coordinates = currentCoordinates {
restoreCursorPosition(coordinates, scroll: true)
}
}

if changes.isOnlyReloads, let indexPaths = selectedIndexPaths {
for indexPath in indexPaths {
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
Expand Down
12 changes: 3 additions & 9 deletions Zavala/Editor/Row/EditorRowTopicTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ class EditorRowTopicTextView: EditorRowTextView {

override var keyCommands: [UIKeyCommand]? {
let shiftTab = UIKeyCommand(input: "\t", modifierFlags: [.shift], action: #selector(moveLeft(_:)))
if #available(iOS 15.0, *) {
shiftTab.wantsPriorityOverSystemBehavior = true
}
shiftTab.wantsPriorityOverSystemBehavior = true

let controlP = UIKeyCommand(input: "p", modifierFlags: [.control], action: #selector(moveCursorUp(_:)))
if #available(iOS 15.0, *) {
shiftTab.wantsPriorityOverSystemBehavior = true
}
shiftTab.wantsPriorityOverSystemBehavior = true

let controlN = UIKeyCommand(input: "n", modifierFlags: [.control], action: #selector(moveCursorDown(_:)))
if #available(iOS 15.0, *) {
shiftTab.wantsPriorityOverSystemBehavior = true
}
shiftTab.wantsPriorityOverSystemBehavior = true

let keys = [
shiftTab,
Expand Down
8 changes: 3 additions & 5 deletions Zavala/Editor/Tag/EditorTagInputTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ class EditorTagInputTextField: SearchTextField {

override var keyCommands: [UIKeyCommand]? {
let tab = UIKeyCommand(action: #selector(createTag), input: "\t")
tab.wantsPriorityOverSystemBehavior = true

let esc = UIKeyCommand(action: #selector(closeSuggestionList), input: UIKeyCommand.inputEscape)

if #available(iOS 15.0, *) {
tab.wantsPriorityOverSystemBehavior = true
esc.wantsPriorityOverSystemBehavior = true
}
esc.wantsPriorityOverSystemBehavior = true

return [tab, esc]
}
Expand Down

0 comments on commit 2c0394c

Please sign in to comment.