Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 175 additions & 27 deletions src/app.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
use crate::{
FxOrderMap,
app::App,
desktop::{DesktopChange, DesktopPos},
tab::{HeadingOptions, Location, View},
};

Expand Down Expand Up @@ -112,12 +113,14 @@ pub enum TypeToSearch {
#[derive(Clone, CosmicConfigEntry, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(default)]
pub struct State {
pub desktop_changes: Vec<DesktopChange>,
pub sort_names: FxOrderMap<String, (HeadingOptions, bool)>,
}

impl Default for State {
fn default() -> Self {
Self {
desktop_changes: Default::default(),
sort_names: FxOrderMap::from_iter(dirs::download_dir().into_iter().map(|dir| {
(
Location::Path(dir).normalize().to_string(),
Expand Down
102 changes: 102 additions & 0 deletions src/desktop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, path::PathBuf};

use crate::{config::DesktopConfig, tab::HeadingOptions};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum DesktopChange {
Primary(String),
Position(PathBuf, DesktopPos),
Sort(String, HeadingOptions, bool),
}

impl DesktopChange {
pub fn retain_before(&self, newer: &Self) -> bool {
//TODO: clean out more prior items?

match (self, newer) {
(Self::Primary(output_name), Self::Primary(new_output_name)) => {
if output_name == new_output_name {
// Drop previous primary output changes with same output name
return false;
}
}
(Self::Position(path, pos), Self::Position(new_path, new_pos)) => {
if path == new_path && pos.display == new_pos.display {
// Drop previous position changes that have the same path and output
return false;
}
}
(
Self::Sort(output_name, ..),
Self::Position(
_,
DesktopPos {
display: new_output_name,
..
},
)
| Self::Sort(new_output_name, ..),
) => {
if output_name == new_output_name {
// Drop previous position and sort changes with same output name
return false;
}
}
_ => {}
}

true
}
}

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct DesktopPos {
pub display: String,
pub row: usize,
pub col: usize,
pub rows: usize,
pub cols: usize,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DesktopLayout {
pub config: DesktopConfig,
pub output_names: Vec<String>,
// Must be BTreeMap to implement Hash for usage inside Location. In the future, remove from Location
pub positions: BTreeMap<PathBuf, DesktopPos>,
pub primary_output_name: Option<String>,
}

impl DesktopLayout {
pub fn new(config: DesktopConfig) -> Self {
DesktopLayout {
config,
output_names: Vec::new(),
positions: BTreeMap::new(),
primary_output_name: None,
}
}

pub fn update_positions(&mut self, changes: &[DesktopChange]) {
self.positions.clear();
for change in changes {
match change {
DesktopChange::Position(path, pos) => {
//TODO: resize grid if rows or columns do not match
if self.output_names.contains(&pos.display) {
self.positions.insert(path.clone(), pos.clone());
}
}
DesktopChange::Primary(output_name) => {
if self.output_names.contains(&output_name) {
self.primary_output_name = Some(output_name.clone());
}
}
DesktopChange::Sort(..) => {
//TODO: what should sort do?
}
}
}
}
}
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: GPL-3.0-only

use cosmic::{app::Settings, iced::Limits};
use std::{env, fs, path::PathBuf, process};
use std::{env, fs, path::PathBuf, process, sync::Arc};

use app::{App, Flags};
pub mod app;
mod archive;
pub mod clipboard;
use config::Config;
pub mod config;
pub mod desktop;
pub mod dialog;
mod key_bind;
pub(crate) mod large_image;
Expand Down Expand Up @@ -88,7 +89,14 @@ pub fn desktop() -> Result<(), Box<dyn std::error::Error>> {
settings = settings.no_main_window(true);
}

let locations = vec![tab::Location::Desktop(desktop_dir(), String::new(), config.desktop)];
let locations = vec![tab::Location::Desktop {
path: desktop_dir(),
display: String::new(),
layout: Arc::new(desktop::DesktopLayout::new(
config.desktop.clone(),
)),
pos_opt: None
}];
let flags = Flags {
config_handler,
config,
Expand Down
6 changes: 3 additions & 3 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn context_menu<'a>(
match (&tab.mode, &tab.location) {
(
tab::Mode::App | tab::Mode::Desktop,
Location::Desktop(..)
Location::Desktop { .. }
| Location::Path(..)
| Location::Search(..)
| Location::Recents
Expand Down Expand Up @@ -310,7 +310,7 @@ pub fn context_menu<'a>(
children.push(sort_item(fl!("sort-by-name"), HeadingOptions::Name));
children.push(sort_item(fl!("sort-by-modified"), HeadingOptions::Modified));
children.push(sort_item(fl!("sort-by-size"), HeadingOptions::Size));
if matches!(tab.location, Location::Desktop(..)) {
if matches!(tab.location, Location::Desktop { .. }) {
children.push(divider::horizontal::light().into());
children.push(
menu_item(fl!("desktop-view-options"), Action::DesktopViewOptions).into(),
Expand All @@ -320,7 +320,7 @@ pub fn context_menu<'a>(
}
(
tab::Mode::Dialog(dialog_kind),
Location::Desktop(..)
Location::Desktop { .. }
| Location::Path(..)
| Location::Search(..)
| Location::Recents
Expand Down
15 changes: 10 additions & 5 deletions src/operation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
app::{ArchiveType, DialogPage, Message, REPLACE_BUTTON_ID},
config::IconSizes,
desktop::DesktopPos,
fl,
spawn_detached::spawn_detached,
tab,
Expand Down Expand Up @@ -129,6 +130,8 @@ async fn copy_or_move(
})
.collect();

let mut context = Context::new(controller.clone());

// Attempt quick and simple renames
//TODO: allow rename to be used for directories in recursive context?
if matches!(method, Method::Move { .. }) {
Expand All @@ -142,6 +145,7 @@ async fn copy_or_move(
match fs::rename(from, to) {
Ok(()) => {
log::info!("renamed {} to {}", from.display(), to.display());
context.op_sel.selected.push(to.clone());
false
}
Err(err) => {
Expand All @@ -157,8 +161,6 @@ async fn copy_or_move(
});
}

let mut context = Context::new(controller.clone());

{
let controller = controller.clone();
context = context.on_progress(move |_op, progress| {
Expand Down Expand Up @@ -342,6 +344,7 @@ pub enum Operation {
Copy {
paths: Vec<PathBuf>,
to: PathBuf,
desktop_pos: Option<DesktopPos>,
},
/// Move items to the trash
Delete {
Expand All @@ -364,6 +367,7 @@ pub enum Operation {
paths: Vec<PathBuf>,
to: PathBuf,
cross_device_copy: bool,
desktop_pos: Option<DesktopPos>,
},
NewFile {
path: PathBuf,
Expand Down Expand Up @@ -470,7 +474,7 @@ impl Operation {
to = file_name(to),
progress = progress()
),
Self::Copy { paths, to } => fl!(
Self::Copy { paths, to, .. } => fl!(
"copying",
items = paths.len(),
from = paths_parent_name(paths),
Expand Down Expand Up @@ -543,7 +547,7 @@ impl Operation {
from = paths_parent_name(paths),
to = file_name(to)
),
Self::Copy { paths, to } => fl!(
Self::Copy { paths, to, .. } => fl!(
"copied",
items = paths.len(),
from = paths_parent_name(paths),
Expand Down Expand Up @@ -816,7 +820,7 @@ impl Operation {
.await
.map_err(wrap_compio_spawn_error)?
}
Self::Copy { paths, to } => {
Self::Copy { paths, to, .. } => {
copy_or_move(paths, to, Method::Copy, msg_tx, controller).await
}
Self::Delete { paths } => {
Expand Down Expand Up @@ -982,6 +986,7 @@ impl Operation {
paths,
to,
cross_device_copy,
..
} => {
copy_or_move(
paths,
Expand Down
1 change: 1 addition & 0 deletions src/operation/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl Context {

if from_parent == to_parent {
// Skip matching source and destination
self.op_sel.selected.push(to_parent);
continue;
}

Expand Down
Loading
Loading