diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-01-02 20:49:10 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-01-03 07:25:35 -0800 |
commit | 513df18f50afc13fcef9f2421b5a33b772eed380 (patch) | |
tree | 1be4f906412b41303a5b1c80355014ed5f969d98 | |
parent | 53ecd2025d00e844fbfb84b5765d975e1e8942be (diff) | |
download | subsurface-513df18f50afc13fcef9f2421b5a33b772eed380.tar.gz |
Even more Mac-i-ness
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>
-rw-r--r-- | display-gtk.h | 11 | ||||
-rw-r--r-- | gtk-gui.c | 27 | ||||
-rw-r--r-- | linux.c | 2 | ||||
-rw-r--r-- | macos.c | 27 | ||||
-rw-r--r-- | windows.c | 2 |
5 files changed, 46 insertions, 23 deletions
diff --git a/display-gtk.h b/display-gtk.h index 35380fa27..f624bf6cc 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -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; @@ -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); @@ -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; @@ -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); } @@ -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; |