Skip to content

Fix open unsupported Documents, support for open image files - #679

Merged
austincondiff merged 18 commits into
CodeEditApp:mainfrom
shibotong:main
Jul 18, 2022
Merged

austincondiff merged 18 commits into
CodeEditApp:mainfrom
shibotong:main

Conversation

@shibotong

@shibotong shibotong commented Jun 29, 2022 •

Copy link
Copy Markdown
Contributor

Description

What's been implemented:

*make unsupported filed can be opened and show error message
*add support for opening image files (#674)

Related Issue

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • UI support for Binary Files
  • support for images
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • I documented my code
  • Review requested

Screenshots

Screen Shot 2022-06-30 at 01 17 51

Screen Shot 2022-06-30 at 01 18 32

@shibotong
shibotong marked this pull request as ready for review June 30, 2022 02:08
@shibotong shibotong changed the title [WIP]Fix open unsupported Documents, support for open image files Fix open unsupported Documents, support for open image files Jun 30, 2022
@austincondiff

austincondiff commented Jul 5, 2022 •

Copy link
Copy Markdown
Collaborator

Nice work! What happens when the image is larger than the viewport? Does it scale to fit or will it scroll? We may at some point consider zoom controls.

@austincondiff

austincondiff commented Jul 5, 2022 •

Copy link
Copy Markdown
Collaborator

We also shouldn't use the same text found in VS Code...

image

I tested howe Xcode handles this and threw many different filetypes at it. It attempts to render just about anything as it does in Quick Look and this also includes images. Sometimes it only shows the file icon in the case of files such as zip. I would try to replicate this if possible.

You may take a look at QLPreviewController.

0xWDG
0xWDG previously approved these changes Jul 5, 2022

@0xWDG 0xWDG left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

pkasila
pkasila previously approved these changes Jul 5, 2022
@shibotong

Copy link
Copy Markdown
Contributor Author

If the image is larger than view port, it will become a scroll view with vertical direction and its width will fit for view port @austincondiff

Thank you for your suggestion of that package, I'll keep working on this,

@austincondiff

Copy link
Copy Markdown
Collaborator

I just update my comment above. Take a look at QuickLookUI instead as this is for macOS.

@austincondiff

Copy link
Copy Markdown
Collaborator

You may also look at QLPreviewView as well because you don't need the QuickLook window (I still don't know much about this, but this looks about right).

@shibotong
shibotong dismissed stale reviews from pkasila and 0xWDG via 88aa2e1 July 10, 2022 08:04
@shibotong

Copy link
Copy Markdown
Contributor Author

Hi @austincondiff
I have updated the code. Now all type of files (except image and text) are opened with QLPreviewView

Screen Shot 2022-07-10 at 18 02 45

@austincondiff

austincondiff commented Jul 10, 2022 •

Copy link
Copy Markdown
Collaborator

Very nice! Why not open images with QLPreviewView too?

@shibotong

shibotong commented Jul 10, 2022 via email

Copy link
Copy Markdown
Contributor Author

@shibotong

Copy link
Copy Markdown
Contributor Author

Hi @austincondiff
If open images with QLPreviewView, the image with lower resolution could be like this
Screen Shot 2022-07-13 at 09 39 28

@austincondiff

austincondiff commented Jul 13, 2022 •

Copy link
Copy Markdown
Collaborator

You might be able to shrink and center the view to inherit the dimension of the images pixel dimension. You might do a check and see if the image width is less than the viewport width set the views maximum width to the image width, then do the same with the height. This way the image can only scale up to its natural pixel dimension but if the viewport is resized smaller, it can scale down. Does that make sense?

@Matejkob Matejkob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work with this feature! I have a few questions and some suggestions for your code. I'd love to hear your feedback to my comments! 💙

