[easytag] Make the file list treeview sortable, bug 694310
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Make the file list treeview sortable, bug 694310
- Date: Sat, 4 May 2013 14:09:43 +0000 (UTC)
commit f33d4af3b7498fa4a4f0d9188a6d92add56663be
Author: DarshanMn <darshan trin gmail com>
Date: Sat May 4 18:52:45 2013 +0530
Make the file list treeview sortable, bug 694310
When a column header is clicked, the file list gets sorted by the
contents of that column and the sort order option in the preferences
dialogue gets automatically updated and vice-versa.
src/browser.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/browser.h | 2 +
src/et_core.c | 54 ++++++++++++++++++++++++++++++++-
src/setting.c | 41 ++++++++++++++++++++++++-
4 files changed, 186 insertions(+), 4 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index ce97f24..c85b296 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -209,6 +209,9 @@ static void et_run_program_list_on_response (GtkDialog *dialog,
gint response_id,
gpointer user_data);
+static void et_browser_set_sorting_file_mode (GtkTreeViewColumn *column,
+ gpointer data);
+
/*************
* Functions *
@@ -3485,6 +3488,7 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
/* Add columns to tree view. See ET_FILE_LIST_COLUMN. */
for (i = 0; i <= LIST_FILE_ENCODED_BY; i++)
{
+ guint ascending_sort = 2 * i;
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
@@ -3498,6 +3502,10 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
LIST_ROW_FOREGROUND, NULL);
gtk_tree_view_column_set_resizable (column, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW (BrowserList), column);
+ gtk_tree_view_column_set_clickable (column, TRUE);
+ g_signal_connect (column, "clicked",
+ G_CALLBACK (et_browser_set_sorting_file_mode),
+ GINT_TO_POINTER (ascending_sort));
}
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(BrowserList), FALSE);
@@ -3505,7 +3513,8 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
// When selecting a line
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)),
Browser_List_Select_Func, NULL, NULL);
// To sort list
- //gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(fileListModel), 0, Browser_List_Sort_Func, NULL,
NULL);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (fileListModel), 0,
+ Browser_List_Sort_Func, NULL, NULL);
Browser_List_Refresh_Sort();
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(fileListModel), 0, GTK_SORT_ASCENDING);
@@ -3545,6 +3554,59 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
return VerticalBox;
}
+/*
+ * et_browser_set_sorting_file_mode:
+ * @column: the tree view column to sort
+ * @data: the (required) #ET_Sorting_Type, converted to a pointer with
+ * #GINT_TO_POINTER
+ *
+ * Set the #SORTING_FILE_MODE and display appropriate sort indicator when
+ * column is clicked.
+ */
+static void
+et_browser_set_sorting_file_mode (GtkTreeViewColumn *column, gpointer data)
+{
+ gint column_id = SORTING_FILE_MODE / 2;
+
+ if (gtk_tree_view_column_get_sort_indicator (column) == FALSE
+ && SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+ {
+ if (get_sort_order_for_column_id (SORTING_FILE_MODE / 2) == GTK_SORT_DESCENDING)
+ {
+ gtk_tree_view_column_set_sort_order (get_column_for_column_id (column_id),
+ GTK_SORT_ASCENDING);
+ }
+ gtk_tree_view_column_set_sort_indicator (get_column_for_column_id (column_id),
+ FALSE);
+ }
+ else if (gtk_tree_view_column_get_sort_order (column) == GTK_SORT_ASCENDING)
+ {
+ gtk_tree_view_column_set_sort_order (column, GTK_SORT_DESCENDING);
+ }
+ else
+ {
+ gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
+ }
+
+ if (SORTING_FILE_MODE > SORTING_BY_DESCENDING_ENCODED_BY)
+ {
+ gtk_tree_view_column_set_sort_indicator (column, TRUE);
+ gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
+ }
+
+ if (gtk_tree_view_column_get_sort_order (column) == GTK_SORT_ASCENDING)
+ {
+ SORTING_FILE_MODE = GPOINTER_TO_INT (data);
+ }
+ else
+ {
+ SORTING_FILE_MODE = GPOINTER_TO_INT (data) + 1;
+ }
+
+ gtk_tree_view_column_set_sort_indicator (column, TRUE);
+
+ Browser_List_Refresh_Sort ();
+}
/*
@@ -4513,3 +4575,32 @@ et_run_program_list_on_response (GtkDialog *dialog, gint response_id,
g_assert_not_reached ();
}
}
+
+/*
+ * get_sort_order_for_column_id:
+ * @column_id: the column ID for which to set the sort order
+ *
+ * Gets the sort order for the given column ID from the browser list treeview
+ * column.
+ *
+ * Returns: the sort order for @column_id
+ */
+GtkSortType
+get_sort_order_for_column_id (gint column_id)
+{
+ return gtk_tree_view_column_get_sort_order (get_column_for_column_id (column_id));
+}
+
+/*
+ * get_column_for_column_id:
+ * @column_id: the column ID of the #GtkTreeViewColumn to fetch
+ *
+ * Gets the browser list treeview column for the given column ID.
+ *
+ * Returns: (transfer none): the tree view column corresponding to @column_id
+ */
+GtkTreeViewColumn *
+get_column_for_column_id (gint column_id)
+{
+ return gtk_tree_view_get_column (GTK_TREE_VIEW (BrowserList), column_id);
+}
diff --git a/src/browser.h b/src/browser.h
index 1f9aafd..5c35faa 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -185,5 +185,7 @@ void Browser_Open_Rename_Directory_Window (void);
void Browser_Open_Run_Program_Tree_Window (void);
void Browser_Open_Run_Program_List_Window (void);
+GtkTreeViewColumn *get_column_for_column_id (gint column_id);
+GtkSortType get_sort_order_for_column_id (gint column_id);
#endif /* __BROWSER_H__ */
diff --git a/src/et_core.c b/src/et_core.c
index 1c6ad2a..ec5d837 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -154,6 +154,10 @@ static gint ET_Comp_Func_Sort_Etfile_Item_By_Ascending_Filename (ET_File *ETFile
ET_File *ETFile2);
static gchar *ET_File_Name_Format_Extension (ET_File *ETFile);
+static void set_sort_order_for_column_id (gint column_id,
+ GtkTreeViewColumn *column,
+ ET_Sorting_Type sort_type);
+
/*******************
* Basic functions *
@@ -894,11 +898,14 @@ ET_Sort_Displayed_File_List (ET_Sorting_Type Sorting_Type)
*/
GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
{
+ gint column_id = Sorting_Type / 2;
+
+ GtkTreeViewColumn *column = get_column_for_column_id (column_id);
+
// Important to rewind before
GList *etfilelist = g_list_first(ETFileList);
- // Save sorting mode (note: needed when called from UI)
- SORTING_FILE_MODE = Sorting_Type;
+ set_sort_order_for_column_id (column_id, column, Sorting_Type);
// Sort...
switch (Sorting_Type)
@@ -1037,6 +1044,9 @@ GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
etfilelist =
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Samplerate);
break;
}
+ /* Save sorting mode (note: needed when called from UI). */
+ SORTING_FILE_MODE = Sorting_Type;
+
//ETFileList = g_list_first(etfilelist);
return g_list_first(etfilelist);
}
@@ -4773,3 +4783,43 @@ ET_Get_Number_Of_Files_In_Directory (const gchar *path_utf8)
return count;
}
+
+/*
+ * Set appropriate sort order for the given column_id
+ */
+static void
+set_sort_order_for_column_id (gint column_id, GtkTreeViewColumn *column,
+ ET_Sorting_Type sort_type)
+{
+ /* Removing the sort indicator for the currently selected treeview
+ * column. */
+ if (SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+ {
+ gtk_tree_view_column_set_sort_indicator (get_column_for_column_id (SORTING_FILE_MODE / 2),
+ FALSE);
+ }
+
+ if (sort_type < SORTING_BY_ASCENDING_CREATION_DATE)
+ {
+ gtk_tree_view_column_clicked (get_column_for_column_id (column_id));
+
+ if (sort_type % 2 == 0)
+ {
+ /* GTK_SORT_ASCENDING */
+ if (get_sort_order_for_column_id (column_id) == GTK_SORT_DESCENDING)
+ {
+ gtk_tree_view_column_set_sort_order (column,
+ GTK_SORT_ASCENDING);
+ }
+ }
+ else
+ {
+ /* GTK_SORT_DESCENDING */
+ if (get_sort_order_for_column_id (column_id) == GTK_SORT_ASCENDING)
+ {
+ gtk_tree_view_column_set_sort_order (column,
+ GTK_SORT_DESCENDING);
+ }
+ }
+ }
+}
diff --git a/src/setting.c b/src/setting.c
index c9fc3c9..4f3d8eb 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -42,6 +42,7 @@
#include "misc.h"
#include "cddb.h"
#include "browser.h"
+#include "et_core.h"
#include "win32/win32dep.h"
@@ -99,6 +100,9 @@ static const gchar CDDB_LOCAL_PATH_HISTORY_FILE[] = "cddb_local_path.history";
static void Save_Config_To_File (void);
static gboolean Create_Easytag_Directory (void);
+static void set_sorting_indicator_for_column_id (gint column_id,
+ ET_Sorting_Type temp_sort,
+ GtkTreeViewColumn *column);
@@ -632,6 +636,9 @@ Apply_Changes_Of_Preferences_Window (void)
{
gchar *temp;
int active;
+ ET_Sorting_Type temp_sort;
+ gint column_id;
+ GtkTreeViewColumn * column;
if (OptionsWindow)
{
@@ -668,7 +675,19 @@ Apply_Changes_Of_Preferences_Window (void)
LOG_MAX_LINES =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(LogMaxLinesSpinButton));
SHOW_LOG_VIEW =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ShowLogView));
- SORTING_FILE_MODE = gtk_combo_box_get_active(GTK_COMBO_BOX(SortingFileCombo));
+ temp_sort = gtk_combo_box_get_active (GTK_COMBO_BOX (SortingFileCombo));
+ column_id = temp_sort / 2;
+ if (SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+ {
+ gtk_tree_view_column_set_sort_indicator (get_column_for_column_id (SORTING_FILE_MODE / 2),
+ FALSE);
+ }
+ if (temp_sort < SORTING_BY_ASCENDING_CREATION_DATE)
+ {
+ column = get_column_for_column_id (column_id);
+ set_sorting_indicator_for_column_id (column_id, temp_sort, column);
+ }
+ SORTING_FILE_MODE = temp_sort;
Browser_List_Refresh_Sort ();
if (AUDIO_FILE_PLAYER) g_free(AUDIO_FILE_PLAYER);
@@ -1578,3 +1597,23 @@ Create_Easytag_Directory (void)
return TRUE;
}
}
+
+static void
+set_sorting_indicator_for_column_id (gint column_id,
+ ET_Sorting_Type temp_sort,
+ GtkTreeViewColumn *column)
+{
+ GtkSortType current_sort;
+ GtkSortType sort_type;
+
+ gtk_tree_view_column_clicked (column);
+
+ current_sort = get_sort_order_for_column_id (column_id);
+
+ sort_type = temp_sort % 2 == 0 ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
+
+ if (sort_type != current_sort)
+ {
+ gtk_tree_view_column_clicked (column);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]