[geany/geany] ada459: Use global menubar on OS X

Jiří Techet git-noreply at xxxxx
Wed Mar 4 11:40:36 UTC 2015


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Wed, 04 Mar 2015 11:40:36 UTC
Commit:      ada4595264def0f96d40e223f41243b46580fc1b
             https://github.com/geany/geany/commit/ada4595264def0f96d40e223f41243b46580fc1b

Log Message:
-----------
Use global menubar on OS X

We have to disable quartz accelerator handling because otherwise
accelerators are performed also from other windows than the main
Geany editor (e.g. Ctrl+V with find dialog open performs the keybinding
Ctrl+V and inserts the text to the editor).

OS X applications have an extra menu entry to the left of the File menu -
an "application menu". This menu usually contains About, Preferences,
Quit. Many users, however, may be used to Geany from other platforms
and expect Preferences to be under the Edit menu so leave them there.
Quit and About are rarely used and the application menu is the place where
they are supposed to be - move these entries from other Geany menus there
and hide them in the affected menus (the quit entry is inserted automatically,
we just need to hide it from File).

Also tell OS X the Help menu is dedicated to help (we get search in
menu entries by name for free thanks to this).

The global menu should refresh automatically based on user actions.
Unfortunately this is not the case when gtk_menu_reorder_child()
is used because it does not emit any signals so the gtk-mac-integration
library doesn't see this call. Refresh the menu manually after calling
this function.


Modified Paths:
--------------
    src/Makefile.am
    src/main.c
    src/osx.c
    src/osx.h
    src/ui_utils.c
    wscript

Modified: src/Makefile.am
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -10,7 +10,6 @@ EXTRA_DIST = \
 	keybindingsprivate.h \
 	pluginprivate.h \
 	projectprivate.h \
-	osx.h \
 	makefile.win32
 
 bin_PROGRAMS = geany
@@ -39,6 +38,7 @@ SRCS = \
 	msgwindow.c msgwindow.h \
 	navqueue.c navqueue.h \
 	notebook.c notebook.h \
+	osx.c osx.h \
 	plugins.c plugins.h \
 	pluginutils.c pluginutils.h \
 	prefix.c prefix.h \


Modified: src/main.c
3 lines changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -266,6 +266,9 @@ static void main_init(void)
 
 	ui_widgets.toolbar_menu = create_toolbar_popup_menu1();
 	ui_init();
+#ifdef MAC_INTEGRATION
+	osx_ui_init();
+#endif
 
 	/* set widget names for matching with .gtkrc-2.0 */
 	gtk_widget_set_name(main_widgets.window, "GeanyMainWindow");


Modified: src/osx.c
49 lines changed, 49 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,49 @@
+/*
+ *      osx.c - this file is part of Geany, a fast and lightweight IDE
+ *
+ *      Copyright 2015 Jiri Techet <techet(at)gmail(dot)com>
+ *
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *
+ *      This program is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *      GNU General Public License for more details.
+ *
+ *      You should have received a copy of the GNU General Public License along
+ *      with this program; if not, write to the Free Software Foundation, Inc.,
+ *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef MAC_INTEGRATION
+
+#include "osx.h"
+
+#include "ui_utils.h"
+
+void osx_ui_init(void)
+{
+	GtkWidget *item;
+	GtkosxApplication *osx_app = gtkosx_application_get();
+
+	item = ui_lookup_widget(main_widgets.window, "menubar1");
+	gtk_widget_hide(item);
+	gtkosx_application_set_menu_bar(osx_app, GTK_MENU_SHELL(item));
+
+	item = ui_lookup_widget(main_widgets.window, "menu_quit1");
+	gtk_widget_hide(item);
+
+	item = ui_lookup_widget(main_widgets.window, "menu_info1");
+	gtkosx_application_insert_app_menu_item(osx_app, item, 0);
+
+	item = ui_lookup_widget(main_widgets.window, "menu_help1");
+	gtkosx_application_set_help_menu(osx_app, GTK_MENU_ITEM(item));
+
+	gtkosx_application_set_use_quartz_accelerators(osx_app, FALSE);
+}
+
+#endif /* MAC_INTEGRATION */
+


