[easytag] Add et_application_window_update_et_file_from_ui()



commit 5daf401c2586ef974139b9e1f96044a585d3d078
Author: David King <amigadave amigadave com>
Date:   Thu Feb 19 18:34:56 2015 +0000

    Add et_application_window_update_et_file_from_ui()
    
    Refactor existing code, which directly called
    ET_Save_File_Data_From_UI() against ETCore->ETFileDisplayed, to instead
    call the new function. Additionally, handle the case that
    ETCore->ETFileDisplayed is NULL, and do not call the function, avoiding
    triggering an invariant check.

 src/application_window.c |   64 ++++++++++++++++++++--------------------------
 src/application_window.h |    1 +
 src/browser.c            |   17 +++++-------
 src/cddb_dialog.c        |    3 +-
 src/easytag.c            |    3 +-
 src/load_files_dialog.c  |    3 +-
 src/scan_dialog.c        |    5 +--
 src/tag_area.c           |    9 +++---
 8 files changed, 46 insertions(+), 59 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index 7a84885..c393674 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -428,8 +428,7 @@ on_invert_selection (GSimpleAction *action,
 
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     et_browser_invert_selection (ET_BROWSER (priv->browser));
     et_application_window_update_actions (self);
@@ -462,8 +461,7 @@ on_delete (GSimpleAction *action,
     self = ET_APPLICATION_WINDOW (user_data);
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Number of files to save */
     selection = et_application_window_browser_get_selection (self);
@@ -610,8 +608,7 @@ on_undo_file_changes (GSimpleAction *action,
     self = ET_APPLICATION_WINDOW (user_data);
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     selection = et_application_window_browser_get_selection (self);
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
@@ -653,8 +650,7 @@ on_redo_file_changes (GSimpleAction *action,
     self = ET_APPLICATION_WINDOW (user_data);
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (user_data));
     selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
@@ -738,8 +734,7 @@ on_select_all (GSimpleAction *action,
                                                  focused))
     /* Assume that other widgets should select all in the file view. */
     {
-        /* Save the current displayed data */
-        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+        et_application_window_update_et_file_from_ui (self);
 
         et_browser_select_all (ET_BROWSER (priv->browser));
         et_application_window_update_actions (self);
@@ -774,8 +769,7 @@ on_unselect_all (GSimpleAction *action,
                                                    focused))
     /* Assume that other widgets should unselect all in the file view. */
     {
-        /* Save the current displayed data */
-        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+        et_application_window_update_et_file_from_ui (self);
 
         et_browser_unselect_all (ET_BROWSER (priv->browser));
 
@@ -795,8 +789,7 @@ on_undo_last_changes (GSimpleAction *action,
 
     g_return_if_fail (ETCore->ETFileList != NULL);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     ETFile = ET_Undo_History_File_Data ();
 
@@ -823,8 +816,7 @@ on_redo_last_changes (GSimpleAction *action,
 
     g_return_if_fail (ETCore->ETFileDisplayedList != NULL);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     ETFile = ET_Redo_History_File_Data ();
 
@@ -860,8 +852,7 @@ on_remove_tags (GSimpleAction *action,
     self = ET_APPLICATION_WINDOW (user_data);
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Initialize status bar */
     et_application_window_progress_set_fraction (self, 0.0);
@@ -1002,8 +993,7 @@ on_file_artist_view_change (GSimpleAction *action,
 
     g_return_if_fail (ETCore->ETFileDisplayedList != NULL);
 
-    /* Save the current displayed data. */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     if (strcmp (state, "file") == 0)
     {
@@ -1275,8 +1265,7 @@ on_go_first (GSimpleAction *action,
     if (!ETCore->ETFileDisplayedList)
         return;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Go to the first item of the list */
     etfilelist = ET_Displayed_File_List_First ();
@@ -1315,8 +1304,7 @@ on_go_previous (GSimpleAction *action,
     if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->prev)
         return;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Go to the prev item of the list */
     etfilelist = ET_Displayed_File_List_Previous ();
@@ -1354,8 +1342,7 @@ on_go_next (GSimpleAction *action,
     if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->next)
         return;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Go to the next item of the list */
     etfilelist = ET_Displayed_File_List_Next ();
@@ -1393,8 +1380,7 @@ on_go_last (GSimpleAction *action,
     if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->next)
         return;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Go to the last item of the list */
     etfilelist = ET_Displayed_File_List_Last ();
@@ -1997,8 +1983,7 @@ et_application_window_select_file_by_et_file (EtApplicationWindow *self,
     if (!ETCore->ETFileDisplayedList)
         return;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     /* Display the item */
     et_application_window_browser_select_file_by_et_file (self, ETFile, TRUE);
@@ -2010,6 +1995,17 @@ et_application_window_select_file_by_et_file (EtApplicationWindow *self,
     et_application_window_scan_dialog_update_previews (self);
 }
 
+void
+et_application_window_update_et_file_from_ui (EtApplicationWindow *self)
+{
+    /* Save the current displayed data */
+    if (ETCore->ETFileDisplayed)
+    {
+        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    }
+
+}
+
 const gchar *
 et_application_window_get_current_path (EtApplicationWindow *self)
 {
@@ -2594,8 +2590,7 @@ et_application_window_browser_unselect_all (EtApplicationWindow *self)
 
     priv = et_application_window_get_instance_private (self);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (self);
 
     et_browser_unselect_all (ET_BROWSER (priv->browser));
     ETCore->ETFileDisplayed = NULL;
@@ -2655,10 +2650,7 @@ et_application_window_quit (EtApplicationWindow *self)
     gint response;
 
     /* If you change the displayed data and quit immediately */
-    if (ETCore->ETFileList)
-    {
-        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
-    }
+    et_application_window_update_et_file_from_ui (self);
 
     /* Check if all files have been saved before exit */
     if (g_settings_get_boolean (MainSettings, "confirm-when-unsaved-files")
diff --git a/src/application_window.h b/src/application_window.h
index 2a3a623..14173da 100644
--- a/src/application_window.h
+++ b/src/application_window.h
@@ -81,6 +81,7 @@ GtkTreeSelection * et_application_window_browser_get_selection (EtApplicationWin
 GtkTreeViewColumn *et_application_window_browser_get_column_for_column_id (EtApplicationWindow *self, gint 
column_id);
 GtkSortType et_application_window_browser_get_sort_order_for_column_id (EtApplicationWindow *self, gint 
column_id);
 void et_application_window_browser_select_file_by_iter_string (EtApplicationWindow *self, const gchar 
*iter_string, gboolean select);
+void et_application_window_update_et_file_from_ui (EtApplicationWindow *self);
 void et_application_window_browser_select_file_by_et_file (EtApplicationWindow *self, const ET_File *file, 
gboolean select);
 GtkTreePath * et_application_window_browser_select_file_by_et_file2 (EtApplicationWindow *self, const 
ET_File *file, gboolean select, GtkTreePath *start_path);
 ET_File * et_application_window_browser_select_file_by_dlm (EtApplicationWindow *self, const gchar *string, 
gboolean select);
diff --git a/src/browser.c b/src/browser.c
index a088230..2e226b1 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -845,8 +845,8 @@ Browser_Tree_Node_Selected (EtBrowser *self, GtkTreeSelection *selection)
     if (!pathName)
         return FALSE;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
+
     /* FIXME: Not clean to put this here. */
     et_application_window_update_actions (ET_APPLICATION_WINDOW (MainWindow));
 
@@ -2405,7 +2405,7 @@ Browser_Artist_List_Load_Files (EtBrowser *self, ET_File *etfile_to_select)
         gtk_tree_model_get(GTK_TREE_MODEL(priv->artist_model), &iter,
                            ARTIST_ALBUM_LIST_POINTER, &AlbumList,
                            -1);
-        ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+        et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
         Browser_Album_List_Load_Files (self, AlbumList,NULL);
     }
 }
@@ -2427,8 +2427,7 @@ Browser_Artist_List_Row_Selected (EtBrowser *self, GtkTreeSelection* selection)
     if(!gtk_tree_selection_get_selected(selection, NULL, &iter))
         return; // We might be called with no row selected
 
-    // Save the current displayed data
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
     gtk_tree_model_get (GTK_TREE_MODEL (priv->artist_model), &iter,
                         ARTIST_ALBUM_LIST_POINTER, &AlbumList, -1);
@@ -2634,7 +2633,7 @@ Browser_Album_List_Load_Files (EtBrowser *self,
         gtk_tree_model_get(GTK_TREE_MODEL(priv->album_model), &iter,
                            ALBUM_ETFILE_LIST_POINTER, &etfilelist,
                            -1);
-        ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+        et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
         /* Set the attached list as "Displayed List". */
         et_displayed_file_list_set (etfilelist);
@@ -2665,8 +2664,7 @@ Browser_Album_List_Row_Selected (EtBrowser *self, GtkTreeSelection *selection)
     gtk_tree_model_get (GTK_TREE_MODEL (priv->album_model), &iter,
                        ALBUM_ETFILE_LIST_POINTER, &etfilelist, -1);
 
-    // Save the current displayed data
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
     /* Set the attached list as "Displayed List". */
     et_displayed_file_list_set (etfilelist);
@@ -2734,8 +2732,7 @@ et_browser_set_display_mode (EtBrowser *self,
 
     priv = et_browser_get_instance_private (self);
 
-    /* Save the current displayed data. */
-    ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
     switch (mode)
     {
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index 115de70..6ddbccd 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -2218,8 +2218,7 @@ Cddb_Set_Track_Infos_To_File_List (EtCDDBDialog *self)
 
     priv = et_cddb_dialog_get_instance_private (self);
 
-    // Save the current displayed data
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
     /* FIXME: Hack! */
     file_selection = et_application_window_browser_get_selection (ET_APPLICATION_WINDOW (MainWindow));
diff --git a/src/easytag.c b/src/easytag.c
index f22b661..40bba1d 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -166,8 +166,7 @@ Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files)
     /* Save the current position in the list */
     etfile_save_position = ETCore->ETFileDisplayed;
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (window);
 
     /* Save widget that has current focus, to give it again the focus after saving */
     widget_focused = gtk_window_get_focus(GTK_WINDOW(MainWindow));
diff --git a/src/load_files_dialog.c b/src/load_files_dialog.c
index b05be00..ed34cf8 100644
--- a/src/load_files_dialog.c
+++ b/src/load_files_dialog.c
@@ -91,8 +91,7 @@ Load_Filename_Set_Filenames (EtLoadFilesDialog *self)
     if ( !ETCore->ETFileList || !priv->load_file_content_view || !priv->load_file_name_view)
         return;
 
-    /* Save current file */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
 
     rowcount = MIN(gtk_tree_model_iter_n_children(GTK_TREE_MODEL(priv->load_file_name_model), NULL),
                    gtk_tree_model_iter_n_children(GTK_TREE_MODEL(priv->load_file_content_model), NULL));
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 86eef88..7543bf7 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -2903,11 +2903,10 @@ et_scan_dialog_scan_selected_files (EtScanDialog *self)
 
     g_return_if_fail (ETCore->ETFileDisplayedList != NULL);
 
-    /* Save the current displayed data */
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    window = ET_APPLICATION_WINDOW (MainWindow);
+    et_application_window_update_et_file_from_ui (window);
 
     /* Initialize status bar */
-    window = ET_APPLICATION_WINDOW (MainWindow);
     selection = et_application_window_browser_get_selection (window);
     selectcount = gtk_tree_selection_count_selected_rows (selection);
     et_application_window_progress_set_fraction (window, 0.0);
diff --git a/src/tag_area.c b/src/tag_area.c
index fd19885..bc1ad96 100644
--- a/src/tag_area.c
+++ b/src/tag_area.c
@@ -150,8 +150,7 @@ on_apply_to_selection (GObject *object,
 
     window = ET_APPLICATION_WINDOW (MainWindow);
 
-    // Save the current displayed data
-    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
+    et_application_window_update_et_file_from_ui (window);
 
     /* Warning : 'selection_filelist' is not a list of 'ETFile' items! */
     selection = et_application_window_browser_get_selection (window);
@@ -1555,9 +1554,10 @@ on_picture_add_button_clicked (GObject *object,
         init_dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow));
     }
 
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
+
     if (ETCore->ETFileDisplayed)
     {
-        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
         ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
     }
 
@@ -2054,9 +2054,10 @@ on_picture_clear_button_clicked (GObject *object,
         gtk_tree_row_reference_free (l->data);
     }
 
+    et_application_window_update_et_file_from_ui (ET_APPLICATION_WINDOW (MainWindow));
+
     if (ETCore->ETFileDisplayed)
     {
-        ET_Save_File_Data_From_UI (ETCore->ETFileDisplayed);
         ET_Display_File_Data_To_UI (ETCore->ETFileDisplayed);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]