visualise cut items (#954)
This commit is contained in:
parent
2d22b6d516
commit
569247acfb
3 changed files with 85 additions and 2 deletions
28
src/app.rs
28
src/app.rs
|
|
@ -401,6 +401,7 @@ pub enum Message {
|
||||||
Cosmic(app::Action),
|
Cosmic(app::Action),
|
||||||
None,
|
None,
|
||||||
Surface(surface::Action),
|
Surface(surface::Action),
|
||||||
|
CutPaths(Vec<PathBuf>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
@ -1100,6 +1101,13 @@ impl App {
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_cut(&mut self, entity_opt: Option<Entity>) {
|
||||||
|
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||||
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
|
tab.cut_selected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_config(&mut self) -> Task<Message> {
|
fn update_config(&mut self) -> Task<Message> {
|
||||||
self.update_nav_model();
|
self.update_nav_model();
|
||||||
// Tabs are collected first to placate the borrowck
|
// Tabs are collected first to placate the borrowck
|
||||||
|
|
@ -2218,6 +2226,11 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Copy(entity_opt) => {
|
Message::Copy(entity_opt) => {
|
||||||
|
if let Some(entity) = entity_opt {
|
||||||
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
|
tab.refresh_cut(&[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
let paths = self.selected_paths(entity_opt);
|
let paths = self.selected_paths(entity_opt);
|
||||||
let contents = ClipboardCopy::new(ClipboardKind::Copy, &paths);
|
let contents = ClipboardCopy::new(ClipboardKind::Copy, &paths);
|
||||||
return clipboard::write_data(contents);
|
return clipboard::write_data(contents);
|
||||||
|
|
@ -2230,6 +2243,7 @@ impl Application for App {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Message::Cut(entity_opt) => {
|
Message::Cut(entity_opt) => {
|
||||||
|
self.set_cut(entity_opt);
|
||||||
let paths = self.selected_paths(entity_opt);
|
let paths = self.selected_paths(entity_opt);
|
||||||
let contents = ClipboardCopy::new(ClipboardKind::Cut, &paths);
|
let contents = ClipboardCopy::new(ClipboardKind::Cut, &paths);
|
||||||
return clipboard::write_data(contents);
|
return clipboard::write_data(contents);
|
||||||
|
|
@ -3491,6 +3505,15 @@ impl Application for App {
|
||||||
if let Some(selection_paths) = selection_paths {
|
if let Some(selection_paths) = selection_paths {
|
||||||
tab.select_paths(selection_paths);
|
tab.select_paths(selection_paths);
|
||||||
}
|
}
|
||||||
|
return clipboard::read_data::<ClipboardPaste>().map(|p| {
|
||||||
|
cosmic::action::app(Message::CutPaths(match p {
|
||||||
|
Some(s) => match s.kind {
|
||||||
|
ClipboardKind::Copy => Vec::new(),
|
||||||
|
ClipboardKind::Cut => s.paths,
|
||||||
|
},
|
||||||
|
None => Vec::new(),
|
||||||
|
}))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3503,6 +3526,11 @@ impl Application for App {
|
||||||
config.view = view;
|
config.view = view;
|
||||||
return self.update(Message::TabConfig(config));
|
return self.update(Message::TabConfig(config));
|
||||||
}
|
}
|
||||||
|
Message::CutPaths(paths) => {
|
||||||
|
if let Some(tab) = self.tab_model.active_data_mut::<Tab>() {
|
||||||
|
tab.refresh_cut(&paths);
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::TimeConfigChange(time_config) => {
|
Message::TimeConfigChange(time_config) => {
|
||||||
self.config.tab.military_time = time_config.military_time;
|
self.config.tab.military_time = time_config.military_time;
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ fn network_scan(uri: &str, sizes: IconSizes) -> Result<Vec<tab::Item>, String> {
|
||||||
overlaps_drag_rect: false,
|
overlaps_drag_rect: false,
|
||||||
//TODO: scan directory size on gvfs mounts?
|
//TODO: scan directory size on gvfs mounts?
|
||||||
dir_size: DirSize::NotDirectory,
|
dir_size: DirSize::NotDirectory,
|
||||||
|
cut: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(items)
|
Ok(items)
|
||||||
|
|
|
||||||
58
src/tab.rs
58
src/tab.rs
|
|
@ -125,6 +125,7 @@ fn button_appearance(
|
||||||
theme: &theme::Theme,
|
theme: &theme::Theme,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
highlighted: bool,
|
highlighted: bool,
|
||||||
|
cut: bool,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
accent: bool,
|
accent: bool,
|
||||||
condensed_radius: bool,
|
condensed_radius: bool,
|
||||||
|
|
@ -136,7 +137,11 @@ fn button_appearance(
|
||||||
if accent {
|
if accent {
|
||||||
appearance.background = Some(Color::from(cosmic.accent_color()).into());
|
appearance.background = Some(Color::from(cosmic.accent_color()).into());
|
||||||
appearance.icon_color = Some(Color::from(cosmic.on_accent_color()));
|
appearance.icon_color = Some(Color::from(cosmic.on_accent_color()));
|
||||||
appearance.text_color = Some(Color::from(cosmic.on_accent_color()));
|
if cut {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.accent.on_disabled));
|
||||||
|
} else {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.on_accent_color()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
||||||
}
|
}
|
||||||
|
|
@ -145,13 +150,24 @@ fn button_appearance(
|
||||||
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
||||||
appearance.icon_color = Some(Color::from(cosmic.on_bg_component_color()));
|
appearance.icon_color = Some(Color::from(cosmic.on_bg_component_color()));
|
||||||
appearance.text_color = Some(Color::from(cosmic.on_bg_component_color()));
|
appearance.text_color = Some(Color::from(cosmic.on_bg_component_color()));
|
||||||
|
if cut {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.background.component.on_disabled));
|
||||||
|
} else {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.on_bg_component_color()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
appearance.background = Some(Color::from(cosmic.bg_component_color()).into());
|
||||||
}
|
}
|
||||||
} else if desktop {
|
} else if desktop {
|
||||||
appearance.background = Some(Color::from(cosmic.bg_color()).into());
|
appearance.background = Some(Color::from(cosmic.bg_color()).into());
|
||||||
appearance.icon_color = Some(Color::from(cosmic.on_bg_color()));
|
appearance.icon_color = Some(Color::from(cosmic.on_bg_color()));
|
||||||
appearance.text_color = Some(Color::from(cosmic.on_bg_color()));
|
if cut {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.background.component.disabled));
|
||||||
|
} else {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.on_bg_color()));
|
||||||
|
}
|
||||||
|
} else if cut {
|
||||||
|
appearance.text_color = Some(Color::from(cosmic.background.component.on_disabled));
|
||||||
}
|
}
|
||||||
if focused && accent {
|
if focused && accent {
|
||||||
appearance.outline_width = 1.0;
|
appearance.outline_width = 1.0;
|
||||||
|
|
@ -170,6 +186,7 @@ fn button_appearance(
|
||||||
fn button_style(
|
fn button_style(
|
||||||
selected: bool,
|
selected: bool,
|
||||||
highlighted: bool,
|
highlighted: bool,
|
||||||
|
cut: bool,
|
||||||
accent: bool,
|
accent: bool,
|
||||||
condensed_radius: bool,
|
condensed_radius: bool,
|
||||||
desktop: bool,
|
desktop: bool,
|
||||||
|
|
@ -181,6 +198,7 @@ fn button_style(
|
||||||
theme,
|
theme,
|
||||||
selected,
|
selected,
|
||||||
highlighted,
|
highlighted,
|
||||||
|
cut,
|
||||||
focused,
|
focused,
|
||||||
accent,
|
accent,
|
||||||
condensed_radius,
|
condensed_radius,
|
||||||
|
|
@ -192,6 +210,7 @@ fn button_style(
|
||||||
theme,
|
theme,
|
||||||
selected,
|
selected,
|
||||||
highlighted,
|
highlighted,
|
||||||
|
cut,
|
||||||
false,
|
false,
|
||||||
accent,
|
accent,
|
||||||
condensed_radius,
|
condensed_radius,
|
||||||
|
|
@ -203,6 +222,7 @@ fn button_style(
|
||||||
theme,
|
theme,
|
||||||
selected,
|
selected,
|
||||||
highlighted,
|
highlighted,
|
||||||
|
cut,
|
||||||
focused,
|
focused,
|
||||||
accent,
|
accent,
|
||||||
condensed_radius,
|
condensed_radius,
|
||||||
|
|
@ -214,6 +234,7 @@ fn button_style(
|
||||||
theme,
|
theme,
|
||||||
selected,
|
selected,
|
||||||
highlighted,
|
highlighted,
|
||||||
|
cut,
|
||||||
focused,
|
focused,
|
||||||
accent,
|
accent,
|
||||||
condensed_radius,
|
condensed_radius,
|
||||||
|
|
@ -614,6 +635,7 @@ pub fn item_from_entry(
|
||||||
highlighted: false,
|
highlighted: false,
|
||||||
overlaps_drag_rect: false,
|
overlaps_drag_rect: false,
|
||||||
dir_size,
|
dir_size,
|
||||||
|
cut: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -839,6 +861,7 @@ pub fn scan_trash(sizes: IconSizes) -> Vec<Item> {
|
||||||
highlighted: false,
|
highlighted: false,
|
||||||
overlaps_drag_rect: false,
|
overlaps_drag_rect: false,
|
||||||
dir_size: DirSize::NotDirectory,
|
dir_size: DirSize::NotDirectory,
|
||||||
|
cut: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1018,6 +1041,7 @@ pub fn scan_desktop(
|
||||||
highlighted: false,
|
highlighted: false,
|
||||||
overlaps_drag_rect: false,
|
overlaps_drag_rect: false,
|
||||||
dir_size: DirSize::NotDirectory,
|
dir_size: DirSize::NotDirectory,
|
||||||
|
cut: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1497,6 +1521,7 @@ pub struct Item {
|
||||||
pub rect_opt: Cell<Option<Rectangle>>,
|
pub rect_opt: Cell<Option<Rectangle>>,
|
||||||
pub selected: bool,
|
pub selected: bool,
|
||||||
pub highlighted: bool,
|
pub highlighted: bool,
|
||||||
|
pub cut: bool,
|
||||||
pub overlaps_drag_rect: bool,
|
pub overlaps_drag_rect: bool,
|
||||||
pub dir_size: DirSize,
|
pub dir_size: DirSize,
|
||||||
}
|
}
|
||||||
|
|
@ -2028,6 +2053,30 @@ impl Tab {
|
||||||
self.items_opt = Some(items);
|
self.items_opt = Some(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cut_selected(&mut self) {
|
||||||
|
if let Some(ref mut items) = self.items_opt {
|
||||||
|
for item in items.iter_mut() {
|
||||||
|
item.cut = item.selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn refresh_cut(&mut self, locations: &[PathBuf]) {
|
||||||
|
if let Some(ref mut items) = self.items_opt {
|
||||||
|
for item in items.iter_mut() {
|
||||||
|
item.cut = false;
|
||||||
|
if let Some(location) = &item.location_opt {
|
||||||
|
if locations
|
||||||
|
.iter()
|
||||||
|
.any(|s| location.path_opt().is_some_and(|b| b == s))
|
||||||
|
{
|
||||||
|
item.cut = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn selected_locations(&self) -> Vec<Location> {
|
pub fn selected_locations(&self) -> Vec<Location> {
|
||||||
let mut locations = Vec::new();
|
let mut locations = Vec::new();
|
||||||
if let Some(ref items) = self.items_opt {
|
if let Some(ref items) = self.items_opt {
|
||||||
|
|
@ -4183,6 +4232,7 @@ impl Tab {
|
||||||
.class(button_style(
|
.class(button_style(
|
||||||
item.selected,
|
item.selected,
|
||||||
item.highlighted,
|
item.highlighted,
|
||||||
|
item.cut,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
@ -4195,6 +4245,7 @@ impl Tab {
|
||||||
.class(button_style(
|
.class(button_style(
|
||||||
item.selected,
|
item.selected,
|
||||||
item.highlighted,
|
item.highlighted,
|
||||||
|
item.cut,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
matches!(self.mode, Mode::Desktop),
|
matches!(self.mode, Mode::Desktop),
|
||||||
|
|
@ -4339,6 +4390,7 @@ impl Tab {
|
||||||
.class(button_style(
|
.class(button_style(
|
||||||
item.selected,
|
item.selected,
|
||||||
item.highlighted,
|
item.highlighted,
|
||||||
|
item.cut,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
|
@ -4352,6 +4404,7 @@ impl Tab {
|
||||||
.class(button_style(
|
.class(button_style(
|
||||||
item.selected,
|
item.selected,
|
||||||
item.highlighted,
|
item.highlighted,
|
||||||
|
item.cut,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
|
@ -4572,6 +4625,7 @@ impl Tab {
|
||||||
.class(button_style(
|
.class(button_style(
|
||||||
item.selected,
|
item.selected,
|
||||||
item.highlighted,
|
item.highlighted,
|
||||||
|
item.cut,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue