implement on_ready callback

This commit is contained in:
yggverse 2025-02-15 00:47:45 +02:00
parent df9e039dd2
commit 1c6e676557
3 changed files with 52 additions and 25 deletions

View File

@ -7,20 +7,33 @@ pub struct Directory {
impl Directory {
pub fn handle(&self, page: &Rc<super::Page>) {
page.content.to_directory(&self.file, {
let page = page.clone();
move |file| {
page.item_action.load.activate(
Some(&format!(
"file://{}",
file.path().unwrap().to_str().unwrap()
)),
true,
)
}
});
page.content.to_directory(
&self.file,
(
// on ready
{
let page = page.clone();
move || {
page.set_progress(0.0);
}
},
// on activate
{
let page = page.clone();
move |file| {
page.item_action.load.activate(
Some(&format!(
"file://{}",
file.path().unwrap().to_str().unwrap()
)),
true,
)
}
},
),
);
page.set_title(&self.file.parse_name());
page.set_progress(0.0);
page.window_action.find.simple_action.set_enabled(false);
}
}

View File

@ -131,7 +131,11 @@ impl Content {
text
}
pub fn to_directory(&self, file: &File, callback: impl Fn(&File) + 'static) {
pub fn to_directory(
&self,
file: &File,
callback: (impl Fn() + 'static, impl Fn(&File) + 'static),
) {
self.clean();
self.g_box.append(&Directory::for_file(file, callback))
}

View File

@ -7,27 +7,31 @@ pub struct Directory; // @TODO save settings
impl Directory {
// Constructors
pub fn for_file(file: &File, callback: impl Fn(&File) + 'static) -> ScrolledWindow {
pub fn for_file(
file: &File,
(on_ready, on_activate): (impl Fn() + 'static, impl Fn(&File) + 'static),
) -> ScrolledWindow {
use column::Column;
use gtk::gio::FileInfo;
// Init model
const ATTRIBUTES: &str =
"standard::display-name,standard::symbolic-icon,standard::size,standard::content-type,standard::modification-date-time";
let directory_list = gtk::DirectoryList::builder()
.file(file)
.attributes(ATTRIBUTES)
.build();
// Init children widget
let column_view = {
const ATTRIBUTES: &str =
"standard::display-name,standard::symbolic-icon,standard::size,standard::content-type,standard::modification-date-time";
let column_view = gtk::ColumnView::builder()
// @TODO implement profile save .reorderable(true)
// @TODO enable this option may cause core dumped errors
// .single_click_activate(true)
.model(
&gtk::SingleSelection::builder()
.model(
&gtk::DirectoryList::builder()
.file(file)
.attributes(ATTRIBUTES)
.build(),
)
.model(&directory_list)
.build(),
)
.build();
@ -49,9 +53,15 @@ impl Directory {
};
// Connect events
directory_list.connect_loading_notify(move |this| {
if !this.is_loading() {
on_ready()
}
});
column_view.connect_activate(move |this, i| {
use gtk::prelude::{Cast, ListModelExt};
callback(
on_activate(
this.model()
.unwrap()
.item(i)