Comment thread CodeEdit/Documents/WorkspaceCodeFileView.swift
Comment on lines +60 to +66
CodeFileView(codeFile: codeFile)
.safeAreaInset(edge: .top, spacing: 0) {
VStack(spacing: 0) {
BreadcrumbsView(file: item, tappedOpenFile: workspace.openTab(item:))
Divider()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in the other two methods, instead of .safeAreaInset(edge:), you used only VStack. I believe this also should work correctly here. @wdg @pkasila @lilingxi01 @lukepistrol @StefKors @austincondiff, does anyone know why someone decided to use .safeAreaInset(edge:) instead of code like this:

VStack(spacing: 0) {
   BreadcrumbsView(file: item, tappedOpenFile: workspace.openTab(item:))
   Divider()
   CodeFileView(codeFile: codeFile)
}

I'm wondering if we can make those three views more consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because if I use safeAreaInset() here, images in ScrollView will have a 1 pixel space on the top.
Screen Shot 2022-07-17 at 14 09 31

I think using VStack is making more sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully agree with you, and I think we should use only VStack. Using safeAreaInset seems to be unneeded to me.

@austincondiff austincondiff Jul 18, 2022 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shibotong @Matejkob We need to use safeAreaInset so that we will see the blurred vibrancy effect in the toolbar when there is overflow. The above screenshot reveals a defect in the tab bar that needs its own issue and needs to be fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @austincondiff I have changed these views to safeAreaInset. I think its ready to merge now

Comment thread CodeEditModules/Modules/CodeFile/src/CodeFile.swift Outdated
Comment on lines +23 to +27
@Published
var content = ""

@Published
var image: NSImage?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder about these two properties. Am I correct that both of them should not be set simultaneously? I can think only about the scenario where one is set, and the other is not. If my thinking is correct, we can consider merging them into one property. It can be achieved using enum, something like this:

enum ContentType {
   case text(String)
   case image(NSImage)
}

@Published
var content: Content? // or var content: Content = .text("") 

Thanks to that solution API of this class is more consistent, and we are assured that an undefined state where image and content are set simultaneously.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea. Thank you so much for this comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Matejkob
I like this idea, but I am having issue with unwrap content to image or text. Could you give me an example of unwrapping context to Binding ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shibotong,
may you try something like this:

enum Content {
    case string(String)
    case int(Int)
}

class Document: ObservableObject {
    @Published var content: Content? = nil
}

let document = Document()

func string(value: Binding<String>) {}

if let content = document.content {
    switch content {
    case let .string(value):
        string(
            value: Binding(
                get: { value },
                set: { document.content = .string($0) }
            )
        )
    case let .int(value):
        break
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reply. I think we need to use QLPreviewView to open images and don't need to use enum for content. Thank you for your help

@@ -44,8 +84,24 @@ public final class CodeFileDocument: NSDocument, ObservableObject {
return data
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If image is set instead of content, should we not return data of the image here?

Comment thread CodeEditModules/Modules/CodeFile/src/CodeFile.swift Outdated
Comment thread CodeEditModules/Modules/CodeFile/src/Image/ImageFileView.swift Outdated
@jiengup

jiengup commented Jul 13, 2022 via email

Copy link
Copy Markdown

@austincondiff

Copy link
Copy Markdown
Collaborator

@shibotong Does all of this make sense? Are you able to resolve these issues so we can get this merged in?

@shibotong

Copy link
Copy Markdown
Contributor Author

You might be able to shrink and center the view to inherit the dimension of the images pixel dimension. You might do a check and see if the image width is less than the viewport width set the views maximum width to the image width, then do the same with the height. This way the image can only scale up to its natural pixel dimension but if the viewport is resized smaller, it can scale down. Does that make sense?

That's make sense, but that's the reason of can't use QLPreviewView for images. QLPreviewView only take the URL of file.
If we would like to detect image pixel, I think treat image as image is better to treat image as other type of file

shibotong and others added 3 commits July 17, 2022 14:12
Co-authored-by: Mateusz Bąk <44930823+Matejkob@users.noreply.github.com>
Co-authored-by: Mateusz Bąk <44930823+Matejkob@users.noreply.github.com>
@shibotong

Copy link
Copy Markdown
Contributor Author

Hi @austincondiff its ready to merge now. Thanks

@austincondiff
austincondiff merged commit b6dd9bb into CodeEditApp:main Jul 18, 2022
@austincondiff

Copy link
Copy Markdown
Collaborator

@allcontributors add @shibotong for code

@allcontributors

Copy link
Copy Markdown
Contributor

@austincondiff

I've put up a pull request to add @shibotong! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants