diff --git a/gnome/src/app.rs b/gnome/src/app.rs new file mode 100644 index 0000000..4421882 --- /dev/null +++ b/gnome/src/app.rs @@ -0,0 +1,65 @@ +use crate::ui; +use adw::prelude::*; +use gtk::{ + gdk, + gio::{self, SimpleAction}, + glib::{self, clone}, + STYLE_PROVIDER_PRIORITY_APPLICATION, +}; + +pub fn start(app: &adw::Application, files: &[gio::File]) { + let app = app.downcast_ref::().unwrap(); + + let style_provider = gtk::CssProvider::new(); + style_provider.load_from_string(include_str!("styles.css")); + gtk::style_context_add_provider_for_display( + &gdk::Display::default().unwrap(), + &style_provider, + STYLE_PROVIDER_PRIORITY_APPLICATION, + ); + + let window = ui::SearchWindow::new(app); + + if let Some(dir) = files.first() { + if let Some(path) = dir.path() { + if path.is_dir() { + window.set_search_path(path); + } + } + } + + let about_action = SimpleAction::new("about", None); + about_action.connect_activate(clone!( + #[weak] + window, + move |_, _| ui::about_dialog().present(Some(&window)) + )); + app.add_action(&about_action); + + let shortcuts_action = SimpleAction::new("shortcuts", None); + shortcuts_action.connect_activate(clone!( + #[weak] + window, + move |_, _| { + ui::show_shortcuts(&window); + } + )); + app.add_action(&shortcuts_action); + + let quit_action = SimpleAction::new("quit", None); + quit_action.connect_activate(clone!( + #[weak] + window, + move |_, _| { + window.close(); + } + )); + app.add_action(&quit_action); + + app.set_accels_for_action("app.quit", &["q"]); + app.set_accels_for_action("app.shortcuts", &["h"]); + app.set_accels_for_action("win.start-search", &["Return"]); + app.set_accels_for_action("app.stop-search", &["s"]); + + window.present(); +} diff --git a/gnome/src/config.rs b/gnome/src/config.rs new file mode 100644 index 0000000..7800b8e --- /dev/null +++ b/gnome/src/config.rs @@ -0,0 +1,111 @@ +use gtk::glib; + +glib::wrapper! { + pub struct Config(ObjectSubclass); +} + +impl Config { + pub fn new() -> Config { + glib::Object::new() + } +} + +impl Default for Config { + fn default() -> Self { + Self::new() + } +} + +mod imp { + use cosmic_config::{ConfigGet, ConfigSet}; + use glib::prelude::*; + use gtk::{glib, subclass::prelude::*}; + use std::cell::{Cell, OnceCell}; + + use crate::APP_ID; + + #[derive(Default, glib::Properties)] + #[properties(wrapper_type = super::Config)] + pub struct Config { + #[property(get, set = Self::set_window_width, default = 1600)] + window_width: Cell, + #[property(get, set = Self::set_window_height, default = 900)] + window_height: Cell, + #[property(get, set = Self::set_window_maximized, default = false)] + window_maximized: Cell, + + #[property(get, set = Self::set_search_pdf, default = false)] + search_pdf: Cell, + #[property(get, set = Self::set_search_office, default = false)] + search_office: Cell, + + config: OnceCell, + } + + #[glib::object_subclass] + impl ObjectSubclass for Config { + const NAME: &'static str = "ClapgrepConfig"; + type Type = super::Config; + } + + #[glib::derived_properties] + impl ObjectImpl for Config { + fn constructed(&self) { + let config = cosmic_config::Config::new(APP_ID, 1).expect("failed to open config"); + + if let Ok(window_width) = config.get("window_width") { + self.window_width.set(window_width); + } + + if let Ok(window_height) = config.get("window_height") { + self.window_height.set(window_height); + } + + if let Ok(window_maximized) = config.get("window_maximized") { + self.window_maximized.set(window_maximized); + } + + if let Ok(search_pdf) = config.get("search_pdf") { + self.search_pdf.set(search_pdf); + } + + if let Ok(search_office) = config.get("search_office") { + self.search_office.set(search_office); + } + + let _ = self.config.set(config); + } + } + + impl Config { + fn set_window_width(&self, width: i32) { + let config = self.config.get().unwrap(); + let _ = config.set("window_width", width); + self.window_width.set(width); + } + + fn set_window_height(&self, height: i32) { + let config = self.config.get().unwrap(); + let _ = config.set("window_height", height); + self.window_height.set(height); + } + + fn set_window_maximized(&self, maximized: bool) { + let config = self.config.get().unwrap(); + let _ = config.set("window_maximized", maximized); + self.window_maximized.set(maximized); + } + + fn set_search_pdf(&self, search_pdf: bool) { + let config = self.config.get().unwrap(); + let _ = config.set("search_pdf", search_pdf); + self.search_pdf.set(search_pdf); + } + + fn set_search_office(&self, search_office: bool) { + let config = self.config.get().unwrap(); + let _ = config.set("search_office", search_office); + self.search_office.set(search_office); + } + } +} diff --git a/gnome/src/config/imp.rs b/gnome/src/config/imp.rs deleted file mode 100644 index 56fff69..0000000 --- a/gnome/src/config/imp.rs +++ /dev/null @@ -1,92 +0,0 @@ -use cosmic_config::{ConfigGet, ConfigSet}; -use glib::prelude::*; -use gtk::{glib, subclass::prelude::*}; -use std::cell::{Cell, OnceCell}; - -use crate::APP_ID; - -#[derive(Default, glib::Properties)] -#[properties(wrapper_type = super::Config)] -pub struct Config { - #[property(get, set = Self::set_window_width, default = 1600)] - window_width: Cell, - #[property(get, set = Self::set_window_height, default = 900)] - window_height: Cell, - #[property(get, set = Self::set_window_maximized, default = false)] - window_maximized: Cell, - - #[property(get, set = Self::set_search_pdf, default = false)] - search_pdf: Cell, - #[property(get, set = Self::set_search_office, default = false)] - search_office: Cell, - - config: OnceCell, -} - -impl Config { - fn set_window_width(&self, width: i32) { - let config = self.config.get().unwrap(); - let _ = config.set("window_width", width); - self.window_width.set(width); - } - - fn set_window_height(&self, height: i32) { - let config = self.config.get().unwrap(); - let _ = config.set("window_height", height); - self.window_height.set(height); - } - - fn set_window_maximized(&self, maximized: bool) { - let config = self.config.get().unwrap(); - let _ = config.set("window_maximized", maximized); - self.window_maximized.set(maximized); - } - - fn set_search_pdf(&self, search_pdf: bool) { - let config = self.config.get().unwrap(); - let _ = config.set("search_pdf", search_pdf); - self.search_pdf.set(search_pdf); - } - - fn set_search_office(&self, search_office: bool) { - let config = self.config.get().unwrap(); - let _ = config.set("search_office", search_office); - self.search_office.set(search_office); - } -} - -// Basic declaration of our type for the GObject type system -#[glib::object_subclass] -impl ObjectSubclass for Config { - const NAME: &'static str = "ClapgrepConfig"; - type Type = super::Config; -} - -#[glib::derived_properties] -impl ObjectImpl for Config { - fn constructed(&self) { - let config = cosmic_config::Config::new(APP_ID, 1).expect("failed to open config"); - - if let Ok(window_width) = config.get("window_width") { - self.window_width.set(window_width); - } - - if let Ok(window_height) = config.get("window_height") { - self.window_height.set(window_height); - } - - if let Ok(window_maximized) = config.get("window_maximized") { - self.window_maximized.set(window_maximized); - } - - if let Ok(search_pdf) = config.get("search_pdf") { - self.search_pdf.set(search_pdf); - } - - if let Ok(search_office) = config.get("search_office") { - self.search_office.set(search_office); - } - - let _ = self.config.set(config); - } -} diff --git a/gnome/src/config/mod.rs b/gnome/src/config/mod.rs deleted file mode 100644 index d0c4b4e..0000000 --- a/gnome/src/config/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -mod imp; - -use gtk::glib; - -glib::wrapper! { - pub struct Config(ObjectSubclass); -} - -impl Config { - pub fn new() -> Config { - glib::Object::new() - } -} - -impl Default for Config { - fn default() -> Self { - Self::new() - } -} diff --git a/gnome/src/main.rs b/gnome/src/main.rs index 4d4a956..c191911 100644 --- a/gnome/src/main.rs +++ b/gnome/src/main.rs @@ -1,18 +1,11 @@ use adw::prelude::*; -use gtk::gio::SimpleAction; -use gtk::gio::{self, ApplicationFlags}; -use gtk::glib::{self, clone}; -use gtk::{gdk, STYLE_PROVIDER_PRIORITY_APPLICATION}; -use gtk_blueprint::include_blp; +use gtk::gio::ApplicationFlags; use std::path::PathBuf; -mod about; +mod app; mod config; -mod error_window; -mod search_match; -mod search_model; -mod search_result; -mod search_window; +mod search; +mod ui; const APP_ID: &str = env!("APP_ID"); @@ -34,77 +27,13 @@ fn setup_gettext() { fn main() { setup_gettext(); - let app = adw::Application::builder() + let application = adw::Application::builder() .application_id(APP_ID) .flags(ApplicationFlags::HANDLES_OPEN) .build(); - app.connect_open(|app, files, _| start(app, files)); - app.connect_activate(|app| start(app, &[])); + application.connect_open(|a, files, _| app::start(a, files)); + application.connect_activate(|a| app::start(a, &[])); - app.run(); -} - -fn start(app: &adw::Application, files: &[gio::File]) { - let app = app.downcast_ref::().unwrap(); - - let style_provider = gtk::CssProvider::new(); - style_provider.load_from_string(include_str!("styles.css")); - gtk::style_context_add_provider_for_display( - &gdk::Display::default().unwrap(), - &style_provider, - STYLE_PROVIDER_PRIORITY_APPLICATION, - ); - - let window = search_window::SearchWindow::new(app); - - if let Some(dir) = files.first() { - if let Some(path) = dir.path() { - if path.is_dir() { - window.set_search_path(path); - } - } - } - - let about_action = SimpleAction::new("about", None); - about_action.connect_activate(clone!( - #[weak] - window, - move |_, _| about::dialog().present(Some(&window)) - )); - app.add_action(&about_action); - - let shortcuts_action = SimpleAction::new("shortcuts", None); - shortcuts_action.connect_activate(clone!( - #[weak] - window, - move |_, _| { - let blueprint = include_blp!("gnome/src/shortcuts.blp"); - let builder = gtk::Builder::from_string(blueprint); - let help_overlay = builder - .object::("help-overlay") - .unwrap(); - help_overlay.set_transient_for(Some(&window)); - help_overlay.set_application(window.application().as_ref()); - help_overlay.present(); - } - )); - app.add_action(&shortcuts_action); - - let quit_action = SimpleAction::new("quit", None); - quit_action.connect_activate(clone!( - #[weak] - window, - move |_, _| { - window.close(); - } - )); - app.add_action(&quit_action); - - app.set_accels_for_action("app.quit", &["q"]); - app.set_accels_for_action("app.shortcuts", &["h"]); - app.set_accels_for_action("win.start-search", &["Return"]); - app.set_accels_for_action("app.stop-search", &["s"]); - - window.present(); + application.run(); } diff --git a/gnome/src/search/mod.rs b/gnome/src/search/mod.rs new file mode 100644 index 0000000..fc0c097 --- /dev/null +++ b/gnome/src/search/mod.rs @@ -0,0 +1,8 @@ +mod model; +pub use model::SearchModel; + +mod range; +pub use range::SearchMatch; + +mod result; +pub use result::SearchResult; diff --git a/gnome/src/search_model/mod.rs b/gnome/src/search/model.rs similarity index 55% rename from gnome/src/search_model/mod.rs rename to gnome/src/search/model.rs index 03b27fc..d1904d2 100644 --- a/gnome/src/search_model/mod.rs +++ b/gnome/src/search/model.rs @@ -1,6 +1,4 @@ -mod imp; - -use crate::search_result::SearchResult; +use crate::search::SearchResult; use gtk::{gio, glib, prelude::*, subclass::prelude::*}; use imp::Section; use std::path::PathBuf; @@ -10,6 +8,12 @@ glib::wrapper! { @implements gio::ListModel, gtk::SectionModel; } +impl Default for SearchModel { + fn default() -> Self { + Self::new() + } +} + impl SearchModel { pub fn new() -> SearchModel { glib::Object::new() @@ -71,8 +75,68 @@ impl SearchModel { } } -impl Default for SearchModel { - fn default() -> Self { - Self::new() +mod imp { + use crate::search::SearchResult; + use gtk::{gio, glib, prelude::*, subclass::prelude::*}; + use std::{cell::RefCell, path::PathBuf}; + + #[derive(Debug, Default)] + pub struct SearchModel { + pub data: RefCell>, + pub sections: RefCell>, + pub base_path: RefCell, + } + + #[derive(Debug, Clone, Copy)] + pub struct Section { + pub start: u32, + pub end: u32, + } + + impl Section { + pub fn size(&self) -> u32 { + self.end - self.start + } + } + + #[glib::object_subclass] + impl ObjectSubclass for SearchModel { + const NAME: &'static str = "ClapgrepSearchModel"; + type Type = super::SearchModel; + type Interfaces = (gio::ListModel, gtk::SectionModel); + } + + impl ObjectImpl for SearchModel {} + + impl ListModelImpl for SearchModel { + fn item_type(&self) -> glib::Type { + SearchResult::static_type() + } + + fn n_items(&self) -> u32 { + self.data.borrow().len() as u32 + } + + fn item(&self, position: u32) -> Option { + self.data + .borrow() + .get(position as usize) + .map(|o| o.clone().upcast::()) + } + } + + impl SectionModelImpl for SearchModel { + fn section(&self, position: u32) -> (u32, u32) { + let mut total = 0; + for section in self.sections.borrow().iter() { + total += section.size(); + + if total > position { + return (section.start, section.end); + } + } + + panic!("missing section") + } } } diff --git a/gnome/src/search/range.rs b/gnome/src/search/range.rs new file mode 100644 index 0000000..e96cdce --- /dev/null +++ b/gnome/src/search/range.rs @@ -0,0 +1,38 @@ +use gtk::glib; + +glib::wrapper! { + pub struct SearchMatch(ObjectSubclass); +} + +impl SearchMatch { + pub fn new(start: u32, end: u32) -> SearchMatch { + glib::Object::builder() + .property("start", start) + .property("end", end) + .build() + } +} + +mod imp { + use glib::prelude::*; + use gtk::{glib, subclass::prelude::*}; + use std::cell::Cell; + + #[derive(Default, glib::Properties)] + #[properties(wrapper_type = super::SearchMatch)] + pub struct SearchMatch { + #[property(get, set)] + start: Cell, + #[property(get, set)] + end: Cell, + } + + #[glib::object_subclass] + impl ObjectSubclass for SearchMatch { + const NAME: &'static str = "ClapgrepSearchMatch"; + type Type = super::SearchMatch; + } + + #[glib::derived_properties] + impl ObjectImpl for SearchMatch {} +} diff --git a/gnome/src/search_result/mod.rs b/gnome/src/search/result.rs similarity index 69% rename from gnome/src/search_result/mod.rs rename to gnome/src/search/result.rs index f12e667..ffa0e8c 100644 --- a/gnome/src/search_result/mod.rs +++ b/gnome/src/search/result.rs @@ -1,6 +1,4 @@ -mod imp; - -use crate::search_match::SearchMatch; +use crate::search::SearchMatch; use clapgrep_core::{Location, Match}; use gtk::{ gio, glib, pango, @@ -82,3 +80,40 @@ impl SearchResult { Vec::new() } } + +mod imp { + use gtk::{ + gio, + glib::{self, prelude::*}, + subclass::prelude::*, + }; + use std::{ + cell::{Cell, RefCell}, + path::PathBuf, + }; + + #[derive(Default, glib::Properties)] + #[properties(wrapper_type = super::SearchResult)] + pub struct SearchResult { + #[property(get, set)] + file: RefCell, + #[property(get, set)] + uri: RefCell, + #[property(get, set)] + line: Cell, + #[property(get, set)] + content: RefCell, + #[property(get, set, construct)] + matches: RefCell>, + } + + // Basic declaration of our type for the GObject type system + #[glib::object_subclass] + impl ObjectSubclass for SearchResult { + const NAME: &'static str = "ClapgrepSearchResult"; + type Type = super::SearchResult; + } + + #[glib::derived_properties] + impl ObjectImpl for SearchResult {} +} diff --git a/gnome/src/search_match/imp.rs b/gnome/src/search_match/imp.rs deleted file mode 100644 index 583aab4..0000000 --- a/gnome/src/search_match/imp.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::cell::Cell; - -use glib::prelude::*; -use gtk::{glib, subclass::prelude::*}; - -#[derive(Default, glib::Properties)] -#[properties(wrapper_type = super::SearchMatch)] -pub struct SearchMatch { - #[property(get, set)] - start: Cell, - #[property(get, set)] - end: Cell, -} - -// Basic declaration of our type for the GObject type system -#[glib::object_subclass] -impl ObjectSubclass for SearchMatch { - const NAME: &'static str = "ClapgrepSearchMatch"; - type Type = super::SearchMatch; -} - -#[glib::derived_properties] -impl ObjectImpl for SearchMatch {} diff --git a/gnome/src/search_match/mod.rs b/gnome/src/search_match/mod.rs deleted file mode 100644 index f05adc6..0000000 --- a/gnome/src/search_match/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -mod imp; - -use gtk::glib; - -glib::wrapper! { - pub struct SearchMatch(ObjectSubclass); -} - -impl SearchMatch { - pub fn new(start: u32, end: u32) -> SearchMatch { - glib::Object::builder() - .property("start", start) - .property("end", end) - .build() - } -} diff --git a/gnome/src/search_model/imp.rs b/gnome/src/search_model/imp.rs deleted file mode 100644 index c4db06f..0000000 --- a/gnome/src/search_model/imp.rs +++ /dev/null @@ -1,63 +0,0 @@ -use crate::search_result::SearchResult; -use gtk::{gio, glib, prelude::*, subclass::prelude::*}; -use std::{cell::RefCell, path::PathBuf}; - -#[derive(Debug, Default)] -pub struct SearchModel { - pub data: RefCell>, - pub sections: RefCell>, - pub base_path: RefCell, -} - -#[derive(Debug, Clone, Copy)] -pub struct Section { - pub start: u32, - pub end: u32, -} - -impl Section { - pub fn size(&self) -> u32 { - self.end - self.start - } -} - -#[glib::object_subclass] -impl ObjectSubclass for SearchModel { - const NAME: &'static str = "ClapgrepSearchModel"; - type Type = super::SearchModel; - type Interfaces = (gio::ListModel, gtk::SectionModel); -} - -impl ObjectImpl for SearchModel {} - -impl ListModelImpl for SearchModel { - fn item_type(&self) -> glib::Type { - SearchResult::static_type() - } - - fn n_items(&self) -> u32 { - self.data.borrow().len() as u32 - } - - fn item(&self, position: u32) -> Option { - self.data - .borrow() - .get(position as usize) - .map(|o| o.clone().upcast::()) - } -} - -impl SectionModelImpl for SearchModel { - fn section(&self, position: u32) -> (u32, u32) { - let mut total = 0; - for section in self.sections.borrow().iter() { - total += section.size(); - - if total > position { - return (section.start, section.end); - } - } - - panic!("missing section") - } -} diff --git a/gnome/src/search_result/imp.rs b/gnome/src/search_result/imp.rs deleted file mode 100644 index 8fb8578..0000000 --- a/gnome/src/search_result/imp.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::{ - cell::{Cell, RefCell}, - path::PathBuf, -}; - -use gtk::{ - gio, - glib::{self, prelude::*}, - subclass::prelude::*, -}; - -#[derive(Default, glib::Properties)] -#[properties(wrapper_type = super::SearchResult)] -pub struct SearchResult { - #[property(get, set)] - file: RefCell, - #[property(get, set)] - uri: RefCell, - #[property(get, set)] - line: Cell, - #[property(get, set)] - content: RefCell, - #[property(get, set, construct)] - matches: RefCell>, -} - -// Basic declaration of our type for the GObject type system -#[glib::object_subclass] -impl ObjectSubclass for SearchResult { - const NAME: &'static str = "ClapgrepSearchResult"; - type Type = super::SearchResult; -} - -#[glib::derived_properties] -impl ObjectImpl for SearchResult {} diff --git a/gnome/src/about.rs b/gnome/src/ui/about.rs similarity index 94% rename from gnome/src/about.rs rename to gnome/src/ui/about.rs index d32fc0b..36e2a9f 100644 --- a/gnome/src/about.rs +++ b/gnome/src/ui/about.rs @@ -8,7 +8,7 @@ static RELEASE_NOTES: &str = r#" "#; -pub fn dialog() -> adw::AboutDialog { +pub fn about_dialog() -> adw::AboutDialog { adw::AboutDialog::builder() .application_name("Clapgrep") .version("1.2") diff --git a/gnome/src/error_window/error_window.blp b/gnome/src/ui/error_window/error_window.blp similarity index 100% rename from gnome/src/error_window/error_window.blp rename to gnome/src/ui/error_window/error_window.blp diff --git a/gnome/src/error_window/imp.rs b/gnome/src/ui/error_window/imp.rs similarity index 91% rename from gnome/src/error_window/imp.rs rename to gnome/src/ui/error_window/imp.rs index 469ece4..2bb2aa8 100644 --- a/gnome/src/error_window/imp.rs +++ b/gnome/src/ui/error_window/imp.rs @@ -4,10 +4,10 @@ use glib::subclass::InitializingObject; use gtk::{glib, CompositeTemplate}; use std::cell::RefCell; -use crate::search_window::SearchWindow; +use crate::ui::SearchWindow; #[derive(CompositeTemplate, glib::Properties, Default)] -#[template(file = "src/error_window/error_window.blp")] +#[template(file = "src/ui/error_window/error_window.blp")] #[properties(wrapper_type = super::ErrorWindow)] pub struct ErrorWindow { #[property(get, set)] diff --git a/gnome/src/error_window/mod.rs b/gnome/src/ui/error_window/mod.rs similarity index 94% rename from gnome/src/error_window/mod.rs rename to gnome/src/ui/error_window/mod.rs index 8661392..93fcde0 100644 --- a/gnome/src/error_window/mod.rs +++ b/gnome/src/ui/error_window/mod.rs @@ -3,7 +3,7 @@ mod imp; use glib::Object; use gtk::{gio, glib, prelude::*}; -use crate::search_window::SearchWindow; +use crate::ui::SearchWindow; glib::wrapper! { pub struct ErrorWindow(ObjectSubclass) diff --git a/gnome/src/ui/mod.rs b/gnome/src/ui/mod.rs new file mode 100644 index 0000000..d8d84f7 --- /dev/null +++ b/gnome/src/ui/mod.rs @@ -0,0 +1,11 @@ +mod about; +pub use about::about_dialog; + +mod shortcuts; +pub use shortcuts::show_shortcuts; + +mod error_window; +pub use error_window::ErrorWindow; + +mod search_window; +pub use search_window::SearchWindow; diff --git a/gnome/src/search_window/imp.rs b/gnome/src/ui/search_window/imp.rs similarity index 98% rename from gnome/src/search_window/imp.rs rename to gnome/src/ui/search_window/imp.rs index 3629e11..7a529e9 100644 --- a/gnome/src/search_window/imp.rs +++ b/gnome/src/ui/search_window/imp.rs @@ -1,4 +1,4 @@ -use crate::{config::Config, error_window::ErrorWindow, search_model::SearchModel}; +use crate::{config::Config, search::SearchModel, ui::ErrorWindow}; use adw::subclass::prelude::*; use clapgrep_core::{SearchEngine, SearchFlags, SearchMessage, SearchParameters}; use glib::subclass::InitializingObject; @@ -15,7 +15,7 @@ use std::{ }; #[derive(CompositeTemplate, glib::Properties, Default)] -#[template(file = "src/search_window/search_window.blp")] +#[template(file = "src/ui/search_window/search_window.blp")] #[properties(wrapper_type = super::SearchWindow)] pub struct SearchWindow { #[property(get, set)] diff --git a/gnome/src/search_window/mod.rs b/gnome/src/ui/search_window/mod.rs similarity index 100% rename from gnome/src/search_window/mod.rs rename to gnome/src/ui/search_window/mod.rs diff --git a/gnome/src/search_window/search_window.blp b/gnome/src/ui/search_window/search_window.blp similarity index 100% rename from gnome/src/search_window/search_window.blp rename to gnome/src/ui/search_window/search_window.blp diff --git a/gnome/src/ui/shortcuts/mod.rs b/gnome/src/ui/shortcuts/mod.rs new file mode 100644 index 0000000..1a185cb --- /dev/null +++ b/gnome/src/ui/shortcuts/mod.rs @@ -0,0 +1,15 @@ +use gtk::prelude::*; +use gtk_blueprint::include_blp; + +use crate::ui::SearchWindow; + +pub fn show_shortcuts(window: &SearchWindow) { + let blueprint = include_blp!("gnome/src/ui/shortcuts/shortcuts.blp"); + let builder = gtk::Builder::from_string(blueprint); + let help_overlay = builder + .object::("help-overlay") + .unwrap(); + help_overlay.set_transient_for(Some(window)); + help_overlay.set_application(window.application().as_ref()); + help_overlay.present(); +} diff --git a/gnome/src/shortcuts.blp b/gnome/src/ui/shortcuts/shortcuts.blp similarity index 100% rename from gnome/src/shortcuts.blp rename to gnome/src/ui/shortcuts/shortcuts.blp