mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement navigation callback
This commit is contained in:
parent
454ebe0170
commit
8ddd90bb11
3 changed files with 140 additions and 93 deletions
|
|
@ -1,12 +1,24 @@
|
|||
use gtk::{gio::File, prelude::FileExt};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Directory {
|
||||
pub file: File,
|
||||
}
|
||||
|
||||
impl Directory {
|
||||
pub fn handle(&self, page: &super::Page) {
|
||||
page.content.to_directory(&self.file);
|
||||
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.set_title(&self.file.parse_name());
|
||||
page.set_progress(0.0);
|
||||
page.window_action.find.simple_action.set_enabled(false);
|
||||
|
|
|
|||
|
|
@ -131,9 +131,9 @@ impl Content {
|
|||
text
|
||||
}
|
||||
|
||||
pub fn to_directory(&self, file: &File) {
|
||||
pub fn to_directory(&self, file: &File, callback: impl Fn(&File) + 'static) {
|
||||
self.clean();
|
||||
self.g_box.append(&Directory::for_file(file))
|
||||
self.g_box.append(&Directory::for_file(file, callback))
|
||||
}
|
||||
|
||||
/// * system `source:`
|
||||
|
|
|
|||
|
|
@ -5,14 +5,17 @@ pub struct Directory;
|
|||
impl Directory {
|
||||
// Constructors
|
||||
|
||||
pub fn for_file(file: &File) -> ScrolledWindow {
|
||||
const ATTRIBUTES:&str = "standard::name,standard::display-name,standard::symbolic-icon,standard::size,standard::content-type";
|
||||
pub fn for_file(file: &File, callback: impl Fn(&File) + 'static) -> ScrolledWindow {
|
||||
use gtk::{gio::FileInfo, Align, ListItem};
|
||||
|
||||
// Init children widget
|
||||
let column_view = {
|
||||
const ATTRIBUTES: &str =
|
||||
"standard::display-name,standard::symbolic-icon,standard::size,standard::content-type";
|
||||
|
||||
ScrolledWindow::builder()
|
||||
.child(
|
||||
&adw::Clamp::builder()
|
||||
.child(&{
|
||||
let column_view = gtk::ColumnView::builder()
|
||||
// @TODO enable this option may cause core dumped errors
|
||||
// .single_click_activate(true)
|
||||
.model(
|
||||
>k::SingleSelection::builder()
|
||||
.model(
|
||||
|
|
@ -24,6 +27,7 @@ impl Directory {
|
|||
.build(),
|
||||
)
|
||||
.build();
|
||||
|
||||
column_view.append_column(
|
||||
>k::ColumnViewColumn::builder()
|
||||
.title("Type")
|
||||
|
|
@ -32,13 +36,12 @@ impl Directory {
|
|||
let factory = gtk::SignalListItemFactory::new();
|
||||
factory.connect_bind(|_, this| {
|
||||
use gtk::gio::FileType;
|
||||
let list_item =
|
||||
this.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
let list_item = this.downcast_ref::<ListItem>().unwrap();
|
||||
let image = gtk::Image::from_gicon(
|
||||
&list_item
|
||||
.item()
|
||||
.unwrap()
|
||||
.downcast_ref::<gtk::gio::FileInfo>()
|
||||
.downcast_ref::<FileInfo>()
|
||||
.unwrap()
|
||||
.symbolic_icon()
|
||||
.unwrap(),
|
||||
|
|
@ -47,7 +50,7 @@ impl Directory {
|
|||
match list_item
|
||||
.item()
|
||||
.unwrap()
|
||||
.downcast_ref::<gtk::gio::FileInfo>()
|
||||
.downcast_ref::<FileInfo>()
|
||||
.unwrap()
|
||||
.file_type()
|
||||
{
|
||||
|
|
@ -61,8 +64,7 @@ impl Directory {
|
|||
_ => None,
|
||||
},
|
||||
);
|
||||
let container =
|
||||
gtk::Box::builder().halign(gtk::Align::Center).build(); // prevents `gtk::Image` blur
|
||||
let container = gtk::Box::builder().halign(Align::Center).build(); // prevents `gtk::Image` blur
|
||||
container.append(&image);
|
||||
list_item.set_child(Some(&container));
|
||||
});
|
||||
|
|
@ -70,6 +72,7 @@ impl Directory {
|
|||
})
|
||||
.build(),
|
||||
);
|
||||
|
||||
column_view.append_column(
|
||||
>k::ColumnViewColumn::builder()
|
||||
.expand(true)
|
||||
|
|
@ -77,18 +80,26 @@ impl Directory {
|
|||
.factory(&{
|
||||
let factory = gtk::SignalListItemFactory::new();
|
||||
factory.connect_bind(|_, this| {
|
||||
use gtk::prelude::{Cast, ListItemExt};
|
||||
let list_item =
|
||||
this.downcast_ref::<gtk::ListItem>().unwrap();
|
||||
use gtk::prelude::{Cast, FileExt, ListItemExt};
|
||||
let list_item = this.downcast_ref::<ListItem>().unwrap();
|
||||
let item = list_item.item().unwrap();
|
||||
let file_info =
|
||||
item.downcast_ref::<gtk::gio::FileInfo>().unwrap();
|
||||
let file_info = item.downcast_ref::<FileInfo>().unwrap();
|
||||
list_item.set_child(Some(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.halign(Align::Start)
|
||||
.ellipsize(gtk::pango::EllipsizeMode::Middle)
|
||||
.label(file_info.display_name())
|
||||
.tooltip_text(file_info.display_name())
|
||||
.tooltip_text(
|
||||
file_info
|
||||
.attribute_object("standard::file")
|
||||
.unwrap()
|
||||
.downcast_ref::<File>()
|
||||
.unwrap()
|
||||
.path()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
)
|
||||
.build(),
|
||||
));
|
||||
});
|
||||
|
|
@ -96,8 +107,32 @@ impl Directory {
|
|||
})
|
||||
.build(),
|
||||
);
|
||||
|
||||
column_view
|
||||
})
|
||||
};
|
||||
|
||||
// Connect events
|
||||
column_view.connect_activate(move |this, i| {
|
||||
use gtk::prelude::{Cast, ListModelExt};
|
||||
callback(
|
||||
this.model()
|
||||
.unwrap()
|
||||
.item(i)
|
||||
.unwrap()
|
||||
.downcast_ref::<FileInfo>()
|
||||
.unwrap()
|
||||
.attribute_object("standard::file")
|
||||
.unwrap()
|
||||
.downcast_ref::<File>()
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
// Build main widget
|
||||
ScrolledWindow::builder()
|
||||
.child(
|
||||
&adw::Clamp::builder()
|
||||
.child(&column_view)
|
||||
.css_classes(["view"])
|
||||
.build(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue