From 7998908ad0579cb41564b40b18bb09ad0765ceaa Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 6 Jan 2024 11:53:29 -0600 Subject: [PATCH] Restructure code to make it more clear how operations are being used --- Zavala.xcodeproj/project.pbxproj | 22 +++++++++++++------ .../CollectionsViewController.swift | 2 +- .../Operations}/ApplySnapshotOperation.swift | 0 .../Operations}/ReloadItemsOperation.swift | 0 .../ReloadVisibleItemsOperation.swift | 0 .../UpdateItemSelectionOperation.swift} | 4 ++-- .../Documents/DocumentsViewController.swift | 1 + 7 files changed, 19 insertions(+), 10 deletions(-) rename Zavala/{Utility => Collections/Operations}/ApplySnapshotOperation.swift (100%) rename Zavala/{Utility => Collections/Operations}/ReloadItemsOperation.swift (100%) rename Zavala/{Utility => Collections/Operations}/ReloadVisibleItemsOperation.swift (100%) rename Zavala/{Utility/UpdateSelectionOperation.swift => Collections/Operations/UpdateItemSelectionOperation.swift} (92%) diff --git a/Zavala.xcodeproj/project.pbxproj b/Zavala.xcodeproj/project.pbxproj index 1695d00f..7b9dfb3f 100644 --- a/Zavala.xcodeproj/project.pbxproj +++ b/Zavala.xcodeproj/project.pbxproj @@ -154,7 +154,7 @@ 51E060EE25A4B5E600194066 /* AppKitWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E060ED25A4B5E600194066 /* AppKitWrapper.swift */; }; 51E14F23255F2D7F00320EDB /* ActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E14F22255F2D7F00320EDB /* ActivityManager.swift */; }; 51E14F342560732F00320EDB /* CollectionsItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E14F332560732F00320EDB /* CollectionsItem.swift */; }; - 51E14F382560738E00320EDB /* UpdateSelectionOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E14F372560738E00320EDB /* UpdateSelectionOperation.swift */; }; + 51E14F382560738E00320EDB /* UpdateItemSelectionOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E14F372560738E00320EDB /* UpdateItemSelectionOperation.swift */; }; 51E14F3C256073D100320EDB /* ApplySnapshotOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E14F3B256073D100320EDB /* ApplySnapshotOperation.swift */; }; 51E2BCBD290EFB15002BA7B2 /* AppKitImageAssets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5162AFF928EFB5C00002A61C /* AppKitImageAssets.swift */; }; 51E5C48F27221F6200A38983 /* IntentOutline+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E5C48E27221F6200A38983 /* IntentOutline+.swift */; }; @@ -381,7 +381,7 @@ 51E060F325A4C13B00194066 /* AppKitPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppKitPlugin.h; sourceTree = ""; }; 51E14F22255F2D7F00320EDB /* ActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityManager.swift; sourceTree = ""; }; 51E14F332560732F00320EDB /* CollectionsItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionsItem.swift; sourceTree = ""; }; - 51E14F372560738E00320EDB /* UpdateSelectionOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateSelectionOperation.swift; sourceTree = ""; }; + 51E14F372560738E00320EDB /* UpdateItemSelectionOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateItemSelectionOperation.swift; sourceTree = ""; }; 51E14F3B256073D100320EDB /* ApplySnapshotOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplySnapshotOperation.swift; sourceTree = ""; }; 51E5C48E27221F6200A38983 /* IntentOutline+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IntentOutline+.swift"; sourceTree = ""; }; 51E5C49027221F6F00A38983 /* IntentRow+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IntentRow+.swift"; sourceTree = ""; }; @@ -441,7 +441,6 @@ 514BB9D5255B595300C8DBDF /* Utility */ = { isa = PBXGroup; children = ( - 51E14F3B256073D100320EDB /* ApplySnapshotOperation.swift */, 5116893F29BD72DE00318832 /* AttributedLabelView.swift */, 519897C32ADE13F3008A6FA4 /* ButtonGroup.swift */, 518F2E37257AEA4C00D05D99 /* ConsistentCollectionViewListCell.swift */, @@ -455,8 +454,6 @@ 5113B08C260C1F1700DBD11B /* OutlineFontCache.swift */, 511D9C7C25F6E5D300CC6C00 /* OutlineLayoutManager.swift */, 51C568CD258B028700AA7B93 /* OutlineTextDropDelegate.swift */, - 51C030AB257E0A7200609262 /* ReloadItemsOperation.swift */, - 51F83B852725BFF30015FC06 /* ReloadVisibleItemsOperation.swift */, 5163ADF125C78CFB008F25CA /* SearchTextField.swift */, 51DFDC17259EA8D300C068C6 /* Selector+.swift */, 51AC0A8D25741CF5003A7532 /* StackedUndoManager.swift */, @@ -468,7 +465,6 @@ 5177B7B32733D0AA006EB1E3 /* UITextInput+.swift */, 519184F227107FDA00B7E177 /* UITextView+.swift */, 51DEE82726FF951E006DAA56 /* UIWindowSceneDelegate+.swift */, - 51E14F372560738E00320EDB /* UpdateSelectionOperation.swift */, 511EC2C62B409A5B002D89A5 /* ValueStepper.swift */, ); path = Utility; @@ -776,6 +772,7 @@ 51DAEC252739838E00BE4A13 /* CollectionsViewController+Drag.swift */, 5147D0C425CCD6AA004673C3 /* CollectionsViewController+Drop.swift */, 51F2859D25AD12860019C573 /* Search */, + 51E508D82B49CAA90041B826 /* Operations */, ); path = Collections; sourceTree = ""; @@ -809,6 +806,17 @@ path = Editor; sourceTree = ""; }; + 51E508D82B49CAA90041B826 /* Operations */ = { + isa = PBXGroup; + children = ( + 51E14F3B256073D100320EDB /* ApplySnapshotOperation.swift */, + 51C030AB257E0A7200609262 /* ReloadItemsOperation.swift */, + 51F83B852725BFF30015FC06 /* ReloadVisibleItemsOperation.swift */, + 51E14F372560738E00320EDB /* UpdateItemSelectionOperation.swift */, + ); + path = Operations; + sourceTree = ""; + }; 51F13F01255E13D1004B85CA /* Dialogs */ = { isa = PBXGroup; children = ( @@ -1099,7 +1107,7 @@ 51A1EC422723246C00463A15 /* EditRowsIntentHandler.swift in Sources */, 5181A93C2554D92000C153E8 /* CollectionsViewController.swift in Sources */, 51D460FA2729E30C0024EC48 /* MetadataTextAttachmentViewProvider.swift in Sources */, - 51E14F382560738E00320EDB /* UpdateSelectionOperation.swift in Sources */, + 51E14F382560738E00320EDB /* UpdateItemSelectionOperation.swift in Sources */, 51AEEC8D2703E6EB00354C59 /* Intents.intentdefinition in Sources */, 516F5373260829060038BAF8 /* OutlineFontDefaults.swift in Sources */, 51341E04272B55080005425B /* InsetLabel.swift in Sources */, diff --git a/Zavala/Collections/CollectionsViewController.swift b/Zavala/Collections/CollectionsViewController.swift index 85771a40..e3da6c16 100644 --- a/Zavala/Collections/CollectionsViewController.swift +++ b/Zavala/Collections/CollectionsViewController.swift @@ -441,7 +441,7 @@ extension CollectionsViewController { func updateSelections(_ containers: [DocumentContainer]?, isNavigationBranch: Bool, animated: Bool, completion: (() -> Void)?) { let items = containers?.map { CollectionsItem.item($0) } ?? [CollectionsItem]() - collectionViewQueue.add(UpdateSelectionOperation(dataSource: dataSource, collectionView: collectionView, items: items, animated: animated)) + collectionViewQueue.add(UpdateItemSelectionOperation(dataSource: dataSource, collectionView: collectionView, items: items, animated: animated)) let containers = items.toContainers() delegate?.documentContainerSelectionsDidChange(self, documentContainers: containers, isNavigationBranch: isNavigationBranch, animated: animated, completion: completion) diff --git a/Zavala/Utility/ApplySnapshotOperation.swift b/Zavala/Collections/Operations/ApplySnapshotOperation.swift similarity index 100% rename from Zavala/Utility/ApplySnapshotOperation.swift rename to Zavala/Collections/Operations/ApplySnapshotOperation.swift diff --git a/Zavala/Utility/ReloadItemsOperation.swift b/Zavala/Collections/Operations/ReloadItemsOperation.swift similarity index 100% rename from Zavala/Utility/ReloadItemsOperation.swift rename to Zavala/Collections/Operations/ReloadItemsOperation.swift diff --git a/Zavala/Utility/ReloadVisibleItemsOperation.swift b/Zavala/Collections/Operations/ReloadVisibleItemsOperation.swift similarity index 100% rename from Zavala/Utility/ReloadVisibleItemsOperation.swift rename to Zavala/Collections/Operations/ReloadVisibleItemsOperation.swift diff --git a/Zavala/Utility/UpdateSelectionOperation.swift b/Zavala/Collections/Operations/UpdateItemSelectionOperation.swift similarity index 92% rename from Zavala/Utility/UpdateSelectionOperation.swift rename to Zavala/Collections/Operations/UpdateItemSelectionOperation.swift index f4ba1919..ee6d760e 100644 --- a/Zavala/Utility/UpdateSelectionOperation.swift +++ b/Zavala/Collections/Operations/UpdateItemSelectionOperation.swift @@ -1,5 +1,5 @@ // -// UpdateSelectionOperation.swift +// UpdateItemSelectionOperation.swift // Zavala // // Created by Maurice Parker on 11/14/20. @@ -8,7 +8,7 @@ import UIKit import VinUtility -class UpdateSelectionOperation: BaseMainThreadOperation { +class UpdateItemSelectionOperation: BaseMainThreadOperation { private var dataSource: UICollectionViewDiffableDataSource private var collectionView: UICollectionView diff --git a/Zavala/Documents/DocumentsViewController.swift b/Zavala/Documents/DocumentsViewController.swift index 59a077df..bf7f8407 100644 --- a/Zavala/Documents/DocumentsViewController.swift +++ b/Zavala/Documents/DocumentsViewController.swift @@ -47,6 +47,7 @@ class DocumentsViewController: UICollectionViewController, MainControllerIdentif private var addButton: UIButton! private var importButton: UIButton! + private let collectionViewQueue = MainThreadOperationQueue() private var loadDocumentsDebouncer = Debouncer(duration: 0.5) private var lastClick: TimeInterval = Date().timeIntervalSince1970