[iagno] Use BaseWindow.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Use BaseWindow.
- Date: Sat, 3 Aug 2019 09:04:57 +0000 (UTC)
commit ae1b1e9e135f187c2d1db562fa53d6a7ee36dbaf
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sun Mar 3 15:16:01 2019 +0100
Use BaseWindow.
data/iagno.css | 2 +
data/iagno.gresource.xml | 1 -
data/ui/game-headerbar.ui | 47 +----------
data/ui/iagno.ui | 53 -------------
src/game-headerbar.vala | 167 +++++++++++++++++++++++++++++----------
src/game-view.vala | 4 +-
src/game-window.vala | 193 +++++++++++++++++++---------------------------
src/iagno.vala | 137 ++++++++++++++++++++------------
src/new-game-screen.vala | 6 +-
src/reversi-view.vala | 6 ++
10 files changed, 311 insertions(+), 305 deletions(-)
---
diff --git a/data/iagno.css b/data/iagno.css
index e60f627..1f176ea 100644
--- a/data/iagno.css
+++ b/data/iagno.css
@@ -17,6 +17,8 @@
along with GNOME Reversi. If not, see <https://www.gnu.org/licenses/>.
*/
+@import url("base-window.css");
+
button.unfullscreen-button {
margin:6px;
}
diff --git a/data/iagno.gresource.xml b/data/iagno.gresource.xml
index 2e9c003..7d329b5 100644
--- a/data/iagno.gresource.xml
+++ b/data/iagno.gresource.xml
@@ -7,7 +7,6 @@
<file compressed="true">base-window.css</file>
<file preprocess="xml-stripblanks" compressed="true" alias="base-window.ui"
ui/base-window.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="game-headerbar.ui"
ui/game-headerbar.ui</file>
- <file preprocess="xml-stripblanks" compressed="true" alias="game-window.ui"
ui/iagno.ui</file>
<file compressed="true">iagno.css</file>
<file preprocess="xml-stripblanks" compressed="true" alias="iagno-screens.ui"
ui/iagno-screens.ui</file>
<file preprocess="xml-stripblanks" compressed="true" alias="notifications-revealer.ui"
ui/notifications-revealer.ui</file>
diff --git a/data/ui/game-headerbar.ui b/data/ui/game-headerbar.ui
index 08f83dc..ffb41ab 100644
--- a/data/ui/game-headerbar.ui
+++ b/data/ui/game-headerbar.ui
@@ -21,28 +21,7 @@
-->
<interface>
<requires lib="gtk+" version="3.12"/>
- <menu id="primary-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 Iagno</attribute>
- <attribute name="action">app.about</attribute>
- </item>
- </section>
- </menu>
- <template class="GameHeaderBar" parent="GtkHeaderBar">
+ <template class="GameHeaderBar" parent="BaseHeaderBar">
<property name="visible">True</property>
<property name="show-close-button">True</property>
<child>
@@ -67,7 +46,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.back</property>
+ <property name="action-name">base.escape</property>
<property name="focus-on-click">False</property>
<style>
<class name="image-button"/>
@@ -97,27 +76,7 @@
</object>
<packing>
<property name="pack-type">end</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkMenuButton" id="info_button">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <property name="can-focus">True</property>
- <property name="menu-model">primary-menu</property>
- <property name="focus-on-click">False</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">open-menu-symbolic</property>
- <property name="icon-size">1</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- <property name="position">1</property>
+ <property name="position">5</property>
</packing>
</child>
</template>
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index 24f3f41..fc4edde 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -21,72 +21,93 @@
using Gtk;
[GtkTemplate (ui = "/org/gnome/Reversi/ui/game-headerbar.ui")]
-private class GameHeaderBar : HeaderBar
+private class GameHeaderBar : BaseHeaderBar, AdaptativeWidget
{
+ [GtkChild] private MenuButton history_button;
+ [GtkChild] private Button new_game_button;
+ [GtkChild] private Button back_button;
+
+ [CCode (notify = false)] public bool window_has_name { private get; protected construct; default =
false; }
[CCode (notify = false)] public string window_name { private get; internal construct; default = ""; }
+ [CCode (notify = false)] public bool has_sound { private get; protected construct; default = false; }
[CCode (notify = false)] public bool show_undo { private get; protected construct; default = false; }
- // [CCode (notify = false)] public bool show_redo { private get; protected construct; default = false; }
- // [CCode (notify = false)] public bool show_hint { private get; protected construct; default = false; }
// TODO something
-
- [CCode (notify = false)] public bool has_help { private get; protected construct; default = false; }
- [CCode (notify = false)] public bool has_keyboard_shortcuts { private get; protected construct; default
= false; }
-
- [GtkChild] private Button new_game_button;
- [GtkChild] private Button back_button;
+ [CCode (notify = false)] public bool show_redo { private get; protected construct; default = false; }
+ [CCode (notify = false)] public bool show_hint { private get; protected construct; default = false; }
// TODO something
construct
{
configure_history_button ();
+ init_modes ();
+
if (window_name != "")
- // window_has_name = true;
- set_title (window_name);
+ window_has_name = true;
}
internal GameHeaderBar (string _window_name,
+ string _about_action_label,
GameWindowFlags flags,
- GLib.Menu? appearance_menu)
+ GLib.Menu? _appearance_menu,
+ NightLightMonitor _night_light_monitor)
{
- Object (has_keyboard_shortcuts: GameWindowFlags.SHORTCUTS in flags,
+ Object (about_action_label: _about_action_label,
+ night_light_monitor: _night_light_monitor,
+ has_keyboard_shortcuts: GameWindowFlags.SHORTCUTS in flags,
+ has_sound: GameWindowFlags.HAS_SOUND in flags,
has_help: GameWindowFlags.SHOW_HELP in flags, // TODO rename show_help
- // show_hint: GameWindowFlags.SHOW_HINT in flags,
- // show_redo: GameWindowFlags.SHOW_REDO in flags,
+ show_hint: GameWindowFlags.SHOW_HINT in flags,
+ show_redo: GameWindowFlags.SHOW_REDO in flags,
show_undo: GameWindowFlags.SHOW_UNDO in flags,
+ appearance_menu: _appearance_menu,
window_name: _window_name);
+ }
- GLib.MenuModel hamburger_menu = (!) info_button.get_menu_model ();
- if (appearance_menu != null)
- {
- GLib.Menu first_section = (GLib.Menu) (!) hamburger_menu.get_item_link (0, "section");
- /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears
pressing Alt) */
- first_section.prepend_submenu (_("A_ppearance"), (!) appearance_menu);
- }
- ((GLib.Menu) hamburger_menu).freeze ();
+ /*\
+ * * adaptative stuff
+ \*/
+
+ private bool is_extra_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_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
+ if (_is_extra_thin == is_extra_thin)
+ return;
+ is_extra_thin = _is_extra_thin;
+ set_default_widgets_default_states (this);
}
- internal void finish_game ()
+ protected override void set_default_widgets_default_states (BaseHeaderBar _this)
{
- if (!history_button.active)
- new_game_button.grab_focus ();
+ string? headerbar_label_text;
+ if (((GameHeaderBar) _this).is_extra_thin)
+ headerbar_label_text = null;
else
- new_game_button.grab_default (); // FIXME: grab_focus, but without closing the popover...
- set_history_button_label (Player.NONE);
+ 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;
+ 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?
+ current_view_is_new_game_screen = true;
- new_game_button.hide ();
+ // new_game_button.hide ();
history_button.hide ();
if (!game_finished && back_button.visible)
@@ -100,7 +121,7 @@ private class GameHeaderBar : HeaderBar
internal /* grabs focus */ bool show_view (bool game_finished)
{
- // current_view_is_new_game_screen = false;
+ current_view_is_new_game_screen = false;
back_button.hide (); // TODO transition?
new_game_button.show (); // TODO transition?
@@ -119,27 +140,95 @@ private class GameHeaderBar : HeaderBar
* * switching the stack
\*/
+ private bool game_created = false;
+
internal void new_game ()
{
+ game_created = true;
back_button.show ();
+ new_game_button.hide (); // TODO transition?
+ }
+
+ /*\
+ * * some public calls
+ \*/
+
+ // internal void new_game_button_grab_focus ()
+ // {
+ // new_game_button.grab_focus ();
+ // }
+
+ internal void finish_game ()
+ {
+ if (!history_button.active)
+ new_game_button.grab_focus ();
+ else
+ new_game_button.grab_default (); // FIXME: grab_focus, but without closing the popover...
+ set_history_button_label (Player.NONE);
}
/*\
* * hamburger menu
\*/
- [GtkChild] private MenuButton info_button;
+ public GLib.Menu? appearance_menu { private get; protected construct; default = null; }
+ protected override void populate_menu (ref GLib.Menu menu)
+ {
+ append_options_section (ref menu, appearance_menu, has_sound);
+ }
- internal void toggle_hamburger ()
+ private static inline void append_options_section (ref GLib.Menu menu, GLib.Menu? appearance_menu, bool
has_sound)
{
- info_button.active = !info_button.active;
+ GLib.Menu section = new GLib.Menu ();
+
+ if (appearance_menu != null)
+ /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears
pressing Alt) */
+ section.append_submenu (_("A_ppearance"), (!) appearance_menu);
+
+ if (has_sound)
+ /* 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);
}
/*\
- * * history menu
+ * * modes
\*/
- [GtkChild] private MenuButton history_button;
+ private void init_modes ()
+ {
+ 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)
+ {
+ if (real_this.game_created)
+ real_this.back_button.show ();
+ }
+ else
+ {
+ real_this.history_button.show ();
+ real_this.new_game_button.show ();
+ }
+ }
+ else
+ {
+ real_this.back_button.hide ();
+ real_this.history_button.hide ();
+ real_this.new_game_button.hide ();
+ }
+ }
+
+ /*\
+ * * history menu
+ \*/
private GLib.Menu history_menu;
private GLib.Menu finish_menu;
diff --git a/src/game-view.vala b/src/game-view.vala
index ef8f021..18dbf8a 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -20,7 +20,7 @@
using Gtk;
-private class GameView : Grid
+private class GameView : BaseView, AdaptativeWidget
{
private Stack game_stack;
private Widget game_content;
@@ -34,7 +34,7 @@ private class GameView : Grid
game_stack.hexpand = true;
game_stack.vexpand = true;
game_stack.show ();
- this.add (game_stack);
+ main_grid.add (game_stack);
scrolled = new ScrolledWindow (null, null);
scrolled.visible = true;
diff --git a/src/game-window.vala b/src/game-window.vala
index a521a32..3db2bc9 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -31,27 +31,40 @@ private enum GameWindowFlags {
SHOW_START_BUTTON;
}
-[GtkTemplate (ui = "/org/gnome/Reversi/ui/game-window.ui")]
-private class GameWindow : ApplicationWindow
+private class GameWindow : BaseWindow, AdaptativeWidget
{
private bool game_finished = false;
- /* settings */
- private bool window_is_tiled;
- private bool window_is_maximized;
- private bool window_is_fullscreen;
- private int window_width;
- private int window_height;
-
/* private widgets */
- [GtkChild] private Overlay main_overlay;
- [GtkChild] private Button unfullscreen_button;
-
private GameHeaderBar headerbar;
private GameView game_view;
+ private Box new_game_screen;
+
+ construct
+ {
+ height_request = 560;
+ width_request = 560;
+ }
- internal GameWindow (string? css_resource, string name, int width, int height, bool maximized, bool
start_now, GameWindowFlags flags, Box new_game_screen, Widget _view, GLib.Menu? appearance_menu)
+ internal GameWindow (string? css_resource, string name, string about_action_label, bool start_now,
GameWindowFlags flags, Box _new_game_screen, Widget view_content, GLib.Menu? appearance_menu,
NightLightMonitor night_light_monitor)
{
+ GameHeaderBar _headerbar = new GameHeaderBar (name, about_action_label, flags, appearance_menu,
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 : Iagno.PROGRAM_NAME,
+ specific_css_class_or_empty : "",
+ help_string_or_empty : "help:iagno",
+ schema_path : "/org/gnome/iagno/");
+
+ headerbar = _headerbar;
+ game_view = _game_view;
+ new_game_screen = _new_game_screen;
+
+ ((ReversiView) view_content).notify_final_animation.connect ((undoing) => {
headerbar.update_history_button (!undoing); });
+
+ /* CSS */
if (css_resource != null)
{
CssProvider css_provider = new CssProvider ();
@@ -61,26 +74,11 @@ private class GameWindow : ApplicationWindow
StyleContext.add_provider_for_screen ((!) gdk_screen, css_provider,
STYLE_PROVIDER_PRIORITY_APPLICATION);
}
- /* window config */
+ /* window actions */
install_ui_action_entries ();
- set_title (name);
-
- headerbar = new GameHeaderBar (name, flags, appearance_menu);
- headerbar.show ();
- set_titlebar (headerbar);
-
- ((ReversiView) _view).notify_final_animation.connect ((undoing) => { headerbar.update_history_button
(!undoing); });
-
- game_view = new GameView (flags, new_game_screen, _view);
- game_view.show ();
- main_overlay.add (game_view);
-
- set_default_size (width, height);
- if (maximized)
- maximize ();
- size_allocate.connect (size_allocate_cb);
- window_state_event.connect (window_state_event_cb);
+ /* window config */
+ set_title (name);
/* start or not */
if (start_now)
@@ -89,18 +87,52 @@ private class GameWindow : ApplicationWindow
show_new_game_screen ();
}
+ protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+ base.set_window_size (new_size);
+
+ ((AdaptativeWidget) new_game_screen).set_window_size (new_size);
+ ((AdaptativeWidget) game_view).set_window_size (new_size);
+ }
+
+ /*\
+ * * some public calls
+ \*/
+
internal void finish_game ()
{
game_finished = true;
headerbar.finish_game ();
}
+ protected override bool escape_pressed ()
+ {
+ if (base.escape_pressed ())
+ return true;
+ if (back_action_disabled)
+ return true;
+ back_cb ();
+ return true;
+ }
+ private void back_cb ()
+ {
+ 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 ();
+ }
+
/*\
- * * Showing the Stack
+ * * showing the stack
\*/
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);
}
@@ -153,20 +185,16 @@ private class GameWindow : ApplicationWindow
{ "new-game", new_game_cb }, // "New game" button or <Shift>n
{ "start-game", start_game_cb },
- { "back", back_cb },
{ "undo", undo_cb },
{ "redo", redo_cb },
- { "hint", hint_cb },
-
- { "toggle-hamburger", toggle_hamburger },
- { "unfullscreen", unfullscreen }
+ { "hint", hint_cb }
};
private void new_game_cb (/* SimpleAction action, Variant? variant */)
{
- // if (game_view.is_in_in_window_mode ())
- // return;
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
@@ -175,8 +203,8 @@ private class GameWindow : ApplicationWindow
private void undo_cb (/* SimpleAction action, Variant? variant */)
{
- // if (game_view.is_in_in_window_mode ())
- // return;
+ if (game_view.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
{
if (!back_action_disabled)
@@ -185,7 +213,7 @@ private class GameWindow : ApplicationWindow
}
game_finished = false;
- // hide_notification ();
+ // hide_notification (); // why? bad behaviour when showing the final board, for no reason?
game_view.show_game_content (/* grab focus */ true);
// redo_action.set_enabled (true);
@@ -194,8 +222,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.is_in_in_window_mode ())
+ return;
if (!game_view.game_content_visible_if_true ())
return;
@@ -208,66 +236,14 @@ private class GameWindow : ApplicationWindow
private void hint_cb (/* SimpleAction action, Variant? variant */)
{
- // if (game_view.is_in_in_window_mode ())
- // return;
+ 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 ();
- }
-
- /*\
- * * Window events
- \*/
-
- private void size_allocate_cb ()
- {
- if (window_is_maximized || window_is_tiled || window_is_fullscreen)
- return;
- get_size (out window_width, out window_height);
- }
-
- private bool window_state_event_cb (Gdk.EventWindowState event)
- {
- if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
- window_is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
-
- /* fullscreen: saved as maximized */
- bool window_was_fullscreen = window_is_fullscreen;
- if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
- window_is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
- if (window_was_fullscreen && !window_is_fullscreen)
- unfullscreen_button.hide ();
- else if (!window_was_fullscreen && window_is_fullscreen)
- unfullscreen_button.show ();
-
- /* tiled: not saved, but should not change saved window size */
- Gdk.WindowState tiled_state = Gdk.WindowState.TILED
- | Gdk.WindowState.TOP_TILED
- | Gdk.WindowState.BOTTOM_TILED
- | Gdk.WindowState.LEFT_TILED
- | Gdk.WindowState.RIGHT_TILED;
- if ((event.changed_mask & tiled_state) != 0)
- window_is_tiled = (event.new_window_state & tiled_state) != 0;
-
- return false;
- }
-
- internal void shutdown (GLib.Settings settings)
- {
- settings.delay ();
- settings.set_int ("window-width", window_width);
- settings.set_int ("window-height", window_height);
- settings.set_boolean ("window-is-maximized", window_is_maximized || window_is_fullscreen);
- settings.apply ();
- destroy ();
- }
-
/*\
* * Some internal calls
\*/
@@ -281,12 +257,7 @@ private class GameWindow : ApplicationWindow
internal void new_turn_start (bool can_undo)
{
undo_action.set_enabled (can_undo);
- headerbar.set_subtitle (null);
- }
-
- internal void set_subtitle (string subtitle)
- {
- headerbar.set_subtitle (subtitle);
+ hide_notification ();
}
internal void clear_subtitle ()
@@ -316,6 +287,9 @@ private class GameWindow : ApplicationWindow
private void start_game_cb ()
{
+ if (game_view.is_in_in_window_mode ())
+ return;
+
if (game_view.game_content_visible_if_true ())
return;
@@ -331,15 +305,4 @@ private class GameWindow : ApplicationWindow
game_view.configure_transition (StackTransitionType.SLIDE_DOWN, 1000);
show_view ();
}
-
- private void back_cb ()
- {
- 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 ();
- }
}
diff --git a/src/iagno.vala b/src/iagno.vala
index 427c1dc..333875e 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -22,7 +22,7 @@
using Gtk;
-private class Iagno : Gtk.Application
+private class Iagno : Gtk.Application, BaseApplication
{
/* Translators: application name, as used in the window manager, the window title, the about dialog... */
internal const string PROGRAM_NAME = _("Iagno");
@@ -93,8 +93,8 @@ private class Iagno : Gtk.Application
private const GLib.ActionEntry app_actions [] =
{
- { "help", help_cb },
- { "about", about_cb },
+ { "set-use-night-mode", set_use_night_mode, "b" },
+
{ "quit", quit }
};
@@ -279,24 +279,28 @@ private class Iagno : Gtk.Application
appearance_menu.freeze ();
/* Window */
+ init_night_mode ();
window = new GameWindow ("/org/gnome/Reversi/ui/iagno.css",
PROGRAM_NAME,
- settings.get_int ("window-width"),
- settings.get_int ("window-height"),
- settings.get_boolean ("window-is-maximized"),
+ /* Translators: hamburger menu entry; open about dialog (with a mnemonic
that appears pressing Alt) */
+ _("About Iagno"),
start_now,
GameWindowFlags.SHOW_START_BUTTON
+ | GameWindowFlags.HAS_SOUND
| GameWindowFlags.SHOW_HELP
| GameWindowFlags.SHOW_UNDO,
(Box) new_game_screen,
view,
- appearance_menu);
+ appearance_menu,
+ night_light_monitor);
window.play.connect (start_game);
window.wait.connect (wait_cb);
window.back.connect (back_cb);
window.undo.connect (undo_cb);
+ window.gtk_theme_changed.connect (view.theme_changed);
+
/* Actions and preferences */
add_action_entries (app_actions, this);
set_accels_for_action ("ui.new-game", { "<Primary>n" });
@@ -305,10 +309,10 @@ private class Iagno : Gtk.Application
"<Shift><Primary>q" });
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" });
+ set_accels_for_action ("base.escape", { "Escape" });
+ set_accels_for_action ("base.toggle-hamburger", { "F10" });
+ // set_accels_for_action ("app.help", { "F1" });
+ // set_accels_for_action ("base.about", { "<Shift>F1" });
add_action (settings.create_action ("sound"));
add_action (settings.create_action ("color"));
add_action (settings.create_action ("num-players"));
@@ -339,49 +343,25 @@ private class Iagno : Gtk.Application
protected override void shutdown ()
{
- window.shutdown (settings);
+ window.destroy ();
base.shutdown ();
}
/*\
- * * App-menu callbacks
+ * * Night mode
\*/
- private void help_cb ()
+ NightLightMonitor night_light_monitor; // keep it here or it is unrefed
+
+ private void init_night_mode ()
{
- try
- {
- show_uri (window.get_screen (), "help:iagno", get_current_event_time ());
- }
- catch (Error e)
- {
- warning ("Failed to show help: %s", e.message);
- }
+ night_light_monitor = new NightLightMonitor ("/org/gnome/iagno/");
}
- private void about_cb ()
+ private void set_use_night_mode (SimpleAction action, Variant? gvariant)
+ requires (gvariant != null)
{
- string [] authors = { "Ian Peters", "Robert Ancell" };
- string [] documenters = { "Tiffany Antopolski" };
-
- show_about_dialog (window,
- "name", PROGRAM_NAME,
- "version", VERSION,
- "copyright",
- "Copyright © 1998–2008 Ian Peters\n"+
- "Copyright © 2013–2015 Michael Catanzaro\n"+
- "Copyright © 2014–2019 Arnaud Bonatti",
- "license-type", License.GPL_3_0,
- "comments",
- /* Translators: about dialog text */
- _("A disk flipping game derived from Reversi"),
- "authors", authors,
- "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.Reversi",
- "website", "https://wiki.gnome.org/Apps/Iagno",
- null);
+ night_light_monitor.set_use_night_mode (((!) gvariant).get_boolean ());
}
/*\
@@ -524,12 +504,12 @@ private class Iagno : Gtk.Application
if (game.current_color == Player.DARK)
{
/* Translators: during a game, notification to display when Light has no possible moves */
- window.set_subtitle (_("Light must pass, Dark’s move"));
+ window.show_notification (_("Light must pass, Dark’s move"));
}
else
{
/* Translators: during a game, notification to display when Dark has no possible moves */
- window.set_subtitle (_("Dark must pass, Light’s move"));
+ window.show_notification (_("Dark must pass, Light’s move"));
}
}
@@ -541,17 +521,17 @@ private class Iagno : Gtk.Application
if (game.n_light_tiles > game.n_dark_tiles)
{
/* Translators: during a game, notification to display when Light has won the game */
- window.set_subtitle (_("Light wins!"));
+ window.show_notification (_("Light wins!"));
}
else if (game.n_dark_tiles > game.n_light_tiles)
{
/* Translators: during a game, notification to display when Dark has won the game */
- window.set_subtitle (_("Dark wins!"));
+ window.show_notification (_("Dark wins!"));
}
else
{
/* Translators: during a game, notification to display when the game is a draw */
- window.set_subtitle (_("The game is draw."));
+ window.show_notification (_("The game is draw."));
}
if (play_gameover_sound)
@@ -568,7 +548,7 @@ private class Iagno : Gtk.Application
if (!game.place_tile (x, y))
{
/* Translators: during a game, notification to display when the player tries to make an illegal
move */
- window.set_subtitle (_("You can’t move there!"));
+ window.show_notification (_("You can’t move there!"));
}
}
@@ -657,4 +637,61 @@ private class Iagno : Gtk.Application
warning (e.message);
}
}
+
+ /*\
+ * * Copy action
+ \*/
+
+ internal void copy (string text)
+ {
+ Gdk.Display? display = Gdk.Display.get_default ();
+ if (display == null)
+ return;
+
+ Gtk.Clipboard clipboard = Gtk.Clipboard.get_default ((!) display);
+ clipboard.set_text (text, text.length);
+ }
+
+ /*\
+ * * 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 disk flipping game derived from Reversi");
+
+ // artists = {
+ // "Masuichi Ito",
+ // "Arnaud Bonatti",
+ // "Jakub Steiner"
+ // };
+ authors = { "Ian Peters", "Robert Ancell", "Arnaud Bonatti" };
+
+ /* Translators: about dialog text */
+ copyright = "Copyright © 1998–2008 Ian Peters\n" +
+ "Copyright © 2013–2015 Michael Catanzaro\n" +
+ "Copyright © 2014–2019 Arnaud Bonatti"; // TODO translation; autogen, to not change
each year?
+ documenters = { "Tiffany Antopolski" };
+ logo_icon_name = "org.gnome.Reversi";
+ program_name = 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/Iagno";
+ /* Translators: about dialog text; label of the website link */
+ website_label = _("Page on GNOME wiki");
+ }
}
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index 1f9bf7b..f39a3ab 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -23,7 +23,7 @@
using Gtk;
[GtkTemplate (ui = "/org/gnome/Reversi/ui/iagno-screens.ui")]
-private class NewGameScreen : Box
+private class NewGameScreen : Box, AdaptativeWidget
{
[GtkChild] private Box level_box;
[GtkChild] private Box color_box;
@@ -33,4 +33,8 @@ private class NewGameScreen : Box
level_box.sensitive = new_sensitivity;
color_box.sensitive = new_sensitivity;
}
+
+ private void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+ }
}
diff --git a/src/reversi-view.vala b/src/reversi-view.vala
index 877289f..e4cc647 100644
--- a/src/reversi-view.vala
+++ b/src/reversi-view.vala
@@ -175,6 +175,12 @@ private class ReversiView : Gtk.DrawingArea
* * theme
\*/
+ internal void theme_changed ()
+ {
+ if (theme == null || (!) theme == "default")
+ theme = "default"; // yes
+ }
+
private string? _theme = null;
[CCode (notify = false)] internal string? theme
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]