Add keyboard shortcuts

This commit is contained in:
heliguy
2023-09-01 02:28:23 -04:00
parent 383d01f736
commit 7c59556709
3 changed files with 40 additions and 2 deletions

View File

@@ -24,6 +24,21 @@ ShortcutsWindow help_overlay {
title: C_("shortcut window", "Quit");
action-name: "app.quit";
}
ShortcutsShortcut {
title: C_("shortcut window", "Toggle Batch Mode");
action-name: "app.toggle-batch-mode";
}
ShortcutsShortcut {
title: C_("shortcut window", "Manage Orphaned Data Folders");
action-name: "app.open-orphans-window";
}
ShortcutsShortcut {
title: C_("shortcut window", "Select All Flatpaks");
action-name: "app.select-all-in-batch-mode";
}
}
}
}

View File

@@ -39,12 +39,28 @@ class FlattoolGuiApplication(Adw.Application):
self.create_action('preferences', self.on_preferences_action)
self.create_action('search', self.on_search_action, ['<primary>f'])
self.create_action('manage-data-folders', self.on_manage_data_folders_action)
#self.create_action('toggle ba')
self.create_action('toggle-batch-mode', self.batch_mode_shortcut, ['<primary>b'])
self.create_action('select-all-in-batch-mode', self.select_all_shortcut, ['<primary>a'])
self.create_action('open-orphans-window', self.manage_data_shortcut, ['<primary>d'])
self.show_runtimes_stateful = Gio.SimpleAction.new_stateful("show-runtimes", None, GLib.Variant.new_boolean(False))
self.show_runtimes_stateful.connect("activate", self.on_show_runtimes_action)
self.add_action(self.show_runtimes_stateful)
def batch_mode_shortcut(self, widget, _):
button = self.props.active_window.batch_mode_button
button.set_active(not button.get_active())
def select_all_shortcut(self, widget, _):
batch_button = self.props.active_window.batch_mode_button
batch_button.set_active(True)
select_button = self.props.active_window.batch_select_all_button
select_button.set_active(not select_button.get_active())
self.props.active_window.batch_select_all_handler(select_button)
def manage_data_shortcut(self, widget, _):
self.props.active_window.orphans_window()
def do_activate(self):
"""Called when the application is activated.

View File

@@ -643,6 +643,10 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
dialog.set_response_appearance("purge", Adw.ResponseAppearance.DESTRUCTIVE)
dialog.connect("response", self.batch_uninstall_on_response, dialog.choose_finish)
Gtk.Window.present(dialog)
def batch_key_handler(self, _b, event, _c, _d):
if event == Gdk.KEY_Escape:
self.batch_mode_button.set_active(False)
def flatpak_row_select_handler(self, tickbox, index):
if tickbox.get_active():
@@ -673,4 +677,7 @@ class FlattoolGuiWindow(Adw.ApplicationWindow):
self.batch_uninstall_button.connect("clicked", self.batch_uninstall_handler)
self.batch_uninstall_button.add_css_class("destructive-action")
self.batch_select_all_button.connect("clicked", self.batch_select_all_handler)
self.batch_actions_enable(False)
self.batch_actions_enable(False)
event_controller = Gtk.EventControllerKey()
event_controller.connect("key-pressed", self.batch_key_handler)
self.add_controller(event_controller)