Index: docs/README.thunarrc =================================================================== --- docs/README.thunarrc (revision 26590) +++ docs/README.thunarrc (working copy) @@ -215,6 +215,11 @@ Controls whether the icon view should display the file names beside the file icons instead of below the file icons. + + * MiscVersionCompare (FALSE/TRUE) + + Determines whether numbers in names should be sorted in the "right" + order. The default is TRUE. * ShortcutsIconEmblems (FALSE/TRUE) Index: thunar/thunar-file.c =================================================================== --- thunar/thunar-file.c (revision 26590) +++ thunar/thunar-file.c (working copy) @@ -1907,7 +1907,7 @@ /* determine the numbers in ap and bp */ anum = strtoul (ap, NULL, 10); bnum = strtoul (bp, NULL, 10); - + /* compare the numbers */ if (anum < bnum) return -1; @@ -1925,12 +1925,16 @@ /** * thunar_file_compare_by_name: - * @file_a : the first #ThunarFile. - * @file_b : the second #ThunarFile. - * @case_sensitive : whether the comparison should be case-sensitive. + * @file_a : the first #ThunarFile. + * @file_b : the second #ThunarFile. + * @case_sensitive : whether the comparison should be case-sensitive. + * @version_compare : whether to sort names with numbers in the "right" + * order. * * Compares @file_a and @file_b by their display names. If @case_sensitive * is %TRUE the comparison will be case-sensitive. + * If @version_compare is %TRUE, names with number will be sorted in the + * "right" order. So jan9 before jan10. * * Return value: -1 if @file_a should be sorted before @file_b, 1 if * @file_b should be sorted before @file_a, 0 if equal. @@ -1938,7 +1942,8 @@ gint thunar_file_compare_by_name (const ThunarFile *file_a, const ThunarFile *file_b, - gboolean case_sensitive) + gboolean case_sensitive, + gboolean version_compare) { const gchar *ap; const gchar *bp; @@ -2014,7 +2019,7 @@ return 0; /* check if one of the characters that differ is a digit */ - if (G_UNLIKELY (g_ascii_isdigit (ac) || g_ascii_isdigit (bc))) + if (G_UNLIKELY (version_compare && (g_ascii_isdigit (ac) || g_ascii_isdigit (bc)))) { /* if both strings differ in a digit, we use a smarter comparison * to get sorting 'file1', 'file5', 'file10' done the right way. Index: thunar/thunar-file.h =================================================================== --- thunar/thunar-file.h (revision 26590) +++ thunar/thunar-file.h (working copy) @@ -193,7 +193,8 @@ gint thunar_file_compare_by_name (const ThunarFile *file_a, const ThunarFile *file_b, - gboolean case_sensitive); + gboolean case_sensitive, + gboolean version_compare); ThunarFile *thunar_file_cache_lookup (const ThunarVfsPath *path); Index: thunar/thunar-list-model.c =================================================================== --- thunar/thunar-list-model.c (revision 26590) +++ thunar/thunar-list-model.c (working copy) @@ -45,6 +45,7 @@ { PROP_0, PROP_CASE_SENSITIVE, + PROP_VERSION_COMPARE, PROP_DATE_STYLE, PROP_FOLDER, PROP_FOLDERS_FIRST, @@ -175,6 +176,9 @@ static gint sort_by_name (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); +static gint sort_by_version (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive); static gint sort_by_owner (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); @@ -233,6 +237,7 @@ guint row_deleted_id; gboolean sort_case_sensitive; + gboolean sort_version_compare; gboolean sort_folders_first; gint sort_sign; /* 1 = ascending, -1 descending */ gint (*sort_func) (const ThunarFile *a, @@ -332,6 +337,19 @@ "case-sensitive", TRUE, EXO_PARAM_READWRITE)); + + /** + * ThunarListModel:version-compare: + * + * Tells whether the sorting should be in the "right" number order. + **/ + g_object_class_install_property (gobject_class, + PROP_VERSION_COMPARE, + g_param_spec_boolean ("version-compare", + "version-compare", + "version-compare", + TRUE, + EXO_PARAM_READWRITE)); /** * ThunarListModel:date-style: @@ -519,6 +537,10 @@ case PROP_CASE_SENSITIVE: g_value_set_boolean (value, thunar_list_model_get_case_sensitive (store)); break; + + case PROP_VERSION_COMPARE: + g_value_set_boolean (value, thunar_list_model_get_version_compare (store)); + break; case PROP_DATE_STYLE: g_value_set_enum (value, thunar_list_model_get_date_style (store)); @@ -561,6 +583,10 @@ case PROP_CASE_SENSITIVE: thunar_list_model_set_case_sensitive (store, g_value_get_boolean (value)); break; + + case PROP_VERSION_COMPARE: + thunar_list_model_set_version_compare (store, g_value_get_boolean (value)); + break; case PROP_DATE_STYLE: thunar_list_model_set_date_style (store, g_value_get_enum (value)); @@ -923,7 +949,7 @@ if (store->sort_func == sort_by_mime_type) *sort_column_id = THUNAR_COLUMN_MIME_TYPE; - else if (store->sort_func == sort_by_name) + else if (store->sort_func == sort_by_name || store->sort_func == sort_by_version) *sort_column_id = THUNAR_COLUMN_NAME; else if (store->sort_func == sort_by_file_name) *sort_column_id = THUNAR_COLUMN_FILE_NAME; @@ -985,7 +1011,10 @@ break; case THUNAR_COLUMN_NAME: - store->sort_func = sort_by_name; + if (store->sort_version_compare) + store->sort_func = sort_by_version; + else + store->sort_func = sort_by_name; break; case THUNAR_COLUMN_OWNER: @@ -1516,12 +1545,22 @@ const ThunarFile *b, gboolean case_sensitive) { - return thunar_file_compare_by_name (a, b, case_sensitive); + return thunar_file_compare_by_name (a, b, case_sensitive, FALSE); } static gint +sort_by_version (const ThunarFile *a, + const ThunarFile *b, + gboolean case_sensitive) +{ + return thunar_file_compare_by_name (a, b, case_sensitive, TRUE); +} + + + +static gint sort_by_owner (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive) @@ -1691,6 +1730,63 @@ /** + * thunar_list_model_get_version_compare: + * @store : a valid #ThunarListModel object. + * + * Returns %TRUE if the sorting is done in the "right" number order. + * + * Return value: %TRUE if sorting is version sensitive. + **/ +gboolean +thunar_list_model_get_version_compare (ThunarListModel *store) +{ + _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); + return store->sort_version_compare; +} + + + +/** + * thunar_list_model_set_version_compare: + * @store : a valid #ThunarListModel object. + * @version_compare : %TRUE to sort in the "righ" number order. + * + * If @version_compare is %TRUE the sorting in @store will be done + * in the "right" number order. + **/ +void +thunar_list_model_set_version_compare (ThunarListModel *store, + gboolean version_compare) +{ + gint sort_column_id; + GtkSortType sort_order; + + _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); + + /* normalize the setting */ + version_compare = !!version_compare; + + /* check if we have a new setting */ + if (store->sort_version_compare != version_compare) + { + /* apply the new setting */ + store->sort_version_compare = version_compare; + + /* update the sort function */ + thunar_list_model_get_sort_column_id (GTK_TREE_SORTABLE (store), &sort_column_id, &sort_order); + thunar_list_model_set_sort_column_id (GTK_TREE_SORTABLE (store), sort_column_id, sort_order); + + /* resort the model with the new setting */ + thunar_list_model_sort (store); + + /* notify listeners */ + g_object_notify (G_OBJECT (store), "version-compare"); + } +} + + + +/** * thunar_list_model_get_date_style: * @store : a valid #ThunarListModel object. * Index: thunar/thunar-list-model.h =================================================================== --- thunar/thunar-list-model.h (revision 26590) +++ thunar/thunar-list-model.h (working copy) @@ -42,6 +42,10 @@ gboolean thunar_list_model_get_case_sensitive (ThunarListModel *store); void thunar_list_model_set_case_sensitive (ThunarListModel *store, gboolean case_sensitive); + +gboolean thunar_list_model_get_version_compare (ThunarListModel *store); +void thunar_list_model_set_version_compare (ThunarListModel *store, + gboolean version_compare); ThunarDateStyle thunar_list_model_get_date_style (ThunarListModel *store); void thunar_list_model_set_date_style (ThunarListModel *store, Index: thunar/thunar-preferences.c =================================================================== --- thunar/thunar-preferences.c (revision 26590) +++ thunar/thunar-preferences.c (working copy) @@ -80,6 +80,7 @@ PROP_MISC_SINGLE_CLICK, PROP_MISC_SINGLE_CLICK_TIMEOUT, PROP_MISC_TEXT_BESIDE_ICONS, + PROP_MISC_VERSION_COMPARE, PROP_SHORTCUTS_ICON_EMBLEMS, PROP_SHORTCUTS_ICON_SIZE, PROP_TREE_ICON_EMBLEMS, @@ -463,7 +464,7 @@ "misc-case-sensitive", FALSE, EXO_PARAM_READWRITE)); - + /** * ThunarPreferences:misc-date-style: * @@ -606,6 +607,19 @@ "misc-text-beside-icons", FALSE, EXO_PARAM_READWRITE)); + + /** + * ThunarPreferences:misc-version-compare: + * + * Whether to sort names in the "right" order. + **/ + g_object_class_install_property (gobject_class, + PROP_MISC_VERSION_COMPARE, + g_param_spec_boolean ("misc-version-compare", + "misc-version-compare", + "misc-version-compare", + TRUE, + EXO_PARAM_READWRITE)); /** * ThunarPreferences:shortcuts-icon-emblems: Index: thunar/thunar-standard-view.c =================================================================== --- thunar/thunar-standard-view.c (revision 26590) +++ thunar/thunar-standard-view.c (working copy) @@ -604,6 +604,7 @@ standard_view->model = thunar_list_model_new (); g_signal_connect (G_OBJECT (standard_view->model), "error", G_CALLBACK (thunar_standard_view_error), standard_view); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-case-sensitive", G_OBJECT (standard_view->model), "case-sensitive"); + exo_binding_new (G_OBJECT (standard_view->preferences), "misc-version-compare", G_OBJECT (standard_view->model), "version-compare"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-date-style", G_OBJECT (standard_view->model), "date-style"); exo_binding_new (G_OBJECT (standard_view->preferences), "misc-folders-first", G_OBJECT (standard_view->model), "folders-first"); Index: thunar/thunar-tree-model.c =================================================================== --- thunar/thunar-tree-model.c (revision 26590) +++ thunar/thunar-tree-model.c (working copy) @@ -48,6 +48,7 @@ { PROP_0, PROP_CASE_SENSITIVE, + PROP_VERSION_COMPARE }; @@ -176,6 +177,7 @@ ThunarFileMonitor *file_monitor; gboolean sort_case_sensitive; + gboolean sort_version_compare; GNode *root; }; @@ -265,6 +267,19 @@ "case-sensitive", TRUE, EXO_PARAM_READWRITE)); + + /** + * ThunarTreeModel:version-compare: + * + * Whether sorting the folder names is done in the "right" number order. + **/ + g_object_class_install_property (gobject_class, + PROP_VERSION_COMPARE, + g_param_spec_boolean ("version-compare", + "version-compare", + "version-compare", + TRUE, + EXO_PARAM_READWRITE)); } @@ -397,6 +412,10 @@ case PROP_CASE_SENSITIVE: g_value_set_boolean (value, thunar_tree_model_get_case_sensitive (model)); break; + + case PROP_VERSION_COMPARE: + g_value_set_boolean (value, thunar_tree_model_get_version_compare (model)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -419,6 +438,10 @@ case PROP_CASE_SENSITIVE: thunar_tree_model_set_case_sensitive (model, g_value_get_boolean (value)); break; + + case PROP_VERSION_COMPARE: + thunar_tree_model_set_version_compare (model, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -823,7 +846,8 @@ /* just sort by name (case-sensitive) */ return thunar_file_compare_by_name (THUNAR_TREE_MODEL_ITEM (((const SortTuple *) a)->node->data)->file, THUNAR_TREE_MODEL_ITEM (((const SortTuple *) b)->node->data)->file, - THUNAR_TREE_MODEL (user_data)->sort_case_sensitive); + THUNAR_TREE_MODEL (user_data)->sort_case_sensitive, + THUNAR_TREE_MODEL (user_data)->sort_version_compare); } @@ -1634,10 +1658,11 @@ model = g_object_new (THUNAR_TYPE_TREE_MODEL, NULL); g_object_add_weak_pointer (G_OBJECT (model), (gpointer) &model); - /* synchronize the the global "misc-case-sensitive" preference */ + /* synchronize the the global "misc-case-sensitive" and "misc-version-compare" preference */ preferences = thunar_preferences_get (); g_object_set_data_full (G_OBJECT (model), I_("thunar-preferences"), preferences, g_object_unref); exo_binding_new (G_OBJECT (preferences), "misc-case-sensitive", G_OBJECT (model), "case-sensitive"); + exo_binding_new (G_OBJECT (preferences), "misc-version-compare", G_OBJECT (model), "version-compare"); } else { @@ -1699,3 +1724,54 @@ } } + + +/** + * thunar_tree_model_get_version_compare: + * @model : a #ThunarTreeModel. + * + * Returns %TRUE if the sorting for @model is done + * in a case-sensitive manner. + * + * Return value: %TRUE if number are sorted in the "right" order. + **/ +gboolean +thunar_tree_model_get_version_compare (ThunarTreeModel *model) +{ + _thunar_return_val_if_fail (THUNAR_IS_TREE_MODEL (model), FALSE); + return model->sort_version_compare; +} + + + +/** + * thunar_tree_model_set_version_compare: + * @model : a #ThunarTreeModel. + * @version_compare : %TRUE to sort number in the @model in the "right" order. + * + * If @version_compare is %TRUE the name numbers in the @model will be sorted + * in the "right" order. + **/ +void +thunar_tree_model_set_version_compare (ThunarTreeModel *model, + gboolean version_compare) +{ + _thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model)); + + /* normalize the setting */ + version_compare = !!version_compare; + + /* check if we have a new setting */ + if (model->sort_version_compare != version_compare) + { + /* apply the new setting */ + model->sort_version_compare = version_compare; + + /* resort the model with the new setting */ + g_node_traverse (model->root, G_POST_ORDER, G_TRAVERSE_NON_LEAVES, -1, thunar_tree_model_node_traverse_sort, model); + + /* notify listeners */ + g_object_notify (G_OBJECT (model), "version-compare"); + } +} + Index: thunar/thunar-tree-model.h =================================================================== --- thunar/thunar-tree-model.h (revision 26590) +++ thunar/thunar-tree-model.h (working copy) @@ -53,14 +53,18 @@ THUNAR_TREE_MODEL_N_COLUMNS, } ThunarTreeModelColumn; -GType thunar_tree_model_get_type (void) G_GNUC_CONST; +GType thunar_tree_model_get_type (void) G_GNUC_CONST; -ThunarTreeModel *thunar_tree_model_get_default (void); +ThunarTreeModel *thunar_tree_model_get_default (void); -gboolean thunar_tree_model_get_case_sensitive (ThunarTreeModel *model); -void thunar_tree_model_set_case_sensitive (ThunarTreeModel *model, - gboolean case_sensitive); +gboolean thunar_tree_model_get_case_sensitive (ThunarTreeModel *model); +void thunar_tree_model_set_case_sensitive (ThunarTreeModel *model, + gboolean case_sensitive); +gboolean thunar_tree_model_get_version_compare (ThunarTreeModel *model); +void thunar_tree_model_set_version_compare (ThunarTreeModel *model, + gboolean version_compare); + G_END_DECLS; #endif /* !__THUNAR_TREE_MODEL_H__ */