cleanup
This commit is contained in:
parent
e6ef9a5357
commit
e48f501b0d
18 changed files with 151 additions and 166 deletions
|
|
@ -142,7 +142,7 @@ impl ObjectImpl for AppGroup {
|
|||
.get::<Variant>()
|
||||
.expect("The icon needs to be a Variant"),
|
||||
)
|
||||
.expect("The icon variant needs to be a Vec<String>");
|
||||
.expect("The icon variant needs to be a Vec<String>");
|
||||
self.data.borrow_mut().app_names = appnames;
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ impl AppGroup {
|
|||
("icon", &data.icon),
|
||||
("category", &data.category),
|
||||
])
|
||||
.expect("Failed to create `ApplicationObject`.");
|
||||
.expect("Failed to create `ApplicationObject`.");
|
||||
if let Err(e) = self_.set_property("appnames", data.app_names.to_variant()) {
|
||||
println!("failed to set category icon property");
|
||||
dbg!(e);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
use gtk::glib;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::CompositeTemplate;
|
||||
use gtk4 as gtk;
|
||||
use gtk4::CompositeTemplate;
|
||||
use gtk4::glib;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
|
||||
#[derive(Debug, Default, CompositeTemplate)]
|
||||
#[template(file = "grid_item.ui")]
|
||||
pub struct GridItem {
|
||||
#[template_child]
|
||||
pub name: TemplateChild<gtk::Label>,
|
||||
pub name: TemplateChild<gtk4::Label>,
|
||||
#[template_child]
|
||||
pub image: TemplateChild<gtk::Image>,
|
||||
pub image: TemplateChild<gtk4::Image>,
|
||||
pub index: Cell<u32>,
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +19,7 @@ pub struct GridItem {
|
|||
impl ObjectSubclass for GridItem {
|
||||
const NAME: &'static str = "GridItem";
|
||||
type Type = super::GridItem;
|
||||
type ParentType = gtk::Box;
|
||||
type ParentType = gtk4::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
Self::bind_template(klass);
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@ use gdk4::ContentProvider;
|
|||
use gdk4::Display;
|
||||
use gio::File;
|
||||
use gio::Icon;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
use gtk4 as gtk;
|
||||
use gtk4::traits::WidgetExt;
|
||||
use gtk4::{gio, glib};
|
||||
use gtk4::DragSource;
|
||||
use gtk4::IconTheme;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::traits::WidgetExt;
|
||||
|
||||
use crate::app_group::AppGroup;
|
||||
|
||||
|
|
@ -16,8 +15,8 @@ mod imp;
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct GridItem(ObjectSubclass<imp::GridItem>)
|
||||
@extends gtk::Widget, gtk::Box,
|
||||
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||
@extends gtk4::Widget, gtk4::Box,
|
||||
@implements gtk4::Accessible, gtk4::Actionable, gtk4::Buildable, gtk4::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl Default for GridItem {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use gtk::gdk::Display;
|
||||
use gtk::prelude::*;
|
||||
use gtk4 as gtk;
|
||||
use gtk4::CssProvider;
|
||||
use gtk4::gdk::Display;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::StyleContext;
|
||||
use once_cell::sync::OnceCell;
|
||||
use x11rb::rust_connection::RustConnection;
|
||||
|
|
@ -16,7 +15,7 @@ mod window;
|
|||
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
|
||||
|
||||
fn main() {
|
||||
let app = gtk::Application::new(Some("com.cosmic.app_library"), Default::default());
|
||||
let app = gtk4::Application::new(Some("com.cosmic.app_library"), Default::default());
|
||||
app.connect_startup(|app| {
|
||||
load_css();
|
||||
build_ui(&app);
|
||||
|
|
@ -38,11 +37,11 @@ fn load_css() {
|
|||
StyleContext::add_provider_for_display(
|
||||
&Display::default().expect("Error initializing GTK CSS provider."),
|
||||
&provider,
|
||||
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
}
|
||||
|
||||
fn build_ui(app: >k::Application) {
|
||||
fn build_ui(app: >k4::Application) {
|
||||
// Create a new custom window and show it
|
||||
let window = Window::new(app);
|
||||
let (conn, _screen_num) = x11rb::connect(None).expect("Failed to connect to X");
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ use std::fs::File;
|
|||
|
||||
use glib::signal::Inhibit;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
use gtk::{CompositeTemplate, GridView, SearchEntry};
|
||||
use gtk4 as gtk;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use gtk4::ScrolledWindow;
|
||||
use gtk4::{gio, glib};
|
||||
use gtk4::{CompositeTemplate, GridView, SearchEntry};
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use crate::app_group::AppGroup;
|
||||
|
|
@ -35,7 +34,7 @@ impl ObjectSubclass for Window {
|
|||
// `NAME` needs to match `class` attribute of template
|
||||
const NAME: &'static str = "LauncherWindow";
|
||||
type Type = super::Window;
|
||||
type ParentType = gtk::ApplicationWindow;
|
||||
type ParentType = gtk4::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
Self::bind_template(klass);
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@ use gdk4_x11::X11Surface;
|
|||
use glib::FromVariant;
|
||||
use glib::Object;
|
||||
use glib::Variant;
|
||||
use gtk::prelude::*;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{gio, glib};
|
||||
use gtk::{Application, SignalListItemFactory};
|
||||
use gtk4 as gtk;
|
||||
use gtk4::{gio, glib};
|
||||
use gtk4::{Application, SignalListItemFactory};
|
||||
use gtk4::Dialog;
|
||||
use gtk4::Entry;
|
||||
use gtk4::Label;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::subclass::prelude::*;
|
||||
use x11rb::connection::Connection;
|
||||
use x11rb::protocol::xproto;
|
||||
use x11rb::protocol::xproto::ConnectionExt;
|
||||
|
|
@ -31,9 +30,9 @@ mod imp;
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct Window(ObjectSubclass<imp::Window>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
@extends gtk4::ApplicationWindow, gtk4::Window, gtk4::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk4::Accessible, gtk4::Buildable,
|
||||
gtk4::ConstraintTarget, gtk4::Native, gtk4::Root, gtk4::ShortcutManager;
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
|
@ -97,7 +96,7 @@ impl Window {
|
|||
.set(app_model.clone())
|
||||
.expect("Could not set model");
|
||||
|
||||
let sorter = gtk::CustomSorter::new(move |obj1, obj2| {
|
||||
let sorter = gtk4::CustomSorter::new(move |obj1, obj2| {
|
||||
let app_info1 = obj1.downcast_ref::<gio::DesktopAppInfo>().unwrap();
|
||||
let app_info2 = obj2.downcast_ref::<gio::DesktopAppInfo>().unwrap();
|
||||
|
||||
|
|
@ -107,14 +106,14 @@ impl Window {
|
|||
.cmp(&app_info2.name().to_lowercase())
|
||||
.into()
|
||||
});
|
||||
let filter = gtk::CustomFilter::new(|_obj| true);
|
||||
let filter = gtk4::CustomFilter::new(|_obj| true);
|
||||
let search_filter_model =
|
||||
gtk::FilterListModel::new(Some(&app_model), Some(filter).as_ref());
|
||||
let filter = gtk::CustomFilter::new(|_obj| true);
|
||||
gtk4::FilterListModel::new(Some(&app_model), Some(filter).as_ref());
|
||||
let filter = gtk4::CustomFilter::new(|_obj| true);
|
||||
let group_filter_model =
|
||||
gtk::FilterListModel::new(Some(&search_filter_model), Some(filter).as_ref());
|
||||
let sorted_model = gtk::SortListModel::new(Some(&group_filter_model), Some(&sorter));
|
||||
let selection_model = gtk::SingleSelection::builder()
|
||||
gtk4::FilterListModel::new(Some(&search_filter_model), Some(filter).as_ref());
|
||||
let sorted_model = gtk4::SortListModel::new(Some(&group_filter_model), Some(&sorter));
|
||||
let selection_model = gtk4::SingleSelection::builder()
|
||||
.model(&sorted_model)
|
||||
.autoselect(false)
|
||||
.can_unselect(true)
|
||||
|
|
@ -172,10 +171,10 @@ impl Window {
|
|||
category: "".to_string(),
|
||||
}),
|
||||
]
|
||||
.iter()
|
||||
.for_each(|group| {
|
||||
group_model.append(group);
|
||||
});
|
||||
.iter()
|
||||
.for_each(|group| {
|
||||
group_model.append(group);
|
||||
});
|
||||
let group_selection = gtk4::SingleSelection::new(Some(&group_model));
|
||||
imp.group_grid_view.set_model(Some(&group_selection));
|
||||
}
|
||||
|
|
@ -183,32 +182,32 @@ impl Window {
|
|||
fn setup_callbacks(&self) {
|
||||
// Get state
|
||||
let imp = imp::Window::from_instance(self);
|
||||
let window = self.clone().upcast::<gtk::Window>();
|
||||
let window = self.clone().upcast::<gtk4::Window>();
|
||||
let app_grid_view = &imp.app_grid_view;
|
||||
let group_grid_view = &imp.group_grid_view;
|
||||
let app_selection_model = app_grid_view
|
||||
.model()
|
||||
.expect("List view missing selection model")
|
||||
.downcast::<gtk::SingleSelection>()
|
||||
.downcast::<gtk4::SingleSelection>()
|
||||
.expect("could not downcast listview model to single selection model");
|
||||
let app_sorted_model = app_selection_model
|
||||
.model()
|
||||
.downcast::<gtk::SortListModel>()
|
||||
.downcast::<gtk4::SortListModel>()
|
||||
.expect("sorted list model could not be downcast");
|
||||
let app_group_filter_model = app_sorted_model
|
||||
.model()
|
||||
.expect("missing model for sort list model.")
|
||||
.downcast::<gtk::FilterListModel>()
|
||||
.downcast::<gtk4::FilterListModel>()
|
||||
.expect("could not downcast sort list model to filter list model");
|
||||
let app_filter_model = app_group_filter_model
|
||||
.model()
|
||||
.expect("missing model for sort list model.")
|
||||
.downcast::<gtk::FilterListModel>()
|
||||
.downcast::<gtk4::FilterListModel>()
|
||||
.expect("could not downcast sort list model to filter list model");
|
||||
let group_selection_model = group_grid_view
|
||||
.model()
|
||||
.expect("List view missing selection model")
|
||||
.downcast::<gtk::SingleSelection>()
|
||||
.downcast::<gtk4::SingleSelection>()
|
||||
.expect("could not downcast listview model to single selection model");
|
||||
|
||||
let entry = &imp.entry;
|
||||
|
|
@ -229,10 +228,10 @@ impl Window {
|
|||
let app_info = item.downcast::<gio::DesktopAppInfo>().unwrap();
|
||||
let context = window.display().app_launch_context();
|
||||
if let Err(err) = app_info.launch(&[], Some(&context)) {
|
||||
gtk::MessageDialog::builder()
|
||||
gtk4::MessageDialog::builder()
|
||||
.text(&format!("Failed to start {}", app_info.name()))
|
||||
.secondary_text(&err.to_string())
|
||||
.message_type(gtk::MessageType::Error)
|
||||
.message_type(gtk4::MessageType::Error)
|
||||
.modal(true)
|
||||
.transient_for(&window)
|
||||
.build()
|
||||
|
|
@ -347,7 +346,7 @@ impl Window {
|
|||
vec![]
|
||||
};
|
||||
dbg!(&app_names);
|
||||
let new_filter: gtk::CustomFilter = gtk::CustomFilter::new(move |obj| {
|
||||
let new_filter: gtk4::CustomFilter = gtk4::CustomFilter::new(move |obj| {
|
||||
let app = obj
|
||||
.downcast_ref::<gio::DesktopAppInfo>()
|
||||
.expect("The Object needs to be of type AppInfo");
|
||||
|
|
@ -363,15 +362,15 @@ impl Window {
|
|||
}));
|
||||
|
||||
entry.connect_changed(
|
||||
glib::clone!(@weak app_filter_model, @weak app_sorted_model => move |search: >k::SearchEntry| {
|
||||
glib::clone!(@weak app_filter_model, @weak app_sorted_model => move |search: >k4::SearchEntry| {
|
||||
let search_text = search.text().to_string().to_lowercase();
|
||||
let new_filter: gtk::CustomFilter = gtk::CustomFilter::new(move |obj| {
|
||||
let new_filter: gtk4::CustomFilter = gtk4::CustomFilter::new(move |obj| {
|
||||
let search_res = obj.downcast_ref::<gio::DesktopAppInfo>()
|
||||
.expect("The Object needs to be of type AppInfo");
|
||||
search_res.name().to_string().to_lowercase().contains(&search_text)
|
||||
});
|
||||
let search_text = search.text().to_string().to_lowercase();
|
||||
let new_sorter: gtk::CustomSorter = gtk::CustomSorter::new(move |obj1, obj2| {
|
||||
let new_sorter: gtk4::CustomSorter = gtk4::CustomSorter::new(move |obj1, obj2| {
|
||||
let app_info1 = obj1.downcast_ref::<gio::DesktopAppInfo>().unwrap();
|
||||
let app_info2 = obj2.downcast_ref::<gio::DesktopAppInfo>().unwrap();
|
||||
if search_text == "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue