aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/FilePreviewTextView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-10-27 21:48:20 -0700
committerDustin Mierau <dustin@mierau.me>2025-10-27 21:48:20 -0700
commit4bb0ffba596e41a8309ba50d222248a0ba3eb42e (patch)
treefcd1c2b11c071a624d0b3b56ed16340272200c7d /Hotline/macOS/FilePreviewTextView.swift
parent924012e6ee03fff5570e9362e29be9b04816b777 (diff)
Random project housekeeping/organizing source files.
Diffstat (limited to 'Hotline/macOS/FilePreviewTextView.swift')
-rw-r--r--Hotline/macOS/FilePreviewTextView.swift127
1 files changed, 0 insertions, 127 deletions
diff --git a/Hotline/macOS/FilePreviewTextView.swift b/Hotline/macOS/FilePreviewTextView.swift
deleted file mode 100644
index c286381..0000000
--- a/Hotline/macOS/FilePreviewTextView.swift
+++ /dev/null
@@ -1,127 +0,0 @@
-import SwiftUI
-import UniformTypeIdentifiers
-
-struct FilePreviewTextView: View {
- enum FilePreviewFocus: Hashable {
- case window
- }
-
- @Environment(\.controlActiveState) private var controlActiveState
- @Environment(\.colorScheme) private var colorScheme
- @Environment(\.dismiss) var dismiss
-
- @Binding var info: PreviewFileInfo?
- @State var preview: FilePreview? = nil
- @FocusState private var focusField: FilePreviewFocus?
-
- var body: some View {
- Group {
- if preview?.state != .loaded {
- VStack(alignment: .center, spacing: 0) {
- Spacer()
- ProgressView(value: max(0.0, min(1.0, preview?.progress ?? 0.0)))
- .focusable(false)
- .progressViewStyle(.circular)
- .controlSize(.extraLarge)
- .tint(.white)
- .frame(maxWidth: 300, alignment: .center)
- Spacer()
- Spacer()
- }
- .background(Color(nsColor: .textBackgroundColor))
- .frame(minWidth: 350, maxWidth: .infinity, minHeight: 150, maxHeight: .infinity)
- .padding()
- }
- else {
- if let text = preview?.text {
- TextEditor(text: .constant(text))
- .textEditorStyle(.plain)
- .font(.system(size: 14))
- .lineSpacing(3)
- .padding(16)
- .contentMargins(.top, -16.0, for: .scrollIndicators)
- .contentMargins(.bottom, -16.0, for: .scrollIndicators)
- .contentMargins(.trailing, -16.0, for: .scrollIndicators)
- .scrollClipDisabled()
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- }
- else {
- VStack(alignment: .center, spacing: 0) {
- Spacer()
-
- Image(systemName: "eye.trianglebadge.exclamationmark")
- .resizable()
- .scaledToFit()
- .frame(maxWidth: .infinity)
- .frame(height: 48)
- .padding(.bottom)
- Group {
- Text("This file type is not previewable")
- .bold()
- Text("Try downloading and opening this file in another application.")
- .foregroundStyle(Color.secondary)
- }
- .font(.system(size: 14.0))
- .frame(maxWidth: 300)
- .multilineTextAlignment(.center)
-
- Spacer()
- Spacer()
- }
- .frame(minWidth: 350, maxWidth: .infinity, minHeight: 150, maxHeight: .infinity)
- .padding()
- }
- }
- }
- .focusable()
- .focusEffectDisabled()
- .background(Color(nsColor: .textBackgroundColor))
- .focused($focusField, equals: .window)
- .navigationTitle(info?.name ?? "File Preview")
- .toolbar {
- ToolbarItem(placement: .navigation) {
- FileIconView(filename: info?.name ?? "", fileType: nil)
- .frame(width: 16, height: 16)
- .opacity(controlActiveState == .inactive ? 0.5 : 1.0)
- }
-
- if let _ = preview?.text {
- if let info = info {
- ToolbarItem(placement: .primaryAction) {
- Button {
- let _ = preview?.data?.saveAsFileToDownloads(filename: info.name)
- } label: {
- Label("Save Text File...", systemImage: "square.and.arrow.down")
- }
- .help("Save Text File")
- }
- }
- }
- }
- .task {
- if let info = info {
- preview = FilePreview(info: info)
- preview?.download()
- }
- }
- .onAppear {
- if info == nil {
- Task {
- dismiss()
- }
- return
- }
-
- focusField = .window
- }
- .onDisappear {
- preview?.cancel()
- dismiss()
- }
- .onChange(of: preview?.state) {
- if preview?.state == .failed {
- dismiss()
- }
- }
- }
-}