basic plugin!
This commit is contained in:
parent
7a8e3fe492
commit
537539f43d
13 changed files with 332 additions and 224 deletions
1
examples/dock/dock_object/.#mod.rs
Symbolic link
1
examples/dock/dock_object/.#mod.rs
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
ashleywulber@pop-os.190471:1641501268
|
||||
|
|
@ -8,6 +8,7 @@ use gtk4::prelude::*;
|
|||
use gtk4::subclass::prelude::*;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::plugin::BoxedDockPlugin;
|
||||
use crate::utils::BoxedWindowList;
|
||||
|
||||
// Object holding the state
|
||||
|
|
@ -15,6 +16,7 @@ use crate::utils::BoxedWindowList;
|
|||
pub struct DockObject {
|
||||
pub(super) appinfo: RefCell<Option<DesktopAppInfo>>,
|
||||
pub(super) active: RefCell<BoxedWindowList>,
|
||||
pub(super) plugin: RefCell<Option<BoxedDockPlugin>>,
|
||||
pub(super) saved: Cell<bool>,
|
||||
pub(super) popover: Cell<bool>,
|
||||
}
|
||||
|
|
@ -93,7 +95,6 @@ impl ObjectImpl for DockObject {
|
|||
self.popover
|
||||
.replace(value.get().expect("Value needs to be a boolean"));
|
||||
}
|
||||
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use std::path::Path;
|
||||
|
||||
use gdk4::glib::Object;
|
||||
use gdk4::prelude::FileExt;
|
||||
use gdk4::subclass::prelude::ObjectSubclassExt;
|
||||
use gio::DesktopAppInfo;
|
||||
use gtk4::glib;
|
||||
use gtk4::prelude::AppInfoExt;
|
||||
|
||||
use crate::plugin::{self, BoxedDockPlugin};
|
||||
use crate::utils::BoxedWindowList;
|
||||
use gdk4::glib::Object;
|
||||
use gdk4::subclass::prelude::ObjectSubclassExt;
|
||||
use gio::{DesktopAppInfo, Icon};
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::{glib, Image};
|
||||
use std::cell::Ref;
|
||||
|
||||
mod imp;
|
||||
|
||||
|
|
@ -37,17 +37,63 @@ impl DockObject {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> Option<String> {
|
||||
pub fn from_plugin(plugin: plugin::BoxedDockPlugin) -> Self {
|
||||
let self_ = Object::new(&[("saved", &true)]).expect("Failed to create `DockObject`.");
|
||||
let imp = imp::DockObject::from_instance(&self_);
|
||||
imp.plugin.replace(Some(plugin));
|
||||
self_
|
||||
}
|
||||
|
||||
pub fn get_path(&self) -> Option<String> {
|
||||
let imp = imp::DockObject::from_instance(&self);
|
||||
if let Some(app_info) = imp.appinfo.borrow().as_ref() {
|
||||
app_info
|
||||
.filename()
|
||||
.map(|name| name.to_string_lossy().into())
|
||||
} else if let Some(plugin) = imp.plugin.borrow().as_ref() {
|
||||
Some(plugin.path.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> Option<String> {
|
||||
let imp = imp::DockObject::from_instance(&self);
|
||||
if let Some(app_info) = imp.appinfo.borrow().as_ref() {
|
||||
Some(app_info.name().to_string())
|
||||
} else if let Some(plugin) = imp.plugin.borrow().as_ref() {
|
||||
Some(plugin.name.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_popover_menu(&self) -> Option<gtk4::Box> {
|
||||
let imp = imp::DockObject::from_instance(&self);
|
||||
if let Some(plugin) = imp.plugin.borrow().as_ref() {
|
||||
Some(plugin.popover_menu.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_image(&self) -> gtk4::Image {
|
||||
let imp = imp::DockObject::from_instance(&self);
|
||||
if let Some(app_info) = imp.appinfo.borrow().as_ref() {
|
||||
let image = Image::new();
|
||||
let icon = app_info
|
||||
.icon()
|
||||
.unwrap_or(Icon::for_string("image-missing").expect("Failed to set default icon"));
|
||||
image.set_from_gicon(&icon);
|
||||
image
|
||||
} else if let Some(plugin) = imp.plugin.borrow().as_ref() {
|
||||
plugin.image.clone()
|
||||
} else {
|
||||
println!("failed to load image");
|
||||
Image::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_saved(&self, is_saved: bool) {
|
||||
let imp = imp::DockObject::from_instance(&self);
|
||||
imp.saved.replace(is_saved);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue