Allow multiple selection when holding ctrl
This commit is contained in:
parent
0708c0eb39
commit
35c08f469e
2 changed files with 83 additions and 4 deletions
72
src/main.rs
72
src/main.rs
|
|
@ -5,7 +5,13 @@ use cosmic::{
|
||||||
app::{message, Command, Core, Settings},
|
app::{message, Command, Core, Settings},
|
||||||
cosmic_config::{self, CosmicConfigEntry},
|
cosmic_config::{self, CosmicConfigEntry},
|
||||||
cosmic_theme, executor,
|
cosmic_theme, executor,
|
||||||
iced::{subscription::Subscription, widget::row, window, Alignment, Length, Point},
|
iced::{
|
||||||
|
event,
|
||||||
|
keyboard::{Event as KeyEvent, KeyCode, Modifiers},
|
||||||
|
subscription::Subscription,
|
||||||
|
widget::row,
|
||||||
|
window, Alignment, Event, Length, Point,
|
||||||
|
},
|
||||||
style,
|
style,
|
||||||
widget::{self, segmented_button},
|
widget::{self, segmented_button},
|
||||||
Application, ApplicationExt, Element,
|
Application, ApplicationExt, Element,
|
||||||
|
|
@ -135,6 +141,7 @@ pub enum Message {
|
||||||
AppTheme(AppTheme),
|
AppTheme(AppTheme),
|
||||||
Config(Config),
|
Config(Config),
|
||||||
Copy(Option<segmented_button::Entity>),
|
Copy(Option<segmented_button::Entity>),
|
||||||
|
KeyModifiers(Modifiers),
|
||||||
MoveToTrash(Option<segmented_button::Entity>),
|
MoveToTrash(Option<segmented_button::Entity>),
|
||||||
NewFile(Option<segmented_button::Entity>),
|
NewFile(Option<segmented_button::Entity>),
|
||||||
NewFolder(Option<segmented_button::Entity>),
|
NewFolder(Option<segmented_button::Entity>),
|
||||||
|
|
@ -176,6 +183,7 @@ pub struct App {
|
||||||
config: Config,
|
config: Config,
|
||||||
app_themes: Vec<String>,
|
app_themes: Vec<String>,
|
||||||
context_page: ContextPage,
|
context_page: ContextPage,
|
||||||
|
modifiers: Modifiers,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
|
@ -345,6 +353,7 @@ impl Application for App {
|
||||||
config: flags.config,
|
config: flags.config,
|
||||||
app_themes,
|
app_themes,
|
||||||
context_page: ContextPage::Settings,
|
context_page: ContextPage::Settings,
|
||||||
|
modifiers: Modifiers::empty(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut commands = Vec::new();
|
let mut commands = Vec::new();
|
||||||
|
|
@ -425,6 +434,9 @@ impl Application for App {
|
||||||
Message::Copy(entity_opt) => {
|
Message::Copy(entity_opt) => {
|
||||||
log::warn!("TODO: COPY");
|
log::warn!("TODO: COPY");
|
||||||
}
|
}
|
||||||
|
Message::KeyModifiers(modifiers) => {
|
||||||
|
self.modifiers = modifiers;
|
||||||
|
}
|
||||||
Message::MoveToTrash(entity_opt) => {
|
Message::MoveToTrash(entity_opt) => {
|
||||||
log::warn!("TODO: MOVE TO TRASH");
|
log::warn!("TODO: MOVE TO TRASH");
|
||||||
}
|
}
|
||||||
|
|
@ -510,7 +522,7 @@ impl Application for App {
|
||||||
let mut update_opt = None;
|
let mut update_opt = None;
|
||||||
match self.tab_model.data_mut::<Tab>(entity) {
|
match self.tab_model.data_mut::<Tab>(entity) {
|
||||||
Some(tab) => {
|
Some(tab) => {
|
||||||
if tab.update(tab_message) {
|
if tab.update(tab_message, self.modifiers) {
|
||||||
update_opt = Some((tab.title(), tab.location.clone()));
|
update_opt = Some((tab.title(), tab.location.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -682,6 +694,62 @@ impl Application for App {
|
||||||
struct ThemeSubscription;
|
struct ThemeSubscription;
|
||||||
|
|
||||||
Subscription::batch([
|
Subscription::batch([
|
||||||
|
event::listen_with(|event, _status| match event {
|
||||||
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
|
key_code: KeyCode::A,
|
||||||
|
modifiers,
|
||||||
|
}) => {
|
||||||
|
if modifiers == Modifiers::CTRL {
|
||||||
|
Some(Message::SelectAll(None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
|
key_code: KeyCode::C,
|
||||||
|
modifiers,
|
||||||
|
}) => {
|
||||||
|
if modifiers == Modifiers::CTRL {
|
||||||
|
Some(Message::Copy(None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
|
key_code: KeyCode::X,
|
||||||
|
modifiers,
|
||||||
|
}) => {
|
||||||
|
if modifiers == Modifiers::CTRL {
|
||||||
|
Some(Message::Copy(None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
|
key_code: KeyCode::T,
|
||||||
|
modifiers,
|
||||||
|
}) => {
|
||||||
|
if modifiers == Modifiers::CTRL {
|
||||||
|
Some(Message::TabNew)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
|
key_code: KeyCode::V,
|
||||||
|
modifiers,
|
||||||
|
}) => {
|
||||||
|
if modifiers == Modifiers::CTRL {
|
||||||
|
Some(Message::Paste(None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
||||||
|
Some(Message::KeyModifiers(modifiers))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}),
|
||||||
cosmic_config::config_subscription(
|
cosmic_config::config_subscription(
|
||||||
TypeId::of::<ConfigSubscription>(),
|
TypeId::of::<ConfigSubscription>(),
|
||||||
Self::APP_ID.into(),
|
Self::APP_ID.into(),
|
||||||
|
|
|
||||||
15
src/tab.rs
15
src/tab.rs
|
|
@ -3,6 +3,7 @@ use cosmic::{
|
||||||
cosmic_theme,
|
cosmic_theme,
|
||||||
iced::{
|
iced::{
|
||||||
alignment::{Horizontal, Vertical},
|
alignment::{Horizontal, Vertical},
|
||||||
|
keyboard::Modifiers,
|
||||||
Alignment, Length, Point,
|
Alignment, Length, Point,
|
||||||
},
|
},
|
||||||
theme, widget, Element,
|
theme, widget, Element,
|
||||||
|
|
@ -505,7 +506,7 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, message: Message) -> bool {
|
pub fn update(&mut self, message: Message, modifiers: Modifiers) -> bool {
|
||||||
let mut cd = None;
|
let mut cd = None;
|
||||||
match message {
|
match message {
|
||||||
Message::Click(click_i_opt) => {
|
Message::Click(click_i_opt) => {
|
||||||
|
|
@ -541,6 +542,9 @@ impl Tab {
|
||||||
}
|
}
|
||||||
//TODO: prevent triple-click and beyond from opening file?
|
//TODO: prevent triple-click and beyond from opening file?
|
||||||
item.click_time = Some(Instant::now());
|
item.click_time = Some(Instant::now());
|
||||||
|
} else if modifiers.contains(Modifiers::CTRL) {
|
||||||
|
// Holding control allows multiple selection
|
||||||
|
item.click_time = None;
|
||||||
} else {
|
} else {
|
||||||
item.selected = false;
|
item.selected = false;
|
||||||
item.click_time = None;
|
item.click_time = None;
|
||||||
|
|
@ -564,7 +568,14 @@ impl Tab {
|
||||||
if !items.get(click_i).map_or(false, |x| x.selected) {
|
if !items.get(click_i).map_or(false, |x| x.selected) {
|
||||||
// If item not selected, clear selection on other items
|
// If item not selected, clear selection on other items
|
||||||
for (i, item) in items.iter_mut().enumerate() {
|
for (i, item) in items.iter_mut().enumerate() {
|
||||||
item.selected = i == click_i;
|
if i == click_i {
|
||||||
|
item.selected = true;
|
||||||
|
} else if modifiers.contains(Modifiers::CTRL) {
|
||||||
|
// Holding control allows multiple selection
|
||||||
|
} else {
|
||||||
|
item.selected = false;
|
||||||
|
}
|
||||||
|
item.click_time = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue