Skip to content

Commit 0e2c5e2

Browse files
committed
feat: make show hidden files effect immedeatly
1 parent 2de2ca9 commit 0e2c5e2

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/headerbar.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use gtk4::prelude::*;
44
use gtk4::{Box as GtkBox, MenuButton, ApplicationWindow, Application};
55
use std::cell::RefCell;
66
use std::rc::Rc;
7-
use gtk4::glib;
7+
use gtk4::{glib, gio};
8+
use crate::files_panel;
89

910
pub fn build_headerbar() -> GtkBox {
1011
let headerbar = GtkBox::new(gtk4::Orientation::Horizontal, 6);
@@ -37,16 +38,24 @@ pub fn build_headerbar() -> GtkBox {
3738
headerbar
3839
}
3940

40-
pub fn implement_actions(window: &ApplicationWindow, app: &Application, fmstate: Rc<RefCell<FmState>>) {
41+
pub fn implement_actions(window: &ApplicationWindow, app: &Application, fmstate: Rc<RefCell<FmState>>, files_list: &gtk4::StringList) {
4142
// Show Hidden Files action
4243
let show_hidden_initial = fmstate.borrow().settings.show_hidden;
4344
let show_hidden_action =
4445
SimpleAction::new_stateful("show_hidden", None, &show_hidden_initial.into());
4546

46-
show_hidden_action.connect_activate(glib::clone!(#[strong] fmstate, move |action, _| {
47+
show_hidden_action.connect_activate(glib::clone!(#[strong] fmstate, #[weak] files_list, move |action, _| {
4748
let current: bool = action.state().unwrap().get().unwrap();
4849
action.set_state(&(!current).into());
49-
fmstate.borrow_mut().settings.show_hidden = !current;
50+
51+
let mut fmstate_mut = fmstate.borrow_mut();
52+
fmstate_mut.settings.show_hidden = !current;
53+
54+
files_panel::populate_files_list(
55+
&files_list,
56+
&fmstate_mut.current_path,
57+
&fmstate_mut.settings.show_hidden,
58+
);
5059
}));
5160

5261
window.add_action(&show_hidden_action);

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ fn build_fm(app: &Application) {
3737
let home_path = gio::File::for_path(glib::home_dir());
3838
let fmstate = Rc::new(RefCell::new(state::FmState::new(home_path.clone())));
3939

40-
// implement all actions for the headerbar
41-
headerbar::implement_actions(&window, &app, fmstate.clone());
42-
4340
let (files_scroll, files_list, list_view) = files_panel::build_files_panel(fmstate.clone());
4441
let (sidebar_box, sidebar_selection) = sidebar::build_sidebar(fmstate.clone(), &files_list);
4542
let path_bar = pathbar::build_pathbar(&mut fmstate.borrow_mut());
@@ -49,6 +46,9 @@ fn build_fm(app: &Application) {
4946
let file_area_menu =
5047
popup_menu::get_file_right_click(&content_area, fmstate.clone(), &files_list);
5148

49+
// implement all actions for the headerbar
50+
headerbar::implement_actions(&window, &app, fmstate.clone(), &files_list);
51+
5252
files_panel::populate_files_list(
5353
&files_list,
5454
&home_path,

0 commit comments

Comments
 (0)