-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from luleyleo/restructure
Restructure gnome module
- Loading branch information
Showing
23 changed files
with
370 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::<adw::Application>().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", &["<ctrl>q"]); | ||
app.set_accels_for_action("app.shortcuts", &["<ctrl>h"]); | ||
app.set_accels_for_action("win.start-search", &["<ctrl>Return"]); | ||
app.set_accels_for_action("app.stop-search", &["<ctrl>s"]); | ||
|
||
window.present(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
use gtk::glib; | ||
|
||
glib::wrapper! { | ||
pub struct Config(ObjectSubclass<imp::Config>); | ||
} | ||
|
||
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<i32>, | ||
#[property(get, set = Self::set_window_height, default = 900)] | ||
window_height: Cell<i32>, | ||
#[property(get, set = Self::set_window_maximized, default = false)] | ||
window_maximized: Cell<bool>, | ||
|
||
#[property(get, set = Self::set_search_pdf, default = false)] | ||
search_pdf: Cell<bool>, | ||
#[property(get, set = Self::set_search_office, default = false)] | ||
search_office: Cell<bool>, | ||
|
||
config: OnceCell<cosmic_config::Config>, | ||
} | ||
|
||
#[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); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.