[gnome-taquin] Use BaseWindow.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-taquin] Use BaseWindow.
- Date: Mon, 21 Jan 2019 06:12:04 +0000 (UTC)
commit 969dbd096022bd5f5eb2a55ef66e386c94ca28ae
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jan 17 14:36:52 2019 +0100
Use BaseWindow.
Use the BaseWindow class and its friends.
data/game-headerbar.ui | 44 +------------
data/org.gnome.Taquin.gschema.xml | 9 +++
data/taquin.css | 2 +
src/game-headerbar.vala | 112 +++++++++++++++++++++++++++++---
src/game-view.vala | 25 +++++---
src/game-window.vala | 77 +++++++++++-----------
src/taquin-main.vala | 130 ++++++++++++++++++++------------------
7 files changed, 243 insertions(+), 156 deletions(-)
---
diff --git a/data/game-headerbar.ui b/data/game-headerbar.ui
index f9b2076..b916eaa 100644
--- a/data/game-headerbar.ui
+++ b/data/game-headerbar.ui
@@ -17,28 +17,7 @@
-->
<interface>
<requires lib="gtk+" version="3.12"/>
- <menu id="window-menu">
- <section>
- <item>
- <!-- Translators: hamburger menu entry; sound togglebutton (with a mnemonic that appears pressing
Alt) -->
- <attribute name="label" translatable="yes">_Sound</attribute>
- <attribute name="action">app.sound</attribute>
- </item>
- </section>
- <section>
- <item>
- <!-- Translators: hamburger menu entry; open help (with a mnemonic that appears pressing Alt) -->
- <attribute name="label" translatable="yes">_Help</attribute>
- <attribute name="action">app.help</attribute>
- </item>
- <item>
- <!-- Translators: hamburger menu entry; open about dialog (with a mnemonic that appears pressing
Alt) -->
- <attribute name="label" translatable="yes">_About Taquin</attribute>
- <attribute name="action">app.about</attribute>
- </item>
- </section>
- </menu>
- <template class="GameHeaderBar" parent="GtkHeaderBar">
+ <template class="GameHeaderBar" parent="BaseHeaderBar">
<property name="show-close-button">True</property>
<child>
<object class="GtkBox" id="controls_box">
@@ -54,7 +33,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">ui.escape</property>
+ <property name="action-name">base.escape</property>
<style><class name="image-button"/></style>
<child>
<object class="GtkImage">
@@ -85,24 +64,5 @@
<property name="pack-type">end</property>
</packing>
</child>
- <child>
- <object class="GtkMenuButton" id="info_button">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="receives-default">False</property>
- <property name="menu-model">window-menu</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="icon-name">open-menu-symbolic</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- <property name="position">2</property>
- </packing>
- </child>
</template>
</interface>
diff --git a/data/org.gnome.Taquin.gschema.xml b/data/org.gnome.Taquin.gschema.xml
index 65c4237..bfad1da 100644
--- a/data/org.gnome.Taquin.gschema.xml
+++ b/data/org.gnome.Taquin.gschema.xml
@@ -50,4 +50,13 @@
<!-- TODO add description? -->
</key>
</schema>
+ <schema id="org.gnome.Taquin.NightLight">
+ <key name="automatic-night-mode" type="b">
+ <default>false</default>
+ <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/taquin/automatic-night-mode'
-->
+ <summary>Follow system night light</summary>
+ <!-- Translators: description of a settings key, see 'dconf-editor
/org/gnome/taquin/automatic-night-mode' -->
+ <description>Use GNOME night light setting to activate night-mode.</description>
+ </key>
+ </schema>
</schemalist>
diff --git a/data/taquin.css b/data/taquin.css
index 36f80c3..0d9a465 100644
--- a/data/taquin.css
+++ b/data/taquin.css
@@ -15,6 +15,8 @@
along with GNOME Taquin. If not, see <https://www.gnu.org/licenses/>.
*/
+@import url("base-window.css");
+
/* GtkXyz is pre-3.19.n */
GtkModelButton.radio-like-toggle#radio-fifteen,
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index a30ee91..b3e3488 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -21,15 +21,32 @@
using Gtk;
[GtkTemplate (ui = "/org/gnome/Taquin/ui/game-headerbar.ui")]
-private class GameHeaderBar : HeaderBar
+private class GameHeaderBar : BaseHeaderBar
{
- [GtkChild] private Box controls_box;
- [GtkChild] private Button new_game_button;
- [GtkChild] private Button back_button;
- [GtkChild] private MenuButton info_button;
+ [GtkChild] private Box controls_box;
+ [GtkChild] private Button new_game_button;
+ [GtkChild] private Button back_button;
- internal GameHeaderBar (GameWindowFlags flags)
+ public bool window_has_name { private get; protected construct; default = false; }
+ public string window_name { private get; internal construct; default = ""; }
+
+ construct
+ {
+ init_modes ();
+
+ if (window_name != "")
+ window_has_name = true;
+ }
+
+ internal GameHeaderBar (string _window_name, GameWindowFlags flags, NightLightMonitor
_night_light_monitor)
{
+ /* Translators: usual menu entry of the hamburger menu */
+ Object (about_action_label: _("About Taquin"),
+ night_light_monitor: _night_light_monitor,
+ has_help: true,
+ has_keyboard_shortcuts: false,
+ window_name: _window_name);
+
if (GameWindowFlags.SHOW_UNDO in flags)
{
Box history_box = new Box (Orientation.HORIZONTAL, 0);
@@ -69,12 +86,50 @@ private class GameHeaderBar : HeaderBar
} */
}
+ /*\
+ * * adaptative stuff
+ \*/
+
+ private bool is_quite_thin = true;
+ protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+ base.set_window_size (new_size);
+
+ if (!window_has_name)
+ return;
+
+ bool _is_quite_thin = AdaptativeWidget.WindowSize.is_quite_thin (new_size);
+ if (_is_quite_thin == is_quite_thin)
+ return;
+ is_quite_thin = _is_quite_thin;
+ set_default_widgets_default_states (this);
+ }
+
+ protected override void set_default_widgets_default_states (BaseHeaderBar _this)
+ {
+ string? headerbar_label_text;
+ if (((GameHeaderBar) _this).is_quite_thin)
+ headerbar_label_text = null;
+ else
+ headerbar_label_text = ((GameHeaderBar) _this).window_name;
+ _this.set_default_widgets_states (/* title_label text or null */ headerbar_label_text,
+ /* show go_back_button */ false,
+ /* show ltr_left_separator */ false,
+ /* show info_button */ true,
+ /* show ltr_right_separator */ _this.disable_action_bar,
+ /* show quit_button_stack */ _this.disable_action_bar);
+ }
+
/*\
* * Showing the Stack
\*/
+ private bool current_view_is_new_game_screen = false;
+
internal /* grabs focus */ bool show_new_game_screen (bool game_finished)
{
+ current_view_is_new_game_screen = true;
+
set_subtitle (null); // TODO save / restore?
controls_box.hide ();
@@ -90,6 +145,8 @@ private class GameHeaderBar : HeaderBar
internal /* grabs focus */ bool show_view (bool game_finished)
{
+ current_view_is_new_game_screen = false;
+
back_button.hide (); // TODO transition?
new_game_button.show (); // TODO transition?
controls_box.show ();
@@ -131,8 +188,47 @@ private class GameHeaderBar : HeaderBar
* * hamburger menu
\*/
- internal void toggle_hamburger (/* SimpleAction action, Variant? variant */)
+ protected override void populate_menu (ref GLib.Menu menu)
+ {
+ append_sound_section (ref menu);
+ }
+
+ private static inline void append_sound_section (ref GLib.Menu menu)
+ {
+ GLib.Menu section = new GLib.Menu ();
+ /* Translators: hamburger menu entry; sound togglebutton (with a mnemonic that appears pressing Alt)
*/
+ section.append (_("_Sound"), "app.sound");
+ section.freeze ();
+ menu.append_section (null, section);
+ }
+
+ /*\
+ * * modes
+ \*/
+
+ private void init_modes ()
{
- info_button.active = !info_button.active;
+ this.change_mode.connect (mode_changed_game);
+ }
+
+ private static void mode_changed_game (BaseHeaderBar _this, uint8 mode_id)
+ {
+ GameHeaderBar real_this = (GameHeaderBar) _this;
+ if (mode_id == default_mode_id)
+ {
+ if (real_this.current_view_is_new_game_screen)
+ real_this.back_button.show ();
+ else
+ {
+ real_this.controls_box.show ();
+ real_this.new_game_button.show ();
+ }
+ }
+ else
+ {
+ real_this.back_button.hide ();
+ real_this.controls_box.hide ();
+ real_this.new_game_button.hide ();
+ }
}
}
diff --git a/src/game-view.vala b/src/game-view.vala
index 2f7ef24..056396e 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -20,14 +20,21 @@
using Gtk;
-private class GameView : Stack
+private class GameView : BaseView
{
+ private Stack game_stack;
private Widget game_content;
private Box new_game_box;
private Button? start_game_button = null;
construct
{
+ game_stack = new Stack ();
+ game_stack.hexpand = true;
+ game_stack.vexpand = true;
+ game_stack.show ();
+ main_grid.add (game_stack);
+
new_game_box = new Box (Orientation.VERTICAL, /* spacing */ 6);
new_game_box.halign = Align.CENTER;
new_game_box.valign = Align.CENTER;
@@ -35,7 +42,7 @@ private class GameView : Stack
new_game_box.width_request = 350;
new_game_box.height_request = 350;
new_game_box.show ();
- add (new_game_box);
+ game_stack.add (new_game_box);
}
internal GameView (GameWindowFlags flags, Box new_game_screen, Widget content)
@@ -58,7 +65,7 @@ private class GameView : Stack
}
game_content = content;
- add (content);
+ game_stack.add (content);
content.margin = 25;
content.can_focus = true;
content.show ();
@@ -66,28 +73,28 @@ private class GameView : Stack
internal void show_new_game_box (bool grab_focus)
{
- set_visible_child (new_game_box);
+ game_stack.set_visible_child (new_game_box);
if (grab_focus && start_game_button != null)
((!) start_game_button).grab_focus ();
- // TODO else if (!grabs_focus && start_game_button == null)
+ // TODO else if (grab_focus && start_game_button == null)
}
internal void show_game_content (bool grab_focus)
{
- set_visible_child (game_content);
+ game_stack.set_visible_child (game_content);
if (grab_focus)
game_content.grab_focus ();
}
internal bool game_content_visible_if_true ()
{
- return get_visible_child () == game_content;
+ return game_stack.get_visible_child () == game_content;
}
internal void configure_transition (StackTransitionType transition_type,
uint transition_duration)
{
- set_transition_type (transition_type);
- set_transition_duration (transition_duration);
+ game_stack.set_transition_type (transition_type);
+ game_stack.set_transition_duration (transition_duration);
}
}
diff --git a/src/game-window.vala b/src/game-window.vala
index e46bf3b..27ca26e 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -28,7 +28,7 @@ public enum GameWindowFlags {
SHOW_START_BUTTON;
}
-private class GameWindow : ApplicationWindow
+private class GameWindow : BaseWindow
{
/* settings */
private bool tiled_state;
@@ -42,14 +42,18 @@ private class GameWindow : ApplicationWindow
private GameHeaderBar headerbar;
private GameView game_view;
- public GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool
start_now, GameWindowFlags flags, Box new_game_screen, Widget view_content)
+ public GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool
start_now, GameWindowFlags flags, Box new_game_screen, Widget view_content, NightLightMonitor
night_light_monitor)
{
- headerbar = new GameHeaderBar (flags);
- headerbar.show ();
- game_view = new GameView (flags, new_game_screen, view_content);
- game_view.show ();
- set_titlebar (headerbar);
- add (game_view);
+ GameHeaderBar _headerbar = new GameHeaderBar (name, flags, night_light_monitor);
+ GameView _game_view = new GameView (flags, new_game_screen, view_content);
+
+ Object (nta_headerbar : (NightTimeAwareHeaderBar) _headerbar,
+ base_view : (BaseView) _game_view,
+ window_title : Taquin.PROGRAM_NAME,
+ specific_css_class_or_empty : "");
+
+ headerbar = _headerbar;
+ game_view = _game_view;
/* CSS */
if (css_resource != null)
@@ -66,7 +70,6 @@ private class GameWindow : ApplicationWindow
/* window config */
set_title (name);
- headerbar.set_title (name);
set_default_size (width, height);
if (maximized)
@@ -123,7 +126,8 @@ private class GameWindow : ApplicationWindow
public void set_subtitle (string? subtitle)
{
- headerbar.set_subtitle (subtitle);
+ if (subtitle != null)
+ show_notification ((!) subtitle);
}
public void finish_game ()
@@ -132,10 +136,22 @@ private class GameWindow : ApplicationWindow
headerbar.new_game_button_grab_focus ();
}
- /* public void about ()
+ protected override bool escape_pressed ()
{
- TODO
- } */
+ if (base.escape_pressed ())
+ return true;
+ if (back_action_disabled)
+ return true;
+ if (game_view.game_content_visible_if_true ())
+ return true;
+
+ // TODO change back headerbar subtitle?
+ game_view.configure_transition (StackTransitionType.SLIDE_RIGHT, 800);
+ show_view ();
+
+ back ();
+ return true;
+ }
/*\
* * Showing the Stack
@@ -143,6 +159,7 @@ private class GameWindow : ApplicationWindow
private void show_new_game_screen ()
{
+ hide_notification ();
bool grabs_focus = headerbar.show_new_game_screen (game_finished);
game_view.show_new_game_box (/* grab focus */ !grabs_focus);
}
@@ -187,17 +204,16 @@ private class GameWindow : ApplicationWindow
{
{ "new-game", new_game_cb },
{ "start-game", start_game_cb },
- { "escape", escape_pressed },
{ "undo", undo_cb },
{ "redo", redo_cb },
- { "hint", hint_cb },
-
- { "toggle-hamburger", toggle_hamburger }
+ { "hint", hint_cb }
};
private void new_game_cb (/* SimpleAction action, Variant? variant */)
{
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
@@ -212,6 +228,8 @@ private class GameWindow : ApplicationWindow
private void start_game_cb (/* SimpleAction action, Variant? variant */)
{
+ if (game_view.is_in_in_window_mode ())
+ return;
if (game_view.game_content_visible_if_true ())
return;
@@ -226,22 +244,10 @@ private class GameWindow : ApplicationWindow
show_view ();
}
- private void escape_pressed (/* SimpleAction action, Variant? variant */)
- {
- if (back_action_disabled)
- return;
- if (game_view.game_content_visible_if_true ())
- return;
-
- // TODO change back headerbar subtitle?
- game_view.configure_transition (StackTransitionType.SLIDE_RIGHT, 800);
- show_view ();
-
- back ();
- }
-
private void undo_cb (/* SimpleAction action, Variant? variant */)
{
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
@@ -256,6 +262,8 @@ private class GameWindow : ApplicationWindow
private void redo_cb (/* SimpleAction action, Variant? variant */)
{
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
@@ -268,14 +276,11 @@ private class GameWindow : ApplicationWindow
private void hint_cb (/* SimpleAction action, Variant? variant */)
{
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
hint ();
}
-
- private void toggle_hamburger (/* SimpleAction action, Variant? variant */)
- {
- headerbar.toggle_hamburger ();
- }
}
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 84c34fe..6a9558c 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -20,7 +20,7 @@
using Gtk;
-public class Taquin : Gtk.Application
+private class Taquin : Gtk.Application, BaseApplication
{
/* Translators: application name, as used in the window manager, the window title, the about dialog... */
internal const string PROGRAM_NAME = _("Taquin");
@@ -77,8 +77,8 @@ public class Taquin : Gtk.Application
{"change-size", change_size_cb, "s"},
{"change-theme", change_theme_cb, "s"},
+ {"set-use-night-mode", set_use_night_mode, "b"},
{"help", help_cb},
- {"about", about_cb},
{"quit", quit}
};
@@ -145,6 +145,7 @@ public class Taquin : Gtk.Application
Builder builder = new Builder.from_resource ("/org/gnome/Taquin/ui/taquin-screens.ui");
/* Window */
+ init_night_mode ();
window = new GameWindow ("/org/gnome/Taquin/ui/taquin.css",
PROGRAM_NAME,
settings.get_int ("window-width"),
@@ -153,19 +154,25 @@ public class Taquin : Gtk.Application
true, // TODO add an option to go to new-game screen?
GameWindowFlags.SHOW_UNDO | GameWindowFlags.SHOW_START_BUTTON,
(Box) builder.get_object ("new-game-screen"),
- view);
+ view,
+ night_light_monitor);
window.play.connect (start_game);
window.undo.connect (undo_cb);
+ set_accels_for_action ("base.copy", { "<Primary>c" });
+ set_accels_for_action ("base.copy-alt", { "<Shift><Primary>c" });
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 ("app.quit", { "<Primary>q",
+ "<Shift><Primary>q" });
+ set_accels_for_action ("base.paste", { "<Primary>v" });
+ set_accels_for_action ("base.paste-alt", { "<Shift><Primary>v" });
set_accels_for_action ("ui.undo", { "<Primary>z" });
set_accels_for_action ("ui.redo", { "<Shift><Primary>z" });
- set_accels_for_action ("ui.escape", { "Escape" });
- set_accels_for_action ("ui.toggle-hamburger", { "F10" });
+ set_accels_for_action ("base.escape", { "Escape" });
+ set_accels_for_action ("base.toggle-hamburger", { "F10",
+ "Menu" });
set_accels_for_action ("app.help", { "F1" });
- set_accels_for_action ("app.about", { "<Shift>F1" });
/* New-game screen signals */
size_button = (MenuButton) builder.get_object ("size-button");
@@ -205,6 +212,23 @@ public class Taquin : Gtk.Application
base.shutdown ();
}
+ /*\
+ * * Night mode
+ \*/
+
+ NightLightMonitor night_light_monitor; // keep it here or it is unrefed
+
+ private void init_night_mode ()
+ {
+ night_light_monitor = new NightLightMonitor ("/org/gnome/taquin/");
+ }
+
+ private void set_use_night_mode (SimpleAction action, Variant? gvariant)
+ requires (gvariant != null)
+ {
+ night_light_monitor.set_use_night_mode (((!) gvariant).get_boolean ());
+ }
+
/*\
* * Creating and starting game
\*/
@@ -241,33 +265,6 @@ public class Taquin : Gtk.Application
* * App-menu callbacks
\*/
- private void about_cb ()
- {
- string[] authors = { "Arnaud Bonatti" };
- string[] artists = { "Abelard (Wikimedia)",
- "Alvesgaspar (Wikimedia)",
- "Mueller-rech.muenchen (Wikimedia)",
- "Ruskis (Wikimedia)",
- "Toyah (Wikimedia)",
- /* Translators: about dialog text; in the Credits, text at the end of the
"Artwork by" section */
- _("(see COPYING.themes for informations)") };
- string[] documenters = { "Arnaud Bonatti" };
- show_about_dialog (window,
- "name", PROGRAM_NAME,
- "version", VERSION,
- "copyright", "Copyright © 2014-2019 Arnaud Bonatti",
- "license-type", License.GPL_3_0,
- /* Translators: about dialog text */
- "comments", _("A classic 15-puzzle game"),
- "authors", authors,
- "artists", artists,
- "documenters", documenters,
- /* Translators: about dialog text; this string should be replaced by a text
crediting yourselves and your translation team, or should be left empty. Do not translate literally! */
- "translator-credits", _("translator-credits"),
- "logo-icon-name", "org.gnome.Taquin",
- "website", "https://wiki.gnome.org/Apps/Taquin");
- }
-
private void help_cb ()
{
try
@@ -402,38 +399,49 @@ public class Taquin : Gtk.Application
Gtk.Clipboard clipboard = Gtk.Clipboard.get_default ((!) display);
clipboard.set_text (text, text.length);
}
-}
-namespace AboutDialogInfos
-{
- // strings
- internal const string program_name = Taquin.PROGRAM_NAME;
- internal const string version = VERSION;
-
- /* Translators: about dialog text */
- internal const string comments = _("A classic 15-puzzle game");
-
- /* Translators: about dialog text */
- internal const string copyright = "Copyright \xc2\xa9 2014-2019 – Arnaud Bonatti"; // TODO translation;
autogen, to not change each year?
-
- /* Translators: about dialog text; this string should be replaced by a text crediting yourselves and
your translation team, or should be left empty. Do not translate literally! */
- internal const string translator_credits = _("translator-credits");
-
- // various
- internal const string logo_icon_name = "gnome-taquin";
- internal const string website = "https://wiki.gnome.org/Apps/Taquin";
- /* Translators: about dialog text; label of the website link */
- internal const string website_label = _("Page on GNOME wiki");
- internal const string [] authors = { "Arnaud Bonatti" };
- internal const License license_type = License.GPL_3_0; /* means "version 3.0 or later" */
- internal const string [] artists = {
+ /*\
+ * * about dialog infos
+ \*/
+
+ internal void get_about_dialog_infos (out string [] artists,
+ out string [] authors,
+ out string comments,
+ out string copyright,
+ out string [] documenters,
+ out string logo_icon_name,
+ out string program_name,
+ out string translator_credits,
+ out string version,
+ out string website,
+ out string website_label)
+ {
+ /* Translators: about dialog text */
+ comments = _("A classic 15-puzzle game");
+
+ artists = {
"Abelard (Wikimedia)",
"Alvesgaspar (Wikimedia)",
"Mueller-rech.muenchen (Wikimedia)",
"Ruskis (Wikimedia)",
- "Toyah (Wikimedia)"
+ "Toyah (Wikimedia)",
/* Translators: about dialog text; in the Credits, text at the end of the "Artwork by" section */
-// _("(see COPYING.themes for informations)") // FIXME
+ _("(see COPYING.themes for informations)")
};
- internal const string [] documenters = { "Arnaud Bonatti" };
+ authors = { "Arnaud Bonatti" };
+
+ /* Translators: about dialog text */
+ copyright = "Copyright \xc2\xa9 2014-2019 – Arnaud Bonatti"; // TODO translation; autogen, to not
change each year?
+ documenters = { "Arnaud Bonatti" };
+ logo_icon_name = "gnome-taquin";
+ program_name = Taquin.PROGRAM_NAME;
+
+ /* Translators: about dialog text; this string should be replaced by a text crediting yourselves and
your translation team, or should be left empty. Do not translate literally! */
+ translator_credits = _("translator-credits");
+ version = VERSION;
+
+ website = "https://wiki.gnome.org/Apps/Taquin";
+ /* Translators: about dialog text; label of the website link */
+ website_label = _("Page on GNOME wiki");
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]