Skip to content

Commit

Permalink
added home/desktop directories shortcut buttons for file browser widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Dec 20, 2024
1 parent 3f9ad6f commit 27d7276
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
5 changes: 3 additions & 2 deletions fyrox-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rust-version = "1.72"
fyrox-core = { path = "../fyrox-core", version = "0.28.1", features = ["serde"] }
fyrox-resource = { path = "../fyrox-resource", version = "0.12.0" }
fyrox-graph = { path = "../fyrox-graph", version = "0.1.0" }
fyrox-animation = { path = "../fyrox-animation", version = "0.2.0"}
fyrox-animation = { path = "../fyrox-animation", version = "0.2.0" }
lazy_static = "1.4.0"
copypasta = "0.10.1"
fontdue = "0.9.2"
Expand All @@ -27,10 +27,11 @@ fxhash = "0.2.1"
strum = "0.26.1"
strum_macros = "0.26.1"
serde = { version = "1", features = ["derive"] }
bytemuck = { version = "1.16.1", features = ["derive"]}
bytemuck = { version = "1.16.1", features = ["derive"] }

[features]
enable_profiler = ["fyrox-core/enable_profiler"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sysinfo = "0.29.0"
directories = "5.0.1"
90 changes: 72 additions & 18 deletions fyrox-ui/src/file_browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
//! OS file selector.
use crate::{
core::pool::Handle,
core::{reflect::prelude::*, type_traits::prelude::*, visitor::prelude::*},
core::{
parking_lot::Mutex, pool::Handle, reflect::prelude::*, type_traits::prelude::*,
uuid_provider, visitor::prelude::*,
},
define_constructor,
file_browser::menu::ItemContextMenu,
grid::{Column, GridBuilder, Row},
Expand All @@ -38,6 +40,11 @@ use crate::{
BuildContext, Control, RcUiNodeHandle, Thickness, UiNode, UserInterface, VerticalAlignment,
};
use core::time;
use fyrox_graph::{
constructor::{ConstructorProvider, GraphNodeConstructor},
BaseSceneGraph,
};
use notify::Watcher;
use std::{
borrow::BorrowMut,
cmp::Ordering,
Expand All @@ -51,18 +58,15 @@ use std::{
},
thread,
};
#[cfg(not(target_arch = "wasm32"))]
use sysinfo::{DiskExt, RefreshKind, SystemExt};

mod menu;
mod selector;

use fyrox_core::parking_lot::Mutex;
use fyrox_core::uuid_provider;
use fyrox_graph::constructor::{ConstructorProvider, GraphNodeConstructor};
use fyrox_graph::BaseSceneGraph;
use notify::Watcher;
use crate::button::{ButtonBuilder, ButtonMessage};
use crate::utils::make_simple_tooltip;
pub use selector::*;
#[cfg(not(target_arch = "wasm32"))]
use sysinfo::{DiskExt, RefreshKind, SystemExt};

#[derive(Debug, Clone, PartialEq)]
pub enum FileBrowserMessage {
Expand Down Expand Up @@ -132,6 +136,8 @@ pub enum FileBrowserMode {
pub struct FileBrowser {
pub widget: Widget,
pub tree_root: Handle<UiNode>,
pub home_dir: Handle<UiNode>,
pub desktop_dir: Handle<UiNode>,
pub path_text: Handle<UiNode>,
pub scroll_viewer: Handle<UiNode>,
pub path: PathBuf,
Expand Down Expand Up @@ -171,6 +177,8 @@ impl Clone for FileBrowser {
Self {
widget: self.widget.clone(),
tree_root: self.tree_root,
home_dir: self.home_dir,
desktop_dir: self.desktop_dir,
path_text: self.path_text,
scroll_viewer: self.scroll_viewer,
path: self.path.clone(),
Expand Down Expand Up @@ -502,6 +510,34 @@ impl Control for FileBrowser {
}
}
}
} else if let Some(ButtonMessage::Click) = message.data() {
if message.direction() == MessageDirection::FromWidget {
#[cfg(not(target_arch = "wasm32"))]
if message.destination() == self.desktop_dir {
let user_dirs = directories::UserDirs::new();
if let Some(desktop_dir) =
user_dirs.as_ref().and_then(|dirs| dirs.desktop_dir())
{
ui.send_message(FileBrowserMessage::path(
self.handle,
MessageDirection::ToWidget,
desktop_dir.to_path_buf(),
));
}
}

#[cfg(not(target_arch = "wasm32"))]
if message.destination() == self.home_dir {
let user_dirs = directories::UserDirs::new();
if let Some(home_dir) = user_dirs.as_ref().map(|dirs| dirs.home_dir()) {
ui.send_message(FileBrowserMessage::path(
self.handle,
MessageDirection::ToWidget,
home_dir.to_path_buf(),
));
}
}
}
}
}

Expand Down Expand Up @@ -944,31 +980,46 @@ impl FileBrowserBuilder {
})
.build(ctx);

let home_dir;
let desktop_dir;
let grid = GridBuilder::new(
WidgetBuilder::new()
.with_child(
GridBuilder::new(
WidgetBuilder::new()
.with_visibility(self.show_path)
.with_height(24.0)
.with_child(
TextBuilder::new(
.with_child({
home_dir = ButtonBuilder::new(
WidgetBuilder::new()
.on_row(0)
.on_column(0)
.with_vertical_alignment(VerticalAlignment::Center)
.with_width(24.0)
.with_tooltip(make_simple_tooltip(ctx, "Home Folder"))
.with_margin(Thickness::uniform(1.0)),
)
.with_text("Path:")
.build(ctx),
)
.with_text("H")
.build(ctx);
home_dir
})
.with_child({
desktop_dir = ButtonBuilder::new(
WidgetBuilder::new()
.on_column(1)
.with_width(24.0)
.with_tooltip(make_simple_tooltip(ctx, "Desktop Folder"))
.with_margin(Thickness::uniform(1.0)),
)
.with_text("D")
.build(ctx);
desktop_dir
})
.with_child({
path_text = TextBoxBuilder::new(
WidgetBuilder::new()
// Disable path if we're in Save mode
.with_enabled(matches!(self.mode, FileBrowserMode::Open))
.on_row(0)
.on_column(1)
.on_column(2)
.with_margin(Thickness::uniform(2.0)),
)
.with_text_commit_mode(TextCommitMode::Immediate)
Expand All @@ -979,7 +1030,8 @@ impl FileBrowserBuilder {
}),
)
.add_row(Row::stretch())
.add_column(Column::strict(80.0))
.add_column(Column::auto())
.add_column(Column::auto())
.add_column(Column::stretch())
.build(ctx),
)
Expand Down Expand Up @@ -1056,6 +1108,8 @@ impl FileBrowserBuilder {
fs_receiver: Some(fs_receiver),
widget,
tree_root,
home_dir,
desktop_dir,
path_text,
path: match self.mode {
FileBrowserMode::Open => self.path,
Expand Down

0 comments on commit 27d7276

Please sign in to comment.