aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/FilesView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-01-05 19:46:13 -0800
committerDustin Mierau <dustin@mierau.me>2024-01-05 19:46:37 -0800
commit2f8f71d0410f59d5d303a4c221a628630168bfe2 (patch)
tree6a18ae2e4dbd72a688667bd9e819ecee72d76b52 /Hotline/macOS/FilesView.swift
parent57c33eb798f6802fe5af8fcd3d1992a4b63a448f (diff)
Add image preview to Files so you don't have to download images to view them, works with animated GIFs too. Added cmd-R shortcut for Servers window. More work on login view.
Diffstat (limited to 'Hotline/macOS/FilesView.swift')
-rw-r--r--Hotline/macOS/FilesView.swift31
1 files changed, 22 insertions, 9 deletions
diff --git a/Hotline/macOS/FilesView.swift b/Hotline/macOS/FilesView.swift
index 09354ed..5443270 100644
--- a/Hotline/macOS/FilesView.swift
+++ b/Hotline/macOS/FilesView.swift
@@ -70,8 +70,7 @@ struct FileView: View {
.padding(.leading, CGFloat(depth * (12 + 10)))
.onChange(of: file.expanded) {
loading = false
- if file.isFolder {
- print("EXPANDED \(file.name)? \(expanded)")
+ if file.isFolder && file.fileSize > 0 {
if file.expanded {
Task {
loading = true
@@ -108,9 +107,14 @@ struct FileView: View {
struct FilesView: View {
@Environment(Hotline.self) private var model: Hotline
+ @Environment(\.openWindow) private var openWindow
@State private var selection: FileInfo?
+ private func openPreviewWindow(_ previewInfo: PreviewFileInfo) {
+ let _ = FilePreviewWindowController(info: previewInfo)
+ }
+
var body: some View {
NavigationStack {
List(model.files, id: \.self, selection: $selection) { file in
@@ -129,7 +133,6 @@ struct FilesView: View {
.contextMenu(forSelectionType: FileInfo.self) { items in
// ...
} primaryAction: { items in
- print("ITEMS?", items)
guard let clickedFile = items.first else {
return
}
@@ -139,7 +142,6 @@ struct FilesView: View {
clickedFile.expanded.toggle()
}
else {
- print("DOWNLOAD FILE", clickedFile.name, clickedFile.path)
model.downloadFile(clickedFile.name, path: clickedFile.path)
}
}
@@ -157,6 +159,17 @@ struct FilesView: View {
}
return .ignored
}
+ .onKeyPress(.space) {
+ if let s = selection, s.isImage {
+ model.previewFile(s.name, path: s.path) { info in
+ if let info = info {
+ openPreviewWindow(info)
+ }
+ }
+ return .handled
+ }
+ return .ignored
+ }
.overlay {
if !model.filesLoaded {
VStack {
@@ -167,8 +180,6 @@ struct FilesView: View {
}
}
.toolbar {
-
-
ToolbarItem(placement: .primaryAction) {
Button {
} label: {
@@ -180,15 +191,17 @@ struct FilesView: View {
ToolbarItem(placement: .primaryAction) {
Button {
if let s = selection, !s.isFolder {
- print("DOWNLOAD FILE", s.name, s.path)
- model.previewFile(s.name, path: s.path, addTransfer: true) { transfer, fileData in
- print("FILE PREVIEWED?", fileData.count)
+ model.previewFile(s.name, path: s.path) { info in
+ if let info = info {
+ openPreviewWindow(info)
+ }
}
}
} label: {
Label("Preview File", systemImage: "eye")
}
.help("Preview File")
+ .disabled(selection?.isImage == false)
}
ToolbarItem(placement: .primaryAction) {