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

Editor: Exposed supported formats in Loader.js; #28324

Merged
merged 3 commits into from May 13, 2024

Conversation

ycw
Copy link
Contributor

@ycw ycw commented May 9, 2024

Why refactor:

Editor supports two ways of importing files from fs: accept does guard users from selecting unsupported files in the first place for File>Import, however there's no equivalent facility for the 2nd way, drag n drop, so DIY UI feedback is needed for notifying users that no-op as they dropped unsupported files, I prefer showing Import Error: Unsupported file format (xxx) together with editor's supported file formats (same purpose of accept that supported file formats are listed in browser file dialog), my attempt was using #28295 and #28295 (comment), so 'introspection of supported formats' is inevitable, that's why file handlers are re-organized to help introspect in getSupportedFileFormats().

The PR:

  • Extracted file handlers into fileHandlers object:

    • The handler interface is (editor, manager, reader, file, ...handlerSpecificOptions): void
    • This object is for internal used
    • To support new file format, simply adds a handler like fileHandlers[ 'myFormat' ] = myFormatHandler
    • To remove support of a file format, simply deletes it from fileHandlers
  • Exposed getSupportedFileFormats():

    • This is a static method
    • The supported file formats are ... auto-derived ... from fileHandlers object
    • Returns array of extension names; sorted by sort()
    • One of the consumer is MenuBar.File.js: Use getSupportedFileFormats() to generate accepts list for File>Import input (not included in this PR)
    • Solved Editor: Alerts if File>Import failed #28295 (comment)

@ycw ycw changed the title Editor: Fixed loading manager isn't propagated; Exposed supported formats in Loader.js; Editor: Exposed supported formats in Loader.js; May 9, 2024
@mrdoob
Copy link
Owner

mrdoob commented May 9, 2024

Hmm, doesn't it make the code less readable?

IMHO maintaining the input.accept list doesn't seem too bad because the file browser wouldn't let the files be loaded if not updated.

@ycw
Copy link
Contributor Author

ycw commented May 9, 2024

IMHO maintaining the input.accept list doesn't seem too bad

see #28295 (comment)

@mrdoob
Copy link
Owner

mrdoob commented May 9, 2024

Hmm, doesn't it make the code less readable?

IMHO maintaining the input.accept list doesn't seem too bad because the file browser wouldn't let the files be loaded if not updated.

@Mugen87 what do you think?

@ycw
Copy link
Contributor Author

ycw commented May 9, 2024

In short, this PR can be closed if ... hardcoded supported file formats is accepted for bith file input `accept` value, and the supported file formats hint in UI feedback :D, Expand it to see why refactoring is needed, thanks.

Why refactor:

Editor supports two ways of importing files from fs: accept does guard users from selecting unsupported files in the first place for File>Import, however there's no equivalent facility for the 2nd way, drag n drop, so DIY UI feedback is needed for notifying users that no-op as they dropped unsupported files, I prefer showing Import Error: Unsupported file format (xxx) together with editor's supported file formats (same purpose of accept that supported file formats are listed in browser file dialog), my attempt was using hardcoded supported formats list here and was rejected, so 'introspection of supported formats' is inevitable, that's why file handlers are re-organized to help introspect in getSupportedFileFormats().

@ycw ycw force-pushed the editor-expose-static-file-handlers branch from 29c24e3 to c5f0406 Compare May 9, 2024 19:21
@Mugen87
Copy link
Collaborator

Mugen87 commented May 9, 2024

Fair enough! Since there is now more than one use case that uses the file format list I'm okay with adding it.

editor/js/Loader.js Outdated Show resolved Hide resolved
@Mugen87
Copy link
Collaborator

Mugen87 commented May 13, 2024

Do you mind resolving the merge conflicts as well?

@ycw
Copy link
Contributor Author

ycw commented May 13, 2024

done

@ycw ycw requested a review from Mugen87 May 13, 2024 10:56
@Mugen87 Mugen87 added this to the r165 milestone May 13, 2024
@Mugen87 Mugen87 merged commit ae7ccbf into mrdoob:dev May 13, 2024
11 checks passed
@mrdoob
Copy link
Owner

mrdoob commented May 17, 2024

As far as I understand, the main purpose of this PR was to enable Loader.getSupportedFileFormats().

Now that #28396 has made the method no longer needed, should we revert this PR?

@Mugen87
Copy link
Collaborator

Mugen87 commented May 17, 2024

TBH, there is no reason anymore for the refactoring. If you prefer the previous code style, I'm fine with reverting, too.

@mrdoob
Copy link
Owner

mrdoob commented May 17, 2024

What code style do you prefer?

@Mugen87
Copy link
Collaborator

Mugen87 commented May 17, 2024

The previous one, tbh. If I would implement the module from scratch, I would rather use a switch/case statement like before than storing the handlers in an object.

mrdoob added a commit that referenced this pull request May 17, 2024
@mrdoob
Copy link
Owner

mrdoob commented May 17, 2024

@ycw

We appreciate all the improvements you're doing to the editor.

However, it may be better to share what you're planing to work on before spending a lot of time working on a PR that changes a lot of files or refactors code.

If you do that, we may be able to help you on coming up with simpler solutions and save you time.

@ycw
Copy link
Contributor Author

ycw commented May 17, 2024

We appreciate all the improvements you're doing to the editor.

Thanks.

it may be better to share what you're planing to work before spending a lot of time working on a PR

Had been in #28324 (comment) I should write it at the OP sorry for that 🙏🏻

that #28396 has made the method no longer needed, should we revert this PR?

This PR was not originally for #28396, instead it was for #28295, (I even added 'TODO: UI Feedback' in commit :D), so no.

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.

None yet

3 participants