Verified Commit 0bf7ee27 authored by M. Sandoval's avatar M. Sandoval 🥑
Browse files

main_window: Simplify create/open file callbacks

Instead of using them in different contexts (clicked signal or action
activate) just use them as actions, they are renamed and annotated to reflect this.
parent 9eefa15d
......@@ -23,7 +23,7 @@
<object class="GtkButton" id="new_file_button">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">New…</property>
<signal name="clicked" handler="create_filechooser" swapped="no"/>
<property name="action_name">app.new</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
......@@ -36,7 +36,7 @@
<object class="GtkButton" id="open_file_button">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Open…</property>
<signal name="clicked" handler="open_filechooser" swapped="no"/>
<property name="action_name">app.open</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
......
......@@ -96,8 +96,8 @@ class Application(Gtk.Application):
("settings", self.show_settings),
("about", self.show_about_dialog),
("quit", self.on_quit_action),
("new", self.window.create_filechooser),
("open", self.window.open_filechooser),
("new", self.window.on_create_file_action),
("open", self.window.on_open_file_action),
]
for name, callback in actions:
......
......@@ -192,14 +192,10 @@ class MainWindow(Handy.ApplicationWindow):
# Open Database Methods
#
@Gtk.Template.Callback()
def open_filechooser(self, _widget, _user_data=None):
"""Callback function to open a safe.
This callback can be called from an action activate event or
a clicked event from a button. In the latter case, no user_data
is set. Having None as a default value allows to handle both
events reliably.
"""
def on_open_file_action(
self, _action: Gio.Action, _parameter: GLib.Variant
) -> None:
"""Callback function to open a safe."""
# pylint: disable=too-many-locals
filechooser_opening_dialog = Gtk.FileChooserNative.new(
# NOTE: Filechooser title for opening an existing keepass safe kdbx file
......@@ -281,15 +277,10 @@ class MainWindow(Handy.ApplicationWindow):
# Create Database Methods
#
@Gtk.Template.Callback()
def create_filechooser(self, _widget, _user_data=None):
"""Callback function to create a new safe.
This callback can be called from an action activate event or
a clicked event from a button. In the latter case, no user_data
is set. Having None as a default value allows to handle both
events reliably.
"""
def on_create_file_action(
self, _action: Gio.Action, _parameter: GLib.Variant
) -> None:
"""Callback function to create a new safe."""
filechooser_creation_dialog = Gtk.FileChooserNative.new(
# NOTE: Filechooser title for creating a new keepass safe kdbx file
_("Choose location for Keepass safe"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment