Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly preview non-text files #1707

Merged
merged 66 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6f30d92
Package.resolved changed
plbstl May 7, 2024
7113389
progress
plbstl May 7, 2024
9a85005
minor doc change in CodeEditUI EffectView
plbstl May 7, 2024
6749915
add WorkspacePdfFileView
plbstl May 7, 2024
3d3893e
allow WorkspacePdfFileView to be able to send data to SwiftUI
plbstl May 7, 2024
bd3fe37
properly name `WorkspacePdfFileView` to `WorkspacePDFView`
plbstl May 8, 2024
a12e51c
improve WorkspacePDFView docs
plbstl May 8, 2024
2b59534
add guards to WorkspacePDFView (makeNSView, updateNSView)
plbstl May 8, 2024
6797552
wip
plbstl May 8, 2024
15291c0
wip 2
plbstl May 8, 2024
2fd13b4
correct padding
plbstl May 8, 2024
7ae71a0
progress? not
plbstl May 8, 2024
ff47ae8
add attachPDFDocumentToView helper in WorkspacePDFView
plbstl May 9, 2024
d820eb9
update WorkspacePDFView docs
plbstl May 9, 2024
b5f1614
remove WorkspaceNonTextFileView
plbstl May 9, 2024
7ef3116
fix SwiftLint violations in WorkspacePDFView, WorkspaceCodeFileView
plbstl May 9, 2024
6d7f7d8
add magic numbers comment to WorkspaceCodeFileView
plbstl May 9, 2024
2192c70
update WorkspacePDFView docs
plbstl May 9, 2024
74cd22b
before i forget
plbstl May 9, 2024
8ef8461
progressss
plbstl May 9, 2024
a643b43
too slow
plbstl May 9, 2024
f583df0
wip: the best work yet
plbstl May 9, 2024
410f62d
it really works!!
plbstl May 9, 2024
b80dc31
add WorkspaceImageView
plbstl May 9, 2024
a9ed5ad
add WorkspaceCannotPreviewFileView
plbstl May 9, 2024
ff57cc8
its working very predictably but showing/hiding navigator pane isn't …
plbstl May 9, 2024
1813416
remove the use of canPreview as it can cause unexpected behaviour
plbstl May 9, 2024
6106b64
remove computeFrame helper in WorkspaceCodeFileView
plbstl May 9, 2024
dc7bcad
update PDF preview's background color
plbstl May 9, 2024
2e4dd02
add note for when PDF preview cannot create PDF document
plbstl May 9, 2024
c2fcacc
improve docs for WorkspaceImageView & WorkspacePDFView
plbstl May 9, 2024
2d448f6
use unnamed parameter for imageUrl in WorkspaceImageView
plbstl May 9, 2024
f2ca164
implement `WorkspaceCannotPreviewFileView`
plbstl May 9, 2024
c248a9d
change url variables in `WorkspaceImageView`, `WorkspacePDFView` & `W…
plbstl May 9, 2024
82ef086
add `WorkspaceLoadingView`
plbstl May 9, 2024
eb15141
spacing violation
plbstl May 9, 2024
d32436a
change onAppear modifier in WorkspaceCannotPreviewFileView
plbstl May 9, 2024
4238f2c
remove `WorkspaceCannotPreviewFileView` as it creates a bug that make…
plbstl May 9, 2024
5c5c81b
improve docs in `WorkspacePDFView` & `WorkspaceImageView`
plbstl May 9, 2024
752fe3b
use `WorkspaceAnyFileView` to preview GIF images
plbstl May 9, 2024
40d52c6
add a note to the documentation for `CodeFileDocument.utType`
plbstl May 9, 2024
b24b6ff
add `WorkspaceAnyFileView` to properly preview files of different fil…
plbstl May 9, 2024
d2664bd
rearrange files in `CodeEdit/Features/Documents/Views`
plbstl May 9, 2024
2fbc351
add `WorkspaceAnyFileView`, `WorkspaceLoadingView`, `WorkspaceImageVi…
plbstl May 9, 2024
afc0a82
update docs in `WorkspaceAnyFileView`, `WorkspaceLoadingView`, `Works…
plbstl May 9, 2024
ccc79b3
rename `CodeFileDocument.typeOfFile` to `CodeFileDocument.utType`
plbstl May 9, 2024
6561d25
fix: allow GIF previews to play, and with their proper dimensions
plbstl May 9, 2024
12aa788
do not return
plbstl May 9, 2024
f039914
update docs for CodeFileDocument.utType
plbstl May 9, 2024
b660ac7
change conformance from movie to audiovisualContent in CodeFileDocume…
plbstl May 9, 2024
d0c2671
properly display CodeFileView contents by undo-ing the padding in its…
plbstl May 10, 2024
1b8c8b3
remove text, image, PDF, video restrictions on `CodeFileDocument.utType`
plbstl May 10, 2024
2ac22a7
update docs in WorkspaceImageView
plbstl May 10, 2024
c3d31a6
WorkspaceCodeFileView: group non-text files, so they inherit modifier…
plbstl May 10, 2024
12e0ba1
WorkspaceCodeFileView: add important note on document.utType
plbstl May 10, 2024
8f04013
remove SwiftUI VideoPlayer view for now, it creates a bug that I can'…
plbstl May 10, 2024
acb8a63
add `NonTextFileView` to clean up code
plbstl May 10, 2024
9688746
remove QLPreviewItem subclass from CodeFileDocument
plbstl May 10, 2024
425f806
rename `WorkspaceCodeFileView` to `EditorAreaFileView`
plbstl May 10, 2024
151e345
rename `EditorView` to `EditorAreaView`
plbstl May 10, 2024
fe1f7bb
rename 4 Workspace view files
plbstl May 10, 2024
cb88ec2
move views for opening files to `CodeEdit/Features/Editor`
plbstl May 10, 2024
096bb68
move `CodeFileDocument` to `CodeEdit/Features/Documents`
plbstl May 10, 2024
cf17bc7
NSTableViewWrapper: minor change in comment
plbstl May 10, 2024
950d7ed
move `WindowCodeFileView` to `CodeEdit/Features/Editor/Views`
plbstl May 10, 2024
b373bb6
use `AnyFileView` to view all images
plbstl May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 33 additions & 65 deletions CodeEdit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "029e3feb7277e502c419e04acfc23af6dd70755f3984e9902ec582890724706b",
"originHash" : "41fcbec1ecbb7853d9ead798bba9d46f35f28767f4d41a009c8eeee022e99a84",
"pins" : [
{
"identity" : "anycodable",
Expand Down Expand Up @@ -87,7 +87,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Wouter01/LogStream",
"state" : {
"revision" : "5378bafdbf5de66b69da8cca9df9d16e19bfcf89",
"revision" : "6f83694b2675dcf3b1cea0a52546ff4469c18282",
"version" : "1.3.0"
}
},
Expand Down Expand Up @@ -200,5 +200,5 @@
}
}
],
"version" : 2
"version" : 3
}
2 changes: 1 addition & 1 deletion CodeEdit/Features/CodeEditUI/Views/EffectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct EffectView: NSViewRepresentable {
///
/// By setting the
/// [`emphasized`](https://developer.apple.com/documentation/appkit/nsvisualeffectview/1644721-isemphasized)
/// flag the emphasized state of the material will be used if available.
/// flag, the emphasized state of the material will be used if available.
///
/// - Parameters:
/// - material: The material to use. Defaults to `.headerView`.
Expand Down
34 changes: 0 additions & 34 deletions CodeEdit/Features/CodeFile/Image/ImageFileView.swift

This file was deleted.

46 changes: 0 additions & 46 deletions CodeEdit/Features/CodeFile/Other/OtherFileView.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CodeFile.swift
// CodeFileDocument.swift
// CodeEditModules/CodeFile
//
// Created by Rehatbir Singh on 12/03/2022.
Expand All @@ -9,7 +9,6 @@ import AppKit
import Foundation
import SwiftUI
import UniformTypeIdentifiers
import QuickLookUI
import CodeEditSourceEditor
import CodeEditTextView
import CodeEditLanguages
Expand All @@ -22,7 +21,7 @@ enum CodeFileError: Error {
}

@objc(CodeFileDocument)
final class CodeFileDocument: NSDocument, ObservableObject, QLPreviewItem {
final class CodeFileDocument: NSDocument, ObservableObject {
struct OpenOptions {
let cursorPositions: [CursorPosition]
}
Expand All @@ -41,37 +40,33 @@ final class CodeFileDocument: NSDocument, ObservableObject, QLPreviewItem {
/// Document-specific overridden line wrap preference.
@Published var wrapLines: Bool?

/*
This is the main type of the document.
For example, if the file is end with '.png', it will be an image,
if the file is end with '.py', it will be a text file.
If text content is not empty, return text
If its neither image or text, this could be nil.
*/
var typeOfFile: UTType? {
/// The type of data this document contains.
///
/// If for example, the file ends with `.py`, its type is a text file.
/// Or if it ends with `.png`, then it is an image.
/// Same goes for PDF and video formats.
///
/// Also, if the text content is not empty, it is a text file.
///
/// - Note: The UTType doesn't necessarily mean the file extension, it can be the MIME
/// type or any other form of data representation.
var utType: UTType? {
if !self.content.isEmpty {
return UTType.text
return .text
}
guard let fileType, let type = UTType(fileType) else {
return nil
}
if type.conforms(to: UTType.image) {
return UTType.image
if type.conforms(to: .text) {
return .text
}
if type.conforms(to: UTType.text) {
return UTType.text
if type.conforms(to: .image) {
return .image
}
if type.conforms(to: .data) {
return .data
if type.conforms(to: .pdf) {
return .pdf
}
return nil
}

/*
This is the QLPreviewItemURL
*/
var previewItemURL: URL? {
fileURL
return type
}

/// Specify options for opening the file such as the initial cursor positions.
Expand Down
102 changes: 0 additions & 102 deletions CodeEdit/Features/Documents/Views/WorkspaceCodeFileView.swift

This file was deleted.

36 changes: 36 additions & 0 deletions CodeEdit/Features/Editor/Views/AnyFileView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AnyFileView.swift
// CodeEdit
//
// Created by Paul Ebose on 2024/5/9.
//

import SwiftUI
import QuickLookUI

/// A view for previewing any kind of file.
///
/// ```swift
/// AnyFileView(fileURL)
/// ```
/// If the file cannot be previewed, a file icon thumbnail is shown instead.
struct AnyFileView: NSViewRepresentable {

/// URL of the file to preview. You can pass in any file type.
private let fileURL: URL

init(_ fileURL: URL) {
self.fileURL = fileURL
}

func makeNSView(context: Context) -> QLPreviewView {
let qlPreviewView = QLPreviewView()
qlPreviewView.previewItem = fileURL as any QLPreviewItem
return qlPreviewView
}

func updateNSView(_ qlPreviewView: QLPreviewView, context: Context) {
qlPreviewView.previewItem = fileURL as any QLPreviewItem
}

}
Loading
Loading