Skip to content

Commit

Permalink
Merge pull request #830 from marhkb/feat/search/overhaul
Browse files Browse the repository at this point in the history
Feat/search/overhaul
  • Loading branch information
marhkb authored Oct 9, 2024
2 parents e137a82 + c4ed3fb commit cee3a5c
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 240 deletions.
10 changes: 10 additions & 0 deletions data/com.github.marhkb.Pods.metainfo.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
<url type="bugtracker">https://github.com/marhkb/pods/issues</url>
<content_rating type="oars-1.1"/>
<releases>
<release version="2.2.0~devel" date="2024-11-25">
<description translatable="no">
<p>Pods 2.2.0 contains the following changes:</p>
<p>Features</p>
<ul>
<li>The search entry to a toggle button in the headerbar. (#830)</li>
<li>Search is now possible in the connection chooser page. (#830)</li>
</ul>
</description>
</release>
<release version="2.1.0~devel" date="2024-11-25">
<description translatable="no">
<p>Pods 2.1.0 contains the following changes:</p>
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ fn init() {
view::RepoTagSimpleRow::static_type();
view::ScalableTextViewPage::static_type();
view::SearchPanel::static_type();
view::SearchRow::static_type();
view::VolumeRow::static_type();
view::VolumesGroup::static_type();
view::VolumesPanel::static_type();
Expand Down
1 change: 0 additions & 1 deletion src/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<file compressed="true" preprocess="xml-stripblanks">view/repo_tag_simple_row.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/scalable_text_view_page.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/search_panel.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/search_row.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/top_page.ui</file>
<file compressed="true" preprocess="xml-stripblanks">view/top_page_action_bar.ui</file>
Expand Down
152 changes: 86 additions & 66 deletions src/view/client_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::model;
use crate::utils;
use crate::view;

const ACTION_GLOBAL_SEARCH: &str = "client-view.global-search";
const ACTION_PANEL_SEARCH: &str = "client-view.panel-search";
const ACTION_SHOW_CONNECTIONS: &str = "client-view.show-connections";
const ACTION_SHOW_ACTIONS: &str = "client-view.show-actions";
const ACTION_CANCEL_OR_DELETE_ACTION: &str = "client-view.cancel-or-delete-action";
Expand All @@ -33,13 +31,17 @@ mod imp {
#[template_child]
pub(super) sidebar_navigation_view: TemplateChild<adw::NavigationView>,
#[template_child]
pub(super) search_button: TemplateChild<gtk::ToggleButton>,
#[template_child]
pub(super) sidebar_list_box: TemplateChild<gtk::ListBox>,
#[template_child]
pub(super) content_navigation_view: TemplateChild<adw::NavigationView>,
pub(super) stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) panels_navigation_view: TemplateChild<adw::NavigationView>,
#[template_child]
pub(super) content_navigation_page: TemplateChild<adw::NavigationPage>,
pub(super) panels_navigation_page: TemplateChild<adw::NavigationPage>,
#[template_child]
pub(super) panel_stack: TemplateChild<gtk::Stack>,
pub(super) panels_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) containers_panel: TemplateChild<view::ContainersPanel>,
#[template_child]
Expand All @@ -49,6 +51,8 @@ mod imp {
#[template_child]
pub(super) volumes_panel: TemplateChild<view::VolumesPanel>,
#[template_child]
pub(super) search_navigation_view: TemplateChild<adw::NavigationView>,
#[template_child]
pub(super) color_bin: TemplateChild<adw::Bin>,
}

Expand All @@ -62,24 +66,6 @@ mod imp {
klass.bind_template();
klass.bind_template_callbacks();

klass.add_binding_action(
gdk::Key::F,
gdk::ModifierType::CONTROL_MASK | gdk::ModifierType::SHIFT_MASK,
ACTION_GLOBAL_SEARCH,
);
klass.install_action(ACTION_GLOBAL_SEARCH, None, |widget, _, _| {
widget.global_search();
});

klass.add_binding_action(
gdk::Key::F,
gdk::ModifierType::CONTROL_MASK,
ACTION_PANEL_SEARCH,
);
klass.install_action(ACTION_PANEL_SEARCH, None, |widget, _, _| {
widget.toggle_panel_search();
});

klass.install_action(ACTION_SHOW_CONNECTIONS, None, |widget, _, _| {
widget.show_connections();
});
Expand Down Expand Up @@ -130,17 +116,15 @@ mod imp {
self.settings
.bind(
"last-used-view",
&self.panel_stack.get(),
&self.panels_stack.get(),
"visible-child-name",
)
.build();

self.sidebar_list_box.set_header_func(|row, _| {
row.set_header(
row.child()
.filter(|child| {
child.is::<view::InfoRow>() || child.is::<view::SearchRow>()
})
.filter(gtk::Widget::is::<view::InfoRow>)
.map(|_| {
gtk::Separator::builder()
.orientation(gtk::Orientation::Horizontal)
Expand All @@ -155,7 +139,7 @@ mod imp {
.style_context()
.add_provider(&self.css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);

self.on_panel_stack_notify_visible_child();
self.on_panels_stack_notify_visible_child();
}

fn dispose(&self) {
Expand All @@ -167,11 +151,25 @@ mod imp {

#[gtk::template_callbacks]
impl ClientView {
#[template_callback]
fn on_key_pressed(
&self,
key: gdk::Key,
_: u32,
_: gdk::ModifierType,
_: &gtk::EventControllerKey,
) -> glib::Propagation {
if key == gdk::Key::Escape {
self.search_button.set_active(false);
}
glib::Propagation::Proceed
}

#[template_callback]
fn on_notify_client(&self) {
self.exit_panel_search_mode();
self.sidebar_navigation_view.pop_to_tag("home");
self.content_navigation_view.pop_to_tag("home");
self.panels_navigation_view.pop_to_tag("home");

if let Some(client) = self.obj().client() {
self.set_background(client.connection().rgb());
Expand All @@ -181,6 +179,7 @@ mod imp {
#[template_callback]
fn on_navigation_split_view_notify_show_content(&self) {
if self.navigation_split_view.is_collapsed() {
self.search_button.set_active(false);
self.sidebar_list_box.select_row(gtk::ListBoxRow::NONE);
self.exit_selection_mode();
}
Expand All @@ -190,22 +189,20 @@ mod imp {
fn on_navigation_split_view_notify_collapsed(&self) {
if !self.navigation_split_view.is_collapsed() {
self.navigation_split_view.set_show_content(true);
self.restore_sidebar();
}
}

self.sidebar_list_box.select_row(
self.sidebar_list_box
.row_at_index(
match self.panel_stack.visible_child_name().unwrap().as_str() {
"containers" => 0,
"pods" => 1,
"images" => 2,
"volumes" => 3,
"info" => 4,
"search" => 5,
_ => unreachable!(),
},
)
.as_ref(),
);
#[template_callback]
fn on_search_button_toggled(&self) {
if self.search_button.is_active() {
self.stack.set_visible_child_name("search");
self.sidebar_list_box.select_row(gtk::ListBoxRow::NONE);
self.navigation_split_view.set_show_content(true);
} else if !self.navigation_split_view.is_collapsed() {
self.stack.set_visible_child_name("panels");
self.search_navigation_view.pop_to_tag("home");
self.restore_sidebar();
}
}

Expand All @@ -214,7 +211,7 @@ mod imp {
if let Some(row) = row {
let child = row.child().unwrap();

self.panel_stack
self.panels_stack
.set_visible_child_name(if child.is::<view::ContainersRow>() {
"containers"
} else if child.is::<view::PodsRow>() {
Expand All @@ -225,14 +222,16 @@ mod imp {
"volumes"
} else if child.is::<view::InfoRow>() {
"info"
} else if child.is::<view::SearchRow>() {
"search"
} else {
unreachable!()
});

self.content_navigation_view.pop_to_tag("home");
self.stack.set_visible_child_name("panels");
self.panels_navigation_view.pop_to_tag("home");
self.search_navigation_view.pop_to_tag("home");
self.navigation_split_view.set_show_content(true);

self.search_button.set_active(false);
}
}

Expand All @@ -242,9 +241,9 @@ mod imp {
}

#[template_callback]
fn on_panel_stack_notify_visible_child(&self) {
self.content_navigation_page.set_title(&match self
.panel_stack
fn on_panels_stack_notify_visible_child(&self) {
self.panels_navigation_page.set_title(&match self
.panels_stack
.visible_child_name()
.unwrap()
.as_str()
Expand All @@ -254,13 +253,33 @@ mod imp {
"images" => gettext("Images"),
"volumes" => gettext("Volumes"),
"info" => gettext("Info"),
"search" => gettext("Search"),
_ => unreachable!(),
});

self.exit_selection_mode();
}

fn restore_sidebar(&self) {
match self.stack.visible_child_name().as_deref() {
Some("search") => self.search_button.set_active(true),
Some("panels") => self.sidebar_list_box.select_row(
self.sidebar_list_box
.row_at_index(
match self.panels_stack.visible_child_name().unwrap().as_str() {
"containers" => 0,
"pods" => 1,
"images" => 2,
"volumes" => 3,
"info" => 4,
_ => unreachable!(),
},
)
.as_ref(),
),
_ => {}
}
}

fn exit_panel_search_mode(&self) {
self.containers_panel.set_search_mode(false);
self.pods_panel.set_search_mode(false);
Expand Down Expand Up @@ -298,27 +317,28 @@ glib::wrapper! {

impl ClientView {
pub(crate) fn navigation_view(&self) -> &adw::NavigationView {
&self.imp().content_navigation_view
&self.imp().panels_navigation_view
}

pub(crate) fn global_search(&self) {
self.imp()
.sidebar_list_box
.row_at_index(7)
.as_ref()
.unwrap()
.activate();
pub(crate) fn toggle_global_search(&self) {
let imp = self.imp();
if imp.client.upgrade().is_some() {
imp.sidebar_navigation_view.pop_to_tag("home");
imp.search_button.set_active(!imp.search_button.is_active());
}
}

pub(crate) fn toggle_panel_search(&self) {
let imp = self.imp();

match imp.panel_stack.visible_child_name().unwrap().as_str() {
"containers" => imp.containers_panel.toggle_search_mode(),
"pods" => imp.pods_panel.toggle_search_mode(),
"images" => imp.images_panel.toggle_search_mode(),
"volumes" => imp.volumes_panel.toggle_search_mode(),
_ => {}
if imp.stack.visible_child_name().as_deref() == Some("panels") {
match imp.panels_stack.visible_child_name().unwrap().as_str() {
"containers" => imp.containers_panel.toggle_search_mode(),
"pods" => imp.pods_panel.toggle_search_mode(),
"images" => imp.images_panel.toggle_search_mode(),
"volumes" => imp.volumes_panel.toggle_search_mode(),
_ => {}
}
}
}

Expand Down
Loading

0 comments on commit cee3a5c

Please sign in to comment.