[gnome-games] iagno: add toolbar (GtkBuilder) and remove statusbar



commit 5c7c52078f3fdf4647da9eb8e4bbd29d7f7ed1e0
Author: Tiffany Antopolski <tiffany antopolski gmail com>
Date:   Fri Jan 6 20:17:58 2012 -0500

    iagno: add toolbar (GtkBuilder) and remove statusbar
    
    Contents of statusbar moved into the toolbar.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664955

 iagno/data/Makefile.am |    3 +
 iagno/data/iagno.ui    |   58 ++++++++++++++++
 iagno/src/Makefile.am  |    1 +
 iagno/src/fixes.vapi   |  177 ++++++++++++++++++++++++++++++++++++++++++++++++
 iagno/src/iagno.vala   |   60 +++++++++++++---
 5 files changed, 287 insertions(+), 12 deletions(-)
---
diff --git a/iagno/data/Makefile.am b/iagno/data/Makefile.am
index b3c7825..12bde74 100644
--- a/iagno/data/Makefile.am
+++ b/iagno/data/Makefile.am
@@ -1,5 +1,8 @@
 SUBDIRS = icons
 
+uidir = $(datadir)/iagno
+ui_DATA = iagno.ui
+
 themedir = $(datadir)/iagno/themes
 theme_DATA = \
 	sun_and_star.svg \
diff --git a/iagno/data/iagno.ui b/iagno/data/iagno.ui
new file mode 100644
index 0000000..a61b836
--- /dev/null
+++ b/iagno/data/iagno.ui
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkApplicationWindow" id="window">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="n_rows">1</property>
+        <property name="n_columns">1</property>
+        <child>
+          <object class="GtkToolbar" id="toolbar">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <child>
+              <object class="GtkToolButton" id="new-button">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="is_important">True</property>
+                <property name="use_underline">True</property>
+                <property name="stock_id">gtk-new</property>
+                <property name="action_name">app.new-game</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="undo-button">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="is_important">True</property>
+                <property name="use_underline">True</property>
+                <property name="stock_id">gtk-undo</property>
+                <property name="action_name">app.undo-move</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/iagno/src/Makefile.am b/iagno/src/Makefile.am
index 74235ce..5c1e637 100644
--- a/iagno/src/Makefile.am
+++ b/iagno/src/Makefile.am
@@ -3,6 +3,7 @@ bin_PROGRAMS = iagno
 iagno_SOURCES = \
 	config.vapi \
 	computer-player.vala \
+	fixes.vapi \
 	game.vala \
 	game-view.vala \
 	iagno.vala
