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

Show tooltips for res:// and uid:// strings in ScriptEditor #100803

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

larspet
Copy link
Contributor

@larspet larspet commented Dec 25, 2024

Closes godotengine/godot-proposals#5027

Following the addition of tooltips (#91060), this PR adds tooltips for res:// and uid:// strings.

res_uid_tooltips.mp4

@larspet larspet requested a review from a team as a code owner December 25, 2024 14:32
@dalexeev dalexeev added this to the 4.4 milestone Dec 25, 2024
@dalexeev dalexeev self-requested a review December 25, 2024 20:13
@dalexeev
Copy link
Member

  1. This should work not only for uid:// but also for res://.
  2. For consistency with other tooltips, I suggest using the following format:
    • Format: Resource <file name>: <Type>
    • Example: Resource icon.png: CompressedTexture2D
    • Or maybe: Resource res://icon.png: CompressedTexture2D
    • Rationale: Documentation uses Pascal style (var name: Type) instead of C style (Type name).
    • Also, we can make the resource type links clickable. You can probably reuse SYMBOL_HINT_ASSIGNABLE.

@larspet
Copy link
Contributor Author

larspet commented Dec 25, 2024

  1. This should work not only for uid:// but also for res://.

Makes sense, I will add that.

2. For consistency with other tooltips, I suggest using the following format:

   * Format: `Resource <file name>: <Type>`
   * Example: `Resource icon.png: CompressedTexture2D`
   * Or maybe: `Resource res://icon.png: CompressedTexture2D`

Resource <file_name>: <Type> is probably good, but I would not want Resource <file_path>: <Type> because paths can get pretty long, which is why i first decided on <Type> <file_name> <file_path>.

I will try adding the full resource path to the tooltip body instead of having it in the title.

@larspet larspet changed the title Show tooltips for UID strings in ScriptEditor Show tooltips for res:// and uid:// strings in ScriptEditor Dec 26, 2024
@larspet
Copy link
Contributor Author

larspet commented Dec 26, 2024

I have now added support for res:// as well. Since you can link to more types of files with res:// I split everything into different types:

  • Resource
  • Directory
  • TextFile (as defined by the docks/filesystem/textfile_extensions editor setting)
  • File (files that are not visible in FileSystem, opens in File Manager instead)

editor/plugins/script_text_editor.cpp Outdated Show resolved Hide resolved
editor/editor_help.h Show resolved Hide resolved
editor/editor_help.cpp Outdated Show resolved Hide resolved
editor/editor_help.cpp Outdated Show resolved Hide resolved
@larspet
Copy link
Contributor Author

larspet commented Jan 4, 2025

I made an attempt to make the width of the tooltip match the content width, but couldn't get it working because of problems similar to #93040. I do think it would make these tooltips look much nicer (regular code-related tooltips are good as they are however), but I'll leave it for someone with more Control knowledge to hopefully implement in another PR.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 8, 2025

I opened a very similar PR:
#101309
The difference is that it shows both path and UID for hovered files and includes the preview.
While the preview is questionable, showing full path could be useful.

@larspet
Copy link
Contributor Author

larspet commented Jan 9, 2025

I opened a very similar PR: #101309 The difference is that it shows both path and UID for hovered files and includes the preview. While the preview is questionable, showing full path could be useful.

The reason I didn't show the full path for res:// was since you're already hovering the full path. Also, the type of the resource is shown after the name, so a long path would push it far away. The full path is shown for UIDs though.

I don't think the preview is questionable. I was thinking of adding that too but it would've been a little troublesome with how I implemented this PR, but your PR made me rethink my implementation a little.


Overall, i like the design of my PR's tooltip since it's consistent with the existing ScriptEditor tooltips (especially after dalexeev's suggestions). I think it's important to not mix styles within the same context. However, I was very limited with what I could do with the tooltip body since I chose to implement it all using the existing tooltip RTL (slightly hacky in some parts).

I'm thinking of keeping the header as is (and keeping the detection of different kinds of file types), but implement the tooltip body using normal Controls instead of using the RTL.
That way I can replace the links with normal buttons like

  • Open
  • Show in FileSystem
  • Copy Path
  • Copy UID

and put a preview to the right of the buttons.

This would make the tooltip much easier to maintain in the future, and also make it easier to add more features.


Finally, I/we have forgotten about user:// paths. They would definitely benefit from tooltips as well.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 14, 2025

I gave this a test and it works great, I think it's good enough for a start. There are some corner cases, like files that don't exist in FileSystem (e.g. try opening res://.godot/editor, the link does nothing), also I'm pretty sure users will expect this to work with relative paths and absolute paths (without res://), but these can be resolved later.

Finally, I/we have forgotten about user:// paths. They would definitely benefit from tooltips as well.

Not really. user:// does not store "permanent" files; they may exist or not, or their type might change. Showing them in tooltip does not provide any useful information. Though I suppose a fast link could be useful, so they could be supported in tooltips even for completeness sake.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Needs rebase.

@akien-mga
Copy link
Member

I'll rebase it as this would be great to merge for 4.4.beta1 today.

@Calinou
Copy link
Member

Calinou commented Jan 14, 2025

Note that this would also benefit from godotengine/godot-proposals#11365, so you can make it show up without having to touch the mouse. It could even use the same keyboard shortcut (since string literals can't have documentation attached to them).

@akien-mga akien-mga merged commit 19bb441 into godotengine:master Jan 14, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@larspet larspet deleted the uid-tooltip branch January 14, 2025 19:32
@pennyloafers
Copy link

I just read the blog post, are we able to reverse search the uid to a file, as the uid has no meaning to humans and removes context to the underlying resource. I hope there is a way to quickly understand what the uid represents?

@KoBeWi
Copy link
Member

KoBeWi commented Jan 15, 2025

Well, this PR allows UID lookup from script editor. There is no other built-in tool for that currently, you either have to paste in script editor and hover or run an EditorScript that translates UID to path.

@linker-err0r
Copy link

I just read the blog post, are we able to reverse search the uid to a file, as the uid has no meaning to humans and removes context to the underlying resource. I hope there is a way to quickly understand what the uid represents?

This occurred to me too... It would be nice if we could alias UIDs so that we can at least render the reference itself human-readable instead of having to copy-pasta magic strings all around the project.

@Tralexium
Copy link

Tralexium commented Jan 17, 2025

Thanks for adding this great addition to the engine. I'm keen on knowing if it's currently possible to drag and drop a resource file using the UID over the absolute file path. If there's no support for that, perhaps I or someone else could make a new MR to add a new Ctrl+Shift shortcut to use the UID instead of the file path when drag & dropping a file into the code editor as it's currently really cumbersome copy paste the UID each time.

Also, I've noticed a bug where the Ctrl+Shift+Alt+C shortcut doesn't work for copying the UID when having the file selected.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 17, 2025

#99094

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

Successfully merging this pull request may close these issues.

Show tooltip with resource path when hovering the uid in ScriptEditor
8 participants