This commit is contained in:
Ashley Wulber 2021-12-03 13:47:53 -05:00 committed by Jeremy Soller
parent a6c5b3b0b4
commit 04b4b88534
3 changed files with 32 additions and 21 deletions

View file

@ -5,30 +5,36 @@ mod window;
use gtk::gdk::Display; use gtk::gdk::Display;
use gtk::prelude::*; use gtk::prelude::*;
use gtk4 as gtk; use gtk4 as gtk;
use gtk4::CssProvider;
use gtk4::StyleContext;
use window::Window; use window::Window;
fn main() { fn main() {
let application = gtk::Application::new( let app = gtk::Application::new(Some("com.cosmic.app_library"), Default::default());
Some("com.github.gtk-rs.examples.apps_launcher"), app.connect_startup(|_app| load_css());
Default::default(),
);
application.connect_activate(|app| { app.connect_activate(|app| {
let provider = gtk::CssProvider::new(); build_ui(app);
provider.load_from_data(include_bytes!("style.css"));
gtk::StyleContext::add_provider_for_display(
&Display::default().expect("Error initializing gtk css provider."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
new_build_ui(app);
}); });
application.run(); app.run();
} }
fn new_build_ui(app: &gtk::Application) { fn load_css() {
// Load the css file and add it to the provider
let provider = CssProvider::new();
provider.load_from_data(include_bytes!("style.css"));
// Add the provider to the default screen
StyleContext::add_provider_for_display(
&Display::default().expect("Error initializing GTK CSS provider."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}
fn build_ui(app: &gtk::Application) {
// Create a new custom window and show it // Create a new custom window and show it
let window = Window::new(app); let window = Window::new(app);
window.show(); window.show();

View file

@ -34,12 +34,18 @@ impl Window {
Object::new(&[("application", app)]).expect("Failed to create `Window`.") Object::new(&[("application", app)]).expect("Failed to create `Window`.")
} }
fn model(&self) -> &gio::ListStore { fn app_model(&self) -> &gio::ListStore {
// Get state // Get state
let imp = imp::Window::from_instance(self); let imp = imp::Window::from_instance(self);
imp.app_model.get().expect("Could not get model") imp.app_model.get().expect("Could not get model")
} }
fn group_model(&self) -> &gio::ListStore {
// Get state
let imp = imp::Window::from_instance(self);
imp.group_model.get().expect("Could not get model")
}
fn setup_model(&self) { fn setup_model(&self) {
// Create new model // Create new model
let app_model = gio::ListStore::new(gio::DesktopAppInfo::static_type()); let app_model = gio::ListStore::new(gio::DesktopAppInfo::static_type());
@ -94,7 +100,6 @@ impl Window {
let filter = gtk::CustomFilter::new(|_obj| true); let filter = gtk::CustomFilter::new(|_obj| true);
let group_filter_model = let group_filter_model =
gtk::FilterListModel::new(Some(&search_filter_model), Some(filter).as_ref()); gtk::FilterListModel::new(Some(&search_filter_model), Some(filter).as_ref());
// TODO add app group filter model
let sorted_model = gtk::SortListModel::new(Some(&group_filter_model), Some(&sorter)); let sorted_model = gtk::SortListModel::new(Some(&group_filter_model), Some(&sorter));
let selection_model = gtk::SingleSelection::new(Some(&sorted_model)); let selection_model = gtk::SingleSelection::new(Some(&sorted_model));
@ -132,7 +137,7 @@ impl Window {
}), }),
AppGroup::new(AppGroupData { AppGroup::new(AppGroupData {
id: 0, id: 0,
name: "Web".to_string(), name: "Custom Web".to_string(),
icon: "folder".to_string(), icon: "folder".to_string(),
mutable: true, mutable: true,
app_names: vec!["Firefox Web Browser".to_string()], app_names: vec!["Firefox Web Browser".to_string()],
@ -210,7 +215,7 @@ impl Window {
group_grid_view.connect_activate(glib::clone!(@weak app_filter_model => move |grid_view, position| { group_grid_view.connect_activate(glib::clone!(@weak app_filter_model => move |grid_view, position| {
// if last item in the model, don't change filter, instead show dialog for adding new group! // if last item in the model, don't change filter, instead show dialog for adding new group!
if position == grid_view.model().unwrap().n_items() - 1 { if position == grid_view.model().unwrap().n_items() - 1 {
println!("TODO: launch action to show the Add/Edit Group Window"); println!("TODO: launch action to show the Add/Edit Group Overlay");
return; return;
}; };
// update the application filter // update the application filter

View file

@ -82,7 +82,7 @@ fn load_css() {
fn main() { fn main() {
let app = gtk::Application::builder() let app = gtk::Application::builder()
.application_id("com.system76.Launcher") .application_id("com.cosmic.Launcher")
.build(); .build();
app.connect_startup(|app| { app.connect_startup(|app| {
@ -99,7 +99,7 @@ fn main() {
let window = Window::new(app); let window = Window::new(app);
let wclone = window.clone(); let wclone = window.clone();
window.show(); window.show();
glib::MainContext::default().spawn_local(async move { glib::MainContext::default().spawn_local(async move {
while let Some(event) = rx.recv().await { while let Some(event) = rx.recv().await {