]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Even more Mac-i-ness
authorDirk Hohndel <dirk@hohndel.org>
Tue, 3 Jan 2012 04:49:10 +0000 (20:49 -0800)
committerDirk Hohndel <dirk@hohndel.org>
Tue, 3 Jan 2012 15:25:35 +0000 (07:25 -0800)
Move the About and Preferences menu item to the App menu.
Switch the accelerator key to be Meta (i.e., Command) instead of Control

This required a bit of restructuring of the code, but it's all for a good
cause.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
display-gtk.h
gtk-gui.c
linux.c
macos.c
windows.c

index 35380fa278f84d68b83069ee21f50acbb6d82374..f624bf6cc99cad9caedec68995f1f9029ffa2270 100644 (file)
@@ -27,6 +27,14 @@ typedef enum {
 #define BOOL_TO_PTR(_cond) ((_cond) ? (void *)1 : NULL)
 #define PTR_TO_BOOL(_ptr) ((_ptr) != NULL)
 
+#if defined __APPLE__
+#define CTRLCHAR "<Meta>"
+#define PREFERENCE_ACCEL "<Meta>,"
+#else
+#define CTRLCHAR "<Control>"
+#define PREFERENCE_ACCEL NULL
+#endif
+
 extern void subsurface_open_conf(void);
 extern void subsurface_set_conf(char *name, pref_type_t type, const void *value);
 extern const void *subsurface_get_conf(char *name, pref_type_t type);
@@ -34,7 +42,8 @@ extern void subsurface_close_conf(void);
 
 extern const char *subsurface_USB_name(void);
 extern const char *subsurface_icon_name(void);
-extern void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar, GtkWidget *vbox);
+extern void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
+               GtkWidget *vbox, GtkUIManager *ui_manager);
 
 extern const char *divelist_font;
 
index a20954dd6e7fdaabd0bc7f150a5ab3609a347e61..625b5fd769f77e2f6343d0f383653e27c11b0f75 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -573,19 +573,19 @@ static GtkActionEntry menu_items[] = {
        { "ViewMenuAction",  GTK_STOCK_FILE, "View", NULL, NULL, NULL},
        { "FilterMenuAction",  GTK_STOCK_FILE, "Filter", NULL, NULL, NULL},
        { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
-       { "OpenFile",       GTK_STOCK_OPEN, NULL,   "<control>O", NULL, G_CALLBACK(file_open) },
-       { "SaveFile",       GTK_STOCK_SAVE, NULL,   "<control>S", NULL, G_CALLBACK(file_save) },
-       { "Print",          GTK_STOCK_PRINT, NULL,  "<control>P", NULL, G_CALLBACK(do_print) },
+       { "OpenFile",       GTK_STOCK_OPEN, NULL,   CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
+       { "SaveFile",       GTK_STOCK_SAVE, NULL,   CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
+       { "Print",          GTK_STOCK_PRINT, NULL,  CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
        { "Import",         NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
-       { "Preferences",    NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) },
+       { "Preferences",    NULL, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) },
        { "Renumber",       NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
        { "SelectEvents",   NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) },
-       { "Quit",           GTK_STOCK_QUIT, NULL,   "<control>Q", NULL, G_CALLBACK(quit) },
+       { "Quit",           GTK_STOCK_QUIT, NULL,   CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
        { "About",          GTK_STOCK_ABOUT, NULL,  NULL, NULL, G_CALLBACK(about_dialog) },
-       { "ViewList",       NULL, "List",  "<control>1", NULL, G_CALLBACK(view_list) },
-       { "ViewProfile",    NULL, "Profile", "<control>2", NULL, G_CALLBACK(view_profile) },
-       { "ViewInfo",       NULL, "Info", "<control>3", NULL, G_CALLBACK(view_info) },
-       { "ViewThree",       NULL, "Three", "<control>4", NULL, G_CALLBACK(view_three) },
+       { "ViewList",       NULL, "List",  CTRLCHAR "1", NULL, G_CALLBACK(view_list) },
+       { "ViewProfile",    NULL, "Profile", CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
+       { "ViewInfo",       NULL, "Info", CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
+       { "ViewThree",       NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
 };
 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
 
@@ -622,12 +622,11 @@ static const gchar* ui_string = " \
        </ui> \
 ";
 
-static GtkWidget *get_menubar_menu(GtkWidget *window)
+static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
 {
        GtkActionGroup *action_group = gtk_action_group_new("Menu");
        gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
 
-       GtkUIManager *ui_manager = gtk_ui_manager_new();
        gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
        GError* error = 0;
        gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
@@ -656,6 +655,7 @@ void init_ui(int *argcp, char ***argvp)
        GdkScreen *screen;
        GtkIconTheme *icon_theme=NULL;
        GtkSettings *settings;
+       GtkUIManager *ui_manager;
 
        gtk_init(argcp, argvp);
        settings = gtk_settings_get_default();
@@ -708,9 +708,10 @@ void init_ui(int *argcp, char ***argvp)
        gtk_container_add(GTK_CONTAINER(win), vbox);
        main_vbox = vbox;
 
-       menubar = get_menubar_menu(win);
+       ui_manager = gtk_ui_manager_new();
+       menubar = get_menubar_menu(win, ui_manager);
 
-       subsurface_ui_setup(settings, menubar, vbox);
+       subsurface_ui_setup(settings, menubar, vbox, ui_manager);
 
        vpane = gtk_vpaned_new();
        gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
diff --git a/linux.c b/linux.c
index bec4f08fb2e96b2284cf12ecaf7be29cb5ede78d..f0ab2841caa48ed6dc4a5377a5c6fd5536d3e97d 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -59,7 +59,7 @@ const char *subsurface_icon_name()
 }
 
 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
-               GtkWidget *vbox)
+               GtkWidget *vbox, GtkUIManager *ui_manager)
 {
        if (!divelist_font)
                divelist_font = DIVELIST_DEFAULT_FONT;
diff --git a/macos.c b/macos.c
index c61546ac83115c84e16d95994c42c3cb0f336966..35793f56ef1c6ec7599d2aaaaad60b42200b0b53 100644 (file)
--- a/macos.c
+++ b/macos.c
@@ -5,7 +5,7 @@
 #include <mach-o/dyld.h>
 #include "gtkosxapplication.h"
 
-static GtkOSXApplication *theApp;
+static GtkOSXApplication *osx_app;
 
 /* macos defines CFSTR to create a CFString object from a constant,
  * but no similar macros if a C string variable is supposed to be
@@ -81,16 +81,29 @@ const char *subsurface_icon_name()
 }
 
 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
-               GtkWidget *vbox)
+               GtkWidget *vbox, GtkUIManager *ui_manager)
 {
+       GtkWidget *menu_item, *sep;
+
        if (!divelist_font)
                divelist_font = DIVELIST_MAC_DEFAULT_FONT;
        g_object_set(G_OBJECT(settings), "gtk-font-name", UI_FONT, NULL);
 
-       theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
+       osx_app = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
        gtk_widget_hide (menubar);
-       gtk_osxapplication_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
-       gtk_osxapplication_set_use_quartz_accelerators(theApp, TRUE);
-       gtk_osxapplication_ready(theApp);
-
+       gtk_osxapplication_set_menu_bar(osx_app, GTK_MENU_SHELL(menubar));
+       menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Quit");
+       gtk_widget_hide (menu_item);
+       menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/Help/About");
+       gtk_osxapplication_insert_app_menu_item(osx_app, menu_item, 0);
+       sep = gtk_separator_menu_item_new();
+       g_object_ref(sep);
+       gtk_osxapplication_insert_app_menu_item (osx_app, sep, 1);
+       menu_item = gtk_ui_manager_get_widget(ui_manager, "/MainMenu/FileMenu/Preferences");
+       gtk_osxapplication_insert_app_menu_item(osx_app, menu_item, 2);
+       sep = gtk_separator_menu_item_new();
+       g_object_ref(sep);
+       gtk_osxapplication_insert_app_menu_item (osx_app, sep, 3);
+       gtk_osxapplication_set_use_quartz_accelerators(osx_app, TRUE);
+       gtk_osxapplication_ready(osx_app);
 }
index 53531cd010cfa9609cb4c710164734ad05e0f983..46b6951bd87bd8c7a9d6ad43020b994d557d263d 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -91,7 +91,7 @@ const char *subsurface_icon_name()
 }
 
 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
-               GtkWidget *vbox)
+               GtkWidget *vbox, GtkUIManager *ui_manager)
 {
        if (!divelist_font)
                divelist_font = DIVELIST_DEFAULT_FONT;