[frogr/macosx: 2/4] Integrate with Mac OSX's global menu bar
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr/macosx: 2/4] Integrate with Mac OSX's global menu bar
- Date: Tue, 22 Feb 2011 01:56:46 +0000 (UTC)
commit a4d55529801f2e900653b5285e7eb0fdc4303bf5
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Tue Feb 22 02:24:28 2011 +0100
Integrate with Mac OSX's global menu bar
data/gtkbuilder/frogr-main-view.xml | 10 ------
src/frogr-main-view.c | 57 +++++++++++++++++++++++++++++++---
src/main.c | 10 ++++++
3 files changed, 62 insertions(+), 15 deletions(-)
---
diff --git a/data/gtkbuilder/frogr-main-view.xml b/data/gtkbuilder/frogr-main-view.xml
index c6f6c84..54e404c 100644
--- a/data/gtkbuilder/frogr-main-view.xml
+++ b/data/gtkbuilder/frogr-main-view.xml
@@ -8,16 +8,6 @@
<object class="GtkVBox" id="main_window_vbox">
<property name="visible">True</property>
<child>
- <object class="GtkMenuBar" id="menu_bar">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
<object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
<child>
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 9f755c0..59908a5 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -34,6 +34,10 @@
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
+#ifdef MAC_INTEGRATION
+#include <gtkosxapplication.h>
+#endif
+
/* Access to old GDK names from GTK+ 2 when compiling with GTK+ 3 */
#ifndef GTK_API_VERSION_2
#include <gdk/gdkkeysyms-compat.h>
@@ -225,6 +229,10 @@ _populate_menu_bar (FrogrMainView *self)
GtkWidget *submenu;
GtkWidget *menu_item;
+#ifdef MAC_INTEGRATION
+ GtkOSXApplication *osx_app = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL);
+#endif
+
/* File menu */
menubar_item = gtk_menu_item_new_with_mnemonic (_("_File"));
gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu_bar), menubar_item);
@@ -262,14 +270,22 @@ _populate_menu_bar (FrogrMainView *self)
self);
priv->auth_menu_item = menu_item;
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
-
menu_item = gtk_menu_item_new_with_mnemonic (_("_Preferencesâ?¦"));
+
+#ifdef MAC_INTEGRATION
+ gtk_osxapplication_insert_app_menu_item (osx_app, menu_item, 1);
+ gtk_osxapplication_insert_app_menu_item (osx_app, gtk_separator_menu_item_new (), 2);
+ gtk_widget_show_all (menu_item);
+#else
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+#endif
+
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (_on_settings_menu_item_activate),
self);
+#ifndef MAC_INTEGRATION
gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
menu_item = gtk_menu_item_new_with_mnemonic (_("_Quit"));
@@ -277,6 +293,8 @@ _populate_menu_bar (FrogrMainView *self)
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (_on_quit_menu_item_activate),
self);
+#endif
+
/* Actions menu */
menubar_item = gtk_menu_item_new_with_mnemonic (_("A_ctions"));
gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu_bar), menubar_item);
@@ -336,17 +354,29 @@ _populate_menu_bar (FrogrMainView *self)
priv->upload_menu_item = menu_item;
/* Help menu */
+
+#ifndef MAC_INTEGRATION
menubar_item = gtk_menu_item_new_with_mnemonic (_("_Help"));
gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu_bar), menubar_item);
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menubar_item), menu);
+#endif
menu_item = gtk_menu_item_new_with_mnemonic (_("_About frogr..."));
+
+#ifdef MAC_INTEGRATION
+ gtk_osxapplication_insert_app_menu_item (osx_app, menu_item, 0);
+ gtk_widget_show_all (menu_item);
+#else
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+#endif
+
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (_on_about_menu_item_activate),
self);
+
+ gtk_widget_show_all (priv->menu_bar);
}
static void
@@ -1352,6 +1382,12 @@ frogr_main_view_init (FrogrMainView *self)
GList *icons;
gchar *account_description;
+#ifdef MAC_INTEGRATION
+ GtkOSXApplication *osx_app;
+#else
+ GtkWidget *main_vbox;
+#endif
+
/* Init model and controller */
priv->model = frogr_main_view_model_new ();
priv->controller = g_object_ref (frogr_controller_get_instance ());
@@ -1392,9 +1428,18 @@ frogr_main_view_init (FrogrMainView *self)
gtk_window_set_title (GTK_WINDOW (window), APP_NAME);
priv->window = window;
- menu_bar = GTK_WIDGET (gtk_builder_get_object (builder, "menu_bar"));
+ menu_bar = gtk_menu_bar_new ();
priv->menu_bar = menu_bar;
+#ifdef MAC_INTEGRATION
+ osx_app = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL);
+ gtk_osxapplication_set_menu_bar (osx_app, GTK_MENU_SHELL(menu_bar));
+#else
+ main_vbox = GTK_WIDGET (gtk_builder_get_object (builder, "main_window_vbox"));
+ gtk_box_pack_start (GTK_BOX (main_vbox), menu_bar, FALSE, FALSE, 0);
+ gtk_box_reorder_child (GTK_BOX (main_vbox), menu_bar, 0);
+#endif
+
icon_view = GTK_WIDGET (gtk_builder_get_object (builder, "icon_view"));
priv->icon_view = icon_view;
@@ -1465,7 +1510,6 @@ frogr_main_view_init (FrogrMainView *self)
gtk_window_set_default_size (GTK_WINDOW (priv->window),
MINIMUM_WINDOW_WIDTH,
MINIMUM_WINDOW_HEIGHT);
-
/* Init status bar */
priv->sb_context_id =
gtk_statusbar_get_context_id (GTK_STATUSBAR (priv->status_bar),
@@ -1505,7 +1549,6 @@ frogr_main_view_init (FrogrMainView *self)
G_CALLBACK (_model_picture_removed), self);
gtk_builder_connect_signals (builder, self);
- g_object_unref (G_OBJECT (builder));
/* Show the UI, but hiding some widgets */
gtk_widget_show_all (GTK_WIDGET(priv->window));
@@ -1513,6 +1556,10 @@ frogr_main_view_init (FrogrMainView *self)
/* Update UI */
_update_ui (FROGR_MAIN_VIEW (self));
+#ifdef MAC_INTEGRATION
+ gtk_osxapplication_ready(osx_app);
+#endif
+
/* Show the auth dialog, if needed, on idle */
g_idle_add ((GSourceFunc) _maybe_show_auth_dialog_on_idle, self);
}
diff --git a/src/main.c b/src/main.c
index 9b108ee..0da29c8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,10 @@
#include <gtk/gtk.h>
#include <libxml/parser.h>
+#ifdef MAC_INTEGRATION
+#include <gtkosxapplication.h>
+#endif
+
static GSList *
_get_uris_list_from_array (char **uris_str, int n_uris)
{
@@ -83,8 +87,14 @@ main (int argc, char **argv)
fileuris = _get_uris_list_from_array (&argv[1], argc - 1);
gtk_init (&argc, &argv);
+
g_set_application_name(APP_SHORTNAME);
+#ifdef MAC_INTEGRATION
+ /* Initialize the GtkOSXApplication singleton */
+ g_object_new (GTK_TYPE_OSX_APPLICATION, NULL);
+#endif
+
/* Translation domain */
bindtextdomain (GETTEXT_PACKAGE, FROGR_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]