Skip to content

Commit 5a17c8b

Browse files
authored
Merge pull request #999 from bummoblizard/uikit-filetree
Re-write file tree in UIKit
2 parents 9196d21 + b02e78b commit 5a17c8b

File tree

11 files changed

+1344
-427
lines changed

11 files changed

+1344
-427
lines changed

Code.xcodeproj/project.pbxproj

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@
692692
9F046C3B29223D1600BDE4E9 /* RemoteExecutionExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F046C3929223D1600BDE4E9 /* RemoteExecutionExtension.swift */; };
693693
9F046C3D29223E1500BDE4E9 /* CodeAppExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F046C3C29223E1500BDE4E9 /* CodeAppExtension.swift */; };
694694
9F046C3E29223E1500BDE4E9 /* CodeAppExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F046C3C29223E1500BDE4E9 /* CodeAppExtension.swift */; };
695+
9F062FE32B58D3F4006210AA /* FileTreeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE22B58D3F4006210AA /* FileTreeView.swift */; };
696+
9F062FE42B58D3F4006210AA /* FileTreeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE22B58D3F4006210AA /* FileTreeView.swift */; };
697+
9F062FE62B58D40D006210AA /* FileTreeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE52B58D40D006210AA /* FileTreeViewController.swift */; };
698+
9F062FE72B58D40D006210AA /* FileTreeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE52B58D40D006210AA /* FileTreeViewController.swift */; };
699+
9F062FE92B58D416006210AA /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE82B58D416006210AA /* TableView.swift */; };
700+
9F062FEA2B58D416006210AA /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F062FE82B58D416006210AA /* TableView.swift */; };
695701
9F170D012A89CEB800D6D7C1 /* String+throwingRemovingPercentEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F170D002A89CEB800D6D7C1 /* String+throwingRemovingPercentEncoding.swift */; };
696702
9F170D022A89CEB800D6D7C1 /* String+throwingRemovingPercentEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F170D002A89CEB800D6D7C1 /* String+throwingRemovingPercentEncoding.swift */; };
697703
9F170D042A89F88D00D6D7C1 /* RegularSidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F170D032A89F88D00D6D7C1 /* RegularSidebar.swift */; };
@@ -1816,6 +1822,9 @@
18161822
9F046C3429222D8E00BDE4E9 /* ExtensionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionManager.swift; sourceTree = "<group>"; };
18171823
9F046C3929223D1600BDE4E9 /* RemoteExecutionExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteExecutionExtension.swift; sourceTree = "<group>"; };
18181824
9F046C3C29223E1500BDE4E9 /* CodeAppExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeAppExtension.swift; sourceTree = "<group>"; };
1825+
9F062FE22B58D3F4006210AA /* FileTreeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTreeView.swift; sourceTree = "<group>"; };
1826+
9F062FE52B58D40D006210AA /* FileTreeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTreeViewController.swift; sourceTree = "<group>"; };
1827+
9F062FE82B58D416006210AA /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
18191828
9F170D002A89CEB800D6D7C1 /* String+throwingRemovingPercentEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+throwingRemovingPercentEncoding.swift"; sourceTree = "<group>"; };
18201829
9F170D032A89F88D00D6D7C1 /* RegularSidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegularSidebar.swift; sourceTree = "<group>"; };
18211830
9F29759B2A1F488E007FDB3D /* deferredRendering.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = deferredRendering.swift; sourceTree = "<group>"; };
@@ -2725,6 +2734,8 @@
27252734
9FD5BCF32927859600F20C4B /* DebugMenu.swift */,
27262735
9F170D032A89F88D00D6D7C1 /* RegularSidebar.swift */,
27272736
9FA939DC2A9317F800C239BF /* SourceControlTextFieldAlert.swift */,
2737+
9F062FE22B58D3F4006210AA /* FileTreeView.swift */,
2738+
9F062FE82B58D416006210AA /* TableView.swift */,
27282739
);
27292740
path = Views;
27302741
sourceTree = "<group>";
@@ -2868,6 +2879,7 @@
28682879
9F37391D293F37F8006886C1 /* ThemeManager.swift */,
28692880
9FA122582A8B17E400E7B417 /* StatusBarManager.swift */,
28702881
9FA122782A8B6C9700E7B417 /* ActivityBarManager.swift */,
2882+
9F062FE52B58D40D006210AA /* FileTreeViewController.swift */,
28712883
);
28722884
path = Managers;
28732885
sourceTree = "<group>";
@@ -3334,6 +3346,7 @@
33343346
9419697C280316C7008AAEB2 /* View+cornerRadius.swift in Sources */,
33353347
9419697E280316C7008AAEB2 /* MonacoIntellisenseExtension.swift in Sources */,
33363348
94E6CC862807502A00939E4F /* ActivityBarItemView.swift in Sources */,
3349+
9F062FE42B58D3F4006210AA /* FileTreeView.swift in Sources */,
33373350
94A045F22804816000182275 /* RemoteCreateSection.swift in Sources */,
33383351
9FAE4994292D153F00B1B962 /* VideoViewerExtension.swift in Sources */,
33393352
944112A2282181E500A8F1D7 /* SFTPTerminalServiceProvider.swift in Sources */,
@@ -3354,6 +3367,7 @@
33543367
94196988280316C7008AAEB2 /* TerminalInstance.swift in Sources */,
33553368
94196989280316C7008AAEB2 /* convertCArguments.swift in Sources */,
33563369
94FF337528435158003DE5DD /* SettingsFontPicker.swift in Sources */,
3370+
9F062FEA2B58D416006210AA /* TableView.swift in Sources */,
33573371
9419698A280316C7008AAEB2 /* NewFileView.swift in Sources */,
33583372
9FD5BCED292495DF00F20C4B /* DefaultUIState.swift in Sources */,
33593373
9419698B280316C7008AAEB2 /* EditorInstance.swift in Sources */,
@@ -3370,6 +3384,7 @@
33703384
94A045F82804822400182275 /* RemoteHostCell.swift in Sources */,
33713385
9FA122772A8B5A4800E7B417 /* RemoteConnectedLabel.swift in Sources */,
33723386
94FE0C95281E50F200C05529 /* UserDefaults+Hosts.swift in Sources */,
3387+
9F062FE72B58D40D006210AA /* FileTreeViewController.swift in Sources */,
33733388
9F046C332922203E00BDE4E9 /* ToolbarManager.swift in Sources */,
33743389
);
33753390
runOnlyForDeploymentPostprocessing = 0;
@@ -3507,6 +3522,7 @@
35073522
94A777B7257B6A43008FE7B2 /* View+cornerRadius.swift in Sources */,
35083523
949B3CBB25DBCCDC00BC83B5 /* MonacoIntellisenseExtension.swift in Sources */,
35093524
94E6CC852807502A00939E4F /* ActivityBarItemView.swift in Sources */,
3525+
9F062FE32B58D3F4006210AA /* FileTreeView.swift in Sources */,
35103526
94A045F12804816000182275 /* RemoteCreateSection.swift in Sources */,
35113527
9FAE4993292D153F00B1B962 /* VideoViewerExtension.swift in Sources */,
35123528
944112A1282181E500A8F1D7 /* SFTPTerminalServiceProvider.swift in Sources */,
@@ -3527,6 +3543,7 @@
35273543
94801F93266FB5E400B29D80 /* TerminalInstance.swift in Sources */,
35283544
94F2FEA926A2EB0E007EBC6D /* convertCArguments.swift in Sources */,
35293545
94FF337428435158003DE5DD /* SettingsFontPicker.swift in Sources */,
3546+
9F062FE92B58D416006210AA /* TableView.swift in Sources */,
35303547
94A77802257B960A008FE7B2 /* NewFileView.swift in Sources */,
35313548
9FD5BCEC292495DF00F20C4B /* DefaultUIState.swift in Sources */,
35323549
94A77796257ABB69008FE7B2 /* EditorInstance.swift in Sources */,
@@ -3543,6 +3560,7 @@
35433560
94A045F72804822400182275 /* RemoteHostCell.swift in Sources */,
35443561
9FA122762A8B5A4800E7B417 /* RemoteConnectedLabel.swift in Sources */,
35453562
94FE0C94281E50F200C05529 /* UserDefaults+Hosts.swift in Sources */,
3563+
9F062FE62B58D40D006210AA /* FileTreeViewController.swift in Sources */,
35463564
9F046C322922203E00BDE4E9 /* ToolbarManager.swift in Sources */,
35473565
);
35483566
runOnlyForDeploymentPostprocessing = 0;
@@ -3622,7 +3640,7 @@
36223640
"$(PROJECT_DIR)/Resources/Java/java-frameworks",
36233641
);
36243642
INFOPLIST_FILE = CodeUI.plist;
3625-
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
3643+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
36263644
LD_RUNPATH_SEARCH_PATHS = (
36273645
"$(inherited)",
36283646
"@executable_path/Frameworks",
@@ -3670,7 +3688,7 @@
36703688
);
36713689
GCC_OPTIMIZATION_LEVEL = s;
36723690
INFOPLIST_FILE = CodeUI.plist;
3673-
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
3691+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
36743692
LD_RUNPATH_SEARCH_PATHS = (
36753693
"$(inherited)",
36763694
"@executable_path/Frameworks",

CodeApp/CodeApp.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ struct CodeApp: App {
204204
}
205205

206206
init() {
207-
UITableView.appearance().backgroundColor = UIColor.clear
208-
UITableViewCell.appearance().backgroundColor = UIColor.clear
209-
UITableView.appearance().separatorStyle = .none
210-
UITextView.appearance().backgroundColor = .clear
211-
212207
replaceCommand("node", "node", true)
213208
replaceCommand("npm", "npm", true)
214209
replaceCommand("npx", "npx", true)

CodeApp/Containers/ExplorerContainer.swift

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,32 @@ struct ExplorerContainer: View {
104104
}
105105
}
106106

107+
func onMoveFile(
108+
from: WorkSpaceStorage.FileItemRepresentable, to: WorkSpaceStorage.FileItemRepresentable
109+
) {
110+
guard let fromUrl = from._url,
111+
let toUrl = to._url?.appending(path: fromUrl.lastPathComponent)
112+
else {
113+
return
114+
}
115+
Task {
116+
do {
117+
try await App.workSpaceStorage.moveItem(at: fromUrl, to: toUrl)
118+
} catch {
119+
App.notificationManager.showErrorMessage(error.localizedDescription)
120+
}
121+
}
122+
}
123+
107124
var body: some View {
108125
VStack(spacing: 0) {
109126

110127
InfinityProgressView(enabled: App.workSpaceStorage.explorerIsBusy)
111128

112-
ScrollViewReader { proxy in
113-
List {
114-
ExplorerEditorListSection(
115-
onOpenNewFile: onOpenNewFile,
116-
onPickNewDirectory: onPickNewDirectory
117-
)
118-
ExplorerFileTreeSection(
119-
searchString: searchString, onDrag: onDragCell,
120-
onDropToFolder: onDropToFolder)
121-
}
122-
.listStyle(SidebarListStyle())
123-
.environment(\.defaultMinListRowHeight, 10)
124-
.environment(\.editMode, $editMode)
125-
.onAppear {
126-
scrollToActiveEditor(proxy: proxy)
127-
}
128-
.onReceive(
129-
NotificationCenter.default.publisher(
130-
for: Notification.Name("explorer.scrollto"),
131-
object: nil),
132-
perform: { notification in
133-
explorerNotificationHandler(notification: notification, proxy: proxy)
134-
})
135-
}
129+
ExplorerFileTree(
130+
searchString: searchString, onDrag: onDragCell,
131+
onMoveFile: onMoveFile
132+
)
136133

137134
Spacer()
138135

CodeApp/Containers/MainScene.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ struct MainScene: View {
9595
.environmentObject(App.stateManager)
9696
.environmentObject(App.alertManager)
9797
.environmentObject(App.safariManager)
98+
.environmentObject(App.directoryPickerManager)
99+
.environmentObject(App.createFileSheetManager)
98100
.onAppear {
99101
restoreSceneState()
100102
App.extensionManager.initializeExtensions(app: App)
@@ -147,6 +149,8 @@ private struct MainView: View {
147149
@EnvironmentObject var stateManager: MainStateManager
148150
@EnvironmentObject var alertManager: AlertManager
149151
@EnvironmentObject var safariManager: SafariManager
152+
@EnvironmentObject var directoryPickerManager: DirectoryPickerManager
153+
@EnvironmentObject var createFileSheetManager: CreateFileSheetManager
150154
@EnvironmentObject var themeManager: ThemeManager
151155

152156
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@@ -272,5 +276,17 @@ private struct MainView: View {
272276
EmptyView()
273277
}
274278
}
279+
.sheet(isPresented: $directoryPickerManager.showsPicker) {
280+
DirectoryPickerView(onOpen: { url in
281+
directoryPickerManager.callback?(url)
282+
})
283+
}
284+
.sheet(isPresented: $createFileSheetManager.showsSheet) {
285+
if let targetURL = createFileSheetManager.targetURL {
286+
NewFileView(targetUrl: targetURL.absoluteString)
287+
} else {
288+
EmptyView()
289+
}
290+
}
275291
}
276292
}

CodeApp/Managers/FileSystem/WorkSpaceStorage.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class WorkSpaceStorage: ObservableObject {
1313
@AppStorage("remoteShouldResolveHomePath") var remoteShouldResolveHomePath = false
1414

1515
@Published var currentDirectory: FileItemRepresentable
16-
@Published var expansionStates: [AnyHashable: Bool] = [:]
1716
@Published var explorerIsBusy = false
1817
@Published var editorIsBusy = false
1918
@Published var remoteFingerprint: String? = nil
2019

20+
@Published var cellState = TableViewCellState<WorkSpaceStorage.FileItemRepresentable>(
21+
highlightedCells: Set<String>(), cellDecorations: [:])
22+
@Published var expandedCells = Set<String>()
23+
2124
private var directoryMonitor = DirectoryMonitor()
2225
private var onDirectoryChangeAction: ((String) -> Void)? = nil
2326
private var onTerminalDataAction: ((Data) -> Void)? = nil
@@ -193,7 +196,7 @@ class WorkSpaceStorage: ObservableObject {
193196
}
194197

195198
func disconnect() {
196-
expansionStates.removeAll()
199+
expandedCells.removeAll()
197200
directoryStorage.removeAll()
198201

199202
fss[currentScheme!] = nil
@@ -218,7 +221,7 @@ class WorkSpaceStorage: ObservableObject {
218221
// Directory is updated
219222
directoryMonitor.removeAll()
220223
directoryStorage.removeAll()
221-
expansionStates.removeAll()
224+
expandedCells.removeAll()
222225
currentDirectory = FileItemRepresentable(name: name, url: url, isDirectory: true)
223226
requestDirectoryUpdateAt(id: url)
224227
} else {
@@ -365,7 +368,7 @@ class WorkSpaceStorage: ObservableObject {
365368
}
366369

367370
extension WorkSpaceStorage {
368-
struct FileItemRepresentable: Identifiable {
371+
struct FileItemRepresentable: Identifiable, Hashable {
369372
var id: String {
370373
self.url
371374
}

0 commit comments

Comments
 (0)