X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=divelist.c;h=97a5674bf56311447d7485da9d40c26cec7f2435;hb=4c113ee01622e515492ac3c3197df0cd281d58d4;hp=88825dd8913465c13d532e05bb638e4f20abb878;hpb=957aaf619f22465b4aa1898c925831a6270c1230;p=ext%2Fsubsurface.git diff --git a/divelist.c b/divelist.c index 88825dd..97a5674 100644 --- a/divelist.c +++ b/divelist.c @@ -1,12 +1,14 @@ /* divelist.c */ -/* this creates the UI for the dive list - +/* this creates the UI for the dive list - * controlled through the following interfaces: - * + * * void flush_divelist(struct dive *dive) * GtkWidget dive_list_create(void) * void dive_list_update_dives(void) * void update_dive_list_units(void) * void set_divelist_font(const char *font) + * void mark_divelist_changed(int changed) + * int unsaved_changes() */ #include #include @@ -24,6 +26,7 @@ struct DiveList { GtkListStore *model; GtkTreeViewColumn *date, *depth, *duration, *location; GtkTreeViewColumn *temperature, *cylinder, *nitrox, *sac; + int changed; }; static struct DiveList dive_list; @@ -45,9 +48,6 @@ enum { DIVELIST_COLUMNS }; -/* the global dive list that we maintain */ -static struct DiveList dive_list; - static void selection_cb(GtkTreeSelection *selection, GtkTreeModel *model) { GtkTreeIter iter; @@ -354,10 +354,10 @@ void update_dive_list_units(void) switch (output_units.length) { case METERS: - unit = "max/m"; + unit = "m"; break; case FEET: - unit = "max/ft"; + unit = "ft"; break; } gtk_tree_view_column_set_title(dive_list.depth, unit); @@ -403,6 +403,11 @@ static void fill_dive_list(void) } update_dive_list_units(); + if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dive_list.model), &iter)) { + GtkTreeSelection *selection; + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view)); + gtk_tree_selection_select_iter(selection, &iter); + } } void dive_list_update_dives(void) @@ -440,12 +445,21 @@ static GtkTreeViewColumn *divelist_column(struct DiveList *dl, int index, const gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), 1.0, 0.5); } gtk_tree_view_column_set_expand(col,expand); - if (expand) + if (expand) gtk_tree_view_column_set_min_width(col,50); gtk_tree_view_append_column(GTK_TREE_VIEW(dl->tree_view), col); return col; } +/* + * This is some crazy crap. The only way to get default focus seems + * to be to grab focus as the widget is being shown the first time. + */ +static void realize_cb(GtkWidget *tree_view, gpointer userdata) +{ + gtk_widget_grab_focus(tree_view); +} + GtkWidget *dive_list_create(void) { GtkTreeSelection *selection; @@ -470,7 +484,7 @@ GtkWidget *dive_list_create(void) gtk_widget_set_size_request(dive_list.tree_view, 200, 200); dive_list.date = divelist_column(&dive_list, DIVE_DATE, "Date", date_data_func, 0, 0); - dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "max/ft", depth_data_func, 1, 0); + dive_list.depth = divelist_column(&dive_list, DIVE_DEPTH, "ft", depth_data_func, 1, 0); dive_list.duration = divelist_column(&dive_list, DIVE_DURATION, "min", duration_data_func, 1, 0); dive_list.location = divelist_column(&dive_list, DIVE_LOCATION, "Location", NULL, 0, 1); dive_list.temperature = divelist_column(&dive_list, DIVE_TEMPERATURE, UTF8_DEGREE "F", temperature_data_func, 1, 0); @@ -481,10 +495,11 @@ GtkWidget *dive_list_create(void) fill_dive_list(); g_object_set(G_OBJECT(dive_list.tree_view), "headers-visible", TRUE, - "search-column", 0, + "search-column", DIVE_LOCATION, "rules-hint", TRUE, NULL); + g_signal_connect_after(dive_list.tree_view, "realize", G_CALLBACK(realize_cb), NULL); g_signal_connect(selection, "changed", G_CALLBACK(selection_cb), dive_list.model); dive_list.container_widget = gtk_scrolled_window_new(NULL, NULL); @@ -492,5 +507,17 @@ GtkWidget *dive_list_create(void) GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(dive_list.container_widget), dive_list.tree_view); + dive_list.changed = 0; + return dive_list.container_widget; } + +void mark_divelist_changed(int changed) +{ + dive_list.changed = changed; +} + +int unsaved_changes() +{ + return dive_list.changed; +}