diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-07-07 02:49:17 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-07-07 02:49:17 +0000 |
commit | ef825ec6d3e07e97a85d52e116338c08c2637432 (patch) | |
tree | cb1d949c934f89e5797b5aeacc3e120bf81b10aa | |
parent | f0ebe6a0750a6772f7ece97e13fe749099784048 (diff) |
Only one place is needed for creating preference panes; this clears up
some warnings from GTK+.
For interior nodes in the preference module tree, we create a page even
if the module itself has no preferences, so there's *something* we can
show if the user clicks on it. (Showing the top-level protocols page is
a bit weird, and requires us to keep track of it.)
svn path=/trunk/; revision=43596
-rw-r--r-- | epan/prefs.c | 8 | ||||
-rw-r--r-- | ui/gtk/prefs_dlg.c | 136 |
2 files changed, 49 insertions, 95 deletions
diff --git a/epan/prefs.c b/epan/prefs.c index 2ea33a275e..bfbcad9c14 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -376,8 +376,12 @@ prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(vo *sep++ = '\0'; if(!(new_module = find_subtree(subtree_module, ptr))) { - /* create it */ - new_module = prefs_register_subtree(subtree_module, ptr, NULL); + /* + * There's no such module; create it, with the description + * being the name (if it's later registered explicitly + * with a description, that will override it). + */ + new_module = prefs_register_subtree(subtree_module, ptr, ptr); } subtree_module = new_module; diff --git a/ui/gtk/prefs_dlg.c b/ui/gtk/prefs_dlg.c index 8865eda395..16875f0941 100644 --- a/ui/gtk/prefs_dlg.c +++ b/ui/gtk/prefs_dlg.c @@ -120,8 +120,6 @@ struct ct_struct { GtkTreeStore *store; }; -static gint protocols_page = 0; - static guint pref_exists(pref_t *pref _U_, gpointer user_data _U_) { @@ -292,42 +290,6 @@ prefs_nb_page_add(GtkWidget *notebook, const gchar *title, GtkWidget *page, cons return frame; } -/* create a basic window for preferences */ -GtkWidget* -simple_prefs_show(module_t *module) -{ - GtkWidget *main_tb, *main_vb, *frame, *main_sw; - - /* Scrolled window */ - main_sw = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - - /* Frame */ - frame = gtk_frame_new(module->description); - gtk_container_set_border_width(GTK_CONTAINER(frame), 5); - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), frame); - g_object_set_data(G_OBJECT(main_sw), E_PAGESW_FRAME_KEY, frame); - - /* Main vertical box */ - main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); - gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); - gtk_container_add(GTK_CONTAINER(frame), main_vb); - - /* Main table */ - main_tb = gtk_table_new(module->numprefs, 2, FALSE); - gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0); - gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10); - gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15); - - /* Add items for each of the preferences */ - prefs_pref_foreach(module, pref_show, main_tb); - - /* Show 'em what we got */ - gtk_widget_show_all(main_vb); - - return main_vb; -} - #define MAX_TREE_NODE_NAME_LEN 64 /* show prefs page for each registered module (protocol) */ @@ -342,7 +304,7 @@ module_prefs_show(module_t *module, gpointer user_data) GtkTreeIter iter; /* - * Is this module a subtree, with modules underneath it? + * Is this module an interior node, with modules underneath it? */ if (!prefs_module_has_submodules(module)) { /* @@ -351,10 +313,12 @@ module_prefs_show(module_t *module, gpointer user_data) */ if (prefs_pref_foreach(module, pref_exists, NULL) == 0) { /* - * No. Don't put the module into the preferences window. - * XXX - we should do the same for subtrees; if a subtree has - * nothing under it that will be displayed, don't put it into - * the window. + * No. Don't put the module into the preferences window, + * as there's nothing to show. + * + * XXX - we should do the same for interior ndes; if the module + * has no non-obsolete preferences *and* nothing under it has + * non-obsolete preferences, don't put it into the window. */ return 0; } @@ -366,27 +330,18 @@ module_prefs_show(module_t *module, gpointer user_data) g_strlcpy(label_str, module->title, MAX_TREE_NODE_NAME_LEN); model = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(cts->tree))); - if (module->parent == NULL) { - prefs_nb_page_add(cts->notebook, label_str, simple_prefs_show(module), module->title); + if (module->parent == NULL) gtk_tree_store_append(model, &iter, NULL); - /* Save the protocols page */ - if (strcmp(module->title, "Protocols") == 0) { - protocols_page = cts->page++; - } else { - cts->page++; - } - } else gtk_tree_store_append(model, &iter, &cts->iter); /* - * Is this a subtree? + * Is this an interior node? */ if (prefs_module_has_submodules(module)) { /* * Yes. */ - gtk_tree_store_set(model, &iter, 0, label_str, 1, -1, -1); /* @@ -398,57 +353,52 @@ module_prefs_show(module_t *module, gpointer user_data) /* keep the page count right */ cts->page = child_cts.page; - } - if(module->prefs) { - /* - * Has preferences. Create a notebook page for it. - */ - /* Scrolled window */ - main_sw = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - - /* Frame */ - frame = gtk_frame_new(module->description); - gtk_container_set_border_width(GTK_CONTAINER(frame), 5); - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), frame); - g_object_set_data(G_OBJECT(main_sw), E_PAGESW_FRAME_KEY, frame); + /* + * We create pages for interior nodes even if they don't have + * preferences, so that we at least have something to show + * if the user clicks on them, even if it's empty. + */ - /* Main vertical box */ - main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); - gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); - gtk_container_add(GTK_CONTAINER(frame), main_vb); + /* Scrolled window */ + main_sw = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(main_sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - /* Main table */ - main_tb = gtk_table_new(module->numprefs, 2, FALSE); - gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0); - gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10); - gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15); + /* Frame */ + frame = gtk_frame_new(module->description); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(main_sw), frame); + g_object_set_data(G_OBJECT(main_sw), E_PAGESW_FRAME_KEY, frame); - /* Add items for each of the preferences */ - prefs_pref_foreach(module, pref_show, main_tb); + /* Main vertical box */ + main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); + gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); + gtk_container_add(GTK_CONTAINER(frame), main_vb); - /* Associate this module with the page's frame. */ - g_object_set_data(G_OBJECT(frame), E_PAGE_MODULE_KEY, module); + /* Main table */ + main_tb = gtk_table_new(module->numprefs, 2, FALSE); + gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0); + gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10); + gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15); - /* Add the page to the notebook */ - gtk_notebook_append_page(GTK_NOTEBOOK(cts->notebook), main_sw, NULL); + /* Add items for each of the preferences */ + prefs_pref_foreach(module, pref_show, main_tb); - /* Attach the page to the tree item */ - gtk_tree_store_set(model, &iter, 0, label_str, 1, cts->page, -1); - g_object_set_data(G_OBJECT(frame), E_PAGE_ITER_KEY, gtk_tree_iter_copy(&iter)); + /* Associate this module with the page's frame. */ + g_object_set_data(G_OBJECT(frame), E_PAGE_MODULE_KEY, module); - cts->page++; + /* Add the page to the notebook */ + gtk_notebook_append_page(GTK_NOTEBOOK(cts->notebook), main_sw, NULL); - /* Show 'em what we got */ - gtk_widget_show_all(main_sw); - } else { - /* show the protocols page */ + /* Attach the page to the tree item */ + gtk_tree_store_set(model, &iter, 0, label_str, 1, cts->page, -1); + g_object_set_data(G_OBJECT(frame), E_PAGE_ITER_KEY, gtk_tree_iter_copy(&iter)); - gtk_tree_store_set(model, &iter, 0, label_str, 1, protocols_page, -1); + cts->page++; - } + /* Show 'em what we got */ + gtk_widget_show_all(main_sw); return 0; } |