Skip to content

Commit

Permalink
at long last... ^C f to search and fix focus xou816#32
Browse files Browse the repository at this point in the history
  • Loading branch information
xou816 committed Feb 20, 2022
1 parent 986e3d8 commit 2ac769f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/app/components/navigation/navigation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use gtk::traits::WidgetExt;
use libadwaita::NavigationDirection;
use std::rc::Rc;

Expand Down Expand Up @@ -92,14 +93,18 @@ impl Navigation {
ScreenName::User(id) => Box::new(self.screen_factory.make_user_details(id.to_owned())),
};

let widget = component.get_root_widget();
let widget = component.get_root_widget().clone();
self.children.push(component);

self.leaflet.navigate(NavigationDirection::Forward);
self.navigation_stack
.add_named(widget, Some(name.identifier().as_ref()));
self.children.push(component);
.add_named(&widget, Some(name.identifier().as_ref()));
self.navigation_stack
.set_visible_child_name(name.identifier().as_ref());

glib::source::idle_add_local_once(move || {
widget.grab_focus();
});
}

fn pop(&mut self) {
Expand Down
8 changes: 7 additions & 1 deletion src/app/components/search/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ mod imp {
}

impl ObjectImpl for SearchResultsWidget {}
impl WidgetImpl for SearchResultsWidget {}
impl BoxImpl for SearchResultsWidget {}

impl WidgetImpl for SearchResultsWidget {
fn grab_focus(&self, _: &Self::Type) -> bool {
self.search_entry.grab_focus()
}
}
}

glib::wrapper! {
Expand Down Expand Up @@ -222,6 +227,7 @@ impl EventListener for SearchResults {
fn on_event(&mut self, app_event: &AppEvent) {
match app_event {
AppEvent::BrowserEvent(BrowserEvent::SearchUpdated) => {
self.get_root_widget().grab_focus();
self.update_search_query();
}
AppEvent::BrowserEvent(BrowserEvent::SearchResultsUpdated) => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/search/search.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<requires lib="gtk" version="4.0" />
<template class="SearchResultsWidget" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="can-focus">1</property>
<child>
<object class="AdwHeaderBar" id="main_header">
<property name="show-end-title-buttons">1</property>
Expand All @@ -17,6 +18,7 @@
<child type="title">
<object class="GtkSearchEntry" id="search_entry">
<property name="receives-default">1</property>
<property name="can-focus">1</property>
</object>
</child>
</object>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/search/search_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl SearchResultsModel {

fn get_query(&self) -> Option<impl Deref<Target = String> + '_> {
self.app_model
.map_state_opt(|s| Some(&s.browser.search_state()?.query))
.map_state_opt(|s| Some(&s.browser.search_state()?.query).filter(|s| !s.is_empty()))
}

pub fn fetch_results(&self) {
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate lazy_static;
#[macro_use]
extern crate log;

use app::state::ScreenName;
use futures::channel::mpsc::UnboundedSender;
use gettextrs::*;
use gio::prelude::*;
Expand Down Expand Up @@ -144,6 +145,12 @@ fn register_actions(app: &gtk::Application, sender: UnboundedSender<AppAction>)
app.add_action(&make_action(
"nav_pop",
AppAction::BrowserAction(BrowserAction::NavigationPop),
sender.clone(),
));

app.add_action(&make_action(
"search",
AppAction::BrowserAction(BrowserAction::NavigationPush(ScreenName::Search)),
sender,
));
}
Expand Down
12 changes: 8 additions & 4 deletions src/window.ui.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
</child>
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;Alt&gt;P</property>
<property name="trigger">P</property>
<property name="action">action(app.player_prev)</property>
</object>
</child>
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;Alt&gt;N</property>
<property name="trigger">N</property>
<property name="action">action(app.player_next)</property>
</object>
</child>
Expand All @@ -41,6 +41,12 @@
<property name="action">action(app.nav_pop)</property>
</object>
</child>
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;Ctrl&gt;F</property>
<property name="action">action(app.search)</property>
</object>
</child>
</object>
</child>
<child>
Expand All @@ -59,7 +65,6 @@
</binding>
<child>
<object class="GtkButton" id="search_button">
<property name="receives-default">1</property>
<property name="icon-name">system-search-symbolic</property>
</object>
</child>
Expand All @@ -70,7 +75,6 @@
</child>
<child type="end">
<object class="GtkMenuButton" id="user">
<property name="receives-default">1</property>
<property name="icon-name">open-menu-symbolic</property>
</object>
</child>
Expand Down

0 comments on commit 2ac769f

Please sign in to comment.