styling tweaks & add separator
This commit is contained in:
parent
7f65293179
commit
b59d8a434c
9 changed files with 199 additions and 212 deletions
|
|
@ -1,7 +1,12 @@
|
|||
use crate::icon_source;
|
||||
use gdk4::ContentProvider;
|
||||
use gdk4::Display;
|
||||
use gio::File;
|
||||
use glib::FromVariant;
|
||||
use glib::Variant;
|
||||
use gtk4 as gtk;
|
||||
use gtk4::DragSource;
|
||||
use gtk4::IconTheme;
|
||||
mod imp;
|
||||
|
||||
use crate::ApplicationObject;
|
||||
|
|
@ -10,70 +15,81 @@ use gtk::prelude::*;
|
|||
use gtk::subclass::prelude::*;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct ApplicationRow(ObjectSubclass<imp::ApplicationRow>)
|
||||
pub struct DockItem(ObjectSubclass<imp::DockItem>)
|
||||
@extends gtk::Widget, gtk::Box;
|
||||
}
|
||||
|
||||
impl Default for ApplicationRow {
|
||||
impl Default for DockItem {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationRow {
|
||||
impl DockItem {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(&[]).expect("Failed to create ApplicationRow")
|
||||
glib::Object::new(&[]).expect("Failed to create DockItem")
|
||||
}
|
||||
|
||||
pub fn set_app_info(&self, app_obj: ApplicationObject) {
|
||||
let self_ = imp::ApplicationRow::from_instance(self);
|
||||
pub fn set_app_info(&self, app_info: &gio::DesktopAppInfo) {
|
||||
dbg!("setting app info");
|
||||
let self_ = imp::DockItem::from_instance(self);
|
||||
self_.image.set_tooltip_text(Some(&app_info.name()));
|
||||
|
||||
if let Ok(name) = app_obj.property("name") {
|
||||
self_.name.set_text(
|
||||
&name
|
||||
.get::<String>()
|
||||
.expect("Property name needs to be a String."),
|
||||
);
|
||||
let drag = DragSource::builder()
|
||||
.name("application library drag source")
|
||||
.actions(gdk4::DragAction::COPY)
|
||||
// .content()
|
||||
.build();
|
||||
self.add_controller(&drag);
|
||||
if let Some(file) = app_info.filename() {
|
||||
let file = File::for_path(file);
|
||||
let provider = ContentProvider::for_value(&file.to_value());
|
||||
drag.set_content(Some(&provider));
|
||||
}
|
||||
if let Ok(desc) = app_obj.property("description") {
|
||||
self_.description.set_text(
|
||||
&desc
|
||||
.get::<String>()
|
||||
.expect("Property description needs to be a String."),
|
||||
);
|
||||
}
|
||||
if let Ok(icon) = app_obj.property("icon") {
|
||||
if let Ok(icon) = icon.get::<Variant>() {
|
||||
let icon = match <(i32, String)>::from_variant(&icon) {
|
||||
Some((i_type, name)) if i_type == pop_launcher::IconSource::Name as i32 => {
|
||||
Some(pop_launcher::IconSource::Name(name.into()))
|
||||
if let Some(icon) = app_info.icon() {
|
||||
dbg!("setting icon {}", app_info.name());
|
||||
self_.image.set_from_gicon(&icon);
|
||||
// set drag source icon if possible...
|
||||
// gio Icon is not easily converted to a Paintable, but this seems to be the correct method
|
||||
if let Some(default_display) = &Display::default() {
|
||||
if let Some(icon_theme) = IconTheme::for_display(default_display) {
|
||||
if let Some(paintable_icon) = icon_theme.lookup_by_gicon(
|
||||
&icon,
|
||||
64,
|
||||
1,
|
||||
gtk4::TextDirection::None,
|
||||
gtk4::IconLookupFlags::empty(),
|
||||
) {
|
||||
drag.set_icon(Some(&paintable_icon), 32, 32);
|
||||
}
|
||||
Some((i_type, name)) if i_type == pop_launcher::IconSource::Mime as i32 => {
|
||||
Some(pop_launcher::IconSource::Mime(name.into()))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
icon_source(&self_.image, &icon);
|
||||
}
|
||||
}
|
||||
if let Ok(icon) = app_obj.property("categoryicon") {
|
||||
if let Ok(icon) = icon.get::<Variant>() {
|
||||
let icon = match <(i32, String)>::from_variant(&icon) {
|
||||
Some((i_type, name)) if i_type == pop_launcher::IconSource::Name as i32 => {
|
||||
Some(pop_launcher::IconSource::Name(name.into()))
|
||||
}
|
||||
Some((i_type, name)) if i_type == pop_launcher::IconSource::Mime as i32 => {
|
||||
Some(pop_launcher::IconSource::Mime(name.into()))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
icon_source(&self_.categoryimage, &icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_shortcut(&self, indx: u32) {
|
||||
let self_ = imp::ApplicationRow::from_instance(self);
|
||||
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
|
||||
}
|
||||
// pub fn set_app_info(&self, app_obj: ApplicationObject) {
|
||||
// let self_ = imp::DockItem::from_instance(self);
|
||||
|
||||
// if let Ok(name) = app_obj.property("name") {
|
||||
// self_.image.set_tooltip_text(Some(
|
||||
// &name
|
||||
// .get::<String>()
|
||||
// .expect("Property name needs to be a String."),
|
||||
// ));
|
||||
// }
|
||||
// if let Ok(icon) = app_obj.property("icon") {
|
||||
// if let Ok(icon) = icon.get::<Variant>() {
|
||||
// let icon = match <(i32, String)>::from_variant(&icon) {
|
||||
// Some((i_type, name)) if i_type == pop_launcher::IconSource::Name as i32 => {
|
||||
// Some(pop_launcher::IconSource::Name(name.into()))
|
||||
// }
|
||||
// Some((i_type, name)) if i_type == pop_launcher::IconSource::Mime as i32 => {
|
||||
// Some(pop_launcher::IconSource::Mime(name.into()))
|
||||
// }
|
||||
// _ => None,
|
||||
// };
|
||||
// icon_source(&self_.image, &icon);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue