Dialog improvements
This commit is contained in:
parent
a936cd4a6d
commit
ab3b5f40d5
4 changed files with 45 additions and 15 deletions
|
|
@ -122,7 +122,7 @@ impl Application for App {
|
||||||
let mut button = widget::button::standard("Save File");
|
let mut button = widget::button::standard("Save File");
|
||||||
if self.dialog_opt.is_none() {
|
if self.dialog_opt.is_none() {
|
||||||
button = button.on_press(Message::DialogOpen(DialogKind::SaveFile {
|
button = button.on_press(Message::DialogOpen(DialogKind::SaveFile {
|
||||||
filename: "test".to_string()
|
filename: "test".to_string(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
column = column.push(button);
|
column = column.push(button);
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ use crate::{
|
||||||
fl, home_dir,
|
fl, home_dir,
|
||||||
key_bind::{key_binds, KeyBind},
|
key_bind::{key_binds, KeyBind},
|
||||||
menu,
|
menu,
|
||||||
util,
|
|
||||||
operation::Operation,
|
operation::Operation,
|
||||||
tab::{self, ItemMetadata, Location, Tab},
|
tab::{self, ItemMetadata, Location, Tab},
|
||||||
|
util,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -881,11 +881,7 @@ impl Application for App {
|
||||||
match command.spawn() {
|
match command.spawn() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!(
|
log::warn!("failed to open {:?}: {}", item_path, err);
|
||||||
"failed to open {:?}: {}",
|
|
||||||
item_path,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -341,6 +341,7 @@ impl Application for App {
|
||||||
|
|
||||||
let mut tab = Tab::new(location, TabConfig::default());
|
let mut tab = Tab::new(location, TabConfig::default());
|
||||||
tab.dialog = Some(flags.kind.clone());
|
tab.dialog = Some(flags.kind.clone());
|
||||||
|
tab.view = tab::View::List;
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
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() {
|
if !paths.is_empty() {
|
||||||
self.result_opt = Some(DialogResult::Open(paths));
|
self.result_opt = Some(DialogResult::Open(paths));
|
||||||
return window::close(self.main_window_id());
|
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 {
|
match &self.tab.location {
|
||||||
Location::Path(tab_path) => {
|
Location::Path(tab_path) => {
|
||||||
self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()]));
|
self.result_opt = Some(DialogResult::Open(vec![tab_path.clone()]));
|
||||||
return window::close(self.main_window_id());
|
return window::close(self.main_window_id());
|
||||||
},
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +537,8 @@ impl Application for App {
|
||||||
log::warn!("Action {:?} not supported in dialog", action);
|
log::warn!("Action {:?} not supported in dialog", action);
|
||||||
}
|
}
|
||||||
tab::Command::ChangeLocation(_tab_title, _tab_path) => {
|
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) => {
|
tab::Command::OpenFile(_item_path) => {
|
||||||
commands.push(self.update(Message::Open));
|
commands.push(self.update(Message::Open));
|
||||||
|
|
|
||||||
19
src/tab.rs
19
src/tab.rs
|
|
@ -536,7 +536,7 @@ impl Tab {
|
||||||
location,
|
location,
|
||||||
context_menu: None,
|
context_menu: None,
|
||||||
items_opt: None,
|
items_opt: None,
|
||||||
view: View::Grid,
|
view: View::List,
|
||||||
dialog: None,
|
dialog: None,
|
||||||
drag_opt: None,
|
drag_opt: None,
|
||||||
scroll_opt: None,
|
scroll_opt: None,
|
||||||
|
|
@ -566,10 +566,6 @@ impl Tab {
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{:?}", rect);
|
println!("{:?}", rect);
|
||||||
let (row, col) = match self.view {
|
|
||||||
View::Grid => (0, 0),
|
|
||||||
View::List => (0, 0),
|
|
||||||
};
|
|
||||||
for (i, item) in items.iter_mut().enumerate() {
|
for (i, item) in items.iter_mut().enumerate() {
|
||||||
item.selected = false;
|
item.selected = false;
|
||||||
//TODO
|
//TODO
|
||||||
|
|
@ -585,6 +581,19 @@ impl Tab {
|
||||||
if let Some(ref mut items) = self.items_opt {
|
if let Some(ref mut items) = self.items_opt {
|
||||||
for (i, item) in items.iter_mut().enumerate() {
|
for (i, item) in items.iter_mut().enumerate() {
|
||||||
if Some(i) == click_i_opt {
|
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;
|
item.selected = true;
|
||||||
if let Some(click_time) = item.click_time {
|
if let Some(click_time) = item.click_time {
|
||||||
if click_time.elapsed() < DOUBLE_CLICK_DURATION {
|
if click_time.elapsed() < DOUBLE_CLICK_DURATION {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue