Rework FileDialogConfig::initial_directory as initial_path#288
Rework FileDialogConfig::initial_directory as initial_path#288crumblingstatue wants to merge 3 commits intojannistpl:mainfrom
Conversation
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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, | ||
| )); | ||
| } |
There was a problem hiding this comment.
We should be able to simplify this using:
if self.config.initial_path.is_file() {
self.select_item(...)
}| 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; |
There was a problem hiding this comment.
Could you keep the initial_directory method and mark it as deprecated?
| &self.config.initial_path, | ||
| &*self.config.file_system, | ||
| )); | ||
| } |
There was a problem hiding this comment.
We should add:
self.scroll_to_selection = true;After selecting the item, so egui automatically scrolls to it in the first frame.
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