From 618a20ba5f2a9adc0e5a35117535f8eaa9fd34a4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 29 Jul 2012 12:13:36 +0300 Subject: Divide the panes evenly in view_three There was a note by Linus that he doesn't know how to get the size, so I'm fixing that. Signed-off-by: Mikko Rasa --- gtk-gui.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gtk-gui.c') diff --git a/gtk-gui.c b/gtk-gui.c index 45aa21263..bdf2952f0 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -609,11 +609,13 @@ static void view_info(GtkWidget *w, gpointer data) gtk_paned_set_position(GTK_PANED(hpane), 65535); } -/* Ooh. I don't know how to get the half-way size. So I'm just using random numbers */ static void view_three(GtkWidget *w, gpointer data) { - gtk_paned_set_position(GTK_PANED(hpane), 400); - gtk_paned_set_position(GTK_PANED(vpane), 200); + GtkAllocation alloc; + gtk_widget_get_allocation(hpane, &alloc); + gtk_paned_set_position(GTK_PANED(hpane), alloc.width/2); + gtk_widget_get_allocation(vpane, &alloc); + gtk_paned_set_position(GTK_PANED(vpane), alloc.height/2); } static GtkActionEntry menu_items[] = { -- cgit v1.2.3-70-g09d2 From d8c8ada6c7f3952394989b6a705624d94e956d7a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 29 Jul 2012 13:15:04 +0300 Subject: Changes to menu icons It's customary for menu bars to not have icons. Some items were lacking icons when there's perfectly good stock icons available. I was a bit torn between the "new" and "add" icons for the "add dive" item, since what it really does is create a new dive, but the "add" icon is an uninteresting sheet of paper in the default icon theme so I decided to use the "add" icon. Signed-off-by: Mikko Rasa --- divelist.c | 6 ++++-- gtk-gui.c | 14 +++++++------- info.c | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'gtk-gui.c') diff --git a/divelist.c b/divelist.c index 21f343f7f..27d24243b 100644 --- a/divelist.c +++ b/divelist.c @@ -702,10 +702,12 @@ void add_dive_cb(GtkWidget *menuitem, gpointer data) static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button) { - GtkWidget *menu, *menuitem; + GtkWidget *menu, *menuitem, *image; menu = gtk_menu_new(); - menuitem = gtk_menu_item_new_with_label("Add dive"); + menuitem = gtk_image_menu_item_new_with_label("Add dive"); + image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); g_signal_connect(menuitem, "activate", G_CALLBACK(add_dive_cb), model); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_widget_show_all(menu); diff --git a/gtk-gui.c b/gtk-gui.c index bdf2952f0..a76b0024a 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -619,17 +619,17 @@ static void view_three(GtkWidget *w, gpointer data) } static GtkActionEntry menu_items[] = { - { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL}, - { "LogMenuAction", GTK_STOCK_FILE, "Log", NULL, NULL, NULL}, - { "ViewMenuAction", GTK_STOCK_FILE, "View", NULL, NULL, NULL}, - { "FilterMenuAction", GTK_STOCK_FILE, "Filter", NULL, NULL, NULL}, - { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL}, + { "FileMenuAction", NULL, "File", NULL, NULL, NULL}, + { "LogMenuAction", NULL, "Log", NULL, NULL, NULL}, + { "ViewMenuAction", NULL, "View", NULL, NULL, NULL}, + { "FilterMenuAction", NULL, "Filter", NULL, NULL, NULL}, + { "HelpMenuAction", NULL, "Help", NULL, NULL, NULL}, { "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) }, - { "AddDive", NULL, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) }, - { "Preferences", NULL, "Preferences", PREFERENCE_ACCEL, NULL, G_CALLBACK(preferences_dialog) }, + { "AddDive", GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) }, + { "Preferences", GTK_STOCK_PREFERENCES, "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, CTRLCHAR "Q", NULL, G_CALLBACK(quit) }, diff --git a/info.c b/info.c index 1847a49bf..e935823b2 100644 --- a/info.c +++ b/info.c @@ -139,9 +139,17 @@ static void info_menu_delete_cb(GtkMenuItem *menuitem, gpointer user_data) delete_dive_info(current_dive); } -static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuItem *, gpointer)) +static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer)) { - GtkWidget *item = gtk_menu_item_new_with_label(label); + GtkWidget *item; + if (icon) { + GtkWidget *image; + item = gtk_image_menu_item_new_with_label(label); + image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); + } else { + item = gtk_menu_item_new_with_label(label); + } g_signal_connect(item, "activate", G_CALLBACK(cb), NULL); gtk_widget_show(item); /* Yes, really */ gtk_menu_prepend(menu, item); @@ -149,8 +157,8 @@ static void add_menu_item(GtkMenu *menu, const char *label, void (*cb)(GtkMenuIt static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data) { - add_menu_item(menu, "Delete", info_menu_delete_cb); - add_menu_item(menu, "Edit", info_menu_edit_cb); + add_menu_item(menu, "Delete", GTK_STOCK_DELETE, info_menu_delete_cb); + add_menu_item(menu, "Edit", GTK_STOCK_EDIT, info_menu_edit_cb); } static GtkEntry *text_value(GtkWidget *box, const char *label) -- cgit v1.2.3-70-g09d2 From 549708c6eaab2d0592c3e520e0debd82d64619b4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 31 Jul 2012 20:55:41 +0300 Subject: Add a separate "Save as" entry to the menu The "Save" entry will now automatically save over the last used file. If no filename has been set, then that entry will also prompt the user for a filename. The filename is set when saving as well, so the next save will use the same filename. Signed-off-by: Mikko Rasa --- gtk-gui.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'gtk-gui.c') diff --git a/gtk-gui.c b/gtk-gui.c index a76b0024a..bef03a04b 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -170,7 +170,7 @@ static void file_open(GtkWidget *w, gpointer data) gtk_widget_destroy(dialog); } -static void file_save(GtkWidget *w, gpointer data) +static void file_save_as(GtkWidget *w, gpointer data) { GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new("Save File", @@ -189,12 +189,21 @@ static void file_save(GtkWidget *w, gpointer data) char *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); save_dives(filename); + set_filename(filename); g_free(filename); mark_divelist_changed(FALSE); } gtk_widget_destroy(dialog); } +static void file_save(GtkWidget *w, gpointer data) +{ + if (!existing_filename) + return file_save_as(w, data); + + save_dives(existing_filename); +} + static void ask_save_changes() { GtkWidget *dialog, *label, *content; @@ -626,6 +635,7 @@ static GtkActionEntry menu_items[] = { { "HelpMenuAction", NULL, "Help", NULL, NULL, NULL}, { "OpenFile", GTK_STOCK_OPEN, NULL, CTRLCHAR "O", NULL, G_CALLBACK(file_open) }, { "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) }, + { "SaveFileAs", GTK_STOCK_SAVE_AS, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save_as) }, { "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) }, { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) }, { "AddDive", GTK_STOCK_ADD, "Add Dive", NULL, NULL, G_CALLBACK(add_dive_cb) }, @@ -647,6 +657,7 @@ static const gchar* ui_string = " \ \ \ \ + \ \ \ \ @@ -1187,7 +1198,9 @@ void update_progressbar_text(progressbar_t *progress, const char *text) void set_filename(const char *filename) { - if (!existing_filename && filename) + if (existing_filename) + free(existing_filename); + existing_filename = NULL; + if (filename) existing_filename = strdup(filename); - return; } -- cgit v1.2.3-70-g09d2