fix merge conflicts

This commit is contained in:
Francesco Pio Gaglione 2024-08-20 08:30:41 +02:00
commit 1ffb3b9870
9 changed files with 780 additions and 324 deletions

View file

@ -71,6 +71,7 @@ pub enum Action {
Cut,
EditHistory,
EditLocation,
ExtractHere,
HistoryNext,
HistoryPrevious,
ItemDown,
@ -84,6 +85,7 @@ pub enum Action {
Open,
OpenInNewTab,
OpenInNewWindow,
OpenItemLocation,
OpenTerminal,
OpenWith,
Paste,
@ -119,6 +121,7 @@ impl Action {
Action::Cut => Message::Cut(entity_opt),
Action::EditHistory => Message::ToggleContextPage(ContextPage::EditHistory),
Action::EditLocation => Message::EditLocation(entity_opt),
Action::ExtractHere => Message::ExtractHere(entity_opt),
Action::HistoryNext => Message::TabMessage(entity_opt, tab::Message::GoNext),
Action::HistoryPrevious => Message::TabMessage(entity_opt, tab::Message::GoPrevious),
Action::ItemDown => Message::TabMessage(entity_opt, tab::Message::ItemDown),
@ -132,6 +135,7 @@ impl Action {
Action::Open => Message::TabMessage(entity_opt, tab::Message::Open),
Action::OpenInNewTab => Message::OpenInNewTab(entity_opt),
Action::OpenInNewWindow => Message::OpenInNewWindow(entity_opt),
Action::OpenItemLocation => Message::OpenItemLocation(entity_opt),
Action::OpenTerminal => Message::OpenTerminal(entity_opt),
Action::OpenWith => Message::ToggleContextPage(ContextPage::OpenWith),
Action::Paste => Message::Paste(entity_opt),
@ -216,6 +220,7 @@ pub enum Message {
DialogPush(DialogPage),
DialogUpdate(DialogPage),
EditLocation(Option<Entity>),
ExtractHere(Option<Entity>),
Key(Modifiers, Key),
LaunchUrl(String),
MaybeExit,
@ -233,6 +238,7 @@ pub enum Message {
OpenWith(PathBuf, mime_app::MimeApp),
OpenInNewTab(Option<Entity>),
OpenInNewWindow(Option<Entity>),
OpenItemLocation(Option<Entity>),
Paste(Option<Entity>),
PasteContents(PathBuf, ClipboardPaste),
PendingComplete(u64),
@ -254,7 +260,7 @@ pub enum Message {
TabConfig(TabConfig),
TabMessage(Option<Entity>, tab::Message),
TabNew,
TabRescan(Entity, Location, Vec<tab::Item>),
TabRescan(Entity, Location, Vec<tab::Item>, Option<PathBuf>),
ToggleContextPage(ContextPage),
Undo(usize),
UndoTrash(usize, Arc<[PathBuf]>),
@ -380,23 +386,30 @@ pub struct App {
}
impl App {
fn open_tab(&mut self, location: Location) -> Command<Message> {
fn open_tab(
&mut self,
location: Location,
activate: bool,
selection_path: Option<PathBuf>,
) -> Command<Message> {
let tab = Tab::new(location.clone(), self.config.tab);
let entity = self
.tab_model
.insert()
.text(tab.title())
.data(tab)
.closable()
.activate()
.id();
.closable();
self.activate_nav_model_location(&location);
let entity = if activate {
entity.activate().id()
} else {
entity.id()
};
Command::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, location),
self.rescan_tab(entity, location, selection_path),
])
}
@ -406,13 +419,20 @@ impl App {
self.pending_operations.insert(id, (operation, 0.0));
}
fn rescan_tab(&mut self, entity: Entity, location: Location) -> Command<Message> {
fn rescan_tab(
&mut self,
entity: Entity,
location: Location,
selection_path: Option<PathBuf>,
) -> Command<Message> {
let icon_sizes = self.config.tab.icon_sizes;
Command::perform(
async move {
let location2 = location.clone();
match tokio::task::spawn_blocking(move || location2.scan(icon_sizes)).await {
Ok(items) => message::app(Message::TabRescan(entity, location, items)),
Ok(items) => {
message::app(Message::TabRescan(entity, location, items, selection_path))
}
Err(err) => {
log::warn!("failed to rescan: {}", err);
message::none()
@ -435,7 +455,7 @@ impl App {
let mut commands = Vec::with_capacity(needs_reload.len());
for (entity, location) in needs_reload {
commands.push(self.rescan_tab(entity, location));
commands.push(self.rescan_tab(entity, location, None));
}
Command::batch(commands)
}
@ -446,16 +466,12 @@ impl App {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
match &tab.location {
Location::Path(path) | Location::Search(path, ..) => {
let location = if !self.search_input.is_empty() {
Location::Search(path.clone(), self.search_input.clone())
}
else {
let location = if !self.search_input.is_empty() {
Location::Search(path.clone(), self.search_input.clone())
} else {
Location::Path(path.clone())
};
tab.change_location(
&location,
None,
);
tab.change_location(&location, None);
title_location_opt = Some((tab.title(), tab.location.clone()));
}
_ => {}
@ -466,7 +482,7 @@ impl App {
return Command::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, location),
self.rescan_tab(entity, location, None),
]);
}
Command::none()
@ -1082,14 +1098,14 @@ impl Application for App {
}
}
};
commands.push(app.open_tab(location));
commands.push(app.open_tab(location, true, None));
}
if app.tab_model.iter().next().is_none() {
if let Ok(current_dir) = env::current_dir() {
commands.push(app.open_tab(Location::Path(current_dir)));
commands.push(app.open_tab(Location::Path(current_dir), true, None));
} else {
commands.push(app.open_tab(Location::Path(home_dir())));
commands.push(app.open_tab(Location::Path(home_dir()), true, None));
}
}
@ -1330,6 +1346,18 @@ impl Application for App {
));
}
}
Message::ExtractHere(entity_opt) => {
let paths = self.selected_paths(entity_opt);
if let Some(current_path) = paths.get(0) {
if let Some(destination) = current_path.parent().zip(current_path.file_stem()) {
let destination_path = destination.0.to_path_buf();
self.operation(Operation::Extract {
paths,
to: destination_path,
});
}
}
}
Message::Key(modifiers, key) => {
let entity = self.tab_model.active();
for (key_bind, action) in self.key_binds.iter() {
@ -1404,7 +1432,7 @@ impl Application for App {
};
if let Some(title) = title_opt {
self.tab_model.text_set(entity, title);
commands.push(self.rescan_tab(entity, home_location.clone()));
commands.push(self.rescan_tab(entity, home_location.clone(), None));
}
}
if !commands.is_empty() {
@ -1502,7 +1530,7 @@ impl Application for App {
let mut commands = Vec::with_capacity(needs_reload.len());
for (entity, location) in needs_reload {
commands.push(self.rescan_tab(entity, location));
commands.push(self.rescan_tab(entity, location, None));
}
return Command::batch(commands);
}
@ -1575,7 +1603,7 @@ impl Application for App {
return Command::batch(self.selected_paths(entity_opt).into_iter().filter_map(
|path| {
if path.is_dir() {
Some(self.open_tab(Location::Path(path)))
Some(self.open_tab(Location::Path(path), false, None))
} else {
None
}
@ -1597,6 +1625,21 @@ impl Application for App {
log::error!("failed to get current executable path: {}", err);
}
},
Message::OpenItemLocation(entity_opt) => {
return Command::batch(self.selected_paths(entity_opt).into_iter().filter_map(
|path| {
if let Some(parent) = path.parent() {
Some(self.open_tab(
Location::Path(parent.to_path_buf()),
true,
Some(path),
))
} else {
None
}
},
))
}
Message::Paste(entity_opt) => {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
@ -1909,14 +1952,14 @@ impl Application for App {
tab::Command::Action(action) => {
commands.push(self.update(action.message(Some(entity))));
}
tab::Command::ChangeLocation(tab_title, tab_path) => {
tab::Command::ChangeLocation(tab_title, tab_path, selection_path) => {
self.activate_nav_model_location(&tab_path);
self.tab_model.text_set(entity, tab_title);
commands.push(Command::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, tab_path),
self.rescan_tab(entity, tab_path, selection_path),
]));
}
tab::Command::EmptyTrash => {
@ -1937,7 +1980,7 @@ impl Application for App {
}
}
tab::Command::OpenInNewTab(path) => {
commands.push(self.open_tab(Location::Path(path.clone())));
commands.push(self.open_tab(Location::Path(path.clone()), false, None));
}
tab::Command::OpenInNewWindow(path) => match env::current_exe() {
Ok(exe) => match process::Command::new(&exe).arg(path).spawn() {
@ -1989,13 +2032,16 @@ impl Application for App {
Some(tab) => tab.location.clone(),
None => Location::Path(home_dir()),
};
return self.open_tab(location);
return self.open_tab(location, true, None);
}
Message::TabRescan(entity, location, items) => {
Message::TabRescan(entity, location, items, selection_path) => {
match self.tab_model.data_mut::<Tab>(entity) {
Some(tab) => {
if location == tab.location {
tab.set_items(items);
if let Some(selection_path) = selection_path {
tab.select_path(selection_path);
}
}
}
_ => (),
@ -2125,7 +2171,7 @@ impl Application for App {
return Command::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, location),
self.rescan_tab(entity, location, None),
]);
}
}
@ -2195,10 +2241,10 @@ impl Application for App {
NavMenuAction::OpenInNewTab(entity) => {
match self.nav_model.data::<Location>(entity) {
Some(Location::Path(ref path)) => {
return self.open_tab(Location::Path(path.clone()));
return self.open_tab(Location::Path(path.clone()), false, None);
}
Some(Location::Trash) => {
return self.open_tab(Location::Trash);
return self.open_tab(Location::Trash, false, None);
}
_ => {}
}
@ -2244,7 +2290,7 @@ impl Application for App {
}
},
Message::Recents => {
return self.open_tab(Location::Recents);
return self.open_tab(Location::Recents, false, None);
}
}