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

Added code preview for “find usages” and related refactorings #7694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

troizet
Copy link
Collaborator

@troizet troizet commented Aug 25, 2024

I have to use find usages a lot and I really miss the ability to quickly view the contents of files.
I have to open tabs in the main editor, which sometimes leads to a lot of unnecessary tabs.

Example of code preview for find usages:

example_finud_usages_preview_2.mp4

An example of code preview for refactoring safely delete, which uses find usages functionality:

example_refactoring_using_find_usages_preview_2.mp4

I borrowed the preview implementation from here:

void showPreview(FileObject fo, Document doc, BookmarkInfo bookmarkInfo) {
if (bookmarkInfo != displayedBookmarkInfo) {
int lineIndex = bookmarkInfo.getCurrentLineIndex();
String mimeType = (String) doc.getProperty("mimeType"); //NOI18N
if (mimeType != null) {
JEditorPane pane = new JEditorPane();
EditorKit editorKit = MimeLookup.getLookup(mimeType).lookup(EditorKit.class);
pane.setEditorKit(editorKit);
pane.setDocument(doc);
pane.setEditable(false);
Component editorComponent;
EditorUI editorUI = Utilities.getEditorUI(pane);
if (editorUI != null) {
editorComponent = editorUI.getExtComponent();
} else {
editorComponent = new JScrollPane(pane);
}
previewPanel.removeAll();
previewPanel.add(editorComponent);
int offset = BookmarkUtils.lineIndex2Offset(doc, lineIndex);
pane.setCaretPosition(offset);
displayedBookmarkInfo = bookmarkInfo;
previewPanel.revalidate();
}
}
}

@troizet troizet added the UI User Interface label Aug 25, 2024
@mbien mbien added Editor ci:all-tests [ci] enable all tests ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Aug 25, 2024
@mbien mbien added this to the NB24 milestone Aug 25, 2024
@apache apache locked and limited conversation to collaborators Aug 25, 2024
@apache apache unlocked this conversation Aug 25, 2024
@mbien mbien removed the ci:all-tests [ci] enable all tests label Aug 25, 2024
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

good idea! It causes some problems though atm. E.g java rename refactoring preview won't show as diff view now if the show-preview button was activated in the find usages window before.

I am also wondering if this is something which should be always enabled (no button), since i looked a bit around and no other window has a button to disable the diff view or preview right now. (checked bookmarks, refactoring and search windows)

(was curious if one of the language tests would be catching this, but everything is green)

@troizet
Copy link
Collaborator Author

troizet commented Aug 25, 2024

It causes some problems though atm. E.g java rename refactoring preview won't show as diff view now if the show-preview button was activated in the find usages window before.

Thank you! I was only testing the case with one open panel and missed the point that multiple panels can be open at the same time. I'll look into it.

I am also wondering if this is something which should be always enabled (no button), since i looked a bit around and no other window has a button to disable the diff view or preview right now. (checked bookmarks, refactoring and search windows)

I think that using the preview for find usages is not mandatory as for refactoring, and should be at the user's discretion.
I also plan to add the same preview for searches.

@Chris2011
Copy link
Contributor

Great work, thx :) @troizet. I didn't look at the code, I just want to thank you.

@troizet
Copy link
Collaborator Author

troizet commented Aug 28, 2024

Regarding the button, I still tend to believe that it is necessary. Maybe put this question on the mailing list for discussion?

@mbien
Copy link
Member

mbien commented Aug 28, 2024

Regarding the button, I still tend to believe that it is necessary. Maybe put this question on the mailing list for discussion?

sure why not. My main point is consistency. A button like this should be on all comparable query-type windows which have a preview. You already mentioned you want to add it to search too, bookmarks window would need it too etc. The easier solution would be no button, since nothing has one atm (this would be also consistent).

The code inspection window (not the refactoring window) has currently no preview, the panel on the right is used for the hint description.

@troizet
Copy link
Collaborator Author

troizet commented Sep 20, 2024

@mbien Removed the preview button. I will try to add it in another PR in all places where it is needed.

@mbien
Copy link
Member

mbien commented Sep 26, 2024

sorry for the delay - I kept getting distracted by other things. Will try to take a look at this this evening - lets try go get this cool feature in.

edit: looks good, I believe most similar windows do have a preview now:
image

@troizet
Copy link
Collaborator Author

troizet commented Sep 26, 2024

I also made a PR for the search results #7779

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

thanks! works great.

Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

Looks sane to me. The search result window might be a good candidate to be enhanced similarly, but that is not necessarily in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Editor UI User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants