mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement on_ready callback
This commit is contained in:
parent
df9e039dd2
commit
1c6e676557
3 changed files with 52 additions and 25 deletions
|
|
@ -7,20 +7,33 @@ pub struct Directory {
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
pub fn handle(&self, page: &Rc<super::Page>) {
|
pub fn handle(&self, page: &Rc<super::Page>) {
|
||||||
page.content.to_directory(&self.file, {
|
page.content.to_directory(
|
||||||
let page = page.clone();
|
&self.file,
|
||||||
move |file| {
|
(
|
||||||
page.item_action.load.activate(
|
// on ready
|
||||||
Some(&format!(
|
{
|
||||||
"file://{}",
|
let page = page.clone();
|
||||||
file.path().unwrap().to_str().unwrap()
|
move || {
|
||||||
)),
|
page.set_progress(0.0);
|
||||||
true,
|
}
|
||||||
)
|
},
|
||||||
}
|
// 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_title(&self.file.parse_name());
|
||||||
page.set_progress(0.0);
|
|
||||||
page.window_action.find.simple_action.set_enabled(false);
|
page.window_action.find.simple_action.set_enabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,11 @@ impl Content {
|
||||||
text
|
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.clean();
|
||||||
self.g_box.append(&Directory::for_file(file, callback))
|
self.g_box.append(&Directory::for_file(file, callback))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,27 +7,31 @@ pub struct Directory; // @TODO save settings
|
||||||
impl Directory {
|
impl Directory {
|
||||||
// Constructors
|
// 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 column::Column;
|
||||||
use gtk::gio::FileInfo;
|
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
|
// Init children widget
|
||||||
let column_view = {
|
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()
|
let column_view = gtk::ColumnView::builder()
|
||||||
// @TODO implement profile save .reorderable(true)
|
// @TODO implement profile save .reorderable(true)
|
||||||
// @TODO enable this option may cause core dumped errors
|
// @TODO enable this option may cause core dumped errors
|
||||||
// .single_click_activate(true)
|
// .single_click_activate(true)
|
||||||
.model(
|
.model(
|
||||||
>k::SingleSelection::builder()
|
>k::SingleSelection::builder()
|
||||||
.model(
|
.model(&directory_list)
|
||||||
>k::DirectoryList::builder()
|
|
||||||
.file(file)
|
|
||||||
.attributes(ATTRIBUTES)
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -49,9 +53,15 @@ impl Directory {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
|
directory_list.connect_loading_notify(move |this| {
|
||||||
|
if !this.is_loading() {
|
||||||
|
on_ready()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
column_view.connect_activate(move |this, i| {
|
column_view.connect_activate(move |this, i| {
|
||||||
use gtk::prelude::{Cast, ListModelExt};
|
use gtk::prelude::{Cast, ListModelExt};
|
||||||
callback(
|
on_activate(
|
||||||
this.model()
|
this.model()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.item(i)
|
.item(i)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue