Skip to content

Commit

Permalink
Merge pull request #12 from luleyleo/remember-search-formats
Browse files Browse the repository at this point in the history
Remember search_pdf and search_office across restarts
  • Loading branch information
luleyleo authored Oct 7, 2024
2 parents dc54cc2 + 1abecb2 commit fbbfa2b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gnome/src/config/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub struct Config {
#[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>,
}

Expand All @@ -36,6 +41,18 @@ impl Config {
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
Expand All @@ -62,6 +79,14 @@ impl ObjectImpl for Config {
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);
}
}
12 changes: 12 additions & 0 deletions gnome/src/search_window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ impl ObjectImpl for SearchWindow {
.sync_create()
.build();

self.config
.bind_property("search_pdf", obj.as_ref(), "search_pdf")
.bidirectional()
.sync_create()
.build();

self.config
.bind_property("search_office", obj.as_ref(), "search_office")
.bidirectional()
.sync_create()
.build();

obj.results().connect_items_changed(clone!(
#[weak]
obj,
Expand Down

0 comments on commit fbbfa2b

Please sign in to comment.