Modified: src/osx.h
6 lines changed, 6 insertions(+), 0 deletions(-)
===================================================================
@@ -25,6 +25,12 @@
 
 #include <gtkosxapplication.h>
 
+G_BEGIN_DECLS
+
+void osx_ui_init(void);
+
+G_END_DECLS
+
 #endif /* MAC_INTEGRATION */
 
 #endif /* GEANY_OSX_H */


Modified: src/ui_utils.c
20 lines changed, 17 insertions(+), 3 deletions(-)
===================================================================
@@ -50,6 +50,7 @@
 #include "toolbar.h"
 #include "utils.h"
 #include "win32.h"
+#include "osx.h"
 
 #include "gtkcompat.h"
 
@@ -1307,6 +1308,19 @@ void ui_update_recent_project_menu(void)
 }
 
 
+/* Use instead of gtk_menu_reorder_child() to update the menubar properly on OS X */
+static void menu_reorder_child(GtkMenu *menu, GtkWidget *child, gint position)
+{
+	gtk_menu_reorder_child(menu, child, position);
+#ifdef MAC_INTEGRATION
+	/* On OS X GtkMenuBar is kept in sync with the native OS X menubar using
+	 * signals. Unfortunately gtk_menu_reorder_child() doesn't emit anything
+	 * so we have to update the OS X menubar manually. */
+	gtkosx_application_sync_menubar(gtkosx_application_get());
+#endif
+}
+
+
 static void add_recent_file_menu_item(const gchar *utf8_filename, GeanyRecentFiles *grf, GtkWidget *menu)
 {
 	GtkWidget *child = gtk_menu_item_new_with_label(utf8_filename);
@@ -1320,7 +1334,7 @@ static void add_recent_file_menu_item(const gchar *utf8_filename, GeanyRecentFil
 		 * gtk_menu_shell_prepend() doesn't emit GtkContainer's "add" signal
 		 * which we need in GeanyMenubuttonAction */
 		gtk_container_add(GTK_CONTAINER(menu), child);
-		gtk_menu_reorder_child(GTK_MENU(menu), child, 0);
+		menu_reorder_child(GTK_MENU(menu), child, 0);
 	}
 	g_signal_connect(child, "activate", G_CALLBACK(grf->activate_cb), NULL);
 }
@@ -1350,7 +1364,7 @@ static void recent_file_loaded(const gchar *utf8_filename, GeanyRecentFiles *grf
 		item = g_list_find_custom(children, utf8_filename, (GCompareFunc) find_recent_file_item);
 		/* either reorder or prepend a new one */
 		if (item)
-			gtk_menu_reorder_child(GTK_MENU(parents[i]), item->data, 0);
+			menu_reorder_child(GTK_MENU(parents[i]), item->data, 0);
 		else
 			add_recent_file_menu_item(utf8_filename, grf, parents[i]);
 		g_list_free(children);
@@ -2781,7 +2795,7 @@ void ui_menu_sort_by_label(GtkMenu *menu)
 	pos = 0;
 	foreach_list(node, list)
 	{
-		gtk_menu_reorder_child(menu, node->data, pos);
+		menu_reorder_child(menu, node->data, pos);
 		pos++;
 	}
 	g_list_free(list);


Modified: wscript
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -131,7 +131,7 @@ geany_sources = set([
     'src/editor.c', 'src/encodings.c', 'src/filetypes.c', 'src/geanyentryaction.c',
     'src/geanymenubuttonaction.c', 'src/geanyobject.c', 'src/geanywraplabel.c',
     'src/highlighting.c', 'src/keybindings.c',
-    'src/keyfile.c', 'src/log.c', 'src/main.c', 'src/msgwindow.c', 'src/navqueue.c', 'src/notebook.c',
+    'src/keyfile.c', 'src/log.c', 'src/main.c', 'src/msgwindow.c', 'src/navqueue.c', 'src/notebook.c', 'src/osx.c',
     'src/plugins.c', 'src/pluginutils.c', 'src/prefix.c', 'src/prefs.c', 'src/printing.c', 'src/project.c',
     'src/sciwrappers.c', 'src/search.c', 'src/socket.c', 'src/stash.c',
     'src/symbols.c',



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list