[iagno] Use custom action group.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Use custom action group.
- Date: Thu, 28 Feb 2019 14:03:05 +0000 (UTC)
commit aa71907bb1af2d39c5ab7bf6f7f433ebb269b918
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Feb 28 14:25:01 2019 +0100
Use custom action group.
Do not expose actions over D-Bus, the API
has not been thought or designed for now.
data/ui/iagno.ui | 6 ++---
src/game-window.vala | 74 +++++++++++++++++++++++++++++-----------------------
src/iagno.vala | 12 ++++-----
3 files changed, 50 insertions(+), 42 deletions(-)
---
diff --git a/data/ui/iagno.ui b/data/ui/iagno.ui
index f47e115..3ac8567 100644
--- a/data/ui/iagno.ui
+++ b/data/ui/iagno.ui
@@ -47,7 +47,7 @@
<!-- Translators: when configuring a new game, if the user has a started game, tooltip text of
the Go back button -->
<property name="tooltip-text" translatable="yes">Go back to the current game</property>
<property name="use-underline">True</property>
- <property name="action-name">win.back</property>
+ <property name="action-name">ui.back</property>
<property name="focus-on-click">False</property>
<style>
<class name="image-button"/>
@@ -130,7 +130,7 @@
<property name="label" translatable="yes">_New Game</property>
<property name="halign">center</property>
<property name="valign">center</property>
- <property name="action-name">win.new-game</property>
+ <property name="action-name">ui.new-game</property>
<!-- Translators: during a game, tooltip text of the Start Over button -->
<property name="tooltip-text" translatable="yes">Start a new game</property>
<property name="width-request">120</property>
@@ -166,7 +166,7 @@
<property name="visible">False</property>
<property name="halign">end</property>
<property name="valign">start</property>
- <property name="action-name">win.unfullscreen</property>
+ <property name="action-name">ui.unfullscreen</property>
<style>
<class name="image-button"/>
<class name="unfullscreen-button"/>
diff --git a/src/game-window.vala b/src/game-window.vala
index c7c23f1..9f23fda 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -65,26 +65,6 @@ private class GameWindow : ApplicationWindow
// internal signal void redo ();
internal signal void hint ();
- /* actions */
- private const GLib.ActionEntry win_actions[] =
- {
- { "new-game", new_game_cb },
- { "start-game", start_game_cb },
- { "back", back_cb },
-
- { "undo", undo_cb },
- // { "redo", redo_cb },
- { "hint", hint_cb },
-
- { "toggle-hamburger", toggle_hamburger },
- { "unfullscreen", unfullscreen }
- };
-
- private SimpleAction back_action;
-
- internal SimpleAction undo_action;
- // internal SimpleAction redo_action;
-
internal GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool
start_now, GameWindowFlags flags, Box new_game_screen, Widget _view)
{
if (css_resource != null)
@@ -98,18 +78,8 @@ private class GameWindow : ApplicationWindow
view = _view;
- /* window actions */
- add_action_entries (win_actions, this);
-
- back_action = (SimpleAction) lookup_action ("back");
- undo_action = (SimpleAction) lookup_action ("undo");
- // redo_action = (SimpleAction) lookup_action ("redo");
-
- back_action.set_enabled (false);
- undo_action.set_enabled (false);
- // redo_action.set_enabled (false);
-
/* window config */
+ install_ui_action_entries ();
set_title (name);
headerbar.set_title (name);
@@ -129,7 +99,7 @@ private class GameWindow : ApplicationWindow
_start_game_button.width_request = 222;
_start_game_button.height_request = 60;
_start_game_button.halign = Align.CENTER;
- _start_game_button.set_action_name ("win.start-game");
+ _start_game_button.set_action_name ("ui.start-game");
/* Translators: when configuring a new game, tooltip text of the blue Start button */
// _start_game_button.set_tooltip_text (_("Start a new game as configured"));
((StyleContext) _start_game_button.get_style_context ()).add_class ("suggested-action");
@@ -151,7 +121,7 @@ private class GameWindow : ApplicationWindow
history_box.get_style_context ().add_class ("linked");
Button undo_button = new Button.from_icon_name ("edit-undo-symbolic", Gtk.IconSize.BUTTON);
- undo_button.action_name = "win.undo";
+ undo_button.action_name = "ui.undo";
/* Translators: during a game, tooltip text of the Undo button */
undo_button.set_tooltip_text (_("Undo your most recent move"));
undo_button.valign = Align.CENTER;
@@ -190,6 +160,44 @@ private class GameWindow : ApplicationWindow
show_new_game_screen ();
}
+ /*\
+ * * actions
+ \*/
+
+ private SimpleAction back_action;
+
+ internal SimpleAction undo_action;
+ // internal SimpleAction redo_action;
+
+ private void install_ui_action_entries ()
+ {
+ SimpleActionGroup action_group = new SimpleActionGroup ();
+ action_group.add_action_entries (ui_action_entries, this);
+ insert_action_group ("ui", action_group);
+
+ back_action = (SimpleAction) action_group.lookup_action ("back");
+ undo_action = (SimpleAction) action_group.lookup_action ("undo");
+ // redo_action = (SimpleAction) lookup_action ("redo");
+
+ back_action.set_enabled (false);
+ undo_action.set_enabled (false);
+ // redo_action.set_enabled (false);
+ }
+
+ private const GLib.ActionEntry [] ui_action_entries =
+ {
+ { "new-game", new_game_cb },
+ { "start-game", start_game_cb },
+ { "back", back_cb },
+
+ { "undo", undo_cb },
+ // { "redo", redo_cb },
+ { "hint", hint_cb },
+
+ { "toggle-hamburger", toggle_hamburger },
+ { "unfullscreen", unfullscreen }
+ };
+
/*\
* * Window events
\*/
diff --git a/src/iagno.vala b/src/iagno.vala
index 259ba7e..2d1fd95 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -238,13 +238,13 @@ private class Iagno : Gtk.Application
/* Actions and preferences */
add_action_entries (app_actions, this);
- set_accels_for_action ("win.new-game", { "<Primary>n" });
- set_accels_for_action ("win.start-game", { "<Shift><Primary>n" });
+ set_accels_for_action ("ui.new-game", { "<Primary>n" });
+ set_accels_for_action ("ui.start-game", { "<Shift><Primary>n" });
set_accels_for_action ("app.quit", { "<Primary>q" });
- set_accels_for_action ("win.undo", { "<Primary>z" });
- // set_accels_for_action ("win.redo", { "<Shift><Primary>z" });
- set_accels_for_action ("win.back", { "Escape" });
- set_accels_for_action ("win.toggle-hamburger", { "F10" });
+ set_accels_for_action ("ui.undo", { "<Primary>z" });
+ // set_accels_for_action ("ui.redo", { "<Shift><Primary>z" });
+ set_accels_for_action ("ui.back", { "Escape" });
+ set_accels_for_action ("ui.toggle-hamburger", { "F10" });
set_accels_for_action ("app.help", { "F1" });
set_accels_for_action ("app.about", { "<Shift>F1" });
add_action (settings.create_action ("sound"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]