[atomix/wip/gtk3-port] Added appmenu, not visible yet



commit acaba9ee515c4d5f3e26d711fbb2d40146b91bc7
Author: Robert Roth <robert roth off gmail com>
Date:   Sat Dec 26 20:10:14 2015 +0200

    Added appmenu, not visible yet

 data/ui/interface.ui |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/main.c           |   15 +++++++++------
 2 files changed, 57 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/interface.ui b/data/ui/interface.ui
index 040881b..be5b251 100644
--- a/data/ui/interface.ui
+++ b/data/ui/interface.ui
@@ -389,4 +389,52 @@
       </object>
     </child>
   </object>
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">New Game</attribute>
+        <attribute name="action">win.GameNew</attribute>
+        <attribute name="accel">&lt;Primary&gt;n</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">End Game</attribute>
+        <attribute name="action">win.GameEnd</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Skip Level</attribute>
+        <attribute name="action">win.GameSkip</attribute>
+        <attribute name="accel">&lt;Primary&gt;s</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Reset Level</attribute>
+        <attribute name="action">win.GameReset</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Undo Move</attribute>
+        <attribute name="action">win.GameUndo</attribute>
+        <attribute name="accel">&lt;Primary&gt;z</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Pause Game</attribute>
+        <attribute name="action">win.GamePause</attribute>
+        <attribute name="accel">&lt;Primary&gt;c</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Continue Game</attribute>
+        <attribute name="action">win.GameContinue</attribute>
+        <attribute name="accel">&lt;Primary&gt;c</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">About</attribute>
+        <attribute name="action">app.GameAbout</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Quit</attribute>
+        <attribute name="action">app.GameQuit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
 </interface>
diff --git a/src/main.c b/src/main.c
index 2851132..3b89dc3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -588,21 +588,19 @@ static AtomixApp *create_gui (GApplication *app_instance)
   GtkBuilder *builder;
   GtkWidget *stats_grid;
   GtkWidget *time_label;
-  GtkWidget *menu_bar;
 
   app = g_new0 (AtomixApp, 1);
   app->level = NULL;
+  app->app_instance = app_instance;
 
   builder = gtk_builder_new ();
-  
+
   ui_path = g_build_filename (PKGDATADIR, "ui", "interface.ui", NULL);
   gtk_builder_add_from_file (builder, ui_path, NULL);
   g_free (ui_path);
 
   app->mainwin = GTK_WIDGET (gtk_builder_get_object (builder, "mainwin"));
 
-  app->app_instance = app_instance;
-
   g_signal_connect (G_OBJECT (app->mainwin), "delete_event",
                     (GCallback) on_app_destroy_event, app);
 
@@ -627,8 +625,13 @@ static AtomixApp *create_gui (GApplication *app_instance)
 
   gtk_widget_show_all (GTK_WIDGET (app->mainwin));
 
-  menu_bar = GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
-//  gtk_widget_set_visible (menu_bar, !gtk_application_prefers_app_menu (GTK_APPLICATION (app_instance)));
+
+  if (gtk_application_prefers_app_menu (GTK_APPLICATION (app_instance))) {
+    GMenu * menu = G_MENU (gtk_builder_get_object (builder, "app-menu"));
+    gtk_application_set_app_menu (GTK_APPLICATION (app->app_instance), G_MENU_MODEL (menu));
+    GtkWidget *menubar = GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
+    gtk_widget_set_visible (menubar, FALSE);
+  }
 
   g_object_unref (builder);
 


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