commit
4ed865289c
4 changed files with 59 additions and 44 deletions
21
src/app.rs
21
src/app.rs
|
|
@ -1,14 +1,11 @@
|
||||||
// Copyright 2023 System76 <info@system76.com>
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::iced::clipboard::dnd::DndAction;
|
|
||||||
use cosmic::widget::dnd_destination::DragId;
|
|
||||||
use cosmic::widget::menu::action::MenuAction;
|
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
app::{message, Command, Core},
|
app::{message, Command, Core},
|
||||||
cosmic_config, cosmic_theme, executor,
|
cosmic_config, cosmic_theme, executor,
|
||||||
iced::{
|
iced::{
|
||||||
|
clipboard::dnd::DndAction,
|
||||||
event,
|
event,
|
||||||
futures::{self, SinkExt},
|
futures::{self, SinkExt},
|
||||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||||
|
|
@ -20,6 +17,8 @@ use cosmic::{
|
||||||
style, theme,
|
style, theme,
|
||||||
widget::{
|
widget::{
|
||||||
self,
|
self,
|
||||||
|
dnd_destination::DragId,
|
||||||
|
menu::{action::MenuAction, key_bind::KeyBind},
|
||||||
segmented_button::{self, Entity},
|
segmented_button::{self, Entity},
|
||||||
},
|
},
|
||||||
Application, ApplicationExt, Element,
|
Application, ApplicationExt, Element,
|
||||||
|
|
@ -42,18 +41,17 @@ use std::{
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::localize::LANGUAGE_SORTER;
|
|
||||||
use crate::tab::HOVER_DURATION;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
||||||
config::{AppTheme, Config, Favorite, IconSizes, TabConfig, CONFIG_VERSION},
|
config::{AppTheme, Config, Favorite, IconSizes, TabConfig, CONFIG_VERSION},
|
||||||
fl, home_dir,
|
fl, home_dir,
|
||||||
key_bind::key_binds,
|
key_bind::key_binds,
|
||||||
|
localize::LANGUAGE_SORTER,
|
||||||
menu, mime_app,
|
menu, mime_app,
|
||||||
mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters},
|
mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters},
|
||||||
operation::{Operation, ReplaceResult},
|
operation::{Operation, ReplaceResult},
|
||||||
spawn_detached::spawn_detached,
|
spawn_detached::spawn_detached,
|
||||||
tab::{self, HeadingOptions, ItemMetadata, Location, Tab},
|
tab::{self, HeadingOptions, ItemMetadata, Location, Tab, HOVER_DURATION},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -814,7 +812,7 @@ impl App {
|
||||||
widget::settings::item::builder(fl!("icon-size-list"))
|
widget::settings::item::builder(fl!("icon-size-list"))
|
||||||
.description(format!("{}%", list))
|
.description(format!("{}%", list))
|
||||||
.control(
|
.control(
|
||||||
widget::slider(75..=500, list, move |list| {
|
widget::slider(50..=500, list, move |list| {
|
||||||
Message::TabConfig(TabConfig {
|
Message::TabConfig(TabConfig {
|
||||||
icon_sizes: IconSizes {
|
icon_sizes: IconSizes {
|
||||||
list: NonZeroU16::new(list).unwrap(),
|
list: NonZeroU16::new(list).unwrap(),
|
||||||
|
|
@ -2391,7 +2389,9 @@ impl Application for App {
|
||||||
|
|
||||||
/// Creates a view after each update.
|
/// Creates a view after each update.
|
||||||
fn view(&self) -> Element<Self::Message> {
|
fn view(&self) -> Element<Self::Message> {
|
||||||
let cosmic_theme::Spacing { space_xxs, .. } = theme::active().cosmic().spacing;
|
let cosmic_theme::Spacing {
|
||||||
|
space_xxs, space_s, ..
|
||||||
|
} = theme::active().cosmic().spacing;
|
||||||
|
|
||||||
let mut tab_column = widget::column::with_capacity(1);
|
let mut tab_column = widget::column::with_capacity(1);
|
||||||
|
|
||||||
|
|
@ -2411,7 +2411,8 @@ impl Application for App {
|
||||||
.drag_id(self.tab_drag_id),
|
.drag_id(self.tab_drag_id),
|
||||||
)
|
)
|
||||||
.style(style::Container::Background)
|
.style(style::Container::Background)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill)
|
||||||
|
.padding([0, space_s]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
use cosmic::{
|
||||||
use cosmic::{iced::keyboard::Key, iced_core::keyboard::key::Named};
|
iced::keyboard::Key,
|
||||||
|
iced_core::keyboard::key::Named,
|
||||||
|
widget::menu::key_bind::{KeyBind, Modifier},
|
||||||
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::app::Action;
|
use crate::app::Action;
|
||||||
use cosmic::widget::menu::key_bind::Modifier;
|
|
||||||
|
|
||||||
//TODO: load from config
|
//TODO: load from config
|
||||||
pub fn key_binds() -> HashMap<KeyBind, Action> {
|
pub fn key_binds() -> HashMap<KeyBind, Action> {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,20 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
|
||||||
use cosmic::widget::menu::{self, ItemHeight, ItemWidth, MenuBar};
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
//TODO: export iced::widget::horizontal_rule in cosmic::widget
|
//TODO: export iced::widget::horizontal_rule in cosmic::widget
|
||||||
iced::{widget::horizontal_rule, Alignment, Background, Border, Length},
|
iced::{widget::horizontal_rule, Alignment, Background, Border, Length},
|
||||||
theme,
|
theme,
|
||||||
widget,
|
widget,
|
||||||
|
widget::menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar},
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::tab::LocationMenuAction;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{Action, Message},
|
app::{Action, Message},
|
||||||
config::TabConfig,
|
config::TabConfig,
|
||||||
fl,
|
fl,
|
||||||
tab::{self, HeadingOptions, Location, Tab},
|
tab::{self, HeadingOptions, Location, LocationMenuAction, Tab},
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! menu_button {
|
macro_rules! menu_button {
|
||||||
|
|
|
||||||
68
src/tab.rs
68
src/tab.rs
|
|
@ -1,9 +1,3 @@
|
||||||
use cosmic::iced::clipboard::dnd::DndAction;
|
|
||||||
use cosmic::iced::Border;
|
|
||||||
use cosmic::iced_core::widget::tree;
|
|
||||||
use cosmic::widget::menu::action::MenuAction;
|
|
||||||
use cosmic::widget::menu::key_bind::KeyBind;
|
|
||||||
use cosmic::widget::{vertical_space, Id, Widget};
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
cosmic_theme, font,
|
cosmic_theme, font,
|
||||||
iced::{
|
iced::{
|
||||||
|
|
@ -12,6 +6,7 @@ use cosmic::{
|
||||||
text::{self, Paragraph},
|
text::{self, Paragraph},
|
||||||
},
|
},
|
||||||
alignment::{Horizontal, Vertical},
|
alignment::{Horizontal, Vertical},
|
||||||
|
clipboard::dnd::DndAction,
|
||||||
futures::SinkExt,
|
futures::SinkExt,
|
||||||
keyboard::Modifiers,
|
keyboard::Modifiers,
|
||||||
subscription::{self, Subscription},
|
subscription::{self, Subscription},
|
||||||
|
|
@ -21,6 +16,7 @@ use cosmic::{
|
||||||
scrollable::{AbsoluteOffset, Viewport},
|
scrollable::{AbsoluteOffset, Viewport},
|
||||||
},
|
},
|
||||||
Alignment,
|
Alignment,
|
||||||
|
Border,
|
||||||
Color,
|
Color,
|
||||||
ContentFit,
|
ContentFit,
|
||||||
Length,
|
Length,
|
||||||
|
|
@ -28,36 +24,42 @@ use cosmic::{
|
||||||
Rectangle,
|
Rectangle,
|
||||||
Size,
|
Size,
|
||||||
},
|
},
|
||||||
theme, widget, Element,
|
iced_core::widget::tree,
|
||||||
|
theme, widget,
|
||||||
|
widget::{
|
||||||
|
menu::{action::MenuAction, key_bind::KeyBind},
|
||||||
|
vertical_space, DndDestination, DndSource, Id, Widget,
|
||||||
|
},
|
||||||
|
Element,
|
||||||
};
|
};
|
||||||
|
|
||||||
use mime_guess::{mime, Mime};
|
use mime_guess::{mime, Mime};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::Cell,
|
cell::{Cell, RefCell},
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt,
|
fmt,
|
||||||
fs::{self, Metadata},
|
fs::{self, Metadata},
|
||||||
num::NonZeroU16,
|
num::NonZeroU16,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste};
|
|
||||||
use crate::localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{self, Action},
|
app::{self, Action},
|
||||||
|
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
||||||
config::{IconSizes, TabConfig, ICON_SCALE_MAX, ICON_SIZE_GRID},
|
config::{IconSizes, TabConfig, ICON_SCALE_MAX, ICON_SIZE_GRID},
|
||||||
dialog::DialogKind,
|
dialog::DialogKind,
|
||||||
fl, menu,
|
fl,
|
||||||
|
localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER},
|
||||||
|
menu,
|
||||||
mime_app::{mime_apps, MimeApp},
|
mime_app::{mime_apps, MimeApp},
|
||||||
mime_icon::{mime_for_path, mime_icon},
|
mime_icon::{mime_for_path, mime_icon},
|
||||||
mouse_area,
|
mouse_area,
|
||||||
};
|
};
|
||||||
use cosmic::widget::{DndDestination, DndSource};
|
|
||||||
|
|
||||||
pub const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500);
|
pub const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500);
|
||||||
pub const HOVER_DURATION: Duration = Duration::from_millis(1600);
|
pub const HOVER_DURATION: Duration = Duration::from_millis(1600);
|
||||||
|
|
@ -1923,7 +1925,9 @@ impl Tab {
|
||||||
} = theme::active().cosmic().spacing;
|
} = theme::active().cosmic().spacing;
|
||||||
let size = self.size_opt.get().unwrap_or(Size::new(0.0, 0.0));
|
let size = self.size_opt.get().unwrap_or(Size::new(0.0, 0.0));
|
||||||
|
|
||||||
let mut row = widget::row::with_capacity(5).align_items(Alignment::Center);
|
let mut row = widget::row::with_capacity(5)
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
.padding([space_xxxs, 0]);
|
||||||
let mut w = 0.0;
|
let mut w = 0.0;
|
||||||
|
|
||||||
let mut prev_button =
|
let mut prev_button =
|
||||||
|
|
@ -1963,9 +1967,13 @@ impl Tab {
|
||||||
.on_input(|input| {
|
.on_input(|input| {
|
||||||
Message::EditLocation(Some(Location::Path(PathBuf::from(input))))
|
Message::EditLocation(Some(Location::Path(PathBuf::from(input))))
|
||||||
})
|
})
|
||||||
.on_submit(Message::Location(location.clone())),
|
.on_submit(Message::Location(location.clone()))
|
||||||
|
.line_height(1.0),
|
||||||
);
|
);
|
||||||
return row.into();
|
let mut column = widget::column::with_capacity(2).padding([0, space_s]);
|
||||||
|
column = column.push(row);
|
||||||
|
column = column.push(horizontal_rule(1));
|
||||||
|
return column.into();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
//TODO: allow editing other locations
|
//TODO: allow editing other locations
|
||||||
|
|
@ -2135,8 +2143,11 @@ impl Tab {
|
||||||
for child in children {
|
for child in children {
|
||||||
row = row.push(child);
|
row = row.push(child);
|
||||||
}
|
}
|
||||||
|
let mut column = widget::column::with_capacity(2).padding([0, space_s]);
|
||||||
|
column = column.push(row);
|
||||||
|
column = column.push(horizontal_rule(1));
|
||||||
|
|
||||||
let mouse_area = crate::mouse_area::MouseArea::new(row)
|
let mouse_area = crate::mouse_area::MouseArea::new(column)
|
||||||
.on_right_press(Message::LocationContextMenuPoint);
|
.on_right_press(Message::LocationContextMenuPoint);
|
||||||
|
|
||||||
let mut popover = widget::popover(mouse_area);
|
let mut popover = widget::popover(mouse_area);
|
||||||
|
|
@ -2230,7 +2241,7 @@ impl Tab {
|
||||||
let mut grid = widget::grid()
|
let mut grid = widget::grid()
|
||||||
.column_spacing(column_spacing)
|
.column_spacing(column_spacing)
|
||||||
.row_spacing(space_xxs)
|
.row_spacing(space_xxs)
|
||||||
.padding([0, space_m].into());
|
.padding(space_xxs.into());
|
||||||
let mut dnd_items: Vec<(usize, (usize, usize), &Item)> = Vec::new();
|
let mut dnd_items: Vec<(usize, (usize, usize), &Item)> = Vec::new();
|
||||||
let mut drag_w_i = usize::MAX;
|
let mut drag_w_i = usize::MAX;
|
||||||
let mut drag_n_i = usize::MAX;
|
let mut drag_n_i = usize::MAX;
|
||||||
|
|
@ -2384,7 +2395,7 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let spacer_height = height
|
let spacer_height = height
|
||||||
.checked_sub(max_bottom + 4 * (space_xxs as usize))
|
.checked_sub(max_bottom + 7 * (space_xxs as usize))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if spacer_height > 0 {
|
if spacer_height > 0 {
|
||||||
children.push(
|
children.push(
|
||||||
|
|
@ -2400,7 +2411,7 @@ impl Tab {
|
||||||
let mut dnd_grid = widget::grid()
|
let mut dnd_grid = widget::grid()
|
||||||
.column_spacing(column_spacing)
|
.column_spacing(column_spacing)
|
||||||
.row_spacing(space_xxs)
|
.row_spacing(space_xxs)
|
||||||
.padding([0, space_m].into());
|
.padding(space_xxs.into());
|
||||||
|
|
||||||
let mut dnd_item_i = 0;
|
let mut dnd_item_i = 0;
|
||||||
for r in drag_n_i..=drag_s_i {
|
for r in drag_n_i..=drag_s_i {
|
||||||
|
|
@ -2472,7 +2483,10 @@ impl Tab {
|
||||||
bool,
|
bool,
|
||||||
) {
|
) {
|
||||||
let cosmic_theme::Spacing {
|
let cosmic_theme::Spacing {
|
||||||
space_m, space_xxs, ..
|
space_m,
|
||||||
|
space_s,
|
||||||
|
space_xxs,
|
||||||
|
..
|
||||||
} = theme::active().cosmic().spacing;
|
} = theme::active().cosmic().spacing;
|
||||||
|
|
||||||
let TabConfig {
|
let TabConfig {
|
||||||
|
|
@ -2532,8 +2546,8 @@ impl Tab {
|
||||||
heading_item(fl!("size"), Length::Fixed(size_width), HeadingOptions::Size),
|
heading_item(fl!("size"), Length::Fixed(size_width), HeadingOptions::Size),
|
||||||
])
|
])
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.height(Length::Fixed(row_height as f32))
|
.height(Length::Fixed((space_m + 4).into()))
|
||||||
.padding(space_xxs)
|
.padding([0, space_xxs])
|
||||||
.spacing(space_xxs)
|
.spacing(space_xxs)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
@ -2635,7 +2649,7 @@ impl Tab {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fixed(row_height as f32))
|
.height(Length::Fixed(row_height as f32))
|
||||||
.id(item.button_id.clone())
|
.id(item.button_id.clone())
|
||||||
.padding(space_xxs)
|
.padding(if icon_size < 24 { 7 } else { space_xxs })
|
||||||
.style(button_style(item.selected, true, false)),
|
.style(button_style(item.selected, true, false)),
|
||||||
)
|
)
|
||||||
.on_press(move |_| Message::Click(Some(i)))
|
.on_press(move |_| Message::Click(Some(i)))
|
||||||
|
|
@ -2765,7 +2779,7 @@ impl Tab {
|
||||||
}
|
}
|
||||||
//TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that
|
//TODO: HACK If we don't reach the bottom of the view, go ahead and add a spacer to do that
|
||||||
{
|
{
|
||||||
let spacer_height = size.height as i32 - y as i32 - 4 * space_xxs as i32;
|
let spacer_height = size.height as i32 - y as i32 - 5 * space_xxs as i32;
|
||||||
if spacer_height > 0 {
|
if spacer_height > 0 {
|
||||||
children.push(
|
children.push(
|
||||||
widget::container(vertical_space(Length::Fixed(spacer_height as f32))).into(),
|
widget::container(vertical_space(Length::Fixed(spacer_height as f32))).into(),
|
||||||
|
|
@ -2780,7 +2794,7 @@ impl Tab {
|
||||||
(
|
(
|
||||||
drag_col,
|
drag_col,
|
||||||
mouse_area::MouseArea::new(
|
mouse_area::MouseArea::new(
|
||||||
widget::column::with_children(children).padding([0, space_m]),
|
widget::column::with_children(children).padding([0, space_s]),
|
||||||
)
|
)
|
||||||
.with_id(Id::new("list-view"))
|
.with_id(Id::new("list-view"))
|
||||||
.on_press(|_| Message::Click(None))
|
.on_press(|_| Message::Click(None))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue