2 * Dialog box for column preferences
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/prefs.h>
34 #include <epan/column_info.h>
35 #include <epan/column.h>
37 #include "../globals.h"
39 #include "gtk/prefs_column.h"
40 #include "gtk/gtkglobals.h"
41 #include "gtk/gui_utils.h"
42 #ifdef NEW_PACKET_LIST
43 #include "gtk/new_packet_list.h"
45 #include "gtk/main_packet_list.h"
47 #include "gtk/filter_dlg.h"
48 #include "gtk/filter_autocomplete.h"
51 static GtkWidget *remove_bt, *field_te, *field_lb, *fmt_cmb;
52 static gulong column_menu_changed_handler_id;
53 static gulong column_field_changed_handler_id;
54 static gulong column_row_deleted_handler_id;
56 static void column_list_new_cb(GtkWidget *, gpointer);
57 static void column_list_delete_cb(GtkWidget *, gpointer);
58 static void column_list_select_cb(GtkTreeSelection *, gpointer);
59 static void column_menu_changed_cb(GtkWidget *, gpointer);
60 static void column_field_changed_cb(GtkEditable *, gpointer);
61 static void column_dnd_row_deleted_cb(GtkTreeModel *, GtkTreePath *, gpointer);
62 static gboolean column_title_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
65 * Create and display the column selection widgets.
66 * Called as part of the creation of the Preferences notebook ( Edit ! Preferences )
69 column_prefs_show(GtkWidget *prefs_window) {
70 GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *tb, *lb;
71 GtkWidget *list_vb, *list_lb, *list_sc;
72 GtkWidget *add_remove_vb;
73 GtkWidget *props_fr, *props_hb;
79 const gchar *column_titles[] = {"Title", "Field type"};
81 GtkCellRenderer *renderer;
82 GtkTreeViewColumn *column;
83 GtkTreeSelection *sel;
85 GtkTreeIter first_iter;
86 gint first_row = TRUE;
88 GtkTooltips *tooltips = gtk_tooltips_new();
90 /* Container for each row of widgets */
91 main_vb = gtk_vbox_new(FALSE, 5);
92 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
93 gtk_widget_show(main_vb);
95 list_vb = gtk_vbox_new (FALSE, 0);
96 gtk_container_set_border_width (GTK_CONTAINER (list_vb), 5);
97 gtk_widget_show (list_vb);
98 gtk_box_pack_start (GTK_BOX (main_vb), list_vb, TRUE, TRUE, 0);
100 list_lb = gtk_label_new (("[The first list entry will be displayed as the leftmost column - Drag and drop entries to change column order]"));
101 gtk_widget_show (list_lb);
102 gtk_box_pack_start (GTK_BOX (list_vb), list_lb, FALSE, FALSE, 0);
104 list_sc = scrolled_window_new(NULL, NULL);
105 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc), GTK_SHADOW_IN);
106 gtk_container_add(GTK_CONTAINER(list_vb), list_sc);
107 gtk_widget_show(list_sc);
109 store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
110 column_row_deleted_handler_id =
111 g_signal_connect(GTK_TREE_MODEL(store), "row-deleted", G_CALLBACK(column_dnd_row_deleted_cb), NULL);
113 column_l = tree_view_new(GTK_TREE_MODEL(store));
114 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(column_l), TRUE);
115 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(column_l), FALSE);
116 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(column_l), TRUE);
117 gtk_tooltips_set_tip (tooltips, column_l,
118 "Click on a title to change its name.\nDrag an item to change its order.", NULL);
120 renderer = gtk_cell_renderer_text_new();
121 g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
122 g_signal_connect (renderer, "edited", G_CALLBACK(column_title_changed_cb), GTK_TREE_MODEL(store));
123 column = gtk_tree_view_column_new_with_attributes(column_titles[0], renderer, "text", 0, NULL);
124 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
125 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
127 renderer = gtk_cell_renderer_text_new();
128 column = gtk_tree_view_column_new_with_attributes(column_titles[1], renderer, "text", 1, NULL);
129 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
130 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
132 /* XXX - make this match the packet list prefs? */
133 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l));
134 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
135 g_signal_connect(sel, "changed", G_CALLBACK(column_list_select_cb), NULL);
137 gtk_container_add(GTK_CONTAINER(list_sc), column_l);
138 gtk_widget_show(column_l);
140 clp = g_list_first(prefs.col_list);
142 cfmt = (fmt_data *) clp->data;
143 cur_fmt = get_column_format_from_str(cfmt->fmt);
144 if (cur_fmt == COL_CUSTOM) {
145 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), cfmt->custom_field);
147 if (cfmt->custom_field) {
148 /* Delete custom_field from previous changes */
149 g_free (cfmt->custom_field);
150 cfmt->custom_field = NULL;
152 fmt = g_strdup_printf("%s", col_format_desc(cur_fmt));
154 gtk_list_store_append(store, &iter);
155 gtk_list_store_set(store, &iter, 0, cfmt->title, 1, fmt, 2, clp, -1);
163 g_object_unref(G_OBJECT(store));
165 /* Bottom row: Add/remove buttons and properties */
166 bottom_hb = gtk_hbox_new(FALSE, 5);
167 gtk_box_pack_start (GTK_BOX (main_vb), bottom_hb, FALSE, TRUE, 0);
168 gtk_widget_show(bottom_hb);
170 /* Add / remove buttons */
171 add_remove_vb = gtk_vbox_new (TRUE, 0);
172 gtk_container_set_border_width (GTK_CONTAINER (add_remove_vb), 5);
173 gtk_box_pack_start (GTK_BOX (bottom_hb), add_remove_vb, FALSE, FALSE, 0);
174 gtk_widget_show(add_remove_vb);
176 add_bt = gtk_button_new_from_stock(GTK_STOCK_ADD);
177 g_signal_connect(add_bt, "clicked", G_CALLBACK(column_list_new_cb), column_l);
178 gtk_box_pack_start (GTK_BOX (add_remove_vb), add_bt, FALSE, FALSE, 0);
179 gtk_tooltips_set_tip (tooltips, add_bt,
180 "Add a new column at the end of the list.", NULL);
181 gtk_widget_show(add_bt);
183 remove_bt = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
184 gtk_widget_set_sensitive(remove_bt, FALSE);
185 g_signal_connect(remove_bt, "clicked", G_CALLBACK(column_list_delete_cb), column_l);
186 gtk_box_pack_start (GTK_BOX (add_remove_vb), remove_bt, FALSE, FALSE, 0);
187 gtk_tooltips_set_tip (tooltips, remove_bt,
188 "Remove the selected column.", NULL);
189 gtk_widget_show(remove_bt);
191 /* properties frame */
192 props_fr = gtk_frame_new("Properties");
193 gtk_box_pack_start (GTK_BOX (bottom_hb), props_fr, TRUE, TRUE, 0);
194 gtk_widget_show(props_fr);
196 /* Column name entry and format selection */
197 tb = gtk_table_new(2, 2, FALSE);
198 gtk_container_set_border_width(GTK_CONTAINER(tb), 5);
199 gtk_container_add(GTK_CONTAINER(props_fr), tb);
200 gtk_table_set_row_spacings(GTK_TABLE(tb), 10);
201 gtk_table_set_col_spacings(GTK_TABLE(tb), 15);
204 lb = gtk_label_new("Field type:");
205 gtk_misc_set_alignment(GTK_MISC(lb), 1.0f, 0.5f);
206 gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 0, 1);
207 gtk_tooltips_set_tip (tooltips, lb,
208 "Select which packet information to present in the column.", NULL);
211 props_hb = gtk_hbox_new(FALSE, 5);
212 gtk_table_attach(GTK_TABLE(tb), props_hb, 1, 2, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0);
213 gtk_tooltips_set_tip (tooltips, props_hb,
214 "Select which packet information to present in the column.", NULL);
215 gtk_widget_show(props_hb);
217 field_lb = gtk_label_new("Field name:");
218 gtk_misc_set_alignment(GTK_MISC(field_lb), 1.0f, 0.5f);
219 gtk_table_attach_defaults(GTK_TABLE(tb), field_lb, 0, 1, 1, 2);
220 gtk_widget_set_sensitive(field_lb, FALSE);
221 gtk_tooltips_set_tip (tooltips, field_lb,
222 "Field name used when field type is \"Custom\". "
223 "This string has the same syntax as a display filter string.", NULL);
224 gtk_widget_show(field_lb);
226 field_te = gtk_entry_new();
227 g_object_set_data (G_OBJECT(field_te), E_FILT_FIELD_NAME_ONLY_KEY, "");
228 g_signal_connect(field_te, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
230 /* XXX: column_field_changed_cb will be called for every character entered in the entry box. */
231 /* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
232 /* Also: entry shouldn't be accepted if it's not a valid filter ? */
233 column_field_changed_handler_id =
234 g_signal_connect(field_te, "changed", G_CALLBACK(column_field_changed_cb), column_l);
236 g_object_set_data(G_OBJECT(main_vb), E_FILT_AUTOCOMP_PTR_KEY, NULL);
237 g_signal_connect(field_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
238 g_signal_connect(prefs_window, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
239 colorize_filter_te_as_empty(field_te);
240 gtk_table_attach_defaults(GTK_TABLE(tb), field_te, 1, 2, 1, 2);
241 gtk_widget_set_sensitive(field_te, FALSE);
242 gtk_tooltips_set_tip (tooltips, field_te,
243 "Field name used when field type is \"Custom\". "
244 "This string has the same syntax as a display filter string.", NULL);
245 gtk_widget_show(field_te);
247 fmt_cmb = gtk_combo_box_new_text();
249 for (i = 0; i < NUM_COL_FMTS; i++)
250 gtk_combo_box_append_text(GTK_COMBO_BOX(fmt_cmb), col_format_desc(i));
252 column_menu_changed_handler_id = g_signal_connect(fmt_cmb, "changed", G_CALLBACK(column_menu_changed_cb), column_l);
254 gtk_widget_set_sensitive(fmt_cmb, FALSE);
255 gtk_box_pack_start(GTK_BOX(props_hb), fmt_cmb, FALSE, FALSE, 0);
256 gtk_widget_show(fmt_cmb);
258 /* select the first menu list row. */
259 /* Triggers call to column_list_select_cb(). */
260 gtk_tree_selection_select_iter(sel, &first_iter);
266 * This function takes a string and copies it, inserting an underscore before
267 * every underscore in it.
270 g_strdup_escape_underscore (const gchar *str)
272 gchar *p, *q, *new_str;
278 /* Worst case: A string that is full of underscores */
279 q = new_str = g_malloc (strlen(str) * 2 + 1);
294 column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field)
297 fmt_data *cfmt, *last_cfmt;
299 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
301 * Because a single underscore is interpreted as a signal that the next character
302 * is going to be marked as accelerator for this header (i.e. is going to be
303 * shown underlined), escape it be inserting a second consecutive underscore.
305 cfmt->title = g_strdup_escape_underscore(title);
306 cfmt->fmt = g_strdup(col_format_to_string(fmt));
307 cfmt->custom_field = g_strdup(custom_field);
310 clp = g_list_last(prefs.col_list);
311 last_cfmt = (fmt_data *) clp->data;
312 if (strcmp(last_cfmt->fmt, "%i") == 0) {
313 /* Last column is COL_INFO, add custom column before this */
314 prefs.col_list = g_list_insert(prefs.col_list, cfmt, g_list_length(prefs.col_list)-1);
316 prefs.col_list = g_list_append(prefs.col_list, cfmt);
319 prefs.col_list = g_list_append(prefs.col_list, cfmt);
324 column_prefs_rename(gint col, const gchar *title)
326 GList *clp = g_list_nth(prefs.col_list, col);
327 fmt_data *cfmt = (fmt_data *) clp->data;
329 g_free (cfmt->title);
330 cfmt->title = g_strdup(title);
334 column_prefs_remove(gint col)
336 GList *clp = g_list_nth(prefs.col_list, col);
337 fmt_data *cfmt = (fmt_data *) clp->data;
341 g_free(cfmt->custom_field);
343 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
346 /* To do: add input checking to each of these callbacks */
349 column_list_new_cb(GtkWidget *w _U_, gpointer data) {
351 const gchar *title = "New Column";
352 GtkTreeView *column_l = GTK_TREE_VIEW(data);
356 GtkTreeViewColumn *title_column;
358 cur_fmt = COL_NUMBER; /* Set the default new column type */
359 column_prefs_add_custom (cur_fmt, title, NULL);
361 model = gtk_tree_view_get_model(column_l);
362 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
363 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
365 1, col_format_desc(cur_fmt),
366 2, g_list_last(prefs.col_list),
369 /* Triggers call to column_list_select_cb() */
370 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(column_l), &iter);
372 /* Set the cursor to the 'Title' column of the newly added row and enable editing */
373 /* XXX: If displaying the new title ["New column"] widens the title column of the */
374 /* treeview, then the set_cursor below doesn't properly generate an entry */
375 /* box around the title text. The width of the box appears to be the column */
376 /* width before the treeview title column was widened. Seems like a bug... */
377 /* I haven't found a work-around. */
378 path = gtk_tree_model_get_path(model, &iter);
379 title_column = gtk_tree_view_get_column(column_l, 0);
380 gtk_tree_view_set_cursor(column_l, path, title_column, TRUE);
381 gtk_tree_path_free(path);
383 cfile.cinfo.columns_changed = TRUE;
388 column_list_delete_cb(GtkWidget *w _U_, gpointer data) {
389 GtkTreeView *column_l = GTK_TREE_VIEW(data);
392 GtkTreeSelection *sel;
395 GtkTreeIter new_iter;
397 sel = gtk_tree_view_get_selection(column_l);
398 if (gtk_tree_selection_get_selected(sel, &model, &iter))
400 gtk_tree_model_get(model, &iter, 2, &clp, -1);
402 cfmt = (fmt_data *) clp->data;
405 g_free(cfmt->custom_field);
407 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
409 /* Change the row selection to the next row (if available) or */
410 /* the previous row (if available). If there's only one row */
411 /* in the store (no previous and no next), then the selection */
412 /* will not be changed. */
414 /* Note that gtk_tree_selection_select_iter() will trigger a */
415 /* call to column_list_select_cb(). */
418 if ( gtk_tree_model_iter_next(model, &new_iter)) {
419 gtk_tree_selection_select_iter(sel, &new_iter);
420 } else { /* "gtk_tree_model_iter_prev" */
421 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
422 if (gtk_tree_path_prev(path)) {
423 gtk_tree_model_get_iter(model, &new_iter, path);
424 gtk_tree_selection_select_iter(sel, &new_iter);
426 gtk_tree_path_free(path);
429 /* Remove the row from the list store. */
430 /* We prevent triggering call to column_row_deleted_cb() since */
431 /* the entry has already been removed from prefs.col_list and */
432 /* since rebuilding the list is not needed because the order */
433 /* of the list hasn't changed. */
435 g_signal_handler_block(model, column_row_deleted_handler_id);
437 /* list_store_remove below will trigger a call to */
438 /* column_list_select_cb() only when deleting the last entry in */
439 /* the column list. */
440 /* (This is because the selection in this case changes to */
441 /* "nothing selected" when the last row is removed. */
443 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
445 g_signal_handler_unblock (model, column_row_deleted_handler_id);
447 cfile.cinfo.columns_changed = TRUE;
453 column_title_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_title, gpointer data) {
456 GtkTreeModel *model = (GtkTreeModel *)data;
457 GtkTreePath *path = gtk_tree_path_new_from_string (str_path);
460 gtk_tree_model_get_iter(model, &iter, path);
462 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, new_title, -1);
464 gtk_tree_model_get(model, &iter, 2, &clp, -1);
466 cfmt = (fmt_data *) clp->data;
468 cfmt->title = g_strdup(new_title);
471 gtk_tree_path_free (path);
472 cfile.cinfo.columns_changed = TRUE;
477 * column list row selection changed.
478 * Set the "Properties" widgets to match the currently selected column row item.
482 column_list_select_cb(GtkTreeSelection *sel, gpointer data _U_)
490 /* if something was selected */
491 if (gtk_tree_selection_get_selected(sel, &model, &iter))
493 gtk_tree_model_get(model, &iter, 2, &clp, -1);
494 g_assert(clp != NULL);
495 cfmt = (fmt_data *) clp->data;
496 cur_fmt = get_column_format_from_str(cfmt->fmt);
497 g_assert(cur_fmt != -1); /* It should always be valid */
499 g_signal_handler_block (fmt_cmb, column_menu_changed_handler_id);
500 gtk_combo_box_set_active(GTK_COMBO_BOX(fmt_cmb), cur_fmt);
501 g_signal_handler_unblock(fmt_cmb, column_menu_changed_handler_id);
503 g_signal_handler_block (field_te, column_field_changed_handler_id);
504 if (cur_fmt == COL_CUSTOM) {
505 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
506 gtk_widget_set_sensitive(field_lb, TRUE);
507 gtk_widget_set_sensitive(field_te, TRUE);
509 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
510 gtk_widget_set_sensitive(field_lb, FALSE);
511 gtk_widget_set_sensitive(field_te, FALSE);
513 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
515 gtk_widget_set_sensitive(remove_bt, TRUE);
516 gtk_widget_set_sensitive(fmt_cmb, TRUE);
520 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
522 gtk_widget_set_sensitive(remove_bt, FALSE);
523 gtk_widget_set_sensitive(field_te, FALSE);
524 gtk_widget_set_sensitive(fmt_cmb, FALSE);
530 * The user selected a new entry in the format combo-box;
531 * Note: column_menu_changed_cb is expected to be called only
532 * when the user changes the format combo-box.
534 * If no selection active in the column list:
535 * Hide 'field"; desensitize buttons.
536 * XXX: Can this happen ?
537 * If a column list selection is active:
538 * 1. Update the display of "field" as req'd (depending upon
539 * whether the active combo-box entry is the "custom"
541 * 2. Update the column_list and prefs.col_formats.
542 * Set columns_changed = TRUE.
546 column_menu_changed_cb(GtkWidget *w, gpointer data) {
547 GtkTreeView *column_l = GTK_TREE_VIEW(data);
553 GtkTreeSelection *sel;
557 sel = gtk_tree_view_get_selection(column_l);
558 if (! (gtk_tree_selection_get_selected(sel, &model, &iter)))
559 return; /* no column list selection [Can this happen ?]: ignore callback */
561 cur_cb_fmt = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
562 gtk_tree_model_get(model, &iter, 2, &clp, -1);
563 cfmt = (fmt_data *) clp->data;
564 cur_fmt = get_column_format_from_str(cfmt->fmt);
566 g_assert(cur_cb_fmt != cur_fmt);
568 /* The User has selected a new format in the combo-box */
569 /* (IE: combo-box format != current selected row format) */
570 /* Update field widgets, list_store, column format array */
571 /* entry as appropriate. */
572 g_signal_handler_block (field_te, column_field_changed_handler_id);
573 if (cur_fmt == COL_CUSTOM) {
574 /* Changing from custom to non-custom */
575 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
576 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
577 gtk_widget_set_sensitive(field_lb, FALSE);
578 gtk_widget_set_sensitive(field_te, FALSE);
580 } else if (cur_cb_fmt == COL_CUSTOM) {
581 /* Changing from non-custom to custom */
582 if (cfmt->custom_field == NULL)
583 cfmt->custom_field = g_strdup("");
584 /* The following doesn't trigger a call to menu_field_changed_cb() */
585 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
586 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_cb_fmt), cfmt->custom_field);
587 gtk_widget_set_sensitive(field_lb, TRUE);
588 gtk_widget_set_sensitive(field_te, TRUE);
591 /* Changing from non-custom to non-custom */
592 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
594 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
596 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, fmt, -1);
599 cfmt->fmt = g_strdup(col_format_to_string(cur_cb_fmt));
600 cfile.cinfo.columns_changed = TRUE;
605 * The user changed the custom field entry box or
606 * the field entry box has been updated because a new
607 * column row with custom format has been selected.
608 * If the current field entry matches that of the current
609 * column row, this is just an update because a new
610 * column row has been selected. Do nothing.
611 * If the two are different, then update the column row & etc.
614 column_field_changed_cb(GtkEditable *te, gpointer data) {
619 GtkTreeView *tree = (GtkTreeView *)data;
620 GtkTreeSelection *sel;
624 sel = gtk_tree_view_get_selection(tree);
625 if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
629 field = gtk_editable_get_chars(te, 0, -1);
630 gtk_tree_model_get(model, &iter, 2, &clp, -1);
631 cfmt = (fmt_data *) clp->data;
632 if (strcmp(cfmt->custom_field, field) == 0) {
633 return; /* no action req'd */
636 /* The user has entered a new value in the field entry box: make the req'd changes */
637 cur_fmt = get_column_format_from_str(cfmt->fmt);
638 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), field);
640 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, fmt, -1);
642 g_free(cfmt->custom_field);
643 cfmt->custom_field = field;
644 cfile.cinfo.columns_changed = TRUE;
649 * Callback for the "row-deleted" signal emitted when a list item is dragged.
650 * http://library.gnome.org/devel/gtk/stable/GtkTreeModel.html#GtkTreeModel-rows-reordered
651 * says that DND deletes, THEN inserts the row.
653 * XXX: For the record: For Gtk+ 2.16.0 testing shows the actual sequence for drag-and-drop to be as follows:
654 * 1. Insert a new, empty row at the destination;
655 * 2. Emit a "row-inserted" signal on the model; invoke any row-inserted callbacks & etc;
656 * 3. Copy the source row data to the new (empty) destination row;
657 * 4. Delete the source row;
658 * 5. Emit a "row-deleted" signal; invoke any row-deleted callbacks & etc.
660 * The code below (invoked as a consequence of a "row-deleted" signal) rebuilds
661 * prefs.col_list by iterating over the (re-ordered) tree model.
664 column_dnd_row_deleted_cb(GtkTreeModel *model, GtkTreePath *path _U_, gpointer data _U_) {
666 GList *clp, *new_col_list = NULL;
670 * XXX - This rebuilds prefs.col_list based on the current model. We
671 * might just want to do this when the prefs are applied
673 for (items_left = gtk_tree_model_get_iter_first (model, &iter);
675 items_left = gtk_tree_model_iter_next (model, &iter)) {
677 gtk_tree_model_get(model, &iter, 2, &clp, -1);
679 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
680 new_col_list = g_list_concat(new_col_list, clp);
683 if (prefs.col_list) {
684 g_warning("column_dnd_row_deleted_cb: prefs.col_list has %d leftover data",
685 g_list_length(prefs.col_list));
686 g_list_free(prefs.col_list);
689 prefs.col_list = new_col_list;
690 cfile.cinfo.columns_changed = TRUE;
695 column_prefs_fetch(GtkWidget *w _U_) {
700 column_prefs_apply(GtkWidget *w _U_)
702 /* Redraw the packet list if the columns were changed */
703 if(cfile.cinfo.columns_changed) {
704 #ifdef NEW_PACKET_LIST
705 new_packet_list_recreate();
707 packet_list_recreate();
709 cfile.cinfo.columns_changed = FALSE; /* Reset value */
715 column_prefs_destroy(GtkWidget *w _U_) {