Proper handling of right click with multiple selection

This commit is contained in:
Jeremy Soller 2024-01-10 10:26:30 -07:00
parent 716991a302
commit ff87795db0
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
2 changed files with 37 additions and 34 deletions

View file

@ -644,9 +644,7 @@ impl Application for App {
tab.view(self.core()) tab.view(self.core())
.map(move |message| Message::TabMessage(entity, message)), .map(move |message| Message::TabMessage(entity, message)),
) )
.on_press(move |_point_opt| { .on_press(move |_point_opt| Message::TabMessage(entity, tab::Message::Click(None)));
Message::TabMessage(entity, tab::Message::Click(None, false))
});
if tab.context_menu.is_some() { if tab.context_menu.is_some() {
mouse_area = mouse_area mouse_area = mouse_area
.on_right_press(move |_point_opt| Message::TabContextMenu(entity, None)); .on_right_press(move |_point_opt| Message::TabContextMenu(entity, None));

View file

@ -349,9 +349,10 @@ impl Location {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Message { pub enum Message {
Click(Option<usize>, bool), Click(Option<usize>),
Location(Location), Location(Location),
Parent, Parent,
RightClick(usize),
View(View), View(View),
} }
@ -507,35 +508,33 @@ impl Tab {
pub fn update(&mut self, message: Message) -> bool { pub fn update(&mut self, message: Message) -> bool {
let mut cd = None; let mut cd = None;
match message { match message {
Message::Click(click_i_opt, handle_double_click) => { Message::Click(click_i_opt) => {
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 {
item.selected = true; item.selected = true;
if handle_double_click { 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 { match self.location {
match self.location { Location::Path(_) => {
Location::Path(_) => { if item.path.is_dir() {
if item.path.is_dir() { cd = Some(Location::Path(item.path.clone()));
cd = Some(Location::Path(item.path.clone())); } else {
} else { let mut command = open_command(&item.path);
let mut command = open_command(&item.path); match command.spawn() {
match command.spawn() { Ok(_) => (),
Ok(_) => (), Err(err) => {
Err(err) => { log::warn!(
log::warn!( "failed to open {:?}: {}",
"failed to open {:?}: {}", item.path,
item.path, err
err );
);
}
} }
} }
} }
Location::Trash => { }
//TODO: open properties? Location::Trash => {
} //TODO: open properties?
} }
} }
} }
@ -562,6 +561,16 @@ impl Tab {
} }
} }
} }
Message::RightClick(click_i) => {
if let Some(ref mut items) = self.items_opt {
if !items.get(click_i).map_or(false, |x| x.selected) {
// If item not selected, clear selection on other items
for (i, item) in items.iter_mut().enumerate() {
item.selected = i == click_i;
}
}
}
}
Message::View(view) => { Message::View(view) => {
self.view = view; self.view = view;
} }
@ -633,15 +642,13 @@ impl Tab {
.width(Length::Fixed(128.0)), .width(Length::Fixed(128.0)),
) )
.style(button_style(item.selected)) .style(button_style(item.selected))
.on_press(Message::Click(Some(i), true)); .on_press(Message::Click(Some(i)));
if self.context_menu.is_some() { if self.context_menu.is_some() {
children.push(button.into()); children.push(button.into());
} else { } else {
children.push( children.push(
crate::mouse_area::MouseArea::new(button) crate::mouse_area::MouseArea::new(button)
.on_right_press_no_capture(move |_point_opt| { .on_right_press_no_capture(move |_point_opt| Message::RightClick(i))
Message::Click(Some(i), false)
})
.into(), .into(),
); );
} }
@ -721,15 +728,13 @@ impl Tab {
.spacing(space_xxs), .spacing(space_xxs),
) )
.style(button_style(item.selected)) .style(button_style(item.selected))
.on_press(Message::Click(Some(i), true)); .on_press(Message::Click(Some(i)));
if self.context_menu.is_some() { if self.context_menu.is_some() {
children.push(button.into()); children.push(button.into());
} else { } else {
children.push( children.push(
crate::mouse_area::MouseArea::new(button) crate::mouse_area::MouseArea::new(button)
.on_right_press_no_capture(move |_point_opt| { .on_right_press_no_capture(move |_point_opt| Message::RightClick(i))
Message::Click(Some(i), false)
})
.into(), .into(),
); );
} }