Skip to content

Rework FileDialogConfig::initial_directory as initial_path#288

Draft
crumblingstatue wants to merge 3 commits intojannistpl:mainfrom
crumblingstatue:preselect
Draft

Rework FileDialogConfig::initial_directory as initial_path#288
crumblingstatue wants to merge 3 commits intojannistpl:mainfrom
crumblingstatue:preselect

Conversation

@crumblingstatue
Copy link
Contributor

@crumblingstatue crumblingstatue commented Sep 26, 2025

If the initial path has an extra component compared to the computed initial directory, use the extra component to pre-select an item in the directory.

Fixes #287

If the initial path has an extra component compared to
the computed initial directory, use the extra component to pre-select
an item in the directory.
let init_dir = self.get_initial_directory();
self.load_directory(&init_dir);
let init_path = &self.config.initial_path;
// If the initial path has an extra component, use it to pre-select an item.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm honestly not sure if this is the best way to go about it, or if we should do a more clear separation of initial directory, and initially selected file at a higher level.

Copy link
Owner

Choose a reason for hiding this comment

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

The problem, if we separate the initial directory and initial file, it can lead to situations where the initial file does not correspond to the initial directory. I think I currently prefer the initial directory idea. But I'll have to try it out for myself to see how it feels when I use it.

Comment on lines +383 to +389
if init_path != &init_dir && init_path.starts_with(init_dir) {
self.select_item(&mut DirectoryEntry::from_path(
&self.config,
&self.config.initial_path,
&*self.config.file_system,
));
}
Copy link
Owner

Choose a reason for hiding this comment

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

We should be able to simplify this using:

if self.config.initial_path.is_file() {
     self.select_item(...)
}

Comment on lines -550 to +563
pub fn initial_directory(mut self, directory: PathBuf) -> Self {
self.config.initial_directory = directory;
pub fn initial_path(mut self, directory: PathBuf) -> Self {
self.config.initial_path = directory;
Copy link
Owner

Choose a reason for hiding this comment

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

Could you keep the initial_directory method and mark it as deprecated?

&self.config.initial_path,
&*self.config.file_system,
));
}
Copy link
Owner

Choose a reason for hiding this comment

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

We should add:

self.scroll_to_selection = true;

After selecting the item, so egui automatically scrolls to it in the first frame.

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.

Allow pre-selecting file when opening file dialog

2 participants