Skip to content

Commit

Permalink
ability to focus current path in the filer browser widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Dec 20, 2024
1 parent fbd30ac commit 2a76bdb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fyrox-ui/src/file_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum FileBrowserMessage {
Filter(Option<Filter>),
Add(PathBuf),
Remove(PathBuf),
FocusCurrentPath,
Rescan,
Drop {
dropped: Handle<UiNode>,
Expand All @@ -92,6 +93,7 @@ impl FileBrowserMessage {
define_constructor!(FileBrowserMessage:Add => fn add(PathBuf), layout: false);
define_constructor!(FileBrowserMessage:Remove => fn remove(PathBuf), layout: false);
define_constructor!(FileBrowserMessage:Rescan => fn rescan(), layout: false);
define_constructor!(FileBrowserMessage:FocusCurrentPath => fn focus_current_path(), layout: false);
define_constructor!(FileBrowserMessage:Drop => fn drop(
dropped: Handle<UiNode>,
path_item: Handle<UiNode>,
Expand Down Expand Up @@ -389,6 +391,18 @@ impl Control for FileBrowser {
}
}
FileBrowserMessage::Rescan | FileBrowserMessage::Drop { .. } => (),
FileBrowserMessage::FocusCurrentPath => {
if let Ok(canonical_path) = self.path.canonicalize() {
let item = find_tree(self.tree_root, &canonical_path, ui);
if item.is_some() {
ui.send_message(ScrollViewerMessage::bring_into_view(
self.scroll_viewer,
MessageDirection::ToWidget,
item,
));
}
}
}
}
}
} else if let Some(TextMessage::Text(txt)) = message.data::<TextMessage>() {
Expand Down
8 changes: 8 additions & 0 deletions fyrox-ui/src/file_browser/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum FileSelectorMessage {
Root(Option<PathBuf>),
Path(PathBuf),
Commit(PathBuf),
FocusCurrentPath,
Cancel,
Filter(Option<Filter>),
}
Expand All @@ -59,6 +60,7 @@ impl FileSelectorMessage {
define_constructor!(FileSelectorMessage:Root => fn root(Option<PathBuf>), layout: false);
define_constructor!(FileSelectorMessage:Path => fn path(PathBuf), layout: false);
define_constructor!(FileSelectorMessage:Cancel => fn cancel(), layout: false);
define_constructor!(FileSelectorMessage:FocusCurrentPath => fn focus_current_path(), layout: false);
define_constructor!(FileSelectorMessage:Filter => fn filter(Option<Filter>), layout: false);
}

Expand Down Expand Up @@ -172,6 +174,12 @@ impl Control for FileSelector {
filter.clone(),
));
}
FileSelectorMessage::FocusCurrentPath => {
ui.send_message(FileBrowserMessage::focus_current_path(
self.browser,
MessageDirection::ToWidget,
));
}
}
}
}
Expand Down

0 comments on commit 2a76bdb

Please sign in to comment.