aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/FilesView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-01-08 14:45:58 -0800
committerDustin Mierau <dustin@mierau.me>2024-01-08 14:45:58 -0800
commite9bae0328801d5a056f33beb0f764c6d35e518a2 (patch)
treefcf853330f8de68948b089a5b15e2ef4c6dbb47c /Hotline/macOS/FilesView.swift
parent4349f50167f50b30d7cd71854882ab33ac6ea5ea (diff)
Move to a standard SwiftUI window for preview windows so I can add toolbar items from SwiftUI. Not ideal. Added support for previewing text files too.
Diffstat (limited to 'Hotline/macOS/FilesView.swift')
-rw-r--r--Hotline/macOS/FilesView.swift25
1 files changed, 14 insertions, 11 deletions
diff --git a/Hotline/macOS/FilesView.swift b/Hotline/macOS/FilesView.swift
index 5443270..1eab0cf 100644
--- a/Hotline/macOS/FilesView.swift
+++ b/Hotline/macOS/FilesView.swift
@@ -41,9 +41,9 @@ struct FileView: View {
Image(systemName: "folder.fill")
}
else {
- fileIcon(name: file.name)
- .resizable()
- .aspectRatio(contentMode: .fit)
+ FileIconView(filename: file.name)
+// .resizable()
+// .aspectRatio(contentMode: .fit)
// .scaledToFill()
.frame(width: 16, height: 16)
}
@@ -98,11 +98,6 @@ struct FileView: View {
FileView.byteFormatter.countStyle = .file
return FileView.byteFormatter.string(fromByteCount: Int64(fileSize))
}
-
- private func fileIcon(name: String) -> Image {
- let fileExtension = (name as NSString).pathExtension
- return Image(nsImage: NSWorkspace.shared.icon(for: UTType(filenameExtension: fileExtension) ?? UTType.content))
- }
}
struct FilesView: View {
@@ -112,7 +107,15 @@ struct FilesView: View {
@State private var selection: FileInfo?
private func openPreviewWindow(_ previewInfo: PreviewFileInfo) {
- let _ = FilePreviewWindowController(info: previewInfo)
+ switch previewInfo.previewType {
+ case .image:
+ openWindow(id: "preview-image", value: previewInfo)
+ case .text:
+ openWindow(id: "preview-text", value: previewInfo)
+ default:
+ return
+ }
+// let _ = FilePreviewWindowController(info: previewInfo)
}
var body: some View {
@@ -160,7 +163,7 @@ struct FilesView: View {
return .ignored
}
.onKeyPress(.space) {
- if let s = selection, s.isImage {
+ if let s = selection, s.isPreviewable {
model.previewFile(s.name, path: s.path) { info in
if let info = info {
openPreviewWindow(info)
@@ -201,7 +204,7 @@ struct FilesView: View {
Label("Preview File", systemImage: "eye")
}
.help("Preview File")
- .disabled(selection?.isImage == false)
+ .disabled(selection?.isPreviewable == false)
}
ToolbarItem(placement: .primaryAction) {