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>
36 #include <epan/strutil.h>
38 #include "../globals.h"
40 #include "gtk/prefs_column.h"
41 #include "gtk/gtkglobals.h"
42 #include "gtk/gui_utils.h"
43 #ifdef NEW_PACKET_LIST
44 #include "gtk/new_packet_list.h"
46 #include "gtk/main_packet_list.h"
48 #include "gtk/filter_dlg.h"
49 #include "gtk/filter_autocomplete.h"
52 static GtkWidget *remove_bt, *field_te, *field_lb, *fmt_cmb;
53 static gulong column_menu_changed_handler_id;
54 static gulong column_field_changed_handler_id;
55 static gulong column_row_deleted_handler_id;
57 static void column_list_new_cb(GtkWidget *, gpointer);
58 static void column_list_delete_cb(GtkWidget *, gpointer);
59 static void column_list_select_cb(GtkTreeSelection *, gpointer);
60 static void column_menu_changed_cb(GtkWidget *, gpointer);
61 static void column_field_changed_cb(GtkEditable *, gpointer);
62 static void column_dnd_row_deleted_cb(GtkTreeModel *, GtkTreePath *, gpointer);
63 static gboolean column_title_changed_cb(GtkCellRendererText *, const gchar *, const gchar *, gpointer);
66 * Create and display the column selection widgets.
67 * Called as part of the creation of the Preferences notebook ( Edit ! Preferences )
70 column_prefs_show(GtkWidget *prefs_window) {
71 GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *tb, *lb;
72 GtkWidget *list_vb, *list_lb, *list_sc;
73 GtkWidget *add_remove_vb;
74 GtkWidget *props_fr, *props_hb;
80 const gchar *column_titles[] = {"Title", "Field type"};
82 GtkCellRenderer *renderer;
83 GtkTreeViewColumn *column;
84 GtkTreeSelection *sel;
86 GtkTreeIter first_iter;
87 gint first_row = TRUE;
89 GtkTooltips *tooltips = gtk_tooltips_new();
91 /* Container for each row of widgets */
92 main_vb = gtk_vbox_new(FALSE, 5);
93 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
94 gtk_widget_show(main_vb);
96 list_vb = gtk_vbox_new (FALSE, 0);
97 gtk_container_set_border_width (GTK_CONTAINER (list_vb), 5);
98 gtk_widget_show (list_vb);
99 gtk_box_pack_start (GTK_BOX (main_vb), list_vb, TRUE, TRUE, 0);
101 list_lb = gtk_label_new (("[The first list entry will be displayed as the leftmost column - Drag and drop entries to change column order]"));
102 gtk_widget_show (list_lb);
103 gtk_box_pack_start (GTK_BOX (list_vb), list_lb, FALSE, FALSE, 0);
105 list_sc = scrolled_window_new(NULL, NULL);
106 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc), GTK_SHADOW_IN);
107 gtk_container_add(GTK_CONTAINER(list_vb), list_sc);
108 gtk_widget_show(list_sc);
110 store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
111 column_row_deleted_handler_id =
112 g_signal_connect(GTK_TREE_MODEL(store), "row-deleted", G_CALLBACK(column_dnd_row_deleted_cb), NULL);
114 column_l = tree_view_new(GTK_TREE_MODEL(store));
115 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(column_l), TRUE);
116 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(column_l), FALSE);
117 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(column_l), TRUE);
118 gtk_tooltips_set_tip (tooltips, column_l,
119 "Click on a title to change its name.\nDrag an item to change its order.", NULL);
121 renderer = gtk_cell_renderer_text_new();
122 g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL);
123 g_signal_connect (renderer, "edited", G_CALLBACK(column_title_changed_cb), GTK_TREE_MODEL(store));
124 column = gtk_tree_view_column_new_with_attributes(column_titles[0], renderer, "text", 0, NULL);
125 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
126 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
128 renderer = gtk_cell_renderer_text_new();
129 column = gtk_tree_view_column_new_with_attributes(column_titles[1], renderer, "text", 1, NULL);
130 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
131 gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column);
133 /* XXX - make this match the packet list prefs? */
134 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l));
135 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
136 g_signal_connect(sel, "changed", G_CALLBACK(column_list_select_cb), NULL);
138 gtk_container_add(GTK_CONTAINER(list_sc), column_l);
139 gtk_widget_show(column_l);
141 clp = g_list_first(prefs.col_list);
143 cfmt = (fmt_data *) clp->data;
144 cur_fmt = get_column_format_from_str(cfmt->fmt);
145 if (cur_fmt == COL_CUSTOM) {
146 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), cfmt->custom_field);
148 if (cfmt->custom_field) {
149 /* Delete custom_field from previous changes */
150 g_free (cfmt->custom_field);
151 cfmt->custom_field = NULL;
153 fmt = g_strdup_printf("%s", col_format_desc(cur_fmt));
155 gtk_list_store_append(store, &iter);
156 gtk_list_store_set(store, &iter, 0, cfmt->title, 1, fmt, 2, clp, -1);
164 g_object_unref(G_OBJECT(store));
166 /* Bottom row: Add/remove buttons and properties */
167 bottom_hb = gtk_hbox_new(FALSE, 5);
168 gtk_box_pack_start (GTK_BOX (main_vb), bottom_hb, FALSE, TRUE, 0);
169 gtk_widget_show(bottom_hb);
171 /* Add / remove buttons */
172 add_remove_vb = gtk_vbox_new (TRUE, 0);
173 gtk_container_set_border_width (GTK_CONTAINER (add_remove_vb), 5);
174 gtk_box_pack_start (GTK_BOX (bottom_hb), add_remove_vb, FALSE, FALSE, 0);
175 gtk_widget_show(add_remove_vb);
177 add_bt = gtk_button_new_from_stock(GTK_STOCK_ADD);
178 g_signal_connect(add_bt, "clicked", G_CALLBACK(column_list_new_cb), column_l);
179 gtk_box_pack_start (GTK_BOX (add_remove_vb), add_bt, FALSE, FALSE, 0);
180 gtk_tooltips_set_tip (tooltips, add_bt,
181 "Add a new column at the end of the list.", NULL);
182 gtk_widget_show(add_bt);
184 remove_bt = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
185 gtk_widget_set_sensitive(remove_bt, FALSE);
186 g_signal_connect(remove_bt, "clicked", G_CALLBACK(column_list_delete_cb), column_l);
187 gtk_box_pack_start (GTK_BOX (add_remove_vb), remove_bt, FALSE, FALSE, 0);
188 gtk_tooltips_set_tip (tooltips, remove_bt,
189 "Remove the selected column.", NULL);
190 gtk_widget_show(remove_bt);
192 /* properties frame */
193 props_fr = gtk_frame_new("Properties");
194 gtk_box_pack_start (GTK_BOX (bottom_hb), props_fr, TRUE, TRUE, 0);
195 gtk_widget_show(props_fr);
197 /* Column name entry and format selection */
198 tb = gtk_table_new(2, 2, FALSE);
199 gtk_container_set_border_width(GTK_CONTAINER(tb), 5);
200 gtk_container_add(GTK_CONTAINER(props_fr), tb);
201 gtk_table_set_row_spacings(GTK_TABLE(tb), 10);
202 gtk_table_set_col_spacings(GTK_TABLE(tb), 15);
205 lb = gtk_label_new("Field type:");
206 gtk_misc_set_alignment(GTK_MISC(lb), 1.0f, 0.5f);
207 gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 0, 1);
208 gtk_tooltips_set_tip (tooltips, lb,
209 "Select which packet information to present in the column.", NULL);
212 props_hb = gtk_hbox_new(FALSE, 5);
213 gtk_table_attach(GTK_TABLE(tb), props_hb, 1, 2, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0);
214 gtk_tooltips_set_tip (tooltips, props_hb,
215 "Select which packet information to present in the column.", NULL);
216 gtk_widget_show(props_hb);
218 field_lb = gtk_label_new("Field name:");
219 gtk_misc_set_alignment(GTK_MISC(field_lb), 1.0f, 0.5f);
220 gtk_table_attach_defaults(GTK_TABLE(tb), field_lb, 0, 1, 1, 2);
221 gtk_widget_set_sensitive(field_lb, FALSE);
222 gtk_tooltips_set_tip (tooltips, field_lb,
223 "Field name used when field type is \"Custom\". "
224 "This string has the same syntax as a display filter string.", NULL);
225 gtk_widget_show(field_lb);
227 field_te = gtk_entry_new();
228 g_object_set_data (G_OBJECT(field_te), E_FILT_FIELD_NAME_ONLY_KEY, "");
229 g_signal_connect(field_te, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
231 /* XXX: column_field_changed_cb will be called for every character entered in the entry box. */
232 /* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */
233 /* Also: entry shouldn't be accepted if it's not a valid filter ? */
234 column_field_changed_handler_id =
235 g_signal_connect(field_te, "changed", G_CALLBACK(column_field_changed_cb), column_l);
237 g_object_set_data(G_OBJECT(main_vb), E_FILT_AUTOCOMP_PTR_KEY, NULL);
238 g_signal_connect(field_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
239 g_signal_connect(prefs_window, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);
240 colorize_filter_te_as_empty(field_te);
241 gtk_table_attach_defaults(GTK_TABLE(tb), field_te, 1, 2, 1, 2);
242 gtk_widget_set_sensitive(field_te, FALSE);
243 gtk_tooltips_set_tip (tooltips, field_te,
244 "Field name used when field type is \"Custom\". "
245 "This string has the same syntax as a display filter string.", NULL);
246 gtk_widget_show(field_te);
248 fmt_cmb = gtk_combo_box_new_text();
250 for (i = 0; i < NUM_COL_FMTS; i++)
251 gtk_combo_box_append_text(GTK_COMBO_BOX(fmt_cmb), col_format_desc(i));
253 column_menu_changed_handler_id = g_signal_connect(fmt_cmb, "changed", G_CALLBACK(column_menu_changed_cb), column_l);
255 gtk_widget_set_sensitive(fmt_cmb, FALSE);
256 gtk_box_pack_start(GTK_BOX(props_hb), fmt_cmb, FALSE, FALSE, 0);
257 gtk_widget_show(fmt_cmb);
259 /* select the first menu list row. */
260 /* Triggers call to column_list_select_cb(). */
261 gtk_tree_selection_select_iter(sel, &first_iter);
267 column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field)
270 fmt_data *cfmt, *last_cfmt;
272 cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
274 * Because a single underscore is interpreted as a signal that the next character
275 * is going to be marked as accelerator for this header (i.e. is going to be
276 * shown underlined), escape it be inserting a second consecutive underscore.
278 cfmt->title = g_strdup(title);
279 cfmt->fmt = g_strdup(col_format_to_string(fmt));
280 cfmt->custom_field = g_strdup(custom_field);
283 clp = g_list_last(prefs.col_list);
284 last_cfmt = (fmt_data *) clp->data;
285 if (strcmp(last_cfmt->fmt, "%i") == 0) {
286 /* Last column is COL_INFO, add custom column before this */
287 prefs.col_list = g_list_insert(prefs.col_list, cfmt, g_list_length(prefs.col_list)-1);
289 prefs.col_list = g_list_append(prefs.col_list, cfmt);
292 prefs.col_list = g_list_append(prefs.col_list, cfmt);
297 column_prefs_rename(gint col, const gchar *title)
299 GList *clp = g_list_nth(prefs.col_list, col);
300 fmt_data *cfmt = (fmt_data *) clp->data;
302 g_free (cfmt->title);
303 cfmt->title = g_strdup(title);
307 column_prefs_remove(gint col)
309 GList *clp = g_list_nth(prefs.col_list, col);
310 fmt_data *cfmt = (fmt_data *) clp->data;
314 g_free(cfmt->custom_field);
316 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
319 /* To do: add input checking to each of these callbacks */
322 column_list_new_cb(GtkWidget *w _U_, gpointer data) {
324 const gchar *title = "New Column";
325 GtkTreeView *column_l = GTK_TREE_VIEW(data);
329 GtkTreeViewColumn *title_column;
331 cur_fmt = COL_NUMBER; /* Set the default new column type */
332 column_prefs_add_custom (cur_fmt, title, NULL);
334 model = gtk_tree_view_get_model(column_l);
335 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
336 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
338 1, col_format_desc(cur_fmt),
339 2, g_list_last(prefs.col_list),
342 /* Triggers call to column_list_select_cb() */
343 gtk_tree_selection_select_iter(gtk_tree_view_get_selection(column_l), &iter);
345 /* Set the cursor to the 'Title' column of the newly added row and enable editing */
346 /* XXX: If displaying the new title ["New column"] widens the title column of the */
347 /* treeview, then the set_cursor below doesn't properly generate an entry */
348 /* box around the title text. The width of the box appears to be the column */
349 /* width before the treeview title column was widened. Seems like a bug... */
350 /* I haven't found a work-around. */
351 path = gtk_tree_model_get_path(model, &iter);
352 title_column = gtk_tree_view_get_column(column_l, 0);
353 gtk_tree_view_set_cursor(column_l, path, title_column, TRUE);
354 gtk_tree_path_free(path);
356 cfile.cinfo.columns_changed = TRUE;
361 column_list_delete_cb(GtkWidget *w _U_, gpointer data) {
362 GtkTreeView *column_l = GTK_TREE_VIEW(data);
365 GtkTreeSelection *sel;
368 GtkTreeIter new_iter;
370 sel = gtk_tree_view_get_selection(column_l);
371 if (gtk_tree_selection_get_selected(sel, &model, &iter))
373 gtk_tree_model_get(model, &iter, 2, &clp, -1);
375 cfmt = (fmt_data *) clp->data;
378 g_free(cfmt->custom_field);
380 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
382 /* Change the row selection to the next row (if available) or */
383 /* the previous row (if available). If there's only one row */
384 /* in the store (no previous and no next), then the selection */
385 /* will not be changed. */
387 /* Note that gtk_tree_selection_select_iter() will trigger a */
388 /* call to column_list_select_cb(). */
391 if ( gtk_tree_model_iter_next(model, &new_iter)) {
392 gtk_tree_selection_select_iter(sel, &new_iter);
393 } else { /* "gtk_tree_model_iter_prev" */
394 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
395 if (gtk_tree_path_prev(path)) {
396 gtk_tree_model_get_iter(model, &new_iter, path);
397 gtk_tree_selection_select_iter(sel, &new_iter);
399 gtk_tree_path_free(path);
402 /* Remove the row from the list store. */
403 /* We prevent triggering call to column_row_deleted_cb() since */
404 /* the entry has already been removed from prefs.col_list and */
405 /* since rebuilding the list is not needed because the order */
406 /* of the list hasn't changed. */
408 g_signal_handler_block(model, column_row_deleted_handler_id);
410 /* list_store_remove below will trigger a call to */
411 /* column_list_select_cb() only when deleting the last entry in */
412 /* the column list. */
413 /* (This is because the selection in this case changes to */
414 /* "nothing selected" when the last row is removed. */
416 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
418 g_signal_handler_unblock (model, column_row_deleted_handler_id);
420 cfile.cinfo.columns_changed = TRUE;
426 column_title_changed_cb(GtkCellRendererText *cell _U_, const gchar *str_path, const gchar *new_title, gpointer data) {
429 GtkTreeModel *model = (GtkTreeModel *)data;
430 GtkTreePath *path = gtk_tree_path_new_from_string (str_path);
433 gtk_tree_model_get_iter(model, &iter, path);
435 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, new_title, -1);
437 gtk_tree_model_get(model, &iter, 2, &clp, -1);
439 cfmt = (fmt_data *) clp->data;
441 cfmt->title = g_strdup(new_title);
444 gtk_tree_path_free (path);
445 cfile.cinfo.columns_changed = TRUE;
450 * column list row selection changed.
451 * Set the "Properties" widgets to match the currently selected column row item.
455 column_list_select_cb(GtkTreeSelection *sel, gpointer data _U_)
463 /* if something was selected */
464 if (gtk_tree_selection_get_selected(sel, &model, &iter))
466 gtk_tree_model_get(model, &iter, 2, &clp, -1);
467 g_assert(clp != NULL);
468 cfmt = (fmt_data *) clp->data;
469 cur_fmt = get_column_format_from_str(cfmt->fmt);
470 g_assert(cur_fmt != -1); /* It should always be valid */
472 g_signal_handler_block (fmt_cmb, column_menu_changed_handler_id);
473 gtk_combo_box_set_active(GTK_COMBO_BOX(fmt_cmb), cur_fmt);
474 g_signal_handler_unblock(fmt_cmb, column_menu_changed_handler_id);
476 g_signal_handler_block (field_te, column_field_changed_handler_id);
477 if (cur_fmt == COL_CUSTOM) {
478 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
479 gtk_widget_set_sensitive(field_lb, TRUE);
480 gtk_widget_set_sensitive(field_te, TRUE);
482 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
483 gtk_widget_set_sensitive(field_lb, FALSE);
484 gtk_widget_set_sensitive(field_te, FALSE);
486 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
488 gtk_widget_set_sensitive(remove_bt, TRUE);
489 gtk_widget_set_sensitive(fmt_cmb, TRUE);
493 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
495 gtk_widget_set_sensitive(remove_bt, FALSE);
496 gtk_widget_set_sensitive(field_te, FALSE);
497 gtk_widget_set_sensitive(fmt_cmb, FALSE);
503 * The user selected a new entry in the format combo-box;
504 * Note: column_menu_changed_cb is expected to be called only
505 * when the user changes the format combo-box.
507 * If no selection active in the column list:
508 * Hide 'field"; desensitize buttons.
509 * XXX: Can this happen ?
510 * If a column list selection is active:
511 * 1. Update the display of "field" as req'd (depending upon
512 * whether the active combo-box entry is the "custom"
514 * 2. Update the column_list and prefs.col_formats.
515 * Set columns_changed = TRUE.
519 column_menu_changed_cb(GtkWidget *w, gpointer data) {
520 GtkTreeView *column_l = GTK_TREE_VIEW(data);
526 GtkTreeSelection *sel;
530 sel = gtk_tree_view_get_selection(column_l);
531 if (! (gtk_tree_selection_get_selected(sel, &model, &iter)))
532 return; /* no column list selection [Can this happen ?]: ignore callback */
534 cur_cb_fmt = gtk_combo_box_get_active(GTK_COMBO_BOX(w));
535 gtk_tree_model_get(model, &iter, 2, &clp, -1);
536 cfmt = (fmt_data *) clp->data;
537 cur_fmt = get_column_format_from_str(cfmt->fmt);
539 g_assert(cur_cb_fmt != cur_fmt);
541 /* The User has selected a new format in the combo-box */
542 /* (IE: combo-box format != current selected row format) */
543 /* Update field widgets, list_store, column format array */
544 /* entry as appropriate. */
545 g_signal_handler_block (field_te, column_field_changed_handler_id);
546 if (cur_fmt == COL_CUSTOM) {
547 /* Changing from custom to non-custom */
548 gtk_editable_delete_text(GTK_EDITABLE(field_te), 0, -1);
549 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
550 gtk_widget_set_sensitive(field_lb, FALSE);
551 gtk_widget_set_sensitive(field_te, FALSE);
553 } else if (cur_cb_fmt == COL_CUSTOM) {
554 /* Changing from non-custom to custom */
555 if (cfmt->custom_field == NULL)
556 cfmt->custom_field = g_strdup("");
557 /* The following doesn't trigger a call to menu_field_changed_cb() */
558 gtk_entry_set_text(GTK_ENTRY(field_te), cfmt->custom_field);
559 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_cb_fmt), cfmt->custom_field);
560 gtk_widget_set_sensitive(field_lb, TRUE);
561 gtk_widget_set_sensitive(field_te, TRUE);
564 /* Changing from non-custom to non-custom */
565 fmt = g_strdup_printf("%s", col_format_desc(cur_cb_fmt));
567 g_signal_handler_unblock(field_te, column_field_changed_handler_id);
569 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, fmt, -1);
572 cfmt->fmt = g_strdup(col_format_to_string(cur_cb_fmt));
573 cfile.cinfo.columns_changed = TRUE;
578 * The user changed the custom field entry box or
579 * the field entry box has been updated because a new
580 * column row with custom format has been selected.
581 * If the current field entry matches that of the current
582 * column row, this is just an update because a new
583 * column row has been selected. Do nothing.
584 * If the two are different, then update the column row & etc.
587 column_field_changed_cb(GtkEditable *te, gpointer data) {
592 GtkTreeView *tree = (GtkTreeView *)data;
593 GtkTreeSelection *sel;
597 sel = gtk_tree_view_get_selection(tree);
598 if ( ! (gtk_tree_selection_get_selected(sel, &model, &iter))) {
602 field = gtk_editable_get_chars(te, 0, -1);
603 gtk_tree_model_get(model, &iter, 2, &clp, -1);
604 cfmt = (fmt_data *) clp->data;
605 if (strcmp(cfmt->custom_field, field) == 0) {
606 return; /* no action req'd */
609 /* The user has entered a new value in the field entry box: make the req'd changes */
610 cur_fmt = get_column_format_from_str(cfmt->fmt);
611 fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), field);
613 gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, fmt, -1);
615 g_free(cfmt->custom_field);
616 cfmt->custom_field = field;
617 cfile.cinfo.columns_changed = TRUE;
622 * Callback for the "row-deleted" signal emitted when a list item is dragged.
623 * http://library.gnome.org/devel/gtk/stable/GtkTreeModel.html#GtkTreeModel-rows-reordered
624 * says that DND deletes, THEN inserts the row.
626 * XXX: For the record: For Gtk+ 2.16.0 testing shows the actual sequence for drag-and-drop to be as follows:
627 * 1. Insert a new, empty row at the destination;
628 * 2. Emit a "row-inserted" signal on the model; invoke any row-inserted callbacks & etc;
629 * 3. Copy the source row data to the new (empty) destination row;
630 * 4. Delete the source row;
631 * 5. Emit a "row-deleted" signal; invoke any row-deleted callbacks & etc.
633 * The code below (invoked as a consequence of a "row-deleted" signal) rebuilds
634 * prefs.col_list by iterating over the (re-ordered) tree model.
637 column_dnd_row_deleted_cb(GtkTreeModel *model, GtkTreePath *path _U_, gpointer data _U_) {
639 GList *clp, *new_col_list = NULL;
643 * XXX - This rebuilds prefs.col_list based on the current model. We
644 * might just want to do this when the prefs are applied
646 for (items_left = gtk_tree_model_get_iter_first (model, &iter);
648 items_left = gtk_tree_model_iter_next (model, &iter)) {
650 gtk_tree_model_get(model, &iter, 2, &clp, -1);
652 prefs.col_list = g_list_remove_link(prefs.col_list, clp);
653 new_col_list = g_list_concat(new_col_list, clp);
656 if (prefs.col_list) {
657 g_warning("column_dnd_row_deleted_cb: prefs.col_list has %d leftover data",
658 g_list_length(prefs.col_list));
659 g_list_free(prefs.col_list);
662 prefs.col_list = new_col_list;
663 cfile.cinfo.columns_changed = TRUE;
668 column_prefs_fetch(GtkWidget *w _U_) {
673 column_prefs_apply(GtkWidget *w _U_)
675 /* Redraw the packet list if the columns were changed */
676 if(cfile.cinfo.columns_changed) {
677 #ifdef NEW_PACKET_LIST
678 new_packet_list_recreate();
680 packet_list_recreate();
682 cfile.cinfo.columns_changed = FALSE; /* Reset value */
688 column_prefs_destroy(GtkWidget *w _U_) {