| | |
| | | var editingBubble: AppBubbleContext? = nil |
| | | var pendingUncategorizedDrop: PendingUncategorizedDrop? = nil |
| | | var pendingTagRemovalDrop: PendingTagRemovalDrop? = nil |
| | | var uncategorizedDropSuppressFuturePrompt = false |
| | | var tagRemovalDropSuppressFuturePrompt = false |
| | | var appDragResetToken = 0 |
| | | var bubbleDraftNote = "" |
| | | var tagNavigationHoveredGroupName: String? = nil |
| | | var tagNavigationAppDropTargetName: String? = nil |
| | | var tagNavigationLastHoverScrollID: String? = nil |
| | | var tagNavigationLastHoverScrollAt: Date? = nil |
| | | } |
| | |
| | | @State private var quickSearchFocusToken = 0 |
| | | @State private var quickSearchSelectionScrollToken = 0 |
| | | @State private var quickSearchCloseHidesOverlay = false |
| | | @State private var quickSearchOnlySession = false |
| | | @State private var quickSearchErrorMessage: String? = nil |
| | | @State private var initialQuickSearchConsumed = false |
| | | |
| | |
| | | self.hideOverlay = hideOverlay |
| | | self.initialQuickSearchSource = initialQuickSearchSource |
| | | let startsInQuickSearch = initialQuickSearchSource != nil |
| | | let startsInQuickSearchOnlySession = initialQuickSearchSource == QuickSearchOpenSource.globalHidden |
| | | _quickSearchVisible = State(initialValue: startsInQuickSearch) |
| | | _quickSearchCloseHidesOverlay = State(initialValue: initialQuickSearchSource == QuickSearchOpenSource.globalHidden) |
| | | _quickSearchCloseHidesOverlay = State(initialValue: startsInQuickSearchOnlySession) |
| | | _quickSearchOnlySession = State(initialValue: startsInQuickSearchOnlySession) |
| | | _quickSearchFocusToken = State(initialValue: startsInQuickSearch ? 1 : 0) |
| | | } |
| | | |
| | |
| | | @AppStorage("showUncommonAppBubbles") private var showUncommonAppBubbles = AppDefaults.showUncommonAppBubbles |
| | | @AppStorage("useAppKitTagNavigation") private var useAppKitTagNavigation = AppDefaults.useAppKitTagNavigation |
| | | @AppStorage("skipTagRemovalDropConfirm") private var skipTagRemovalDropConfirm = false |
| | | @AppStorage("skipUncategorizedDropConfirm") private var skipUncategorizedDropConfirm = false |
| | | |
| | | private let editSidebarWidth: CGFloat = 188 |
| | | private let editSidebarHorizontalInset: CGFloat = 12 |
| | |
| | | } |
| | | |
| | | private var shouldRenderAppGridBehindQuickSearch: Bool { |
| | | !quickSearchVisible || !quickSearchCloseHidesOverlay |
| | | if quickSearchOnlySession { |
| | | return false |
| | | } |
| | | return !quickSearchVisible || !quickSearchCloseHidesOverlay |
| | | } |
| | | |
| | | var body: some View { |
| | |
| | | refreshAppsIfNeeded() |
| | | if let initialQuickSearchSource, !initialQuickSearchConsumed { |
| | | initialQuickSearchConsumed = true |
| | | quickSearchCloseHidesOverlay = initialQuickSearchSource == QuickSearchOpenSource.globalHidden |
| | | if initialQuickSearchSource == QuickSearchOpenSource.globalHidden { |
| | | quickSearchCloseHidesOverlay = true |
| | | quickSearchOnlySession = true |
| | | } |
| | | if !quickSearchVisible { |
| | | quickSearchVisible = true |
| | | quickSearchFocusToken &+= 1 |
| | |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | | userInfo: ["active": true] |
| | | userInfo: [ |
| | | "active": true, |
| | | "hideOverlayOnClose": quickSearchCloseHidesOverlay |
| | | ] |
| | | ) |
| | | } |
| | | } |
| | |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherOverlayDidHide)) { _ in |
| | | resetTransientDragState() |
| | | closeQuickSearch(notify: true, hideOverlayIfNeeded: false) |
| | | quickSearchOnlySession = false |
| | | quickSearchCloseHidesOverlay = false |
| | | } |
| | | .onReceive(NotificationCenter.default.publisher(for: .tagLauncherQuickSearchRequested)) { notification in |
| | | let source = notification.userInfo?["source"] as? String ?? QuickSearchOpenSource.mainOverlay |
| | |
| | | private func openQuickSearch(source: String) { |
| | | guard canOpenQuickSearch else { return } |
| | | dismissAppBubble() |
| | | quickSearchCloseHidesOverlay = source == QuickSearchOpenSource.globalHidden |
| | | if source == QuickSearchOpenSource.globalHidden { |
| | | quickSearchOnlySession = true |
| | | } |
| | | quickSearchCloseHidesOverlay = quickSearchCloseHidesOverlay |
| | | || source == QuickSearchOpenSource.globalHidden |
| | | quickSearchVisible = true |
| | | quickSearchQuery = "" |
| | | quickSearchManualSelection = false |
| | |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | | userInfo: ["active": true] |
| | | userInfo: [ |
| | | "active": true, |
| | | "hideOverlayOnClose": quickSearchCloseHidesOverlay |
| | | ] |
| | | ) |
| | | } |
| | | |
| | |
| | | quickSearchSelectedID = nil |
| | | quickSearchManualSelection = false |
| | | quickSearchErrorMessage = nil |
| | | quickSearchCloseHidesOverlay = false |
| | | if notify { |
| | | NotificationCenter.default.post( |
| | | name: .tagLauncherQuickSearchVisibilityChanged, |
| | | object: nil, |
| | | userInfo: ["active": false] |
| | | userInfo: [ |
| | | "active": false, |
| | | "hideOverlayOnClose": shouldHideOverlay |
| | | ] |
| | | ) |
| | | } |
| | | if shouldHideOverlay { |
| | | hideOverlay() |
| | | } else { |
| | | quickSearchCloseHidesOverlay = false |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | private func appKitTagNavigation(orientation: TagNavigationView.Orientation) -> some View { |
| | | let isHorizontal = orientation == .horizontal |
| | | let appDropTargetID = appGridInteraction.tagNavigationAppDropTargetName |
| | | return TagNavigationView( |
| | | items: tagLabels, |
| | | orientation: orientation, |
| | |
| | | : NSEdgeInsets(top: 12, left: 12, bottom: 12, right: 12), |
| | | dragModeActive: tagNavDragModeActive, |
| | | draggingItemID: tagNavDragItem, |
| | | appDragModeActive: appGridInteraction.appDragModeActive, |
| | | appDropTargetID: appDropTargetID, |
| | | onActivate: { tagID in |
| | | activateTagNavigation(tagID) |
| | | }, |
| | |
| | | canReorder: { tagID in |
| | | canReorderTag(tagID) |
| | | }, |
| | | canAcceptAppDrop: { tagID in |
| | | canAssignDroppedAppToTag(tagID) |
| | | }, |
| | | onReorderBegan: { tagID in |
| | | beginTagNavReorder(tagID) |
| | | }, |
| | |
| | | }, |
| | | onReorderEnded: { |
| | | endTagNavReorder() |
| | | }, |
| | | onAppDropHoverChange: { tagID, active in |
| | | handleTagNavigationAppDropHover(tagID, active: active) |
| | | }, |
| | | onAppDrop: { path, source, targetTag, copy in |
| | | dropAppOnTagNavigation(path: path, sourceTag: source, targetTag: targetTag, copy: copy) |
| | | } |
| | | ) |
| | | } |
| | |
| | | UncategorizedDropConfirmBubble( |
| | | title: tr("drop.uncategorizedConfirmTitle"), |
| | | message: uncategorizedConfirmMessage(for: pendingDrop), |
| | | doNotRemindTitle: tr("drop.removeTagDoNotAskAgain"), |
| | | doNotRemind: $appGridInteraction.uncategorizedDropSuppressFuturePrompt, |
| | | cancelTitle: tr("tag.cancel"), |
| | | confirmTitle: tr("edit.confirm"), |
| | | onCancel: dismissUncategorizedDropConfirm, |
| | |
| | | } |
| | | |
| | | private func handleAppGridScrollActivity() { |
| | | appGridInteraction.hoveredBubble = nil |
| | | if appGridInteraction.hoveredBubble != nil { |
| | | appGridInteraction.hoveredBubble = nil |
| | | } |
| | | } |
| | | |
| | | private func handleBubbleHover(app: AppInfo, frame: CGRect, event: AppBubbleHoverEvent) { |
| | |
| | | } |
| | | |
| | | private func handleTagNavigationHover(_ id: String, active: Bool) { |
| | | if appGridInteraction.appDragModeActive { |
| | | if !active, appGridInteraction.tagNavigationHoveredGroupName == id { |
| | | appGridInteraction.tagNavigationHoveredGroupName = nil |
| | | } |
| | | return |
| | | } |
| | | |
| | | guard active else { |
| | | if appGridInteraction.tagNavigationHoveredGroupName == id { |
| | | appGridInteraction.tagNavigationHoveredGroupName = nil |
| | |
| | | appGridInteraction.tagNavigationHoveredGroupName = id |
| | | fillColorlessContainer(id) |
| | | scrollToTagFromHover(id) |
| | | } |
| | | |
| | | private func handleTagNavigationAppDropHover(_ id: String, active: Bool) { |
| | | guard appGridInteraction.appDragModeActive else { |
| | | if appGridInteraction.tagNavigationAppDropTargetName == id { |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | return |
| | | } |
| | | |
| | | guard active, canAssignDroppedAppToTag(id) else { |
| | | if appGridInteraction.tagNavigationAppDropTargetName == id { |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | return |
| | | } |
| | | |
| | | appGridInteraction.tagNavigationAppDropTargetName = id |
| | | } |
| | | |
| | | private func scrollToTagFromHover(_ id: String) { |
| | |
| | | refreshApps(forceLayoutRefresh: true) |
| | | } |
| | | |
| | | private func dropAppOnTagNavigation(path: String, sourceTag: String, targetTag: String, copy: Bool) { |
| | | resetTransientDragState() |
| | | guard canAssignDroppedAppToTag(targetTag) else { return } |
| | | guard let app = allApps.first(where: { $0.path.path == path }) else { return } |
| | | guard !appHasTag(app, tagName: targetTag) else { return } |
| | | TagEditor.appendTags([targetTag], to: [path]) |
| | | showDropRefresh() |
| | | refreshApps(forceLayoutRefresh: true) |
| | | } |
| | | |
| | | private func canAssignDroppedAppToTag(_ tagName: String) -> Bool { |
| | | tagColors[tagName] != nil |
| | | && !isAppleBuiltInDropTarget(tagName) |
| | | && !isUncategorizedDropTarget(tagName) |
| | | } |
| | | |
| | | private func dropAppOutsideGroup(path: String, sourceTag: String, copy: Bool) { |
| | | resetTransientDragState(keepingPendingTagRemovalDrop: true) |
| | | guard isRemovableRegularTag(sourceTag) else { return } |
| | |
| | | guard !removableTags.isEmpty else { return } |
| | | let assignedTags = assignedRegularDisplayTags(for: removableTags) |
| | | |
| | | if skipUncategorizedDropConfirm { |
| | | moveDroppedAppToUncategorized(path: app.path.path, tags: removableTags) |
| | | return |
| | | } |
| | | |
| | | clearAppBubbleState() |
| | | appGridInteraction.uncategorizedDropSuppressFuturePrompt = false |
| | | withAnimation(.spring(response: 0.24, dampingFraction: 0.84)) { |
| | | appGridInteraction.pendingUncategorizedDrop = PendingUncategorizedDrop( |
| | | app: app, |
| | |
| | | } |
| | | |
| | | private func dismissUncategorizedDropConfirm() { |
| | | appGridInteraction.uncategorizedDropSuppressFuturePrompt = false |
| | | resetTransientDragState(keepingPendingUncategorizedDrop: true) |
| | | withAnimation(.easeOut(duration: 0.18)) { |
| | | appGridInteraction.pendingUncategorizedDrop = nil |
| | |
| | | guard let pendingDrop = appGridInteraction.pendingUncategorizedDrop else { return } |
| | | let path = pendingDrop.app.path.path |
| | | let tags = pendingDrop.removableTags |
| | | let shouldSuppressFuturePrompt = appGridInteraction.uncategorizedDropSuppressFuturePrompt |
| | | if shouldSuppressFuturePrompt { |
| | | skipUncategorizedDropConfirm = true |
| | | } |
| | | appGridInteraction.uncategorizedDropSuppressFuturePrompt = false |
| | | resetTransientDragState(keepingPendingUncategorizedDrop: true) |
| | | withAnimation(.easeOut(duration: 0.16)) { |
| | | appGridInteraction.pendingUncategorizedDrop = nil |
| | | } |
| | | moveDroppedAppToUncategorized(path: path, tags: tags) |
| | | } |
| | | |
| | | private func moveDroppedAppToUncategorized(path: String, tags: [String]) { |
| | | guard !tags.isEmpty else { return } |
| | | TagEditor.removeTags(tags, from: [path]) |
| | | showDropRefresh() |
| | |
| | | if active { |
| | | endTagNavReorder() |
| | | clearAppBubbleState() |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | appGridInteraction.appDragModeActive = active |
| | | if !active { |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | if active { |
| | | DispatchQueue.main.asyncAfter(deadline: .now() + 8) { |
| | | if appGridInteraction.appDragModeActive && !AppDragCoordinator.shared.hasActiveDrag { |
| | | appGridInteraction.appDragModeActive = false |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | } |
| | | } |
| | |
| | | AppDragCoordinator.shared.cancelDrag() |
| | | if appGridInteraction.appDragModeActive { |
| | | appGridInteraction.appDragModeActive = false |
| | | } |
| | | if appGridInteraction.tagNavigationAppDropTargetName != nil { |
| | | appGridInteraction.tagNavigationAppDropTargetName = nil |
| | | } |
| | | if hadAppDragState { |
| | | appGridInteraction.appDragResetToken &+= 1 |
| | |
| | | ) { |
| | | appGridInteraction.appDragModeActive = false |
| | | endTagNavReorder() |
| | | let closeQuickSearchAndOverlayBeforeOpening = closeQuickSearchOnSuccess |
| | | && closeOverlayOnSuccess |
| | | && (quickSearchCloseHidesOverlay || quickSearchOnlySession) |
| | | if closeQuickSearchAndOverlayBeforeOpening { |
| | | closeQuickSearch(hideOverlayIfNeeded: true) |
| | | hideOverlay() |
| | | } |
| | | let configuration = NSWorkspace.OpenConfiguration() |
| | | NSWorkspace.shared.openApplication(at: app.path, configuration: configuration) { _, error in |
| | | DispatchQueue.main.async { |
| | |
| | | DispatchQueue.global(qos: .utility).async { |
| | | TagEditor.recordLauncherOpen(for: app.path.path) |
| | | } |
| | | if closeQuickSearchOnSuccess { |
| | | closeQuickSearch(hideOverlayIfNeeded: false) |
| | | if closeQuickSearchOnSuccess && !closeQuickSearchAndOverlayBeforeOpening { |
| | | closeQuickSearch(hideOverlayIfNeeded: closeOverlayOnSuccess) |
| | | } |
| | | if closeOverlayOnSuccess { |
| | | if closeOverlayOnSuccess && !closeQuickSearchAndOverlayBeforeOpening { |
| | | hideOverlay() |
| | | } |
| | | } |