r19196 - gnucash/trunk/src/gnome-utils - Change from ige-mac-menu to GtkOSXApplication for OSX integration. Fixes 600590.
John Ralls
jralls at code.gnucash.org
Fri May 21 15:37:24 EDT 2010
Author: jralls
Date: 2010-05-21 15:37:23 -0400 (Fri, 21 May 2010)
New Revision: 19196
Trac: http://svn.gnucash.org/trac/changeset/19196
Modified:
gnucash/trunk/src/gnome-utils/gnc-main-window.c
Log:
Change from ige-mac-menu to GtkOSXApplication for OSX integration. Fixes 600590.
Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c 2010-05-20 20:43:21 UTC (rev 19195)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c 2010-05-21 19:37:23 UTC (rev 19196)
@@ -69,7 +69,7 @@
#include "gnc-autosave.h"
#include "print-session.h"
#ifdef MAC_INTEGRATION
-#include <igemacintegration/ige-mac-menu.h>
+#include <igemacintegration/gtkosxapplication.h>
#endif
/** Names of signals generated by the main window. */
@@ -152,6 +152,8 @@
static GtkAction *gnc_main_window_find_action (GncMainWindow *window, const gchar *name);
#ifdef MAC_INTEGRATION
+static void gtk_quartz_shutdown(GtkOSXApplication *theApp, gpointer data);
+static gboolean gtk_quartz_should_quit(GtkOSXApplication *theApp, GncMainWindow *window);
static void gtk_quartz_set_menu(GncMainWindow* window);
#endif
@@ -1470,7 +1472,9 @@
book = qof_session_get_book(session);
qof_book_set_dirty_cb(book, gnc_main_window_book_dirty_cb, NULL);
gnc_main_window_update_all_titles();
+#ifndef MAC_INTEGRATION
gnc_main_window_update_all_menu_items();
+#endif
}
@@ -1521,8 +1525,9 @@
(char *)NULL);
#ifdef MAC_INTEGRATION
{
- GtkWidget *menu = gtk_ui_manager_get_widget(window->ui_merge, "/menubar");
- ige_mac_menu_sync(GTK_MENU_SHELL( menu ));
+ GtkOSXApplication *theApp =
+ g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
+ gtk_osxapplication_sync_menubar(theApp);
}
#endif
LEAVE(" ");
@@ -1567,13 +1572,18 @@
/* Block the signal so as not to affect window ordering (top to
* bottom) on the screen */
action_list = gtk_radio_action_get_group(GTK_RADIO_ACTION(action));
- first_action = g_slist_last(action_list)->data;
- g_signal_handlers_block_by_func(G_OBJECT(first_action),
- G_CALLBACK(gnc_main_window_cmd_window_raise), window);
- DEBUG("blocked signal on %p, set %p active, window %p", first_action, action, window);
- gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
- g_signal_handlers_unblock_by_func(G_OBJECT(first_action),
- G_CALLBACK(gnc_main_window_cmd_window_raise), window);
+ if (action_list) {
+ first_action = g_slist_last(action_list)->data;
+ g_signal_handlers_block_by_func(G_OBJECT(first_action),
+ G_CALLBACK(gnc_main_window_cmd_window_raise),
+ window);
+ DEBUG("blocked signal on %p, set %p active, window %p", first_action,
+ action, window);
+ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
+ g_signal_handlers_unblock_by_func(G_OBJECT(first_action),
+ G_CALLBACK(gnc_main_window_cmd_window_raise),
+ window);
+ }
g_free(action_name);
LEAVE(" ");
}
@@ -1649,7 +1659,7 @@
gint i;
ENTER("");
-
+#ifndef MAC_INTEGRATION
/* First update the entries for all existing windows */
g_list_foreach(active_windows,
(GFunc)gnc_main_window_update_menu_item,
@@ -1673,6 +1683,7 @@
g_free(data.action_name);
g_free(label);
}
+#endif
LEAVE(" ");
}
@@ -2206,9 +2217,6 @@
qof_event_register_handler(gnc_main_window_event_handler, window);
gnc_main_window_setup_window (window);
-#ifdef MAC_INTEGRATION
- gtk_quartz_set_menu(window);
-#endif
gnc_gobject_tracking_remember(G_OBJECT(window),
G_OBJECT_CLASS(klass));
}
@@ -3242,11 +3250,13 @@
gtk_action_group_add_toggle_actions (priv->action_group,
toggle_actions, n_toggle_actions,
window);
+#ifndef MAC_INTEGRATION
gtk_action_group_add_radio_actions (priv->action_group,
radio_entries, n_radio_entries,
0,
G_CALLBACK(gnc_main_window_cmd_window_raise),
window);
+#endif
gnc_plugin_update_actions(priv->action_group,
initially_insensitive_actions,
"sensitive", FALSE);
@@ -3328,9 +3338,34 @@
#ifdef MAC_INTEGRATION
static void
+gtk_quartz_shutdown (GtkOSXApplication *theApp, gpointer data)
+{
+ gnc_shutdown(0);
+}
+
+static gboolean
+gtk_quartz_should_quit (GtkOSXApplication *theApp, GncMainWindow *window)
+{
+ QofSession *session;
+ gboolean needs_save, do_shutdown;
+
+ gboolean finished = gnc_main_window_all_finish_pending();
+ if (!finished)
+ return TRUE;
+ session = gnc_get_current_session();
+ needs_save = qof_book_not_saved(qof_session_get_book(session)) &&
+ !gnc_file_save_in_progress();
+ if (needs_save && gnc_main_window_prompt_for_save(GTK_WIDGET(window)))
+ return TRUE;
+ gnc_shutdown(0);
+ return FALSE;
+}
+
+static void
gtk_quartz_set_menu(GncMainWindow* window)
{
- IgeMacMenuGroup *group;
+ GtkOSXApplicationMenuGroup *group;
+ GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
GtkWidget *menu;
GtkWidget *item;
@@ -3338,29 +3373,40 @@
if (GTK_IS_MENU_ITEM (menu))
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
gtk_widget_hide(menu);
- ige_mac_menu_set_menu_bar (GTK_MENU_SHELL (menu));
+ gtk_osxapplication_set_menu_bar (theApp, GTK_MENU_SHELL (menu));
item = gtk_ui_manager_get_widget (window->ui_merge,
"/menubar/File/FileQuit");
if (GTK_IS_MENU_ITEM (item))
- ige_mac_menu_set_quit_menu_item (GTK_MENU_ITEM (item));
+ gtk_widget_hide (GTK_WIDGET (item));
/* the about group */
- group = ige_mac_menu_add_app_menu_group ();
+ group = gtk_osxapplication_add_app_menu_group (theApp);
item = gtk_ui_manager_get_widget (window->ui_merge,
"/menubar/Help/HelpAbout");
if (GTK_IS_MENU_ITEM (item))
- ige_mac_menu_add_app_menu_item (group, GTK_MENU_ITEM (item), _("About GnuCash"));
+ gtk_osxapplication_add_app_menu_item (theApp, group,
+ GTK_MENU_ITEM (item));
/* the preferences group */
- group = ige_mac_menu_add_app_menu_group ();
+ group = gtk_osxapplication_add_app_menu_group (theApp);
item = gtk_ui_manager_get_widget (window->ui_merge,
"/menubar/Edit/EditPreferences");
if (GTK_IS_MENU_ITEM (item))
- ige_mac_menu_add_app_menu_item (group, GTK_MENU_ITEM (item), NULL);
+ gtk_osxapplication_add_app_menu_item (theApp, group,
+ GTK_MENU_ITEM (item));
+ item = gtk_ui_manager_get_widget (window->ui_merge,
+ "/menubar/Help");
+ gtk_osxapplication_set_help_menu(theApp, GTK_MENU_ITEM(item));
+ item = gtk_ui_manager_get_widget (window->ui_merge,
+ "/menubar/Windows");
+ gtk_osxapplication_set_window_menu(theApp, GTK_MENU_ITEM(item));
+ g_signal_connect(theApp, "NSApplicationBlockTermination",
+ G_CALLBACK(gtk_quartz_should_quit), window);
+
}
#endif //MAC_INTEGRATION
@@ -3956,10 +4002,21 @@
gnc_main_window_show_all_windows(void)
{
GList *window_iter;
+#ifdef MAC_INTEGRATION
+ GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
+#endif
for (window_iter = active_windows; window_iter != NULL; window_iter = window_iter->next)
{
gtk_widget_show(GTK_WIDGET(window_iter->data));
+#ifdef MAC_INTEGRATION
+ gtk_quartz_set_menu(window_iter->data);
+#endif
}
+#ifdef MAC_INTEGRATION
+ g_signal_connect(theApp, "NSApplicationWillTerminate",
+ G_CALLBACK(gtk_quartz_shutdown), NULL);
+ gtk_osxapplication_ready(theApp);
+#endif
}
/** Get a pointer to the first active top level window or NULL
More information about the gnucash-changes
mailing list