Add batch selection and bulk operations to library view
This commit is contained in:
@@ -349,11 +349,19 @@ impl DriftwoodWindow {
|
||||
|
||||
self.set_content(Some(&toast_overlay));
|
||||
|
||||
// Wire up card/row activation to push detail view
|
||||
// Wire up card/row activation to push detail view (or toggle selection)
|
||||
{
|
||||
let nav = navigation_view.clone();
|
||||
let db = self.database().clone();
|
||||
let window_weak = self.downgrade();
|
||||
library_view.connect_grid_activated(move |record_id| {
|
||||
if let Some(window) = window_weak.upgrade() {
|
||||
let lib_view = window.imp().library_view.get().unwrap();
|
||||
if lib_view.in_selection_mode() {
|
||||
lib_view.toggle_selection(record_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Ok(Some(record)) = db.get_appimage_by_id(record_id) {
|
||||
let page = detail_view::build_detail_page(&record, &db);
|
||||
nav.push(&page);
|
||||
@@ -363,7 +371,15 @@ impl DriftwoodWindow {
|
||||
{
|
||||
let nav = navigation_view.clone();
|
||||
let db = self.database().clone();
|
||||
let window_weak = self.downgrade();
|
||||
library_view.connect_list_activated(move |record_id| {
|
||||
if let Some(window) = window_weak.upgrade() {
|
||||
let lib_view = window.imp().library_view.get().unwrap();
|
||||
if lib_view.in_selection_mode() {
|
||||
lib_view.toggle_selection(record_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Ok(Some(record)) = db.get_appimage_by_id(record_id) {
|
||||
let page = detail_view::build_detail_page(&record, &db);
|
||||
nav.push(&page);
|
||||
@@ -583,6 +599,73 @@ impl DriftwoodWindow {
|
||||
show_drop_hint_action,
|
||||
]);
|
||||
|
||||
// --- Batch actions ---
|
||||
let batch_integrate_action = gio::SimpleAction::new("batch-integrate", None);
|
||||
{
|
||||
let window_weak = self.downgrade();
|
||||
batch_integrate_action.connect_activate(move |_, _| {
|
||||
let Some(window) = window_weak.upgrade() else { return };
|
||||
let lib_view = window.imp().library_view.get().unwrap();
|
||||
let ids = lib_view.selected_ids();
|
||||
if ids.is_empty() { return; }
|
||||
let db = window.database().clone();
|
||||
let toast_overlay = window.imp().toast_overlay.get().unwrap().clone();
|
||||
let mut count = 0;
|
||||
for id in &ids {
|
||||
if let Ok(Some(record)) = db.get_appimage_by_id(*id) {
|
||||
if !record.integrated {
|
||||
if let Ok(result) = integrator::integrate_tracked(&record, &db) {
|
||||
let desktop_path = result.desktop_file_path.to_string_lossy().to_string();
|
||||
db.set_integrated(*id, true, Some(&desktop_path)).ok();
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lib_view.exit_selection_mode();
|
||||
if count > 0 {
|
||||
toast_overlay.add_toast(adw::Toast::new(&format!("Integrated {} apps", count)));
|
||||
if let Ok(records) = db.get_all_appimages() {
|
||||
lib_view.populate(records);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
self.add_action(&batch_integrate_action);
|
||||
|
||||
let batch_delete_action = gio::SimpleAction::new("batch-delete", None);
|
||||
{
|
||||
let window_weak = self.downgrade();
|
||||
batch_delete_action.connect_activate(move |_, _| {
|
||||
let Some(window) = window_weak.upgrade() else { return };
|
||||
let lib_view = window.imp().library_view.get().unwrap();
|
||||
let ids = lib_view.selected_ids();
|
||||
if ids.is_empty() { return; }
|
||||
let db = window.database().clone();
|
||||
let toast_overlay = window.imp().toast_overlay.get().unwrap().clone();
|
||||
let mut count = 0;
|
||||
for id in &ids {
|
||||
if let Ok(Some(record)) = db.get_appimage_by_id(*id) {
|
||||
if record.integrated {
|
||||
integrator::undo_all_modifications(&db, *id).ok();
|
||||
integrator::remove_integration(&record).ok();
|
||||
}
|
||||
std::fs::remove_file(&record.path).ok();
|
||||
db.remove_appimage(*id).ok();
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
lib_view.exit_selection_mode();
|
||||
if count > 0 {
|
||||
toast_overlay.add_toast(adw::Toast::new(&format!("Deleted {} apps", count)));
|
||||
if let Ok(records) = db.get_all_appimages() {
|
||||
lib_view.populate(records);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
self.add_action(&batch_delete_action);
|
||||
|
||||
// --- Context menu actions (parameterized with record ID) ---
|
||||
let param_type = Some(glib::VariantTy::INT64);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user