mirror of
https://github.com/morgan9e/warehouse
synced 2026-04-14 00:04:08 +09:00
Implemented batch mode copy button.
Disabled batch action buttons when no rows are selected.
This commit is contained in:
@@ -4,9 +4,8 @@ using Adw 1;
|
|||||||
template FlattoolGuiWindow : Adw.ApplicationWindow {
|
template FlattoolGuiWindow : Adw.ApplicationWindow {
|
||||||
default-width: 800;
|
default-width: 800;
|
||||||
default-height: 500;
|
default-height: 500;
|
||||||
title: "Flattool";
|
|
||||||
|
|
||||||
Adw.ToolbarView {
|
Adw.ToolbarView letool {
|
||||||
[top]
|
[top]
|
||||||
HeaderBar header_bar {
|
HeaderBar header_bar {
|
||||||
[start]
|
[start]
|
||||||
@@ -75,17 +74,20 @@ template FlattoolGuiWindow : Adw.ApplicationWindow {
|
|||||||
[end]
|
[end]
|
||||||
Button batch_uninstall_button {
|
Button batch_uninstall_button {
|
||||||
icon-name: "user-trash-symbolic";
|
icon-name: "user-trash-symbolic";
|
||||||
|
label: _("Uninstall");
|
||||||
tooltip-text: _("Uninstall Selected Flatpaks");
|
tooltip-text: _("Uninstall Selected Flatpaks");
|
||||||
}
|
}
|
||||||
[end]
|
[end]
|
||||||
Button batch_clean_button {
|
Button batch_clean_button {
|
||||||
icon-name: "brush-symbolic";
|
icon-name: "brush-symbolic";
|
||||||
|
label: _("Trash User Data");
|
||||||
tooltip-text: _("Send Slected Flatpaks' Data to the Trash");
|
tooltip-text: _("Send Slected Flatpaks' Data to the Trash");
|
||||||
}
|
}
|
||||||
[end]
|
[end]
|
||||||
Button batch_copy_button {
|
Button batch_copy_button {
|
||||||
icon-name: "edit-copy-symbolic";
|
icon-name: "edit-copy-symbolic";
|
||||||
tooltip-text: _("Refresh the List of Installed Apps");
|
label: _("Copy");
|
||||||
|
tooltip-text: _("Copy Selected Flatpaks' Ref Seperated by a New Line");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import os
|
|||||||
@Gtk.Template(resource_path='/io/github/heliguy4599/FlattoolGUI/window.ui')
|
@Gtk.Template(resource_path='/io/github/heliguy4599/FlattoolGUI/window.ui')
|
||||||
class FlattoolGuiWindow(Adw.ApplicationWindow):
|
class FlattoolGuiWindow(Adw.ApplicationWindow):
|
||||||
__gtype_name__ = 'FlattoolGuiWindow'
|
__gtype_name__ = 'FlattoolGuiWindow'
|
||||||
|
main_window_title = "Flattool"
|
||||||
list_of_flatpaks = Gtk.Template.Child()
|
list_of_flatpaks = Gtk.Template.Child()
|
||||||
search_entry = Gtk.Template.Child()
|
search_entry = Gtk.Template.Child()
|
||||||
search_button = Gtk.Template.Child()
|
search_button = Gtk.Template.Child()
|
||||||
@@ -40,8 +41,6 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
|
|||||||
batch_clean_button = Gtk.Template.Child()
|
batch_clean_button = Gtk.Template.Child()
|
||||||
batch_copy_button = Gtk.Template.Child()
|
batch_copy_button = Gtk.Template.Child()
|
||||||
|
|
||||||
selected_host_flatpak_indexes = []
|
|
||||||
|
|
||||||
clipboard = Gdk.Display.get_default().get_clipboard()
|
clipboard = Gdk.Display.get_default().get_clipboard()
|
||||||
host_home = str(pathlib.Path.home())
|
host_home = str(pathlib.Path.home())
|
||||||
user_data_path = host_home + "/.var/app/"
|
user_data_path = host_home + "/.var/app/"
|
||||||
@@ -459,7 +458,11 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
|
|||||||
properties_window.set_content(properties_title_bar)
|
properties_window.set_content(properties_title_bar)
|
||||||
properties_window.present()
|
properties_window.present()
|
||||||
|
|
||||||
|
selected_host_flatpak_indexes = []
|
||||||
|
|
||||||
def generate_list_of_flatpaks(self):
|
def generate_list_of_flatpaks(self):
|
||||||
|
self.set_title(self.main_window_title)
|
||||||
|
self.selected_host_flatpak_indexes = []
|
||||||
def get_host_flatpaks():
|
def get_host_flatpaks():
|
||||||
output = subprocess.run(['flatpak-spawn', '--host', 'flatpak', 'list', '--columns=all'], capture_output=True, text=True).stdout
|
output = subprocess.run(['flatpak-spawn', '--host', 'flatpak', 'list', '--columns=all'], capture_output=True, text=True).stdout
|
||||||
lines = output.strip().split('\n')
|
lines = output.strip().split('\n')
|
||||||
@@ -548,14 +551,34 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
|
|||||||
else:
|
else:
|
||||||
self.in_batch_mode = False
|
self.in_batch_mode = False
|
||||||
self.refresh_list_of_flatpaks(self, False)
|
self.refresh_list_of_flatpaks(self, False)
|
||||||
|
|
||||||
|
def batch_actions_enable(self, should_enable):
|
||||||
|
self.batch_copy_button.set_sensitive(should_enable)
|
||||||
|
self.batch_clean_button.set_sensitive(should_enable)
|
||||||
|
self.batch_uninstall_button.set_sensitive(should_enable)
|
||||||
|
|
||||||
|
def batch_copy_handler(self, widget):
|
||||||
|
to_copy = ""
|
||||||
|
for i in range(len(self.selected_host_flatpak_indexes)):
|
||||||
|
self.host_flatpak_index = self.selected_host_flatpak_indexes[i]
|
||||||
|
to_copy += f"{(self.host_flatpaks[self.host_flatpak_index][8])}\n"
|
||||||
|
print(to_copy)
|
||||||
|
self.clipboard.set(to_copy)
|
||||||
|
|
||||||
def flatpak_row_select_handler(self, tickbox, index):
|
def flatpak_row_select_handler(self, tickbox, index):
|
||||||
if tickbox.get_active():
|
if tickbox.get_active():
|
||||||
self.selected_host_flatpak_indexes.append(index)
|
self.selected_host_flatpak_indexes.append(index)
|
||||||
print(self.selected_host_flatpak_indexes)
|
|
||||||
else:
|
else:
|
||||||
self.selected_host_flatpak_indexes.remove(index)
|
self.selected_host_flatpak_indexes.remove(index)
|
||||||
print(self.selected_host_flatpak_indexes)
|
|
||||||
|
buttons_enable = True
|
||||||
|
if len(self.selected_host_flatpak_indexes) == 0:
|
||||||
|
buttons_enable = False
|
||||||
|
self.set_title(self.main_window_title)
|
||||||
|
else:
|
||||||
|
self.set_title(f"{len(self.selected_host_flatpak_indexes)} Selected")
|
||||||
|
|
||||||
|
self.batch_actions_enable(buttons_enable)
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -564,4 +587,8 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
|
|||||||
self.search_entry.connect("search-changed", lambda *_: self.list_of_flatpaks.invalidate_filter())
|
self.search_entry.connect("search-changed", lambda *_: self.list_of_flatpaks.invalidate_filter())
|
||||||
self.search_bar.connect_entry(self.search_entry)
|
self.search_bar.connect_entry(self.search_entry)
|
||||||
self.refresh_button.connect("clicked", self.refresh_list_of_flatpaks, True)
|
self.refresh_button.connect("clicked", self.refresh_list_of_flatpaks, True)
|
||||||
self.batch_mode_button.connect("toggled", self.batch_mode_handler)
|
self.batch_mode_button.connect("toggled", self.batch_mode_handler)
|
||||||
|
self.batch_copy_button.connect("clicked", self.batch_copy_handler)
|
||||||
|
|
||||||
|
self.batch_uninstall_button.add_css_class("destructive-action")
|
||||||
|
self.batch_actions_enable(False)
|
||||||
Reference in New Issue
Block a user