|
1 | | -// |
2 | | -// FavoritesNavigationAdapter.swift |
3 | | -// MiMiNavigator |
4 | | -// |
5 | | -// Created by Iakov Senatov on 17.01.2026. |
6 | | -// Copyright © 2026 Senatov. All rights reserved. |
7 | | -// |
8 | | -// Adapter to connect FavoritesKit with MiMiNavigator's AppState |
9 | | - |
10 | | -import FavoritesKit |
11 | | -import FileModelKit |
12 | | -import Foundation |
13 | | - |
14 | | -// MARK: - Adapter connecting FavoritesKit to AppState |
15 | | -@MainActor |
16 | | -final class FavoritesNavigationAdapter: FavoritesNavigationDelegate { |
17 | | - |
18 | | - private let appState: AppState |
19 | | - |
20 | | - init(appState: AppState) { |
21 | | - self.appState = appState |
22 | | - } |
| 1 | + // |
| 2 | + // FavoritesNavigationAdapter.swift |
| 3 | + // MiMiNavigator |
| 4 | + // |
| 5 | + // Created by Iakov Senatov on 17.01.2026. |
| 6 | + // Copyright © 2026 Senatov. All rights reserved. |
| 7 | + // |
| 8 | + // Adapter to connect FavoritesKit with MiMiNavigator's AppState |
| 9 | + |
| 10 | + import FavoritesKit |
| 11 | + import FileModelKit |
| 12 | + import Foundation |
| 13 | + |
| 14 | + // MARK: - Adapter connecting FavoritesKit to AppState |
| 15 | + @MainActor |
| 16 | + final class FavoritesNavigationAdapter: FavoritesNavigationDelegate { |
| 17 | + |
| 18 | + private let appState: AppState |
| 19 | + |
| 20 | + init(appState: AppState) { |
| 21 | + self.appState = appState |
| 22 | + } |
23 | 23 |
|
24 | | - // MARK: - FavoritesNavigationDelegate |
| 24 | + // MARK: - FavoritesNavigationDelegate |
25 | 25 |
|
26 | | - var focusedPanel: FavPanelSide { |
27 | | - appState.focusedPanel == .left ? .left : .right |
28 | | - } |
| 26 | + var focusedPanel: FavPanelSide { |
| 27 | + appState.focusedPanel == .left ? .left : .right |
| 28 | + } |
29 | 29 |
|
30 | | - func setFocusedPanel(_ panel: FavPanelSide) { |
31 | | - appState.focusedPanel = panel == .left ? .left : .right |
32 | | - } |
| 30 | + func setFocusedPanel(_ panel: FavPanelSide) { |
| 31 | + appState.focusedPanel = panel == .left ? .left : .right |
| 32 | + } |
33 | 33 |
|
34 | | - func navigate(to url: URL, panel: FavPanelSide) async { |
35 | | - let targetPanel: PanelSide = panel == .left ? .left : .right |
| 34 | + func navigate(to url: URL, panel: FavPanelSide) async { |
| 35 | + let targetPanel: PanelSide = panel == .left ? .left : .right |
36 | 36 |
|
37 | | - log.info("\(#function) url=\(url.path) panel=\(panel)") |
| 37 | + log.info("\(#function) url=\(url.path) panel=\(panel)") |
38 | 38 |
|
39 | | - // Update path |
40 | | - appState.updatePath(url.path, for: targetPanel) |
| 39 | + // Update path |
| 40 | + appState.updatePath(url.path, for: targetPanel) |
41 | 41 |
|
42 | | - // Update selectedDir for UI consistency |
43 | | - let file = CustomFile(name: url.lastPathComponent, path: url.path) |
44 | | - appState.selectedDir.selectedFSEntity = file |
| 42 | + // Update selectedDir for UI consistency |
| 43 | + let file = CustomFile(name: url.lastPathComponent, path: url.path) |
| 44 | + appState.selectedDir.selectedFSEntity = file |
45 | 45 |
|
46 | | - // Refresh files |
47 | | - await appState.scanner.resetRefreshTimer(for: targetPanel) |
48 | | - await appState.scanner.refreshFiles(currSide: targetPanel) |
49 | | - } |
| 46 | + // Refresh files |
| 47 | + await appState.scanner.resetRefreshTimer(for: targetPanel) |
| 48 | + await appState.scanner.refreshFiles(currSide: targetPanel) |
| 49 | + } |
50 | 50 |
|
51 | | - func navigateBack(panel: FavPanelSide) { |
52 | | - log.info("\(#function) panel=\(panel)") |
| 51 | + func navigateBack(panel: FavPanelSide) { |
| 52 | + log.info("\(#function) panel=\(panel)") |
53 | 53 |
|
54 | | - let targetPanel: PanelSide = panel == .left ? .left : .right |
55 | | - let history = appState.navigationHistory(for: targetPanel) |
| 54 | + let targetPanel: PanelSide = panel == .left ? .left : .right |
| 55 | + let history = appState.navigationHistory(for: targetPanel) |
56 | 56 |
|
57 | | - guard let path = history.goBack() else { |
58 | | - log.debug("\(#function) no history to go back to") |
59 | | - return |
60 | | - } |
| 57 | + guard let path = history.goBack() else { |
| 58 | + log.debug("\(#function) no history to go back to") |
| 59 | + return |
| 60 | + } |
61 | 61 |
|
62 | | - log.debug("\(#function) goBack returned path=\(path)") |
| 62 | + log.debug("\(#function) goBack returned path=\(path)") |
63 | 63 |
|
64 | | - Task { |
65 | | - appState.isNavigatingFromHistory = true |
66 | | - log.debug("\(#function) set isNavigatingFromHistory=true") |
67 | | - await navigate(to: URL(fileURLWithPath: path), panel: panel) |
68 | | - appState.isNavigatingFromHistory = false |
69 | | - log.debug("\(#function) set isNavigatingFromHistory=false") |
| 64 | + Task { |
| 65 | + appState.isNavigatingFromHistory = true |
| 66 | + log.debug("\(#function) set isNavigatingFromHistory=true") |
| 67 | + await navigate(to: path, panel: panel) |
| 68 | + appState.isNavigatingFromHistory = false |
| 69 | + log.debug("\(#function) set isNavigatingFromHistory=false") |
| 70 | + } |
70 | 71 | } |
71 | | - } |
72 | 72 |
|
73 | | - func navigateForward(panel: FavPanelSide) { |
74 | | - log.info("\(#function) panel=\(panel)") |
| 73 | + func navigateForward(panel: FavPanelSide) { |
| 74 | + log.info("\(#function) panel=\(panel)") |
75 | 75 |
|
76 | | - let targetPanel: PanelSide = panel == .left ? .left : .right |
77 | | - let history = appState.navigationHistory(for: targetPanel) |
| 76 | + let targetPanel: PanelSide = panel == .left ? .left : .right |
| 77 | + let history = appState.navigationHistory(for: targetPanel) |
78 | 78 |
|
79 | | - guard let path = history.goForward() else { |
80 | | - log.debug("\(#function) no history to go forward to") |
81 | | - return |
82 | | - } |
| 79 | + guard let path = history.goForward() else { |
| 80 | + log.debug("\(#function) no history to go forward to") |
| 81 | + return |
| 82 | + } |
83 | 83 |
|
84 | | - log.debug("\(#function) goForward returned path=\(path)") |
| 84 | + log.debug("\(#function) goForward returned path=\(path)") |
85 | 85 |
|
86 | | - Task { |
87 | | - appState.isNavigatingFromHistory = true |
88 | | - log.debug("\(#function) set isNavigatingFromHistory=true") |
89 | | - await navigate(to: URL(fileURLWithPath: path), panel: panel) |
90 | | - appState.isNavigatingFromHistory = false |
91 | | - log.debug("\(#function) set isNavigatingFromHistory=false") |
| 86 | + Task { |
| 87 | + appState.isNavigatingFromHistory = true |
| 88 | + log.debug("\(#function) set isNavigatingFromHistory=true") |
| 89 | + await navigate(to: path, panel: panel) |
| 90 | + appState.isNavigatingFromHistory = false |
| 91 | + log.debug("\(#function) set isNavigatingFromHistory=false") |
| 92 | + } |
92 | 93 | } |
93 | | - } |
94 | 94 |
|
95 | | - func navigateUp(panel: FavPanelSide) { |
96 | | - log.info("\(#function) panel=\(panel)") |
| 95 | + func navigateUp(panel: FavPanelSide) { |
| 96 | + log.info("\(#function) panel=\(panel)") |
97 | 97 |
|
98 | | - let currentPath = panel == .left ? appState.leftPath : appState.rightPath |
99 | | - let parentURL = URL(fileURLWithPath: currentPath).deletingLastPathComponent() |
| 98 | + let currentPath = panel == .left ? appState.leftPath : appState.rightPath |
| 99 | + let parentURL = URL(fileURLWithPath: currentPath).deletingLastPathComponent() |
100 | 100 |
|
101 | | - guard parentURL.path != currentPath else { |
102 | | - log.debug("\(#function) already at root") |
103 | | - return |
104 | | - } |
| 101 | + guard parentURL.path != currentPath else { |
| 102 | + log.debug("\(#function) already at root") |
| 103 | + return |
| 104 | + } |
105 | 105 |
|
106 | | - Task { |
107 | | - await navigate(to: parentURL, panel: panel) |
| 106 | + Task { |
| 107 | + await navigate(to: parentURL, panel: panel) |
| 108 | + } |
108 | 109 | } |
109 | | - } |
110 | 110 |
|
111 | | - func navigateToURL(_ url: URL, panel: FavoritesKit.FavPanelSide) async { |
112 | | - // Forward to the main navigation implementation |
113 | | - await navigate(to: url, panel: panel) |
114 | | - } |
| 111 | + func navigateToURL(_ url: URL, panel: FavoritesKit.FavPanelSide) async { |
| 112 | + // Forward to the main navigation implementation |
| 113 | + await navigate(to: url, panel: panel) |
| 114 | + } |
115 | 115 |
|
116 | | - func currentURL(for panel: FavoritesKit.FavPanelSide) -> URL { |
117 | | - // Convert AppState path to URL |
118 | | - let path = panel == .left ? appState.leftPath : appState.rightPath |
119 | | - return URL(fileURLWithPath: path) |
120 | | - } |
| 116 | + func currentURL(for panel: FavoritesKit.FavPanelSide) -> URL { |
| 117 | + // Convert AppState path to URL |
| 118 | + let path = panel == .left ? appState.leftPath : appState.rightPath |
| 119 | + return URL(fileURLWithPath: path) |
| 120 | + } |
121 | 121 |
|
122 | | - func canGoBack(panel: FavPanelSide) -> Bool { |
123 | | - let targetPanel: PanelSide = panel == .left ? .left : .right |
124 | | - return appState.navigationHistory(for: targetPanel).canGoBack |
125 | | - } |
| 122 | + func canGoBack(panel: FavPanelSide) -> Bool { |
| 123 | + let targetPanel: PanelSide = panel == .left ? .left : .right |
| 124 | + return appState.navigationHistory(for: targetPanel).canGoBack |
| 125 | + } |
126 | 126 |
|
127 | | - func canGoForward(panel: FavPanelSide) -> Bool { |
128 | | - let targetPanel: PanelSide = panel == .left ? .left : .right |
129 | | - return appState.navigationHistory(for: targetPanel).canGoForward |
130 | | - } |
| 127 | + func canGoForward(panel: FavPanelSide) -> Bool { |
| 128 | + let targetPanel: PanelSide = panel == .left ? .left : .right |
| 129 | + return appState.navigationHistory(for: targetPanel).canGoForward |
| 130 | + } |
131 | 131 |
|
132 | | - func currentPath(for panel: FavPanelSide) -> String { |
133 | | - panel == .left ? appState.leftPath : appState.rightPath |
| 132 | + func currentPath(for panel: FavPanelSide) -> String { |
| 133 | + panel == .left ? appState.leftPath : appState.rightPath |
| 134 | + } |
134 | 135 | } |
135 | | -} |
136 | 136 |
|
137 | | -// MARK: - Extension to convert between PanelSide and FavPanelSide |
138 | | -extension PanelSide { |
139 | | - var toFavPanelSide: FavPanelSide { |
140 | | - self == .left ? .left : .right |
141 | | - } |
| 137 | + // MARK: - Extension to convert between PanelSide and FavPanelSide |
| 138 | + extension PanelSide { |
| 139 | + var toFavPanelSide: FavPanelSide { |
| 140 | + self == .left ? .left : .right |
| 141 | + } |
142 | 142 |
|
143 | | - init(from favPanel: FavPanelSide) { |
144 | | - self = favPanel == .left ? .left : .right |
| 143 | + init(from favPanel: FavPanelSide) { |
| 144 | + self = favPanel == .left ? .left : .right |
| 145 | + } |
145 | 146 | } |
146 | | -} |
0 commit comments