@@ -13,6 +13,7 @@ use gtk4::{Application, ApplicationWindow, Box as GtkBox, GestureClick, Orientat
1313use std:: cell:: RefCell ;
1414use std:: path:: PathBuf ;
1515use std:: rc:: Rc ;
16+ use gtk4:: gio:: SimpleAction ;
1617
1718const APP_ID : & str = "org.filemanager.axfm" ;
1819
@@ -38,6 +39,17 @@ fn build_fm(app: &Application) {
3839 let home_path = dirs:: home_dir ( ) . unwrap_or ( PathBuf :: from ( "/" ) ) . join ( "" ) ;
3940 let fmstate = Rc :: new ( RefCell :: new ( state:: FmState :: new ( home_path. clone ( ) ) ) ) ;
4041
42+ // TODO: Move it to its own module
43+ let initial = fmstate. borrow ( ) . settings . show_hidden ;
44+ let show_hidden_action = SimpleAction :: new_stateful ( "show_hidden" , None , & initial. into ( ) ) ;
45+
46+ show_hidden_action. connect_activate ( glib:: clone!( #[ strong] fmstate, move |action, _| {
47+ let current: bool = action. state( ) . unwrap( ) . get( ) . unwrap( ) ;
48+ action. set_state( & ( !current) . into( ) ) ;
49+ fmstate. borrow_mut( ) . settings. show_hidden = !current;
50+ } ) ) ;
51+ window. add_action ( & show_hidden_action) ;
52+
4153 let ( files_scroll, files_list, list_view) = files_panel:: build_files_panel ( fmstate. clone ( ) ) ;
4254 let ( sidebar_box, sidebar_selection) = sidebar:: build_sidebar ( fmstate. clone ( ) , & files_list) ;
4355 let path_bar = pathbar:: build_pathbar ( & mut fmstate. borrow_mut ( ) ) ;
@@ -47,7 +59,11 @@ fn build_fm(app: &Application) {
4759 let file_area_menu =
4860 popup_menu:: get_file_right_click ( & content_area, fmstate. clone ( ) , & files_list) ;
4961
50- files_panel:: populate_files_list ( & files_list, & home_path) ;
62+ files_panel:: populate_files_list (
63+ & files_list,
64+ & home_path,
65+ & fmstate. borrow ( ) . settings . show_hidden ,
66+ ) ;
5167
5268 sidebar_selection. connect_selected_notify ( glib:: clone!(
5369 #[ weak]
@@ -71,15 +87,13 @@ fn build_fm(app: &Application) {
7187 ] ;
7288
7389 if let Some ( path) = paths. get( idx as usize ) {
74- while files_list. n_items( ) > 0 {
75- files_list. remove( 0 ) ;
76- }
77- if let Ok ( entries) = std:: fs:: read_dir( path) {
78- for entry in entries. flatten( ) {
79- files_list. append( & entry. path( ) . to_string_lossy( ) ) ;
80- }
81- }
82- fmstate. borrow_mut( ) . set_path( path. clone( ) ) ;
90+ let mut fmstate_mut = fmstate. borrow_mut( ) ;
91+ files_panel:: populate_files_list(
92+ & files_list,
93+ & path,
94+ & fmstate_mut. settings. show_hidden,
95+ ) ;
96+ fmstate_mut. set_path( path. clone( ) ) ;
8397 }
8498 }
8599 ) ) ;
@@ -89,19 +103,17 @@ fn build_fm(app: &Application) {
89103 files_list,
90104 #[ weak]
91105 sidebar_selection,
106+ #[ strong]
107+ fmstate,
92108 move |widget| {
93109 let path = PathBuf :: from( widget. text( ) ) ;
94- if let Ok ( entries) = std:: fs:: read_dir( path) {
95- while files_list. n_items( ) > 0 {
96- files_list. remove( 0 ) ;
97- }
110+ files_panel:: populate_files_list(
111+ & files_list,
112+ & path,
113+ & fmstate. borrow( ) . settings. show_hidden,
114+ ) ;
98115
99- for entry in entries. flatten( ) {
100- files_list. append( & entry. path( ) . to_string_lossy( ) ) ;
101- }
102-
103- sidebar_selection. unselect_all( ) ;
104- }
116+ sidebar_selection. unselect_all( ) ;
105117 }
106118 ) ) ;
107119
@@ -118,7 +130,11 @@ fn build_fm(app: &Application) {
118130 obj. downcast:: <gtk4:: StringObject >( ) . unwrap( ) . string( ) ,
119131 ) ;
120132 if path. is_dir( ) {
121- files_panel:: populate_files_list( & files_list, & path) ;
133+ files_panel:: populate_files_list(
134+ & files_list,
135+ & path,
136+ & fmstate. borrow( ) . settings. show_hidden,
137+ ) ;
122138 fmstate. borrow_mut( ) . set_path( path. join( "" ) ) ;
123139 sidebar_selection. unselect_all( ) ;
124140 }
0 commit comments