Skip to content

Commit 2843799

Browse files
committed
ui: use path tree in decrypter view
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 33455f9 commit 2843799

File tree

3 files changed

+34
-69
lines changed

3 files changed

+34
-69
lines changed

Localizable.xcstrings

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13118,52 +13118,6 @@
1311813118
}
1311913119
}
1312013120
},
13121-
"File name" : {
13122-
"localizations" : {
13123-
"de" : {
13124-
"stringUnit" : {
13125-
"state" : "translated",
13126-
"value" : "Dateiname"
13127-
}
13128-
},
13129-
"es" : {
13130-
"stringUnit" : {
13131-
"state" : "translated",
13132-
"value" : "Nombre de archivo"
13133-
}
13134-
},
13135-
"it" : {
13136-
"stringUnit" : {
13137-
"state" : "translated",
13138-
"value" : "Nome file"
13139-
}
13140-
},
13141-
"ja" : {
13142-
"stringUnit" : {
13143-
"state" : "translated",
13144-
"value" : "ファイル名"
13145-
}
13146-
},
13147-
"nl" : {
13148-
"stringUnit" : {
13149-
"state" : "translated",
13150-
"value" : "Bestandsnaam"
13151-
}
13152-
},
13153-
"uk" : {
13154-
"stringUnit" : {
13155-
"state" : "translated",
13156-
"value" : "Ім'я файлу"
13157-
}
13158-
},
13159-
"zh-Hans" : {
13160-
"stringUnit" : {
13161-
"state" : "translated",
13162-
"value" : "文件名"
13163-
}
13164-
}
13165-
}
13166-
},
1316713121
"File not found" : {
1316813122
"localizations" : {
1316913123
"de" : {

Sushitrain/DecrypterView.swift

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import SwiftUI
2929
@State private var folderPassword: String = ""
3030
@State private var searchText: String = ""
3131
@State private var destURL: URL? = nil
32-
@State private var selection: Set<EncryptedFileEntry.ID> = []
32+
@State private var selectedDecryptedPaths: Set<String> = []
3333
@State private var showSuccessMessage = false
3434
@State private var keepFolderStructure = true
3535

@@ -63,7 +63,7 @@ import SwiftUI
6363
.disabled(folderPassword.isEmpty || folderID.isEmpty || sourceURL == nil)
6464
}
6565

66-
Section("\(selection.count) files selected") {
66+
Section("\(selectedDecryptedPaths.count) files selected") {
6767
LabeledContent("Folder") {
6868
HStack {
6969
Text(destURL?.lastPathComponent ?? "")
@@ -78,12 +78,12 @@ import SwiftUI
7878
Text("Recreate folder structure")
7979
}
8080

81-
Button("Decrypt \(selection.count) files") {
81+
Button("Decrypt \(selectedDecryptedPaths.count) files") {
8282
Task {
8383
await self.decryptSelection()
8484
}
8585
}.disabled(destURL == nil)
86-
}.disabled(folderPassword.isEmpty || folderID.isEmpty || sourceURL == nil || selection.isEmpty)
86+
}.disabled(folderPassword.isEmpty || folderID.isEmpty || sourceURL == nil || selectedDecryptedPaths.isEmpty)
8787
}
8888
.formStyle(.grouped)
8989
.disabled(loading)
@@ -104,8 +104,9 @@ import SwiftUI
104104
else if sourceURL != nil && !folderID.isEmpty && !folderPassword.isEmpty {
105105
// List of files
106106
DecrypterItemsView(
107-
folderID: folderID, folderPassword: folderPassword, entries: searchText.isEmpty ? allEntries : foundEntries,
108-
selection: $selection)
107+
folderID: folderID, folderPassword: folderPassword,
108+
entries: searchText.isEmpty ? allEntries : foundEntries,
109+
selectedDecryptedPaths: $selectedDecryptedPaths)
109110
}
110111
else {
111112
ContentUnavailableView {
@@ -190,18 +191,23 @@ import SwiftUI
190191
let folderID = self.folderID
191192
let folderPassword = self.folderPassword
192193
let destURL = self.destURL
193-
let selection = self.selection
194+
let selectedDecryptedPaths = self.selectedDecryptedPaths
194195
let sourceURL = self.sourceURL
195196
let keepFolderStructure = self.keepFolderStructure
197+
let entries = self.allEntries
196198

197199
await Task.detached(priority: .userInitiated) {
198200
do {
199201
// Keep a bookmark accessor alive whle we write files to the destination URL
200202
try withExtendedLifetime(try BookmarkManager.Accessor(url: destURL!)) {
201203
let folderKey = SushitrainNewFolderKey(folderID, folderPassword)
202-
for fileURL in selection {
204+
for entry in entries {
205+
if !selectedDecryptedPaths.contains(entry.decryptedPath) {
206+
continue
207+
}
208+
203209
let rootPath = sourceURL!.path(percentEncoded: false)
204-
let filePath = URL(string: fileURL)!.path(percentEncoded: false)
210+
let filePath = entry.url.path(percentEncoded: false)
205211
let trimmedPath = String(filePath.trimmingPrefix(rootPath))
206212
Log.info("Decrypt \(trimmedPath) \(sourceURL!) \(destURL!)")
207213
try folderKey?.decryptFile(
@@ -289,22 +295,23 @@ import SwiftUI
289295
let folderID: String
290296
let folderPassword: String
291297
let entries: [EncryptedFileEntry]
298+
@State private var decryptedPaths: [String] = []
292299

293-
@Binding var selection: Set<EncryptedFileEntry.ID>
300+
@Binding var selectedDecryptedPaths: Set<String>
294301

295302
var body: some View {
296-
Table(
297-
of: EncryptedFileEntry.self, selection: $selection,
298-
columns: {
299-
TableColumn("File name") { (entry: EncryptedFileEntry) in
300-
Text(entry.decryptedPath)
301-
}
302-
},
303-
rows: {
304-
ForEach(entries) { entry in
305-
TableRow(entry)
306-
}
307-
})
303+
List(selection: $selectedDecryptedPaths) {
304+
PathsOutlineGroup(paths: decryptedPaths) { decryptedPath, isIntermediate in
305+
Text(decryptedPath.lastPathComponent)
306+
}
307+
}
308+
.task {
309+
await self.update()
310+
}
311+
}
312+
313+
private func update() async {
314+
self.decryptedPaths = self.entries.map { $0.decryptedPath }
308315
}
309316
}
310317

Sushitrain/PathsOutlineView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,15 @@ private struct TreeNodeView<Content: View>: View {
128128
}
129129
) {
130130
self.content(tree.value, tree.intermediate)
131-
}.selectionDisabled(tree.intermediate)
131+
.selectionDisabled(tree.intermediate)
132+
.disabled(tree.intermediate)
133+
}
132134
}
133135
}
134136
else {
135137
self.content(tree.value, tree.intermediate)
138+
.selectionDisabled(tree.intermediate)
139+
.disabled(tree.intermediate)
136140
}
137141
}
138142
}

0 commit comments

Comments
 (0)