diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-05-20 08:56:06 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-05-20 08:56:06 +0000 |
commit | 4a9b825c49a228b6456fbf24731aadcdd47d2c4e (patch) | |
tree | 55a654e285d7298213738a4b58db5e65a09e59d8 /ui | |
parent | acc2a3706bf20e518f63492f424d0276d70e7e32 (diff) | |
download | wireshark-4a9b825c49a228b6456fbf24731aadcdd47d2c4e.tar.gz |
Change the "user_saved" member of a capture_file structure to
"unsaved_changes", and have it be TRUE iff changes have been made to the
file since it was read - *not* if it's a temporary file from a live
capture.
Check the "is_tempfile" member, and the "unsaved_changes" member, when
appropriate.
Just have a set_toolbar_for_capture_file() routine that updates the
"save", "close", and "reload" toolbar as appropriate, given a
capture_file structure - absorb the function of
set_toolbar_for_unsaved_capture_file() into it.
svn path=/trunk/; revision=42721
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/capture_dlg.c | 6 | ||||
-rw-r--r-- | ui/gtk/capture_file_dlg.c | 26 | ||||
-rw-r--r-- | ui/gtk/drag_and_drop.c | 6 | ||||
-rw-r--r-- | ui/gtk/file_import_dlg.c | 6 | ||||
-rw-r--r-- | ui/gtk/main.c | 14 | ||||
-rw-r--r-- | ui/gtk/main_menubar.c | 22 | ||||
-rw-r--r-- | ui/gtk/main_toolbar.c | 57 | ||||
-rw-r--r-- | ui/gtk/main_toolbar.h | 16 | ||||
-rw-r--r-- | ui/gtk/new_packet_list.c | 4 | ||||
-rw-r--r-- | ui/gtk/summary_dlg.c | 4 |
10 files changed, 94 insertions, 67 deletions
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c index c9b21748ba..86d5a8fcd3 100644 --- a/ui/gtk/capture_dlg.c +++ b/ui/gtk/capture_dlg.c @@ -4251,8 +4251,10 @@ capture_start_cb(GtkWidget *w _U_, gpointer d _U_) return; } - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, "%sSave capture file before starting a new capture?%s\n\n" "If you start a new capture without saving, your current capture data will\nbe discarded.", diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index 05765f6813..cd22ebdf04 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -604,8 +604,10 @@ void file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) { gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't save his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, "%sSave capture file before opening a new one?%s\n\n" "If you open a new capture file without saving, your capture data will be discarded.", @@ -908,8 +910,10 @@ void file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) { gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL, "%sSave the capture file before merging to another one?%s\n\n" "A temporary capture file can't be merged.", @@ -1078,8 +1082,10 @@ void file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) { gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, "%sSave capture file before closing it?%s\n\n" "If you close without saving, your capture data will be discarded.", @@ -1094,10 +1100,14 @@ file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) { void file_save_cmd_cb(GtkWidget *w _U_, gpointer data _U_) { - /* If the file's already been saved, do nothing. */ - if (cfile.user_saved) + /* If the file has no unsaved changes, and is not a temporary file, + do nothing. */ + if (!cfile.unsaved_changes && !cfile.is_tempfile) return; + /* XXX TODO - if it's not a temporary file, "save" should just save + on top of the existing file. */ + /* Do a "Save As". */ file_save_as_cmd(after_save_no_action, NULL, FALSE); } diff --git a/ui/gtk/drag_and_drop.c b/ui/gtk/drag_and_drop.c index 5db1be8a34..a11853d2b7 100644 --- a/ui/gtk/drag_and_drop.c +++ b/ui/gtk/drag_and_drop.c @@ -356,8 +356,10 @@ dnd_data_received(GtkWidget *widget _U_, GdkDragContext *dc _U_, gint x _U_, gin cf_names_freeme[sel_data_len] = '\0'; /* ask the user to save it's current capture file first */ - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, "%sSave capture file before opening a new one?%s\n\n" diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c index 5390874c17..70174184a5 100644 --- a/ui/gtk/file_import_dlg.c +++ b/ui/gtk/file_import_dlg.c @@ -800,9 +800,11 @@ file_import_ok_cb(GtkWidget *widget _U_, gpointer data) { text_import_info_t *text_import_info; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ gpointer dialog; - /* user didn't save his current file, ask him */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, "%sSave capture file before opening a new one?%s\n\n" "If you open a new capture file without saving, your capture data will be discarded.", diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 547d586f6c..2b5605a6a8 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -1009,9 +1009,11 @@ main_window_delete_event_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer { gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ gtk_window_present(GTK_WINDOW(top_level)); - /* user didn't saved his current file, ask him */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ((cfile.state == FILE_READ_IN_PROGRESS) ? ESD_BTNS_QUIT_DONTSAVE_CANCEL : ESD_BTNS_SAVE_QUIT_DONTSAVE_CANCEL), "%sSave capture file before program quit?%s\n\n" @@ -1115,10 +1117,12 @@ static void file_quit_answered_cb(gpointer dialog _U_, gint btn, gpointer data _ void file_quit_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) { - gpointer dialog; + gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ((cfile.state == FILE_READ_IN_PROGRESS) ? ESD_BTNS_QUIT_DONTSAVE_CANCEL : ESD_BTNS_SAVE_QUIT_DONTSAVE_CANCEL), "%sSave capture file before program quit?%s\n\n" diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index 99b4dc9ab6..f24f4edcf3 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -4196,8 +4196,10 @@ menu_open_recent_file_cmd_cb(GtkAction *action, gpointer data _U_) { gpointer dialog; - if((cfile.state != FILE_CLOSED) && !cfile.user_saved && prefs.gui_ask_unsaved) { - /* user didn't saved his current file, ask him */ + if((cfile.state != FILE_CLOSED) && (cfile.is_tempfile || cfile.unsaved_changes) && + prefs.gui_ask_unsaved) { + /* This is a temporary capture file or has unsaved changes; ask the + user whether to save the capture. */ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO_CANCEL, "%sSave capture file before opening a new one?%s\n\n" "If you open a new capture file without saving, your current capture data will be discarded.", @@ -4638,25 +4640,27 @@ set_menus_for_capture_file(capture_file *cf) set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/SaveAs", FALSE); set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Export", FALSE); set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/Reload", FALSE); - set_toolbar_for_capture_file(FALSE, FALSE); - set_toolbar_for_unsaved_capture_file(FALSE); } else { set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Merge", cf_can_save_as(cf)); set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Close", TRUE); - set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Save", !cf->user_saved); + /* + * "Save" should be available only if the file is a temporary file + * or has unsaved changes. + */ + set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Save", + (cf->is_tempfile || cf->unsaved_changes)); /* * "Save As..." works only if we can write the file out in at least * one format (so we can save the whole file or just a subset) or - * if we have an unsaved capture (so writing the whole file out + * if the file is a temporary file (so writing the whole file out * with a raw data copy makes sense). */ set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/SaveAs", - cf_can_save_as(cf) || !cf->user_saved); + cf_can_save_as(cf) || cf->is_tempfile); set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/FileMenu/Export", TRUE); set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/Reload", TRUE); - set_toolbar_for_unsaved_capture_file(!cf->user_saved); - set_toolbar_for_capture_file(TRUE, cf_can_save_as(cf) || !cf->user_saved); } + set_toolbar_for_capture_file(cf); } /* Enable or disable menu items based on whether there's a capture in diff --git a/ui/gtk/main_toolbar.c b/ui/gtk/main_toolbar.c index 5fabfa74a8..488a6c2279 100644 --- a/ui/gtk/main_toolbar.c +++ b/ui/gtk/main_toolbar.c @@ -103,35 +103,45 @@ toolbar_redraw_all(void) } /* Enable or disable toolbar items based on whether you have a capture file - you've finished reading. */ -void set_toolbar_for_capture_file(gboolean have_capture_file, gboolean can_save_as) { + and, if so, whether you've finished reading it and whether there's stuff + in it that hasn't yet been saved to a permanent file. */ +void set_toolbar_for_capture_file(capture_file *cf) { if (toolbar_init) { - gtk_widget_set_sensitive(GTK_WIDGET(save_button), have_capture_file && can_save_as); - gtk_widget_set_sensitive(GTK_WIDGET(close_button), have_capture_file); - gtk_widget_set_sensitive(GTK_WIDGET(reload_button), have_capture_file); - } -} - -/* Enable or disable menu items based on whether you have an unsaved - capture file you've finished reading. */ -void set_toolbar_for_unsaved_capture_file(gboolean have_unsaved_capture_file) { - - if (toolbar_init) { - if(have_unsaved_capture_file) { - if (strcmp(gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(save_button)), GTK_STOCK_SAVE) != 0) { - gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(save_button), GTK_STOCK_SAVE); - gtk_widget_set_tooltip_text(GTK_WIDGET(save_button),SAVE_BUTTON_TOOLTIP_TEXT); - g_object_set_data(G_OBJECT(save_button), "save", GINT_TO_POINTER(1)); - } - } else { + if (cf == NULL || cf->state == FILE_READ_IN_PROGRESS) { + /* We have no open capture file, or we have one but we're in + the process of reading it. Disable everything having to + do with the file*/ if (strcmp(gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(save_button)), GTK_STOCK_SAVE_AS) != 0) { gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(save_button), GTK_STOCK_SAVE_AS); gtk_widget_set_tooltip_text(GTK_WIDGET(save_button), SAVE_AS_BUTTON_TOOLTIP_TEXT); g_object_set_data(G_OBJECT(save_button), "save", GINT_TO_POINTER(0)); } + gtk_widget_set_sensitive(GTK_WIDGET(save_button), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(close_button), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(reload_button), FALSE); + } else { + /* We have an open capture file and we're finished reading it. + Enable "Save As", "Close", and "Reload"; enable "Save" iff + it has stuff not saved to a permanent file (and we support + saving in its format). */ + if (cf->is_tempfile || cf->unsaved_changes) { + if (strcmp(gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(save_button)), GTK_STOCK_SAVE) != 0) { + gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(save_button), GTK_STOCK_SAVE); + gtk_widget_set_tooltip_text(GTK_WIDGET(save_button),SAVE_BUTTON_TOOLTIP_TEXT); + g_object_set_data(G_OBJECT(save_button), "save", GINT_TO_POINTER(1)); + } + } else { + if (strcmp(gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(save_button)), GTK_STOCK_SAVE_AS) != 0) { + gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(save_button), GTK_STOCK_SAVE_AS); + gtk_widget_set_tooltip_text(GTK_WIDGET(save_button), SAVE_AS_BUTTON_TOOLTIP_TEXT); + g_object_set_data(G_OBJECT(save_button), "save", GINT_TO_POINTER(0)); + } + } + gtk_widget_set_sensitive(GTK_WIDGET(save_button), + (cf->is_tempfile || cf->unsaved_changes) && cf_can_save_as(cf)); + gtk_widget_set_sensitive(GTK_WIDGET(close_button), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(reload_button), TRUE); } - /*gtk_widget_set_sensitive((GTK_WIDGET(save_button), have_unsaved_capture_file); - gtk_widget_set_sensitive(GTK_WIDGET(save_as_button), !have_unsaved_capture_file);*/ } } @@ -408,9 +418,8 @@ toolbar_new(void) /* disable all "sensitive" items by default */ toolbar_init = TRUE; - set_toolbar_for_unsaved_capture_file(FALSE); set_toolbar_for_captured_packets(FALSE); - set_toolbar_for_capture_file(FALSE, FALSE); + set_toolbar_for_capture_file(NULL); #ifdef HAVE_LIBPCAP set_toolbar_for_capture_in_progress(FALSE); #endif /* HAVE_LIBPCAP */ diff --git a/ui/gtk/main_toolbar.h b/ui/gtk/main_toolbar.h index 5d7743e458..701798340b 100644 --- a/ui/gtk/main_toolbar.h +++ b/ui/gtk/main_toolbar.h @@ -50,18 +50,12 @@ void toolbar_colorize_changed(gboolean packet_list_colorize); void toolbar_auto_scroll_live_changed(gboolean auto_scroll_live); #endif -/** We have (or don't have) a capture file now. - * - * @param have_capture_file TRUE, if we have a capture file - * @param can_save_as TRUE, if we can save this capture file - */ -void set_toolbar_for_capture_file(gboolean have_capture_file, gboolean can_save_as); - -/** We have (or don't have) an unsaved capture file now. - * - * @param have_unsaved_capture_file TRUE, if we have an unsaved capture file +/* Enable or disable toolbar items based on whether you have a capture file + * and, if so, whether you've finished reading it and whether there's stuff + * in it that hasn't yet been saved to a permanent file. + * @param cf cfile_t for the capture file in question */ -void set_toolbar_for_unsaved_capture_file(gboolean have_unsaved_capture_file); +void set_toolbar_for_capture_file(capture_file *cf); /** We have (or don't have) a capture in progress now. * diff --git a/ui/gtk/new_packet_list.c b/ui/gtk/new_packet_list.c index 394320e01d..e6e6fbf0d9 100644 --- a/ui/gtk/new_packet_list.c +++ b/ui/gtk/new_packet_list.c @@ -1752,8 +1752,8 @@ new_packet_list_update_packet_comment(gchar *new_packet_comment) g_free(record->fdata->opt_comment); record->fdata->opt_comment = new_packet_comment; - /* Mark the file as unsaved */ - cfile.user_saved = FALSE; + /* Mark the file as having unsaved changes */ + cfile.unsaved_changes = TRUE; set_menus_for_capture_file(&cfile); new_packet_list_queue_draw(); diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c index 690eee669c..bf0ba04f96 100644 --- a/ui/gtk/summary_dlg.c +++ b/ui/gtk/summary_dlg.c @@ -144,8 +144,8 @@ summary_comment_text_buff_save_cb(GtkWidget *w _U_, GtkWidget *view) /*g_warning("The new comment is '%s'",new_packet_comment);*/ summary_update_comment(&cfile, new_comment); - /* Mark the file as unsaved, caues a popup asking to save the file if we quit the file */ - cfile.user_saved = FALSE; + /* Mark the file as having unsaved changes; this causes a popup asking to save the file if we quit the file */ + cfile.unsaved_changes = TRUE; set_menus_for_capture_file(&cfile); } |