Skip to content

Commit

Permalink
gnome: Add help-overlay for shortcuts.
Browse files Browse the repository at this point in the history
  • Loading branch information
luleyleo committed Sep 4, 2024
1 parent 0e9cbb1 commit 10e48a4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 7 deletions.
84 changes: 78 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gnome/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ adw = { version = "0.7.0", package = "libadwaita", features = ["v1_5"] }
gtk = { version = "0.9.0", package = "gtk4", features = ["blueprint", "v4_14"] }
flume = "0.11.0"
gettext-rs = { version = "0.7.1", features = ["gettext-system"] }
gtk-blueprint = "0.2.0"
19 changes: 19 additions & 0 deletions gnome/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::PathBuf;
use gtk::{gio::SimpleAction, License};
use adw::prelude::*;
use gtk::glib::{self, clone};
use gtk_blueprint::include_blp;

mod search_match;
mod search_model;
Expand Down Expand Up @@ -49,6 +50,24 @@ fn main() {
}));
app.add_action(&about_action);

let shortcuts_action = SimpleAction::new("shortcuts", None);
shortcuts_action.connect_activate(clone!(#[weak] window, move |_, _| {
let builder = gtk::Builder::from_string(include_blp!("gnome/src/shortcuts.blp"));
let help_overlay = builder.object::<gtk::ShortcutsWindow>("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);
app.set_accels_for_action("app.shortcuts", &["<ctrl>h"]);

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"]);

window.present();
});

Expand Down
40 changes: 40 additions & 0 deletions gnome/src/shortcuts.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Gtk 4.0;

ShortcutsWindow help-overlay {
modal: true;
title: _("Clapgrep Shortcuts");

ShortcutsSection {
ShortcutsGroup {
title: _("General");

ShortcutsShortcut {
title: _("Quit");
accelerator: "<ctrl>q";
action-name: "app.quit";
}

ShortcutsShortcut {
title: _("Shortcuts");
accelerator: "<ctrl>h";
action-name: "app.shortcuts";
}
}

ShortcutsGroup {
title: _("Control Search");

ShortcutsShortcut {
title: _("Start Search");
accelerator: "<ctrl>Return";
action-name: "win.start-search";
}

ShortcutsShortcut {
title: _("Stop Search");
accelerator: "<ctrl>s";
action-name: "win.stop-search";
}
}
}
}
4 changes: 3 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
gnome/src/window/window.blp
gnome/src/search_window/search_window.blp
gnome/src/error_window/error_window.blp
gnome/src/shortcuts.blp

0 comments on commit 10e48a4

Please sign in to comment.