Merge branch 'master' into rustc-hash
This commit is contained in:
commit
78f2ed2bdd
14 changed files with 367 additions and 212 deletions
271
src/app.rs
271
src/app.rs
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||
use cosmic::iced::{
|
||||
Limits,
|
||||
Limits, Point,
|
||||
event::wayland::{Event as WaylandEvent, OutputEvent, OverlapNotifyEvent},
|
||||
platform_specific::runtime::wayland::layer_surface::{
|
||||
IcedMargin, IcedOutput, SctkLayerSurfaceSettings,
|
||||
|
|
@ -20,7 +20,7 @@ use cosmic::{
|
|||
cosmic_config::{self, ConfigSet},
|
||||
cosmic_theme, executor,
|
||||
iced::{
|
||||
self, Alignment, Event, Length, Point, Rectangle, Size, Subscription,
|
||||
self, Alignment, Event, Length, Rectangle, Size, Subscription,
|
||||
clipboard::dnd::DndAction,
|
||||
core::SmolStr,
|
||||
event,
|
||||
|
|
@ -31,6 +31,7 @@ use cosmic::{
|
|||
window::{self, Event as WindowEvent, Id as WindowId},
|
||||
},
|
||||
iced_runtime::clipboard,
|
||||
iced_widget::button::focus,
|
||||
style, surface, theme,
|
||||
widget::{
|
||||
self,
|
||||
|
|
@ -59,7 +60,7 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
process,
|
||||
sync::{Arc, Mutex},
|
||||
sync::{Arc, LazyLock, Mutex},
|
||||
time::{self, Duration, Instant},
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -93,6 +94,27 @@ use crate::{
|
|||
};
|
||||
use crate::{config::State, dialog::DialogSettings};
|
||||
|
||||
static PERMANENT_DELETE_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("permanent-delete-button"));
|
||||
|
||||
static CONFIRM_OPEN_WITH_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("confirm-open-with-button"));
|
||||
|
||||
static EMPTY_TRASH_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("empty-trash-button"));
|
||||
|
||||
static SET_EXECUTABLE_AND_LAUNCH_CONFIRM_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("set-executable-and-launch-confirm-button"));
|
||||
|
||||
static FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("favorite-path-error-remove-button"));
|
||||
|
||||
static MOUNT_ERROR_TRY_AGAIN_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("mount-error-try-again-button"));
|
||||
|
||||
pub(crate) static REPLACE_BUTTON_ID: LazyLock<widget::Id> =
|
||||
LazyLock::new(|| widget::Id::new("replace-button"));
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Mode {
|
||||
App,
|
||||
|
|
@ -317,7 +339,7 @@ pub enum Message {
|
|||
DialogComplete,
|
||||
Eject,
|
||||
FileDialogMessage(DialogMessage),
|
||||
DialogPush(DialogPage),
|
||||
DialogPush(DialogPage, Option<widget::Id>),
|
||||
DialogUpdate(DialogPage),
|
||||
DialogUpdateComplete(DialogPage),
|
||||
ExtractHere(Option<Entity>),
|
||||
|
|
@ -665,6 +687,7 @@ pub struct App {
|
|||
network_drive_input: String,
|
||||
#[cfg(feature = "notify")]
|
||||
notification_opt: Option<Arc<Mutex<notify_rust::NotificationHandle>>>,
|
||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||
overlap: FxHashMap<String, (window::Id, Rectangle)>,
|
||||
pending_operation_id: u64,
|
||||
pending_operations: BTreeMap<u64, (Operation, Controller)>,
|
||||
|
|
@ -695,6 +718,15 @@ pub struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
fn push_dialog(&mut self, page: DialogPage, focus_id: Option<widget::Id>) -> Task<Message> {
|
||||
let t = self.dialog_pages.push_back(page);
|
||||
if let Some(focus_id) = focus_id {
|
||||
Task::batch(vec![t, focus(focus_id)])
|
||||
} else {
|
||||
t
|
||||
}
|
||||
}
|
||||
|
||||
fn open_file(&mut self, paths: &[impl AsRef<Path>]) -> Task<Message> {
|
||||
let mut tasks = Vec::new();
|
||||
|
||||
|
|
@ -741,10 +773,11 @@ impl App {
|
|||
Err(err) => match err.kind() {
|
||||
io::ErrorKind::PermissionDenied => {
|
||||
// If permission is denied, try marking as executable, then running
|
||||
tasks.push(self.dialog_pages.push_back(
|
||||
tasks.push(self.push_dialog(
|
||||
DialogPage::SetExecutableAndLaunch {
|
||||
path: path.to_path_buf(),
|
||||
},
|
||||
Some(SET_EXECUTABLE_AND_LAUNCH_CONFIRM_BUTTON_ID.clone()),
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -1092,9 +1125,12 @@ impl App {
|
|||
|
||||
let mut tasks = Vec::new();
|
||||
if !dialog_paths.is_empty() {
|
||||
tasks.push(self.dialog_pages.push_back(DialogPage::PermanentlyDelete {
|
||||
paths: dialog_paths,
|
||||
}));
|
||||
tasks.push(self.update(Message::DialogPush(
|
||||
DialogPage::PermanentlyDelete {
|
||||
paths: dialog_paths,
|
||||
},
|
||||
Some(PERMANENT_DELETE_BUTTON_ID.clone()),
|
||||
)));
|
||||
}
|
||||
if !trash_paths.is_empty() {
|
||||
tasks.push(self.operation(Operation::Delete { paths: trash_paths }));
|
||||
|
|
@ -2124,7 +2160,7 @@ impl Application for App {
|
|||
compio_tx,
|
||||
context_page: ContextPage::Preview(None, PreviewKind::Selected),
|
||||
dialog_pages: DialogPages::new(),
|
||||
dialog_text_input: widget::Id::unique(),
|
||||
dialog_text_input: widget::Id::new("Dialog Text Input"),
|
||||
key_binds,
|
||||
margin: FxHashMap::default(),
|
||||
mime_app_cache: MimeAppCache::new(),
|
||||
|
|
@ -2135,14 +2171,15 @@ impl Application for App {
|
|||
network_drive_input: String::new(),
|
||||
#[cfg(feature = "notify")]
|
||||
notification_opt: None,
|
||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||
overlap: FxHashMap::default(),
|
||||
pending_operation_id: 0,
|
||||
pending_operations: BTreeMap::new(),
|
||||
progress_operations: BTreeSet::new(),
|
||||
complete_operations: BTreeMap::new(),
|
||||
failed_operations: BTreeMap::new(),
|
||||
scrollable_id: widget::Id::unique(),
|
||||
search_id: widget::Id::unique(),
|
||||
scrollable_id: widget::Id::new("File Scrollable"),
|
||||
search_id: widget::Id::new("File Search"),
|
||||
size: None,
|
||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||
surface_ids: FxHashMap::default(),
|
||||
|
|
@ -2345,27 +2382,36 @@ impl Application for App {
|
|||
}
|
||||
|
||||
log::warn!("failed to open favorite, path does not exist: {:?}", path);
|
||||
return self.dialog_pages.push_back(DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
});
|
||||
return self.push_dialog(
|
||||
DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
},
|
||||
Some(FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
Location::Path(path) | Location::Network(_, _, Some(path)) => {
|
||||
match path.try_exists() {
|
||||
Ok(true) => true,
|
||||
Ok(false) => {
|
||||
log::warn!("failed to open favorite, path does not exist: {:?}", path);
|
||||
return self.dialog_pages.push_back(DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
});
|
||||
return self.push_dialog(
|
||||
DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
},
|
||||
Some(FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("failed to open favorite for path: {:?}, {}", path, err);
|
||||
return self.dialog_pages.push_back(DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
});
|
||||
return self.push_dialog(
|
||||
DialogPage::FavoritePathError {
|
||||
path: path.clone(),
|
||||
entity,
|
||||
},
|
||||
Some(FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2551,16 +2597,16 @@ impl Application for App {
|
|||
let to = destination.0.to_path_buf();
|
||||
let name = destination.1.to_str().unwrap_or_default().to_string();
|
||||
let archive_type = ArchiveType::default();
|
||||
return Task::batch([
|
||||
self.dialog_pages.push_back(DialogPage::Compress {
|
||||
return self.push_dialog(
|
||||
DialogPage::Compress {
|
||||
paths,
|
||||
to,
|
||||
name,
|
||||
archive_type,
|
||||
password: None,
|
||||
}),
|
||||
widget::text_input::focus(self.dialog_text_input.clone()),
|
||||
]);
|
||||
},
|
||||
Some(self.dialog_text_input.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2855,8 +2901,8 @@ impl Application for App {
|
|||
return Task::batch(tasks);
|
||||
}
|
||||
}
|
||||
Message::DialogPush(dialog_page) => {
|
||||
return self.dialog_pages.push_back(dialog_page);
|
||||
Message::DialogPush(dialog_page, focused_id) => {
|
||||
return self.push_dialog(dialog_page, focused_id);
|
||||
}
|
||||
Message::DialogUpdate(dialog_page) => {
|
||||
self.dialog_pages.update_front(dialog_page);
|
||||
|
|
@ -2915,7 +2961,11 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
Message::Key(window_id, modifiers, key, text) => {
|
||||
if self.core.main_window_id() == Some(window_id) {
|
||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||
let in_surface_ids = self.surface_ids.values().any(|id| *id == window_id);
|
||||
#[cfg(not(all(feature = "wayland", feature = "desktop-applet")))]
|
||||
let in_surface_ids = false;
|
||||
if self.core.main_window_id() == Some(window_id) || in_surface_ids {
|
||||
let entity = self.tab_model.active();
|
||||
for (key_bind, action) in self.key_binds.iter() {
|
||||
if key_bind.matches(modifiers, &key) {
|
||||
|
|
@ -3061,23 +3111,26 @@ impl Application for App {
|
|||
}
|
||||
Err(error) => {
|
||||
log::warn!("failed to connect to {:?}: {}", item, error);
|
||||
return self.dialog_pages.push_back(DialogPage::MountError {
|
||||
mounter_key,
|
||||
item,
|
||||
error,
|
||||
});
|
||||
return self.push_dialog(
|
||||
DialogPage::MountError {
|
||||
mounter_key,
|
||||
item,
|
||||
error,
|
||||
},
|
||||
Some(MOUNT_ERROR_TRY_AGAIN_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
},
|
||||
Message::NetworkAuth(mounter_key, uri, auth, auth_tx) => {
|
||||
return Task::batch([
|
||||
self.dialog_pages.push_back(DialogPage::NetworkAuth {
|
||||
return self.push_dialog(
|
||||
DialogPage::NetworkAuth {
|
||||
mounter_key,
|
||||
uri,
|
||||
auth,
|
||||
auth_tx,
|
||||
}),
|
||||
widget::text_input::focus(self.dialog_text_input.clone()),
|
||||
]);
|
||||
},
|
||||
Some(self.dialog_text_input.clone()),
|
||||
);
|
||||
}
|
||||
Message::NetworkDriveInput(input) => {
|
||||
self.network_drive_input = input;
|
||||
|
|
@ -3338,17 +3391,20 @@ impl Application for App {
|
|||
let Some(path) = item.path_opt() else {
|
||||
continue;
|
||||
};
|
||||
return self.update(Message::DialogPush(DialogPage::OpenWith {
|
||||
path: path.to_path_buf(),
|
||||
mime: item.mime.clone(),
|
||||
selected: 0,
|
||||
store_opt: "x-scheme-handler/mime"
|
||||
.parse::<mime_guess::Mime>()
|
||||
.ok()
|
||||
.and_then(|mime| {
|
||||
self.mime_app_cache.get(&mime).first().cloned()
|
||||
}),
|
||||
}));
|
||||
return self.push_dialog(
|
||||
DialogPage::OpenWith {
|
||||
path: path.to_path_buf(),
|
||||
mime: item.mime.clone(),
|
||||
selected: 0,
|
||||
store_opt: "x-scheme-handler/mime"
|
||||
.parse::<mime_guess::Mime>()
|
||||
.ok()
|
||||
.and_then(|mime| {
|
||||
self.mime_app_cache.get(&mime).first().cloned()
|
||||
}),
|
||||
},
|
||||
Some(CONFIRM_OPEN_WITH_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3488,6 +3544,8 @@ impl Application for App {
|
|||
},
|
||||
}));
|
||||
}
|
||||
tasks.push(widget::text_input::focus(self.dialog_text_input.clone()));
|
||||
|
||||
// Remove from progress
|
||||
self.progress_operations.remove(&id);
|
||||
self.failed_operations
|
||||
|
|
@ -3526,9 +3584,10 @@ impl Application for App {
|
|||
Message::PermanentlyDelete(entity_opt) => {
|
||||
let paths = self.selected_paths(entity_opt);
|
||||
if !paths.is_empty() {
|
||||
return self
|
||||
.dialog_pages
|
||||
.push_back(DialogPage::PermanentlyDelete { paths });
|
||||
return self.push_dialog(
|
||||
DialogPage::PermanentlyDelete { paths },
|
||||
Some(PERMANENT_DELETE_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
Message::Preview(entity_opt) => {
|
||||
|
|
@ -3944,7 +4003,10 @@ impl Application for App {
|
|||
commands.push(self.update(Message::PasteContents(to, from)));
|
||||
}
|
||||
tab::Command::EmptyTrash => {
|
||||
return self.dialog_pages.push_back(DialogPage::EmptyTrash);
|
||||
return self.push_dialog(
|
||||
DialogPage::EmptyTrash,
|
||||
Some(EMPTY_TRASH_BUTTON_ID.clone()),
|
||||
);
|
||||
}
|
||||
#[cfg(feature = "desktop")]
|
||||
tab::Command::ExecEntryAction(entry, action) => {
|
||||
|
|
@ -4400,17 +4462,20 @@ impl Application for App {
|
|||
{
|
||||
match tab::item_from_path(&path, IconSizes::default()) {
|
||||
Ok(item) => {
|
||||
return self.update(Message::DialogPush(DialogPage::OpenWith {
|
||||
path: path.to_path_buf(),
|
||||
mime: item.mime.clone(),
|
||||
selected: 0,
|
||||
store_opt: "x-scheme-handler/mime"
|
||||
.parse::<mime_guess::Mime>()
|
||||
.ok()
|
||||
.and_then(|mime| {
|
||||
self.mime_app_cache.get(&mime).first().cloned()
|
||||
}),
|
||||
}));
|
||||
return self.push_dialog(
|
||||
DialogPage::OpenWith {
|
||||
path: path.to_path_buf(),
|
||||
mime: item.mime.clone(),
|
||||
selected: 0,
|
||||
store_opt: "x-scheme-handler/mime"
|
||||
.parse::<mime_guess::Mime>()
|
||||
.ok()
|
||||
.and_then(|mime| {
|
||||
self.mime_app_cache.get(&mime).first().cloned()
|
||||
}),
|
||||
},
|
||||
None,
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("failed to get item for path {:?}: {}", path, err);
|
||||
|
|
@ -4517,7 +4582,8 @@ impl Application for App {
|
|||
}
|
||||
|
||||
NavMenuAction::EmptyTrash => {
|
||||
return self.dialog_pages.push_front(DialogPage::EmptyTrash);
|
||||
return self
|
||||
.push_dialog(DialogPage::EmptyTrash, Some(EMPTY_TRASH_BUTTON_ID.clone()));
|
||||
}
|
||||
},
|
||||
Message::Recents => {
|
||||
|
|
@ -4572,7 +4638,7 @@ impl Application for App {
|
|||
id: surface_id,
|
||||
layer: Layer::Bottom,
|
||||
keyboard_interactivity: KeyboardInteractivity::OnDemand,
|
||||
pointer_interactivity: true,
|
||||
input_zone: None,
|
||||
anchor: Anchor::TOP | Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT,
|
||||
output: IcedOutput::Output(output),
|
||||
namespace: "cosmic-files-applet".into(),
|
||||
|
|
@ -4902,7 +4968,9 @@ impl Application for App {
|
|||
.title(fl!("empty-trash"))
|
||||
.body(fl!("empty-trash-warning"))
|
||||
.primary_action(
|
||||
widget::button::suggested(fl!("empty-trash")).on_press(Message::DialogComplete),
|
||||
widget::button::suggested(fl!("empty-trash"))
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(EMPTY_TRASH_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
|
|
@ -4921,23 +4989,24 @@ impl Application for App {
|
|||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
)
|
||||
}
|
||||
DialogPage::ExtractPassword { id, password } => {
|
||||
widget::dialog()
|
||||
.title(fl!("extract-password-required"))
|
||||
.icon(icon::from_name("dialog-error").size(64))
|
||||
.control(widget::text_input("", password).password().on_input(
|
||||
move |password| {
|
||||
DialogPage::ExtractPassword { id, password } => widget::dialog()
|
||||
.title(fl!("extract-password-required"))
|
||||
.icon(icon::from_name("dialog-error").size(64))
|
||||
.control(
|
||||
widget::text_input("", password)
|
||||
.password()
|
||||
.on_input(move |password| {
|
||||
Message::DialogUpdate(DialogPage::ExtractPassword { id: *id, password })
|
||||
},
|
||||
))
|
||||
.primary_action(
|
||||
widget::button::suggested(fl!("extract-here"))
|
||||
.on_press(Message::DialogComplete),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
)
|
||||
}
|
||||
})
|
||||
.id(self.dialog_text_input.clone()),
|
||||
)
|
||||
.primary_action(
|
||||
widget::button::suggested(fl!("extract-here"))
|
||||
.on_press(Message::DialogComplete),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
),
|
||||
DialogPage::MountError {
|
||||
mounter_key: _,
|
||||
item: _,
|
||||
|
|
@ -4947,7 +5016,9 @@ impl Application for App {
|
|||
.body(error)
|
||||
.icon(icon::from_name("dialog-error").size(64))
|
||||
.primary_action(
|
||||
widget::button::standard(fl!("try-again")).on_press(Message::DialogComplete),
|
||||
widget::button::standard(fl!("try-again"))
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(MOUNT_ERROR_TRY_AGAIN_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
|
|
@ -5233,7 +5304,9 @@ impl Application for App {
|
|||
let mut dialog = widget::dialog()
|
||||
.title(fl!("open-with-title", name = name))
|
||||
.primary_action(
|
||||
widget::button::suggested(fl!("open")).on_press(Message::DialogComplete),
|
||||
widget::button::suggested(fl!("open"))
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(CONFIRM_OPEN_WITH_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
|
|
@ -5279,7 +5352,8 @@ impl Application for App {
|
|||
.title(fl!("permanently-delete-question"))
|
||||
.primary_action(
|
||||
widget::button::destructive(fl!("delete"))
|
||||
.on_press(Message::DialogComplete),
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(PERMANENT_DELETE_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||
|
|
@ -5385,9 +5459,13 @@ impl Application for App {
|
|||
from.replace_view(fl!("replace-with"), military_time)
|
||||
.map(|x| Message::TabMessage(None, x)),
|
||||
)
|
||||
.primary_action(widget::button::suggested(fl!("replace")).on_press(
|
||||
Message::ReplaceResult(ReplaceResult::Replace(*apply_to_all)),
|
||||
));
|
||||
.primary_action(
|
||||
widget::button::suggested(fl!("replace"))
|
||||
.on_press(Message::ReplaceResult(ReplaceResult::Replace(
|
||||
*apply_to_all,
|
||||
)))
|
||||
.id(REPLACE_BUTTON_ID.clone()),
|
||||
);
|
||||
if *multiple {
|
||||
dialog
|
||||
.control(
|
||||
|
|
@ -5434,7 +5512,8 @@ impl Application for App {
|
|||
.primary_action(
|
||||
widget::button::text(fl!("set-and-launch"))
|
||||
.class(theme::Button::Suggested)
|
||||
.on_press(Message::DialogComplete),
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(SET_EXECUTABLE_AND_LAUNCH_CONFIRM_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::text(fl!("cancel"))
|
||||
|
|
@ -5454,7 +5533,9 @@ impl Application for App {
|
|||
))
|
||||
.icon(icon::from_name("dialog-error").size(64))
|
||||
.primary_action(
|
||||
widget::button::destructive(fl!("remove")).on_press(Message::DialogComplete),
|
||||
widget::button::destructive(fl!("remove"))
|
||||
.on_press(Message::DialogComplete)
|
||||
.id(FAVORITE_PATH_ERROR_REMOVE_BUTTON_ID.clone()),
|
||||
)
|
||||
.secondary_action(
|
||||
widget::button::standard(fl!("keep")).on_press(Message::DialogCancel),
|
||||
|
|
@ -5816,7 +5897,7 @@ impl Application for App {
|
|||
Some(Message::OutputEvent(output_event, output))
|
||||
}
|
||||
#[cfg(feature = "desktop")]
|
||||
WaylandEvent::OverlapNotify(event) => {
|
||||
WaylandEvent::OverlapNotify(event, _, _) => {
|
||||
Some(Message::Overlap(window_id, event))
|
||||
}
|
||||
_ => None,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
app::{Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind},
|
||||
app::{
|
||||
Action, ContextPage, Message as AppMessage, PreviewItem, PreviewKind, REPLACE_BUTTON_ID,
|
||||
},
|
||||
config::{Config, DialogConfig, Favorite, TIME_CONFIG_ID, ThumbCfg, TimeConfig, TypeToSearch},
|
||||
fl, home_dir,
|
||||
key_bind::key_binds,
|
||||
|
|
@ -977,15 +979,15 @@ impl Application for App {
|
|||
context_menu_window: None,
|
||||
context_page: ContextPage::Preview(None, PreviewKind::Selected),
|
||||
dialog_pages: VecDeque::new(),
|
||||
dialog_text_input: widget::Id::unique(),
|
||||
dialog_text_input: widget::Id::new("Dialog Text Input"),
|
||||
filters: Vec::new(),
|
||||
filter_selected: None,
|
||||
filename_id: widget::Id::unique(),
|
||||
filename_id: widget::Id::new("Dialog Filename"),
|
||||
modifiers: Modifiers::empty(),
|
||||
mounter_items: FxHashMap::default(),
|
||||
nav_model: segmented_button::ModelBuilder::default().build(),
|
||||
result_opt: None,
|
||||
search_id: widget::Id::unique(),
|
||||
search_id: widget::Id::new("Dialog File Search"),
|
||||
tab,
|
||||
key_binds,
|
||||
watcher_opt: None,
|
||||
|
|
@ -1598,6 +1600,7 @@ impl Application for App {
|
|||
self.dialog_pages.push_back(DialogPage::Replace {
|
||||
filename: filename.clone(),
|
||||
});
|
||||
return widget::button::focus(REPLACE_BUTTON_ID.clone());
|
||||
} else {
|
||||
self.result_opt = Some(DialogResult::Open(vec![path]));
|
||||
return window::close(self.flags.window_id);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
app::{ArchiveType, DialogPage, Message},
|
||||
app::{ArchiveType, DialogPage, Message, REPLACE_BUTTON_ID},
|
||||
config::IconSizes,
|
||||
fl,
|
||||
spawn_detached::spawn_detached,
|
||||
|
|
@ -53,13 +53,16 @@ async fn handle_replace(
|
|||
let _ = msg_tx
|
||||
.lock()
|
||||
.await
|
||||
.send(Message::DialogPush(DialogPage::Replace {
|
||||
from: item_from,
|
||||
to: item_to,
|
||||
multiple,
|
||||
apply_to_all: false,
|
||||
tx,
|
||||
}))
|
||||
.send(Message::DialogPush(
|
||||
DialogPage::Replace {
|
||||
from: item_from,
|
||||
to: item_to,
|
||||
multiple,
|
||||
apply_to_all: false,
|
||||
tx,
|
||||
},
|
||||
Some(REPLACE_BUTTON_ID.clone()),
|
||||
))
|
||||
.await;
|
||||
rx.recv().await.unwrap_or(ReplaceResult::Cancel)
|
||||
}
|
||||
|
|
@ -1198,7 +1201,7 @@ mod tests {
|
|||
let handle_messages = async move {
|
||||
while let Some(msg) = rx.next().await {
|
||||
match msg {
|
||||
Message::DialogPush(DialogPage::Replace { tx, .. }) => {
|
||||
Message::DialogPush(DialogPage::Replace { tx, .. }, _id_to_focus) => {
|
||||
debug!("[{id}] Replace request");
|
||||
tx.send(ReplaceResult::Cancel)
|
||||
.await
|
||||
|
|
|
|||
125
src/tab.rs
125
src/tab.rs
|
|
@ -1579,7 +1579,6 @@ pub enum Message {
|
|||
SetSort(HeadingOptions, bool),
|
||||
TabComplete(PathBuf, Vec<(String, PathBuf)>),
|
||||
Thumbnail(PathBuf, ItemThumbnail),
|
||||
View(View),
|
||||
ToggleSort(HeadingOptions),
|
||||
Drop(Option<(Location, ClipboardPaste)>),
|
||||
DndHover(Location),
|
||||
|
|
@ -3000,73 +2999,60 @@ impl Tab {
|
|||
.select_range
|
||||
.map_or(Some((click_i, click_i)), |r| Some((r.0, click_i)));
|
||||
if let Some(range) = self.select_range {
|
||||
let min = range.0.min(range.1);
|
||||
let max = range.0.max(range.1);
|
||||
let (sort_name, sort_direction, _) = self.sort_options();
|
||||
//TODO: this assumes the default sort order!
|
||||
if sort_name == HeadingOptions::Name && sort_direction {
|
||||
// A default/unsorted tab's view is consistent with how the
|
||||
// Items are laid out internally (items_opt), so Items can be
|
||||
// linearly selected
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for item in items.iter_mut().skip(min).take(max - min + 1) {
|
||||
let range_min = range.0.min(range.1);
|
||||
let range_max = range.0.max(range.1);
|
||||
// A sorted tab's items can't be linearly selected
|
||||
// Let's say we have:
|
||||
// index | file
|
||||
// 0 | file0
|
||||
// 1 | file1
|
||||
// 2 | file2
|
||||
// This is both the default sort and internal ordering
|
||||
// When sorted it may be displayed as:
|
||||
// 1 | file1
|
||||
// 0 | file0
|
||||
// 2 | file2
|
||||
// However, the internal ordering is still the same thus
|
||||
// linearly selecting items doesn't work. Shift selecting
|
||||
// file0 and file2 would select indices 0 to 2 when it should
|
||||
// select indices 0 AND 2 from items_opt
|
||||
let indices: Vec<_> = self
|
||||
.column_sort()
|
||||
.map(|sorted| sorted.into_iter().map(|(i, _)| i).collect())
|
||||
.unwrap_or_else(|| {
|
||||
let len = self
|
||||
.items_opt
|
||||
.as_deref()
|
||||
.map(|items| items.len())
|
||||
.unwrap_or_default();
|
||||
(0..len).collect()
|
||||
});
|
||||
|
||||
// Find the true indices for the min and max element w.r.t.
|
||||
// a sorted tab.
|
||||
let min = indices
|
||||
.iter()
|
||||
.position(|&offset| offset == range_min)
|
||||
.unwrap_or_default();
|
||||
// We can't skip `min_real` elements here because the index of
|
||||
// `max` may actually be before `min` in a sorted tab
|
||||
let max = indices
|
||||
.iter()
|
||||
.position(|&offset| offset == range_max)
|
||||
.unwrap_or(indices.len());
|
||||
let min_real = min.min(max);
|
||||
let max_real = max.max(min);
|
||||
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for index in indices
|
||||
.into_iter()
|
||||
.skip(min_real)
|
||||
.take(max_real - min_real + 1)
|
||||
{
|
||||
if let Some(item) = items.get_mut(index) {
|
||||
item.selected = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// A sorted tab's items can't be linearly selected
|
||||
// Let's say we have:
|
||||
// index | file
|
||||
// 0 | file0
|
||||
// 1 | file1
|
||||
// 2 | file2
|
||||
// This is both the default sort and internal ordering
|
||||
// When sorted it may be displayed as:
|
||||
// 1 | file1
|
||||
// 0 | file0
|
||||
// 2 | file2
|
||||
// However, the internal ordering is still the same thus
|
||||
// linearly selecting items doesn't work. Shift selecting
|
||||
// file0 and file2 would select indices 0 to 2 when it should
|
||||
// select indices 0 AND 2 from items_opt
|
||||
let indices: Vec<_> = self
|
||||
.column_sort()
|
||||
.map(|sorted| sorted.into_iter().map(|(i, _)| i).collect())
|
||||
.unwrap_or_else(|| {
|
||||
let len = self
|
||||
.items_opt
|
||||
.as_deref()
|
||||
.map(|items| items.len())
|
||||
.unwrap_or_default();
|
||||
(0..len).collect()
|
||||
});
|
||||
|
||||
// Find the true indices for the min and max element w.r.t.
|
||||
// a sorted tab.
|
||||
let min = indices
|
||||
.iter()
|
||||
.position(|&offset| offset == min)
|
||||
.unwrap_or_default();
|
||||
// We can't skip `min_real` elements here because the index of
|
||||
// `max` may actually be before `min` in a sorted tab
|
||||
let max = indices
|
||||
.iter()
|
||||
.position(|&offset| offset == max)
|
||||
.unwrap_or(indices.len());
|
||||
let min_real = min.min(max);
|
||||
let max_real = max.max(min);
|
||||
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for index in indices
|
||||
.into_iter()
|
||||
.skip(min_real)
|
||||
.take(max_real - min_real + 1)
|
||||
{
|
||||
if let Some(item) = items.get_mut(index) {
|
||||
item.selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.clicked = click_i_opt;
|
||||
|
|
@ -3130,6 +3116,12 @@ impl Tab {
|
|||
));
|
||||
}
|
||||
}
|
||||
// Unhighlight all items when config changes
|
||||
if let Some(ref mut items) = self.items_opt {
|
||||
for item in items.iter_mut() {
|
||||
item.highlighted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::ContextAction(action) => {
|
||||
// Close context menu
|
||||
|
|
@ -3816,9 +3808,6 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
}
|
||||
Message::View(view) => {
|
||||
self.config.view = view;
|
||||
}
|
||||
Message::ToggleSort(heading_option) => {
|
||||
if !matches!(self.location, Location::Search(..)) {
|
||||
let heading_sort = if self.sort_name == heading_option {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue