diff --git a/src/app.rs b/src/app.rs index 103ca0b..e6951bb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,14 +1,11 @@ // Copyright 2023 System76 // 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::{ app::{message, Command, Core}, cosmic_config, cosmic_theme, executor, iced::{ + clipboard::dnd::DndAction, event, futures::{self, SinkExt}, keyboard::{Event as KeyEvent, Key, Modifiers}, @@ -20,6 +17,8 @@ use cosmic::{ style, theme, widget::{ self, + dnd_destination::DragId, + menu::{action::MenuAction, key_bind::KeyBind}, segmented_button::{self, Entity}, }, Application, ApplicationExt, Element, @@ -42,18 +41,17 @@ use std::{ }; use tokio::sync::mpsc; -use crate::localize::LANGUAGE_SORTER; -use crate::tab::HOVER_DURATION; use crate::{ clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste}, config::{AppTheme, Config, Favorite, IconSizes, TabConfig, CONFIG_VERSION}, fl, home_dir, key_bind::key_binds, + localize::LANGUAGE_SORTER, menu, mime_app, mounter::{mounters, MounterItem, MounterItems, MounterKey, Mounters}, operation::{Operation, ReplaceResult}, spawn_detached::spawn_detached, - tab::{self, HeadingOptions, ItemMetadata, Location, Tab}, + tab::{self, HeadingOptions, ItemMetadata, Location, Tab, HOVER_DURATION}, }; #[derive(Clone, Debug)] @@ -814,7 +812,7 @@ impl App { widget::settings::item::builder(fl!("icon-size-list")) .description(format!("{}%", list)) .control( - widget::slider(75..=500, list, move |list| { + widget::slider(50..=500, list, move |list| { Message::TabConfig(TabConfig { icon_sizes: IconSizes { list: NonZeroU16::new(list).unwrap(), @@ -2391,7 +2389,9 @@ impl Application for App { /// Creates a view after each update. fn view(&self) -> Element { - 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); @@ -2411,7 +2411,8 @@ impl Application for App { .drag_id(self.tab_drag_id), ) .style(style::Container::Background) - .width(Length::Fill), + .width(Length::Fill) + .padding([0, space_s]), ); } diff --git a/src/key_bind.rs b/src/key_bind.rs index b8a2b35..2070e00 100644 --- a/src/key_bind.rs +++ b/src/key_bind.rs @@ -1,9 +1,11 @@ -use cosmic::widget::menu::key_bind::KeyBind; -use cosmic::{iced::keyboard::Key, iced_core::keyboard::key::Named}; +use cosmic::{ + iced::keyboard::Key, + iced_core::keyboard::key::Named, + widget::menu::key_bind::{KeyBind, Modifier}, +}; use std::collections::HashMap; use crate::app::Action; -use cosmic::widget::menu::key_bind::Modifier; //TODO: load from config pub fn key_binds() -> HashMap { diff --git a/src/menu.rs b/src/menu.rs index 70163ac..5621d84 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,22 +1,20 @@ // SPDX-License-Identifier: GPL-3.0-only -use cosmic::widget::menu::key_bind::KeyBind; -use cosmic::widget::menu::{self, ItemHeight, ItemWidth, MenuBar}; use cosmic::{ //TODO: export iced::widget::horizontal_rule in cosmic::widget iced::{widget::horizontal_rule, Alignment, Background, Border, Length}, theme, widget, + widget::menu::{self, key_bind::KeyBind, ItemHeight, ItemWidth, MenuBar}, Element, }; use std::collections::HashMap; -use crate::tab::LocationMenuAction; use crate::{ app::{Action, Message}, config::TabConfig, fl, - tab::{self, HeadingOptions, Location, Tab}, + tab::{self, HeadingOptions, Location, LocationMenuAction, Tab}, }; macro_rules! menu_button { diff --git a/src/tab.rs b/src/tab.rs index 9f4fd40..b33b0bc 100644 --- a/src/tab.rs +++ b/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::{ cosmic_theme, font, iced::{ @@ -12,6 +6,7 @@ use cosmic::{ text::{self, Paragraph}, }, alignment::{Horizontal, Vertical}, + clipboard::dnd::DndAction, futures::SinkExt, keyboard::Modifiers, subscription::{self, Subscription}, @@ -21,6 +16,7 @@ use cosmic::{ scrollable::{AbsoluteOffset, Viewport}, }, Alignment, + Border, Color, ContentFit, Length, @@ -28,36 +24,42 @@ use cosmic::{ Rectangle, 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 once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::sync::{Arc, Mutex}; use std::{ - cell::Cell, + cell::{Cell, RefCell}, cmp::Ordering, collections::HashMap, fmt, fs::{self, Metadata}, num::NonZeroU16, path::PathBuf, + sync::{Arc, Mutex}, time::{Duration, Instant}, }; -use crate::clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste}; -use crate::localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER}; use crate::{ app::{self, Action}, + clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste}, config::{IconSizes, TabConfig, ICON_SCALE_MAX, ICON_SIZE_GRID}, dialog::DialogKind, - fl, menu, + fl, + localize::{LANGUAGE_CHRONO, LANGUAGE_SORTER}, + menu, mime_app::{mime_apps, MimeApp}, mime_icon::{mime_for_path, mime_icon}, mouse_area, }; -use cosmic::widget::{DndDestination, DndSource}; pub const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500); pub const HOVER_DURATION: Duration = Duration::from_millis(1600); @@ -1923,7 +1925,9 @@ impl Tab { } = theme::active().cosmic().spacing; 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 prev_button = @@ -1963,9 +1967,13 @@ impl Tab { .on_input(|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 @@ -2135,8 +2143,11 @@ impl Tab { for child in children { 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); let mut popover = widget::popover(mouse_area); @@ -2230,7 +2241,7 @@ impl Tab { let mut grid = widget::grid() .column_spacing(column_spacing) .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 drag_w_i = usize::MAX; let mut drag_n_i = usize::MAX; @@ -2384,7 +2395,7 @@ impl Tab { } } 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); if spacer_height > 0 { children.push( @@ -2400,7 +2411,7 @@ impl Tab { let mut dnd_grid = widget::grid() .column_spacing(column_spacing) .row_spacing(space_xxs) - .padding([0, space_m].into()); + .padding(space_xxs.into()); let mut dnd_item_i = 0; for r in drag_n_i..=drag_s_i { @@ -2472,7 +2483,10 @@ impl Tab { bool, ) { let cosmic_theme::Spacing { - space_m, space_xxs, .. + space_m, + space_s, + space_xxs, + .. } = theme::active().cosmic().spacing; let TabConfig { @@ -2532,8 +2546,8 @@ impl Tab { heading_item(fl!("size"), Length::Fixed(size_width), HeadingOptions::Size), ]) .align_items(Alignment::Center) - .height(Length::Fixed(row_height as f32)) - .padding(space_xxs) + .height(Length::Fixed((space_m + 4).into())) + .padding([0, space_xxs]) .spacing(space_xxs) .into(), ); @@ -2635,7 +2649,7 @@ impl Tab { .width(Length::Fill) .height(Length::Fixed(row_height as f32)) .id(item.button_id.clone()) - .padding(space_xxs) + .padding(if icon_size < 24 { 7 } else { space_xxs }) .style(button_style(item.selected, true, false)), ) .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 { - 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 { children.push( widget::container(vertical_space(Length::Fixed(spacer_height as f32))).into(), @@ -2780,7 +2794,7 @@ impl Tab { ( drag_col, 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")) .on_press(|_| Message::Click(None))