diff --git a/iagno/src/fixes.vapi b/iagno/src/fixes.vapi
new file mode 100644
index 0000000..d96d761
--- /dev/null
+++ b/iagno/src/fixes.vapi
@@ -0,0 +1,177 @@
+[CCode (cprefix = "G", gir_namespace = "Gio", gir_version = "2.0", lower_case_cprefix = "g_")]
+namespace GLib2 {
+	[CCode (cheader_filename = "gio/gio.h", cname = "GApplication")]
+	public class Application : GLib.Object, GLib.ActionGroup, GLib2.ActionMap {
+		[CCode (has_construct_function = false)]
+		public Application (string application_id, GLib.ApplicationFlags flags);
+		[NoWrapper]
+		public virtual void add_platform_data (GLib.VariantBuilder builder);
+		[NoWrapper]
+		public virtual void after_emit (GLib.Variant platform_data);
+		[NoWrapper]
+		public virtual void before_emit (GLib.Variant platform_data);
+		public unowned string get_application_id ();
+		public GLib.ApplicationFlags get_flags ();
+		public uint get_inactivity_timeout ();
+		public bool get_is_registered ();
+		public bool get_is_remote ();
+		public void hold ();
+		public static bool id_is_valid (string application_id);
+		[NoWrapper]
+		public virtual bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status);
+		[CCode (cname = "g_application_quit_with_data")]
+		public bool quit (GLib.Variant? platform_data = null);
+		[NoWrapper]
+		public virtual void quit_mainloop ();
+		public bool register (GLib.Cancellable? cancellable = null) throws GLib.Error;
+		public void release ();
+		public int run ([CCode (array_length_pos = 0.9)] string[]? argv = null);
+		[NoWrapper]
+		public virtual void run_mainloop ();
+		public void set_action_group (GLib.ActionGroup action_group);
+		public void set_application_id (string application_id);
+		public void set_flags (GLib.ApplicationFlags flags);
+		public void set_inactivity_timeout (uint inactivity_timeout);
+		public GLib.ActionGroup action_group { set; }
+		public string application_id { get; set construct; }
+		public GLib.ApplicationFlags flags { get; set; }
+		public uint inactivity_timeout { get; set; }
+		public bool is_registered { get; }
+		public bool is_remote { get; }
+		[HasEmitter]
+		public virtual signal void activate ();
+		public virtual signal int command_line (GLib.ApplicationCommandLine command_line);
+		[HasEmitter]
+		public virtual signal void open (GLib.File[] files, string hint);
+		public virtual signal void shutdown ();
+		public virtual signal void startup ();
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public interface ActionMap : GLib.ActionGroup, GLib.Object {
+		public abstract void add_action (GLib.Action action);
+		public void add_action_entries (GLib2.ActionEntry[] entries, void* user_data);
+		public abstract unowned GLib.Action lookup_action (string action_name);
+		public abstract void remove_action (string action_name);
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public class Menu : GLib2.MenuModel {
+		[CCode (has_construct_function = false)]
+		public Menu ();
+		public void append (string label, string detailed_action);
+		public void append_item (GLib2.MenuItem item);
+		public void append_section (string label, GLib2.MenuModel section);
+		public void append_submenu (string label, GLib2.MenuModel submenu);
+		public void freeze ();
+		public void insert (int position, string label, string detailed_action);
+		public void insert_item (int position, GLib2.MenuItem item);
+		public void insert_section (int position, string label, GLib2.MenuModel section);
+		public void insert_submenu (int position, string label, GLib2.MenuModel submenu);
+		public static unowned GLib.HashTable markup_parser_end (GLib.MarkupParseContext context);
+		public static unowned GLib2.Menu markup_parser_end_menu (GLib.MarkupParseContext context);
+		public static void markup_parser_start (GLib.MarkupParseContext context, string domain, GLib.HashTable objects);
+		public static void markup_parser_start_menu (GLib.MarkupParseContext context, string domain, GLib.HashTable objects);
+		public static void markup_print_stderr (GLib2.MenuModel model);
+		public static unowned GLib.StringBuilder markup_print_string (GLib.StringBuilder str, GLib2.MenuModel model, int indent, int tabstop);
+		public void prepend (string label, string detailed_action);
+		public void prepend_item (GLib2.MenuItem item);
+		public void prepend_section (string label, GLib2.MenuModel section);
+		public void prepend_submenu (string label, GLib2.MenuModel submenu);
+		public void remove (int position);
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public class MenuAttributeIter : GLib.Object {
+		[CCode (has_construct_function = false)]
+		protected MenuAttributeIter ();
+		public unowned string get_name ();
+		public virtual bool get_next (string out_name, out unowned GLib.Variant value);
+		public GLib.Variant get_value ();
+		public bool next ();
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public class MenuItem : GLib.Object {
+		[CCode (has_construct_function = false)]
+		public MenuItem (string label, string detailed_action);
+		[CCode (has_construct_function = false)]
+		public MenuItem.section (string label, GLib2.MenuModel section);
+		public void set_action_and_target (string action, string format_string);
+		public void set_action_and_target_value (string action, GLib.Variant target_value);
+		public void set_attribute (string attribute, string format_string);
+		public void set_attribute_value (string attribute, GLib.Variant value);
+		public void set_detailed_action (string detailed_action);
+		public void set_label (string label);
+		public void set_link (string link, GLib2.MenuModel model);
+		public void set_section (GLib2.MenuModel section);
+		public void set_submenu (GLib2.MenuModel submenu);
+		[CCode (has_construct_function = false)]
+		public MenuItem.submenu (string label, GLib2.MenuModel submenu);
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public class MenuLinkIter : GLib.Object {
+		[CCode (has_construct_function = false)]
+		protected MenuLinkIter ();
+		public unowned string get_name ();
+		public virtual bool get_next (string out_link, out unowned GLib2.MenuModel value);
+		public GLib2.MenuModel get_value ();
+		public bool next ();
+	}
+	[CCode (cheader_filename = "gio/gio.h")]
+	public class MenuModel : GLib.Object {
+		[CCode (has_construct_function = false)]
+		protected MenuModel ();
+		public bool get_item_attribute (int item_index, string attribute, string format_string);
+		public virtual GLib.Variant get_item_attribute_value (int item_index, string attribute, GLib.VariantType expected_type);
+		[NoWrapper]
+		public virtual void get_item_attributes (int item_index, GLib.HashTable attributes);
+		public virtual GLib2.MenuModel get_item_link (int item_index, string link);
+		[NoWrapper]
+		public virtual void get_item_links (int item_index, GLib.HashTable links);
+		public virtual int get_n_items ();
+		public virtual bool is_mutable ();
+		public virtual GLib2.MenuAttributeIter iterate_item_attributes (int item_index);
+		public virtual GLib2.MenuLinkIter iterate_item_links (int item_index);
+		[HasEmitter]
+		public virtual signal void items_changed (int p0, int p1, int p2);
+	}
+	public delegate void SimpleActionActivateCallback (GLib.SimpleAction action, GLib.Variant? parameter);
+	public delegate void SimpleActionChangeStateCallback (GLib.SimpleAction action, GLib.Variant value);
+	[CCode (cheader_filename = "gio/gio.h")]
+	public struct ActionEntry {
+		public weak string name;
+		[CCode (delegate_target = false)]
+		public SimpleActionActivateCallback activate;
+		public weak string parameter_type;
+		public weak string state;
+		[CCode (delegate_target = false)]
+		public SimpleActionChangeStateCallback change_state;
+	}
+}
+
+[CCode (cprefix = "Gtk", gir_namespace = "Gtk", gir_version = "3.0", lower_case_cprefix = "gtk_")]
+namespace Gtk3 {
+	[CCode (cheader_filename = "gtk/gtk.h")]
+	public class Application : GLib2.Application, GLib.ActionGroup, GLib2.ActionMap {
+		[CCode (has_construct_function = false)]
+		public Application (string application_id, GLib.ApplicationFlags flags);
+		public void add_accelerator (string accelerator, string action_name, GLib.Variant parameter);
+		public void add_window (Gtk.Window window);
+		public unowned GLib2.MenuModel get_app_menu ();
+		public unowned GLib2.MenuModel get_menubar ();
+		public unowned GLib.List<weak Gtk.Window> get_windows ();
+		public void remove_accelerator (string action_name, GLib.Variant parameter);
+		public void remove_window (Gtk.Window window);
+		public void set_app_menu (GLib2.MenuModel model);
+		public void set_menubar (GLib2.MenuModel model);
+		public GLib2.MenuModel app_menu { get; set; }
+		public GLib2.MenuModel menubar { get; set; }
+		public virtual signal void window_added (Gtk.Window window);
+		public virtual signal void window_removed (Gtk.Window window);
+	}
+	[CCode (cheader_filename = "gtk/gtk.h")]
+	public class ApplicationWindow : Gtk.Window, Atk.Implementor, Gtk.Buildable, GLib.ActionGroup, GLib2.ActionMap {
+		[CCode (has_construct_function = false, type = "GtkWidget*")]
+		public ApplicationWindow (Gtk3.Application application);
+		public bool get_show_menubar ();
+		public void set_show_menubar (bool show_menubar);
+		public bool show_menubar { get; set construct; }
+	}
+}
diff --git a/iagno/src/iagno.vala b/iagno/src/iagno.vala
index 8956ad9..c975f5c 100644
--- a/iagno/src/iagno.vala
+++ b/iagno/src/iagno.vala
@@ -1,4 +1,4 @@
-public class Iagno : Gtk.Application
+public class Iagno : Gtk3.Application
 {
     /* Application settings */
     private Settings settings;
@@ -24,7 +24,7 @@ public class Iagno : Gtk.Application
 
     /* The game being played */
     private Game? game = null;
-    
+
     /* true if the last move was a pass */
     private bool was_pass = false;
 
@@ -44,6 +44,19 @@ public class Iagno : Gtk.Application
         {"About", Gtk.Stock.ABOUT, null, null, null, about_cb}
     };
 
+    private const GLib2.ActionEntry app_actions[] =
+    {
+        {"new-game", new_game_cb},
+        {"undo-move", undo_move_cb}
+
+    };
+
+    protected override void startup()
+    {
+        base.startup ();
+        add_action_entries (app_actions, this);
+    }
+
     private string ui_description =
         "<ui>" +
         "  <menubar name='MainMenu'>" +
@@ -79,16 +92,23 @@ public class Iagno : Gtk.Application
 
         settings = new Settings ("org.gnome.iagno");
 
-        window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+        var builder = new Gtk.Builder ();
+        try
+        {
+            builder.add_from_file (DATA_DIRECTORY + "/iagno.ui");
+        }
+        catch (Error e)
+        {
+            stderr.printf ("Could not load UI: %s\n", e.message);
+            return;
+        }
+        window = builder.get_object ("window") as Gtk.Window;
+        var top_grid = builder.get_object ("grid") as Gtk.Grid;
         window.set_title (_("Iagno"));
 
         GnomeGamesSupport.settings_bind_window_state ("/org/gnome/iagno/", window);
         add_window (window);
 
-        var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
-        vbox.show ();
-        window.add (vbox);
-
         var ui_manager = new Gtk.UIManager ();
         var action_group = new Gtk.ActionGroup ("group");
 
@@ -111,9 +131,11 @@ public class Iagno : Gtk.Application
         undo_action = action_group.get_action ("UndoMove");
         undo_action.set_sensitive (false);
         var menubar = (Gtk.MenuBar) ui_manager.get_widget ("/MainMenu");
-        vbox.pack_start (menubar, false, false, 0);
+        top_grid.attach (menubar, 0, 0, 1, 1);
 
         view = new GameView ();
+        view.hexpand = true;
+        view.vexpand = true;
         view.game = game;
         view.move.connect (player_move_cb);
         view.show_grid = settings.get_boolean ("show-grid");
@@ -126,17 +148,31 @@ public class Iagno : Gtk.Application
         }
         view.theme = theme;
         view.show ();
-        vbox.pack_start (view, true, true, 0);
+        top_grid.attach (view, 0, 2, 1, 1);
 
         statusbar = new Gtk.Statusbar ();
         statusbar.show ();
-        vbox.pack_start (statusbar, false, false, 0);
+
+        var toolbar = builder.get_object ("toolbar") as Gtk.Toolbar;
+        toolbar.insert (new Gtk.SeparatorToolItem (), -1);
+        var status_item = new Gtk.ToolItem ();
+        status_item.set_visible_horizontal (true);
+        status_item.set_expand (true);
+
+        var status_alignment = new Gtk.Alignment (1.0f, 0.5f, 0.0f, 0.0f);
+        status_alignment.add (statusbar);
+        status_item.add (status_alignment);
+
+        toolbar.insert (status_item, -1);
+        toolbar.show_all ();
 
         var grid = new Gtk.Grid ();
         grid.set_column_spacing (6);
         grid.show ();
         statusbar.pack_start (grid, false, true, 0);
 
+        GnomeGamesSupport.stock_prepare_for_statusbar_tooltips (ui_manager, grid);
+
         var label = new Gtk.Label (_("Dark:"));
         label.show ();
         grid.attach (label, 1, 0, 1, 1);
@@ -200,7 +236,7 @@ public class Iagno : Gtk.Application
         game.move.connect (game_move_cb);
         game.complete.connect (game_complete_cb);
         view.game = game;
-        
+
         var dark_level = settings.get_int ("black-level");
         if (dark_level > 0)
             dark_computer = new ComputerPlayer (game, dark_level);
@@ -216,7 +252,7 @@ public class Iagno : Gtk.Application
 
         game.start ();
     }
-    
+
     private void update_ui ()
     {
         /* Can't undo when running two computer players */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]