Skip to content

Commit

Permalink
Merge pull request #16 from luleyleo/adaptive-design
Browse files Browse the repository at this point in the history
Make the UI adaptive to smaller screens
  • Loading branch information
luleyleo authored Nov 2, 2024
2 parents 475c20d + 16820ab commit 9be977b
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 164 deletions.
3 changes: 1 addition & 2 deletions assets/de.leopoldluley.Clapgrep.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
<color type="primary" scheme_preference="dark">#575243</color>
</branding>
<requires>
<display_length compare="ge">567</display_length>
<display_length compare="ge">400</display_length>
<internet>offline-only</internet>
</requires>
<recommends>
<display_length compare="ge">900</display_length>
</recommends>
<supports>
<control>keyboard</control>
Expand Down
10 changes: 10 additions & 0 deletions gnome/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 std::path::PathBuf;

Expand Down Expand Up @@ -46,6 +47,15 @@ fn main() {

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 = search_window::SearchWindow::new(app);

if let Some(dir) = files.first() {
Expand Down
63 changes: 61 additions & 2 deletions gnome/src/search_window/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,30 @@ pub struct SearchWindow {
pub searched_files: Cell<u32>,
#[property(get)]
pub number_of_matches: Cell<u32>,
#[property(get)]
pub search_progress_notification: RefCell<String>,

#[property(get)]
pub errors: StringList,
#[property(get)]
pub number_of_errors: Cell<u32>,
#[property(get)]
pub has_errors: Cell<bool>,
#[property(get)]
pub search_errors_notification: RefCell<String>,

#[template_child]
pub results_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub no_search_page: TemplateChild<gtk::StackPage>,
#[template_child]
pub no_results_page: TemplateChild<gtk::StackPage>,
#[template_child]
pub results_page: TemplateChild<gtk::StackPage>,
#[template_child]
pub search_progress_banner: TemplateChild<gtk::Revealer>,
#[template_child]
pub split_view: TemplateChild<adw::NavigationSplitView>,

pub engine: SearchEngine,
pub config: Config,
Expand Down Expand Up @@ -88,10 +105,15 @@ impl SearchWindow {
}

#[template_callback]
fn on_cancel_search(&self, _: &adw::ActionRow) {
fn on_cancel_search(&self, _: &gtk::Button) {
self.stop_search();
}

#[template_callback]
fn on_close_search_progress(&self, _: &gtk::Button) {
self.search_progress_banner.set_reveal_child(false);
}

#[template_callback]
fn on_cd(&self, _: &gtk::Button) {
let obj = self.obj();
Expand All @@ -118,7 +140,7 @@ impl SearchWindow {
}

#[template_callback]
fn on_show_errors(&self, _: &adw::ActionRow) {
fn on_show_errors(&self, _: &adw::Banner) {
let error_window = ErrorWindow::new(&self.obj());
error_window.present();
}
Expand Down Expand Up @@ -180,6 +202,8 @@ impl SearchWindow {
self.errors.splice(0, self.errors.n_items(), &[]);
self.obj().set_searched_files(0);
self.obj().set_search_running(true);
self.search_progress_banner.set_reveal_child(true);
self.split_view.set_show_content(true);

self.engine.search(search);
}
Expand All @@ -188,6 +212,15 @@ impl SearchWindow {
self.obj().set_search_running(false);
self.engine.cancel();
}

fn update_search_progress(&self) {
let files = self.searched_files.get();
let matches = self.number_of_matches.get();
let message = format!("Searched {files} files and found {matches} matches");

*self.search_progress_notification.borrow_mut() = message;
self.obj().notify("search_progress_notification");
}
}

#[glib::derived_properties]
Expand Down Expand Up @@ -254,6 +287,32 @@ impl ObjectImpl for SearchWindow {
obj.notify("search-directory")
});

obj.connect_search_running_notify(|obj| {
let imp = obj.imp();

if imp.search_running.get() || imp.number_of_matches.get() > 0 {
imp.results_stack
.set_visible_child(&imp.results_page.child());
} else {
imp.results_stack
.set_visible_child(&imp.no_results_page.child());
}
});

obj.connect_searched_files_notify(|obj| {
obj.imp().update_search_progress();
});
obj.connect_number_of_matches_notify(|obj| {
obj.imp().update_search_progress();
});

obj.connect_number_of_errors_notify(|obj| {
let errors = obj.number_of_errors();
*obj.imp().search_errors_notification.borrow_mut() =
format!("Encountered {errors} errors during search");
obj.notify("search_errors_notification")
});

if !self.search_path.borrow().is_dir() {
if let Ok(absolute) = Path::new(".").canonicalize() {
self.obj().set_search_path(absolute);
Expand Down
Loading

0 comments on commit 9be977b

Please sign in to comment.