Dialog improvements

This commit is contained in:
Jeremy Soller 2024-02-26 14:31:50 -07:00
parent a936cd4a6d
commit ab3b5f40d5
4 changed files with 45 additions and 15 deletions

View file

@ -122,7 +122,7 @@ impl Application for App {
let mut button = widget::button::standard("Save File");
if self.dialog_opt.is_none() {
button = button.on_press(Message::DialogOpen(DialogKind::SaveFile {
filename: "test".to_string()
filename: "test".to_string(),
}));
}
column = column.push(button);

View file

@ -30,9 +30,9 @@ use crate::{
fl, home_dir,
key_bind::{key_binds, KeyBind},
menu,
util,
operation::Operation,
tab::{self, ItemMetadata, Location, Tab},
util,
};
#[derive(Clone, Debug)]
@ -881,11 +881,7 @@ impl Application for App {
match command.spawn() {
Ok(_) => (),
Err(err) => {
log::warn!(
"failed to open {:?}: {}",
item_path,
err
);
log::warn!("failed to open {:?}: {}", item_path, err);
}
}
}

View file

@ -341,6 +341,7 @@ impl Application for App {
let mut tab = Tab::new(location, TabConfig::default());
tab.dialog = Some(flags.kind.clone());
tab.view = tab::View::List;
let mut app = App {
core,
@ -457,15 +458,38 @@ impl Application for App {
}
}
}
// Ensure selection is allowed
//TODO: improve tab logic so this doesn't block the open button so often
for path in paths.iter() {
let path_is_dir = path.is_dir();
if path_is_dir != self.flags.kind.is_dir() {
if path_is_dir && paths.len() == 1 {
// If the only selected item is a directory and we are selecting files, cd to it
let message = Message::TabMessage(tab::Message::Location(
Location::Path(path.clone()),
));
return self.update(message);
} else {
// Otherwise, this is not a legal selection
return Command::none();
}
}
}
// If there are proper matching items, return them
if !paths.is_empty() {
self.result_opt = Some(DialogResult::Open(paths));
return window::close(self.main_window_id());
} else if self.flags.kind.is_dir() {
}
// If we are in directory mode, return the current directory
if self.flags.kind.is_dir() {
match &self.tab.location {
Location::Path(tab_path) => {
self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()]));
return window::close(self.main_window_id());
},
}
_ => {}
}
}
@ -513,7 +537,8 @@ impl Application for App {
log::warn!("Action {:?} not supported in dialog", action);
}
tab::Command::ChangeLocation(_tab_title, _tab_path) => {
commands.push(Command::batch([self.update_watcher(), self.rescan_tab()]));
commands
.push(Command::batch([self.update_watcher(), self.rescan_tab()]));
}
tab::Command::OpenFile(_item_path) => {
commands.push(self.update(Message::Open));

View file

@ -536,7 +536,7 @@ impl Tab {
location,
context_menu: None,
items_opt: None,
view: View::Grid,
view: View::List,
dialog: None,
drag_opt: None,
scroll_opt: None,
@ -566,10 +566,6 @@ impl Tab {
};
println!("{:?}", rect);
let (row, col) = match self.view {
View::Grid => (0, 0),
View::List => (0, 0),
};
for (i, item) in items.iter_mut().enumerate() {
item.selected = false;
//TODO
@ -585,6 +581,19 @@ impl Tab {
if let Some(ref mut items) = self.items_opt {
for (i, item) in items.iter_mut().enumerate() {
if Some(i) == click_i_opt {
// Filter out selection if it does not match dialog kind
if let Some(dialog) = &self.dialog {
let item_is_dir = item.path.is_dir();
if item_is_dir != dialog.is_dir() {
// Allow selecting folder if dialog is for files to make it
// possible to double click
//TODO: clear any other selection when selecting a folder
if !item_is_dir {
continue;
}
}
}
item.selected = true;
if let Some(click_time) = item.click_time {
if click_time.elapsed() < DOUBLE_CLICK_DURATION {