mirror of
https://github.com/morgan9e/warehouse
synced 2026-04-14 00:04:08 +09:00
add batch trashing
This commit is contained in:
@@ -81,8 +81,11 @@ class DataSubpage(Gtk.Stack):
|
||||
idx += 1
|
||||
box = box.get_child()
|
||||
if not is_enabled:
|
||||
# continue
|
||||
GLib.idle_add(lambda *_, box=box: box.check_button.set_active(False))
|
||||
GLib.idle_add(lambda *_, box=box: box.check_button.set_visible(is_enabled))
|
||||
# if not is_enabled:
|
||||
# return
|
||||
|
||||
def box_select_handler(self, _, box):
|
||||
box = box.get_child()
|
||||
@@ -90,10 +93,10 @@ class DataSubpage(Gtk.Stack):
|
||||
return
|
||||
cb = box.check_button
|
||||
if cb.get_active():
|
||||
cb.set_active(False)
|
||||
GLib.idle_add(lambda *_: cb.set_active(False))
|
||||
self.selected_boxes.remove(box)
|
||||
else:
|
||||
cb.set_active(True)
|
||||
GLib.idle_add(lambda *_: cb.set_active(True))
|
||||
self.selected_boxes.append(box)
|
||||
|
||||
total = len(self.selected_boxes)
|
||||
@@ -104,7 +107,8 @@ class DataSubpage(Gtk.Stack):
|
||||
idx = 0
|
||||
while box := self.flow_box.get_child_at_index(idx):
|
||||
idx += 1
|
||||
self.box_select_handler(None, box)
|
||||
if not box.get_child().check_button.get_active():
|
||||
self.box_select_handler(None, box)
|
||||
|
||||
def generate_list(self, flatpaks, data):
|
||||
self.boxes.clear()
|
||||
@@ -131,8 +135,6 @@ class DataSubpage(Gtk.Stack):
|
||||
self.flow_box.append(box)
|
||||
child = self.flow_box.get_child_at_index(i)
|
||||
child.set_focusable(False)
|
||||
|
||||
self.flow_box.connect("child-activated", self.box_select_handler)
|
||||
|
||||
idx = 0
|
||||
while box := self.flow_box.get_child_at_index(idx):
|
||||
@@ -218,6 +220,7 @@ class DataSubpage(Gtk.Stack):
|
||||
|
||||
# Connections
|
||||
parent_page.search_entry.connect("search-changed", self.on_invalidate)
|
||||
self.flow_box.connect("child-activated", self.box_select_handler)
|
||||
|
||||
# self.title.get_preferred_size()[1].width + self.subtitle.get_preferred_size()[1].width
|
||||
self.scrolled_window.get_hadjustment().connect("changed", self.label_orientation_handler)
|
||||
@@ -3,7 +3,9 @@ from .error_toast import ErrorToast
|
||||
from .data_box import DataBox
|
||||
from .data_subpage import DataSubpage
|
||||
from .host_info import HostInfo
|
||||
import os
|
||||
import os, subprocess
|
||||
|
||||
import time
|
||||
|
||||
@Gtk.Template(resource_path="/io/github/flattool/Warehouse/user_data_page/user_data_page.ui")
|
||||
class UserDataPage(Adw.BreakpointBin):
|
||||
@@ -50,6 +52,7 @@ class UserDataPage(Adw.BreakpointBin):
|
||||
self.leftover_data.append(folder)
|
||||
|
||||
def start_loading(self, *args):
|
||||
self.select_button.set_active(False)
|
||||
self.adp.set_visible_child(self.adp.loading_data)
|
||||
self.adp.size_label.set_label("Loading Size")
|
||||
self.adp.spinner.set_visible(True)
|
||||
@@ -80,8 +83,7 @@ class UserDataPage(Adw.BreakpointBin):
|
||||
elif self.sort_size.get_active():
|
||||
self.adp.sort_mode = "size"
|
||||
self.ldp.sort_mode = "size"
|
||||
|
||||
|
||||
|
||||
self.adp.sort_ascend = self.sort_ascend.get_active()
|
||||
self.ldp.sort_ascend = self.sort_ascend.get_active()
|
||||
|
||||
@@ -124,11 +126,46 @@ class UserDataPage(Adw.BreakpointBin):
|
||||
for box in child.selected_boxes:
|
||||
to_copy += "\n" + box.data_path
|
||||
|
||||
if len(to_copy) > 0:
|
||||
if len(to_copy) == 0:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not copy paths"), _("No boxes were selected")).toast)
|
||||
else:
|
||||
HostInfo.clipboard.set(to_copy.replace("\n", "", 1))
|
||||
self.toast_overlay.add_toast(Adw.Toast(title=_("Copied paths")))
|
||||
else:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not copy paths"), _("No boxes were selected")).toast)
|
||||
|
||||
def trash_handler(self, *args):
|
||||
error = [None]
|
||||
|
||||
def thread(path):
|
||||
cmd = ['gio', 'trash'] + path
|
||||
try:
|
||||
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
error[0] = cpe.stderr
|
||||
except Exception as e:
|
||||
error[0] = e
|
||||
|
||||
def callback(*args):
|
||||
self.start_loading()
|
||||
self.end_loading()
|
||||
if error[0]:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not trash data"), str(error[0])).toast)
|
||||
else:
|
||||
self.toast_overlay.add_toast(Adw.Toast(title=_("Trashed data")))
|
||||
|
||||
child = self.stack.get_visible_child()
|
||||
to_trash = []
|
||||
for box in child.selected_boxes:
|
||||
to_trash.append(box.data_path)
|
||||
|
||||
if len(to_trash) == 0:
|
||||
self.toast_overlay.add_toast(ErrorToast(_("Could not trash data"), _("No boxes were selected")).toast)
|
||||
return
|
||||
|
||||
self.select_button.set_active(False)
|
||||
child.set_visible_child(child.loading_data)
|
||||
Gio.Task.new(None, None, callback).run_in_thread(lambda *_: thread(to_trash))
|
||||
|
||||
# self.toast_overlay.add_toast(Adw.Toast(title=_("Trashed data")))
|
||||
|
||||
def __init__(self, main_window, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -169,6 +206,7 @@ class UserDataPage(Adw.BreakpointBin):
|
||||
|
||||
self.select_all_button.connect("clicked", self.select_all_handler)
|
||||
self.copy_button.connect("clicked", self.copy_handler)
|
||||
self.trash_button.connect("clicked", self.trash_handler)
|
||||
|
||||
self.sort_ascend.connect("clicked", self.sorter)
|
||||
self.sort_descend.connect("clicked", self.sorter)
|
||||
|
||||
Reference in New Issue
Block a user