Skip to content

Commit

Permalink
Application: Use ActionEntry in favor of better extendability
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano committed Feb 18, 2024
1 parent ea350ea commit 1d44f06
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,35 @@ public class Application : Gtk.Application {
}
}

private MainWindow window;
public static GLib.Settings settings;

private const ActionEntry[] ACTION_ENTRIES = {
{ "quit", on_quit_activate },
};

private MainWindow window;

public Application () {
Object (
application_id: "com.github.ryonakano.konbucase",
flags: ApplicationFlags.FLAGS_NONE
);
}

construct {
static construct {
settings = new GLib.Settings ("com.github.ryonakano.konbucase");
}

protected override void startup () {
base.startup ();

Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);
}

static construct {
settings = new GLib.Settings ("com.github.ryonakano.konbucase");
add_action_entries (ACTION_ENTRIES, this);
set_accels_for_action ("app.quit", { "<Control>q" });
}

protected override void activate () {
Expand All @@ -53,15 +63,12 @@ public class Application : Gtk.Application {
}

settings.bind ("window-maximized", window, "maximized", SettingsBindFlags.SET);
}

var quit_action = new GLib.SimpleAction ("quit", null);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});
quit_action.activate.connect (() => {
if (window != null) {
window.destroy ();
}
});
private void on_quit_activate () {
if (window != null) {
window.destroy ();
}
}

public static int main (string[] args) {
Expand Down

0 comments on commit 1d44f06

Please sign in to comment.