X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=7db777ab92e4254fdb14644ad2ac2c9348387dc4;hb=9d46581913ce33664e333a4d6eaf7f4e26e20b1c;hp=5bc46d2190248be4c7a7c68b121c2766258b9f0b;hpb=d2d4364afcc3fb310ea43573f0d455f90c9212ce;p=ext%2Fsubsurface.git
diff --git a/gtk-gui.c b/gtk-gui.c
index 5bc46d2..7db777a 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -21,6 +21,8 @@ GtkWidget *main_vbox;
GtkWidget *error_info_bar;
GtkWidget *error_label;
GtkWidget *vpane, *hpane;
+GtkWidget *notebook;
+
int error_count;
const char *divelist_font;
@@ -96,7 +98,7 @@ void report_error(GError* error)
{
return;
}
-
+
if (error_info_bar == NULL)
{
error_count = 1;
@@ -106,11 +108,11 @@ void report_error(GError* error)
g_signal_connect(error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
gtk_info_bar_set_message_type(GTK_INFO_BAR(error_info_bar),
GTK_MESSAGE_ERROR);
-
+
error_label = gtk_label_new(error->message);
GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(error_info_bar));
gtk_container_add(GTK_CONTAINER(container), error_label);
-
+
gtk_box_pack_start(GTK_BOX(main_vbox), error_info_bar, FALSE, FALSE, 0);
gtk_widget_show_all(main_vbox);
}
@@ -149,7 +151,7 @@ static void file_open(GtkWidget *w, gpointer data)
GSList *filenames, *fn_glist;
char *filename;
filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-
+
GError *error = NULL;
while(filenames != NULL) {
filename = filenames->data;
@@ -160,7 +162,7 @@ static void file_open(GtkWidget *w, gpointer data)
g_error_free(error);
error = NULL;
}
-
+
g_free(filename);
filenames = g_slist_next(filenames);
}
@@ -170,10 +172,43 @@ static void file_open(GtkWidget *w, gpointer data)
gtk_widget_destroy(dialog);
}
+/* return the path and the file component contained in the full path */
+static char *path_and_file(char *pathin, char **fileout) {
+ char *slash = pathin, *next;
+ char *result;
+ size_t len, n;
+
+ if (! pathin) {
+ *fileout = strdup("");
+ return strdup("");
+ }
+ while ((next = strpbrk(slash + 1, "\\/")))
+ slash = next;
+ if (pathin != slash)
+ slash++;
+ *fileout = strdup(slash);
+
+ /* strndup(pathin, slash - pathin) */
+ n = slash - pathin;
+ len = strlen(pathin);
+ if (n < len)
+ len = n;
+
+ result = (char *)malloc(len + 1);
+ if (!result)
+ return 0;
+
+ result[len] = '\0';
+ return (char *)memcpy(result, pathin, len);
+}
+
static void file_save_as(GtkWidget *w, gpointer data)
{
GtkWidget *dialog;
- char *filename;
+ char *filename = NULL;
+ char *current_file;
+ char *current_dir;
+
dialog = gtk_file_chooser_dialog_new("Save File As",
GTK_WINDOW(main_window),
GTK_FILE_CHOOSER_ACTION_SAVE,
@@ -182,7 +217,13 @@ static void file_save_as(GtkWidget *w, gpointer data)
NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), existing_filename);
+ current_dir = path_and_file(existing_filename, ¤t_file);
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), current_dir);
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), current_file);
+
+ free(current_dir);
+ free(current_file);
+
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
}
@@ -221,7 +262,7 @@ static gboolean ask_save_changes()
label = gtk_label_new (
"You have unsaved changes\nWould you like to save those before exiting the program?");
} else {
- char *label_text = (char*) malloc(sizeof(char) * (92 + strlen(existing_filename)));
+ char *label_text = (char*) malloc(sizeof(char) * (93 + strlen(existing_filename)));
sprintf(label_text,
"You have unsaved changes to file: %s \nWould you like to save those before exiting the program?",
existing_filename);
@@ -387,6 +428,7 @@ OPTIONCALLBACK(temperature_toggle, visible_cols.temperature)
OPTIONCALLBACK(totalweight_toggle, visible_cols.totalweight)
OPTIONCALLBACK(suit_toggle, visible_cols.suit)
OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder)
+OPTIONCALLBACK(autogroup_toggle, autogroup)
static void event_toggle(GtkWidget *w, gpointer _data)
{
@@ -482,8 +524,22 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(suit_toggle), NULL);
+ frame = gtk_frame_new("Divelist Font");
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
+
font = gtk_font_button_new_with_font(divelist_font);
- gtk_box_pack_start(GTK_BOX(vbox), font, FALSE, FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(frame),font);
+
+ frame = gtk_frame_new("Misc. Options");
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
+
+ box = gtk_hbox_new(FALSE, 6);
+ gtk_container_add(GTK_CONTAINER(frame), box);
+
+ button = gtk_check_button_new_with_label("Automatically group dives in trips");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), autogroup);
+ gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+ g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(autogroup_toggle), NULL);
gtk_widget_show_all(dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
@@ -512,6 +568,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac));
subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu));
subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
+ subsurface_set_conf("autogroup", PREF_BOOL, BOOL_TO_PTR(autogroup));
/* Flush the changes out to the system */
subsurface_flush_conf();
@@ -662,10 +719,21 @@ static void view_info(GtkWidget *w, gpointer data)
static void view_three(GtkWidget *w, gpointer data)
{
GtkAllocation alloc;
+ GtkRequisition requisition;
+
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);
+ gtk_widget_size_request(notebook, &requisition);
+ /* pick the requested size for the notebook plus 6 pixels for frame */
+ gtk_paned_set_position(GTK_PANED(vpane), requisition.height + 6);
+}
+
+static void toggle_zoom(GtkWidget *w, gpointer data)
+{
+ zoomed_plot = (zoomed_plot)?0 : 1;
+ /*Update dive*/
+ repaint_dive();
}
static GtkActionEntry menu_items[] = {
@@ -688,7 +756,8 @@ static GtkActionEntry menu_items[] = {
{ "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) },
+ { "ViewThree", NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
+ { "ToggleZoom", NULL, "Toggle Zoom", CTRLCHAR "0", NULL, G_CALLBACK(toggle_zoom) },
};
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
@@ -710,6 +779,7 @@ static const gchar* ui_string = " \
\
\
\
+ \