From df43b9ff7fd9a1a4319b1d14e1110ee0f28a245a Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sun, 19 Feb 2023 23:36:09 +0300 Subject: [PATCH] Copy by double tap --- AutoCat.xcodeproj/project.pbxproj | 4 ++ .../Extensions/GestureRecognizers.swift | 42 +++++++++++++++++++ AutoCat/AppDelegate.swift | 4 ++ AutoCat/Controllers/NewNumberController.swift | 4 ++ AutoCat/Controllers/ReportController.swift | 16 +++++++ 5 files changed, 70 insertions(+) create mode 100644 AutoCat/ACUIKit/Extensions/GestureRecognizers.swift diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 44b6ee0..536e4d6 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 7A8A220B248D67B60073DFD9 /* VehicleReportImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A8A220A248D67B60073DFD9 /* VehicleReportImage.swift */; }; 7A8AB76525A0DB8F00ECF2C1 /* BundleVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A8AB76425A0DB8F00ECF2C1 /* BundleVersion.swift */; }; 7A8AB76B25A1D95500ECF2C1 /* SourceStatusRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A8AB76A25A1D95500ECF2C1 /* SourceStatusRow.swift */; }; + 7A91894F29A2BD8700519C74 /* GestureRecognizers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A91894E29A2BD8700519C74 /* GestureRecognizers.swift */; }; 7A96AE2D246B2B7400297C33 /* GoogleSignInController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A96AE2C246B2B7400297C33 /* GoogleSignInController.swift */; }; 7A96AE2F246B2BCD00297C33 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A96AE2E246B2BCD00297C33 /* WebKit.framework */; }; 7A99406426E4BFAE002E9CB6 /* VehicleNoteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A99406326E4BFAE002E9CB6 /* VehicleNoteCell.swift */; }; @@ -250,6 +251,7 @@ 7A8AB76425A0DB8F00ECF2C1 /* BundleVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleVersion.swift; sourceTree = ""; }; 7A8AB76725A0DC8200ECF2C1 /* DebugInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugInfo.swift; sourceTree = ""; }; 7A8AB76A25A1D95500ECF2C1 /* SourceStatusRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceStatusRow.swift; sourceTree = ""; }; + 7A91894E29A2BD8700519C74 /* GestureRecognizers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GestureRecognizers.swift; sourceTree = ""; }; 7A92D0AB240425B100EF3B77 /* ATGMediaBrowser.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ATGMediaBrowser.framework; path = Carthage/Build/iOS/ATGMediaBrowser.framework; sourceTree = ""; }; 7A96AE2C246B2B7400297C33 /* GoogleSignInController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleSignInController.swift; sourceTree = ""; }; 7A96AE2E246B2BCD00297C33 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; }; @@ -604,6 +606,7 @@ 7AC3555129696E3F00889457 /* UIView+layout.swift */, 7AC355582969746600889457 /* UIControl.swift */, 7AC3555A296995B200889457 /* UIEdgeInsets.swift */, + 7A91894E29A2BD8700519C74 /* GestureRecognizers.swift */, ); path = Extensions; sourceTree = ""; @@ -900,6 +903,7 @@ 7A8A220B248D67B60073DFD9 /* VehicleReportImage.swift in Sources */, 7AC3555B296995B200889457 /* UIEdgeInsets.swift in Sources */, 7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */, + 7A91894F29A2BD8700519C74 /* GestureRecognizers.swift in Sources */, 7A27ADC7249D43210035F39E /* RegionsController.swift in Sources */, 7AE492A1259232F000322D2E /* MultilineLinkRow.swift in Sources */, 7ADF6C93250B954900F237B2 /* Navigation.swift in Sources */, diff --git a/AutoCat/ACUIKit/Extensions/GestureRecognizers.swift b/AutoCat/ACUIKit/Extensions/GestureRecognizers.swift new file mode 100644 index 0000000..75e03f6 --- /dev/null +++ b/AutoCat/ACUIKit/Extensions/GestureRecognizers.swift @@ -0,0 +1,42 @@ +// +// GestureRecognizers.swift +// AutoCat +// +// Created by Selim Mustafaev on 19.02.2023. +// Copyright © 2023 Selim Mustafaev. All rights reserved. +// + +import UIKit + +extension UIGestureRecognizer { + + typealias Action = ((UIGestureRecognizer) -> ()) + + private struct Keys { + static var actionKey = "ActionKey" + } + + private var block: Action? { + set { + if let newValue = newValue { + // Computed properties get stored as associated objects + objc_setAssociatedObject(self, &Keys.actionKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) + } + } + + get { + let action = objc_getAssociatedObject(self, &Keys.actionKey) as? Action + return action + } + } + + @objc func handleAction(recognizer: UIGestureRecognizer) { + block?(recognizer) + } + + convenience public init(block: @escaping ((UIGestureRecognizer) -> ())) { + self.init() + self.block = block + self.addTarget(self, action: #selector(handleAction(recognizer:))) + } +} diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index 0e35db4..bed0ee2 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -195,6 +195,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: - Global menu + #if targetEnvironment(macCatalyst) + override func buildMenu(with builder: UIMenuBuilder) { super.buildMenu(with: builder) @@ -213,5 +215,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { sceneDelegate.showAddNumberPanel() } + + #endif } diff --git a/AutoCat/Controllers/NewNumberController.swift b/AutoCat/Controllers/NewNumberController.swift index a5cbfea..36271d1 100644 --- a/AutoCat/Controllers/NewNumberController.swift +++ b/AutoCat/Controllers/NewNumberController.swift @@ -60,7 +60,11 @@ class NewNumberController: UIViewController { view.addSubview(mainStackView) mainStackView.pin(to: view, insets: .all(16)) + #if targetEnvironment(macCatalyst) + addKeyCommand(UIKeyCommand(input: "v", modifierFlags: .command, action: #selector(pasteText))) + + #endif } func check() { diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 4460128..fc50335 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -147,6 +147,22 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource <<< SourceStatusRow("DebugVin01History") { $0.title = NSLocalizedString("Vin01 (history)", comment: "GIBDD registration history") } <<< SourceStatusRow("DebugNomerogram") { $0.title = NSLocalizedString("Nomerogram", comment: "") } } + + setupCopyBehaviour() + } + + func setupCopyBehaviour() { + + for row in form.allRows { + if let labelRow = row as? LabelRow { + let doubleTap = UITapGestureRecognizer { _ in + UIPasteboard.general.string = labelRow.value + } + + doubleTap.numberOfTapsRequired = 2 + labelRow.cell.addGestureRecognizer(doubleTap) + } + } } func update(row tag: String, with value: String) {