Skip to content

Commit

Permalink
feat: πŸ“ Create new folders (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jun 24, 2024
1 parent 07df226 commit cd320fa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Reconnect/Model/BrowserModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BrowserModel {
private var navigationStack = NavigationStack()
var state: State = .loading
var selection = Set<FileServer.DirectoryEntry.ID>()
var lastError: Error? = nil

init() {
guard fileServer.connect() else {
Expand Down Expand Up @@ -102,4 +103,19 @@ class BrowserModel {
update()
}

func newFolder() {
guard let path = navigationStack.path else {
return
}
Task {
do {
try await fileServer.mkdir(path: path + "untitled folder")
update()
} catch {
print("Failed to create new folder with error \(error).")
lastError = error
}
}
}

}
3 changes: 3 additions & 0 deletions Reconnect/Model/ReconnectError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

import Foundation

import plpftp

enum ReconnectError: Error {
case invalidString
case unknownMachineType
case general
case rfsvError(rfsv.errs)
}
21 changes: 21 additions & 0 deletions Reconnect/PLP/FileServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ class FileServer {
}
}

func syncQueue_mkdir(path: String) throws {
dispatchPrecondition(condition: .onQueue(workQueue))
let result = client.mkdir(path)
guard result.rawValue == 0 else {
throw ReconnectError.rfsvError(result)
}
}

func mkdir(path: String) async throws {
return try await withCheckedThrowingContinuation { continuation in
workQueue.async {
do {
try self.syncQueue_mkdir(path: path)
continuation.resume()
} catch {
continuation.resume(throwing: error)
}
}
}
}

func devlist() -> [String] {
var devbits: UInt32 = 0
client.devlist(&devbits)
Expand Down
17 changes: 17 additions & 0 deletions Reconnect/Views/BrowserView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ struct BrowserView: View {
}
model.navigate(to: item)
}
.contextMenu {
Button("New Folder") {
model.newFolder()
}
}
case .error(let error):
Text(String(describing: error))
}
Expand Down Expand Up @@ -136,8 +141,20 @@ struct BrowserView: View {
Label("Refresh", systemImage: "arrow.clockwise")
}
}

ToolbarItem(id: "action") {
Menu {
Button("New Folder") {
model.newFolder()
}
} label: {
Label("Action", systemImage: "ellipsis.circle")
}
}

}
.navigationTitle(model.path?.windowsLastPathComponent ?? "My Psion")
.presents($model.lastError)
.onAppear {
model.navigate(to: "C:\\")
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies/plptools
Submodule plptools updated 2 files
+17 βˆ’2 plpftp/libplp.cc
+4 βˆ’1 plpftp/libplp.h

0 comments on commit cd320fa

Please sign in to comment.