[fractal/fractal-next] Add Ctrl+K shortcut to toggle room list search
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] Add Ctrl+K shortcut to toggle room list search
- Date: Tue, 15 Jun 2021 10:06:14 +0000 (UTC)
commit 71061f96978a9b6cd8982fe906601a27fd4e5cb8
Author: Kai A. Hiller <V02460 gmail com>
Date: Mon Jun 14 18:22:10 2021 +0200
Add Ctrl+K shortcut to toggle room list search
data/resources/ui/session.ui | 2 +-
data/resources/ui/shortcuts.ui | 6 ++++++
data/resources/ui/sidebar.ui | 3 ++-
src/application.rs | 1 +
src/session/mod.rs | 7 +++++++
src/session/sidebar/sidebar.rs | 7 +++++++
src/window.rs | 13 +++++++++++++
7 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/ui/session.ui b/data/resources/ui/session.ui
index 7d5f4d59..b53a91db 100644
--- a/data/resources/ui/session.ui
+++ b/data/resources/ui/session.ui
@@ -47,7 +47,7 @@
<child>
<object class="AdwLeaflet" id="content">
<child>
- <object class="Sidebar">
+ <object class="Sidebar" id="sidebar">
<property name="compact" bind-source="content" bind-property="folded"
bind-flags="sync-create"/>
<property name="room-list" bind-source="Session" bind-property="room-list"
bind-flags="sync-create"/>
<property name="selected-room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create | bidirectional"/>
diff --git a/data/resources/ui/shortcuts.ui b/data/resources/ui/shortcuts.ui
index e3cba51f..e1a75664 100644
--- a/data/resources/ui/shortcuts.ui
+++ b/data/resources/ui/shortcuts.ui
@@ -21,6 +21,12 @@
<property name="action-name">app.quit</property>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="title" translatable="yes" context="shortcut window">Search Room
List</property>
+ <property name="action-name">win.toggle-room-search</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/data/resources/ui/sidebar.ui b/data/resources/ui/sidebar.ui
index 8228b87d..c56907c3 100644
--- a/data/resources/ui/sidebar.ui
+++ b/data/resources/ui/sidebar.ui
@@ -29,6 +29,8 @@
<child type="start">
<object class="GtkToggleButton" id="search_button">
<property name="icon-name">system-search-symbolic</property>
+ <property name="active" bind-source="room_search" bind-property="search-mode-enabled"
bind-flags="sync-create"/>
+ <property name="action-name">win.toggle-room-search</property>
</object>
</child>
<child type="end">
@@ -41,7 +43,6 @@
</child>
<child>
<object class="GtkSearchBar" id="room_search">
- <property name="search-mode-enabled" bind-source="search_button" bind-property="active"/>
<property name="child">
<object class="GtkSearchEntry" id="room_search_entry"/>
</property>
diff --git a/src/application.rs b/src/application.rs
index 886519b7..6fdc3e7d 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -124,6 +124,7 @@ impl Application {
fn setup_accels(&self) {
self.set_accels_for_action("app.quit", &["<Control>q"]);
self.set_accels_for_action("win.show-help-overlay", &["<Control>question"]);
+ self.set_accels_for_action("win.toggle-room-search", &["<Control>k"]);
}
fn setup_css(&self) {
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 07c13f56..de622e7f 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -53,6 +53,8 @@ mod imp {
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub content: TemplateChild<adw::Leaflet>,
+ #[template_child]
+ pub sidebar: TemplateChild<Sidebar>,
/// Contains the error if something went wrong
pub error: RefCell<Option<matrix_sdk::Error>>,
pub client: OnceCell<Client>,
@@ -262,6 +264,11 @@ impl Session {
);
}
+ pub fn room_search_bar(&self) -> gtk::SearchBar {
+ let priv_ = imp::Session::from_instance(self);
+ priv_.sidebar.room_search_bar()
+ }
+
pub fn login_with_previous_session(&self, session: StoredSession) {
do_async(
glib::PRIORITY_DEFAULT_IDLE,
diff --git a/src/session/sidebar/sidebar.rs b/src/session/sidebar/sidebar.rs
index 4b868516..d934e188 100644
--- a/src/session/sidebar/sidebar.rs
+++ b/src/session/sidebar/sidebar.rs
@@ -26,6 +26,8 @@ mod imp {
pub listview: TemplateChild<gtk::ListView>,
#[template_child]
pub room_search_entry: TemplateChild<gtk::SearchEntry>,
+ #[template_child]
+ pub room_search: TemplateChild<gtk::SearchBar>,
}
#[glib::object_subclass]
@@ -187,6 +189,11 @@ impl Sidebar {
priv_.selected_room.borrow().clone()
}
+ pub fn room_search_bar(&self) -> gtk::SearchBar {
+ let priv_ = imp::Sidebar::from_instance(self);
+ priv_.room_search.clone()
+ }
+
pub fn set_room_list(&self, room_list: Option<RoomList>) {
let priv_ = imp::Sidebar::from_instance(self);
diff --git a/src/window.rs b/src/window.rs
index 88615b82..396b0300 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -4,6 +4,7 @@ use crate::Application;
use crate::Login;
use crate::Session;
use adw::subclass::prelude::AdwApplicationWindowImpl;
+use gio::PropertyAction;
use glib::signal::Inhibit;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
@@ -97,6 +98,18 @@ impl Window {
let priv_ = &imp::Window::from_instance(self);
priv_.main_stack.add_child(session);
priv_.main_stack.set_visible_child(session);
+ self.install_session_actions(session);
+ }
+
+ /// Installs session-related actions to the Window.
+ fn install_session_actions(&self, session: &Session) {
+ let room_search_bar = session.room_search_bar();
+ let room_search_toggle_action = PropertyAction::new(
+ "toggle-room-search",
+ &room_search_bar,
+ "search-mode-enabled",
+ );
+ self.add_action(&room_search_toggle_action);
}
fn restore_sessions(&self) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]