@@ -4,7 +4,8 @@ use slint::{ComponentHandle, Model, ModelRc, VecModel};
4
4
5
5
use crate :: common:: connect_i32_into_u64;
6
6
use crate :: connect_row_selection:: recalculate_small_selection_if_needed;
7
- use crate :: { ActiveTab , Callabler , GuiState , MainListModel , MainWindow , SortMode } ;
7
+ use crate :: connect_translation:: translate_sort_mode;
8
+ use crate :: { ActiveTab , Callabler , GuiState , MainListModel , MainWindow , SortMode , SortModel } ;
8
9
9
10
pub ( crate ) fn connect_sort ( app : & MainWindow ) {
10
11
let a = app. as_weak ( ) ;
@@ -28,6 +29,46 @@ pub(crate) fn connect_sort(app: &MainWindow) {
28
29
} ) ;
29
30
}
30
31
32
+ pub ( crate ) fn connect_showing_proper_sort_buttons ( app : & MainWindow ) {
33
+ set_sort_buttons ( app) ;
34
+ let a = app. as_weak ( ) ;
35
+ app. global :: < Callabler > ( ) . on_tab_changed ( move || {
36
+ let app = a. upgrade ( ) . expect ( "Failed to upgrade app :(" ) ;
37
+ set_sort_buttons ( & app) ;
38
+ } ) ;
39
+ }
40
+
41
+ fn set_sort_buttons ( app : & MainWindow ) {
42
+ let active_tab = app. global :: < GuiState > ( ) . get_active_tab ( ) ;
43
+ let mut base_buttons = vec ! [
44
+ SortMode :: Checked ,
45
+ SortMode :: FullName ,
46
+ SortMode :: ItemName ,
47
+ SortMode :: ModificationDate ,
48
+ SortMode :: ParentName ,
49
+ SortMode :: Reverse ,
50
+ SortMode :: Selection ,
51
+ ] ;
52
+
53
+ let additional_buttons = match active_tab. get_int_size_opt_idx ( ) {
54
+ Some ( _) => vec ! [ SortMode :: Size ] ,
55
+ None => vec ! [ ] ,
56
+ } ;
57
+
58
+ base_buttons. extend ( additional_buttons) ;
59
+ base_buttons. reverse ( ) ;
60
+
61
+ let new_sort_model = base_buttons
62
+ . into_iter ( )
63
+ . map ( |e| SortModel {
64
+ name : translate_sort_mode ( e) ,
65
+ data : e,
66
+ } )
67
+ . collect :: < Vec < _ > > ( ) ;
68
+
69
+ app. global :: < GuiState > ( ) . set_sort_results_list ( ModelRc :: new ( VecModel :: from ( new_sort_model) ) ) ;
70
+ }
71
+
31
72
mod sorts {
32
73
use super :: * ;
33
74
0 commit comments