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

codenav/goto_file: Improvements & fixes (tab key autocomplete, absolute dirs, ~/) #1390

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

gkatev
Copy link
Contributor

@gkatev gkatev commented Nov 27, 2024

Hi, this supercharges codenav/goto_file with a wide range of changes, fixes, and new features.

I've included all the smaller commits, in case someone wants to take a closer look at each change, but I can squash them together before merging. This also supersedes #1329.

Features & changes:

  • The Tab key can now be used to:
    (Inspired from shells, and GtkFileChooser)
    • Show the completion list when it's hidden
    • Trigger an inline completion
    • Accept a suggested inline completion
  • Keep dialog open after user denies creation of not-found file (codenav: Keep "Go to file" dialog open after denying creation of file that wasn't found #1329)
  • Allow absolute paths, and recognize ~ as the user's home dir
  • If no document is open, the current dir is the user's home dir
  • Show error if the entered path is a directory
  • Show completion list as soon as dialog opens
    • Did we actually want this? Input welcome.
  • Bug fixes, improvements, code formatting fixes

Demo:

codenav.mp4

…nd file

Previously, if the file wasn't found and you replied 'no' to the prompt
for creating it, all dialogs closed. This can be annoying in situations
where the name/path was entered wrong, and you have to start all over
again after receiving the file not found error. This commit allows one
to amend the mistake from right where they left off.

It was deemed necessary to add GTK_DIALOG_MODAL flag to the dialog creation.
Without it, after the repeat gtk_dialog_run call (through the goto), the UI
got kinda bugged, with the focus (correctly) being in the dialog, but visually
appearing as if it had shifted back to the editor pane.
The user's home directory is used as a relative path reference.
1. Can now use Tab key to 'accept' autocomplete's 'suggestion'

2. Add dir separator to end of items in completion list that are
directories, to make traversing a path quicker, especially when
used together with (1).

3. Show the completion list as soon as the goto_file dialog opens
(at the same directory as the document). The code kind of reads
like this is also what the original author intended.
The pre-existing funcionality of using Tab to
accept a completion suggestion is still supported.

Furthermore, the Enter key may also be used
now to accept a suggestion.
The way the completion model to use when no directory separator is found
is unecessarily convoluted. This change simplifies and improves it.

Also fixes a bug that can cause junky behaviour when pasting a path as soon
as the dialog opens, if that was also the last path in the dialog the last
time it was opened. The root cause is that the completion model is set during
init to the reference directory, but directory_check() does not create a new
one for the pasted path, because curr_dir (which is static) has not been
updated to reflect that the reference mode is now active.
The new directory_check is (IMHO) simpler, easier to follow and maintain,
and less prone to edge cases.

As part of simplifications, do away with the "reference model". We do keep
track of the "reference dir" and if need be simply calculate a mode for it
as if any other dir.

Bonus (admittedly rare) issue solved: not having to close and reopen the
dialog if a file is created while it's opened...
Move the respective g_signal_connect before gtk_entry_set_completion(),
which is where the GtkEntryCompletion's handler gets installed.
…vent

Does not seem our place to decide whether the default handler
should not run, and it doesn't harm us any way if it does...
@gkatev gkatev force-pushed the codenav_goto_file_improvements branch from 6d6b2e8 to 09e5004 Compare November 27, 2024 11:33
@gkatev gkatev force-pushed the codenav_goto_file_improvements branch from 09e5004 to 798c804 Compare November 27, 2024 12:03
gkatev added a commit to gkatev/geany-plugins that referenced this pull request Nov 27, 2024
… dirs, ~/)

PR geany#1390

New features & changes:

- The Tab key can now be used to:
  (Inspired from shells, and GtkFileChooser)
	- Show the completion list when it's hidden
	- Trigger an inline completion
	- Accept a suggested inline completion
- Keep dialog open after user denies creation of not-found file (geany#1329)
- Allow absolute paths, and recognize ~ as the user's home dir
- If no document is open, the current dir is the user's home dir
- Show error if the entered path is a directory
- Bug fixes, improvements, code formatting fixes
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.

1 participant