Commit 98538ffb authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

Search: finally working thanks to Chris & Felix :D

parent e001f439
Pipeline #97046 passed with stages
in 6 minutes and 38 seconds
......@@ -15,7 +15,12 @@
"--share=ipc",
"--socket=x11",
"--socket=wayland",
"--device=dri"
"--device=dri",
/* FIXME: only needed for Inspector till it's fixed upstream */
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
"build-options" : {
"append-path" : "/usr/lib/sdk/rust-stable/bin",
......
......@@ -21,12 +21,11 @@
<property name="can_focus">False</property>
<property name="maximum_width">400</property>
<property name="linear_growth_width">400</property>
<property name="hexpand">True</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
......
use gtk::prelude::{BoxExt, ContainerExt, FlowBoxExt, GtkWindowExt, IconThemeExt, StyleContextExt, WidgetExt};
use gtk::{Box, FlowBox, IconTheme, Image, Label};
use crate::widgets::export::ExportDialog;
use glib::Cast;
use gtk;
use gtk::prelude::{BoxExt, ContainerExt, FlowBoxExt, GtkWindowExt, IconThemeExt, StyleContextExt, WidgetExt};
struct IconView {
pub widget: Box,
pub widget: gtk::Box,
icon_name: String,
}
impl IconView {
pub fn new(icon_name: String) -> IconView {
let container = Box::new(gtk::Orientation::Vertical, 6);
let container = gtk::Box::new(gtk::Orientation::Vertical, 6);
container.set_name(icon_name.as_str());
let icon_img = Image::new_from_icon_name(Some(icon_name.as_str()), gtk::IconSize::Dnd);
let icon_img = gtk::Image::new_from_icon_name(Some(icon_name.as_str()), gtk::IconSize::Dnd);
container.pack_start(&icon_img, false, false, 0);
......@@ -24,17 +24,64 @@ impl IconView {
}
pub struct IconsView {
pub widget: Box,
pub context: String,
pub widget: gtk::Box,
}
impl IconsView {
pub fn new(context: String, parent: &gtk::ApplicationWindow) -> IconsView {
let widget = Box::new(gtk::Orientation::Vertical, 6);
pub fn new(parent: &gtk::ApplicationWindow) -> IconsView {
let widget = gtk::Box::new(gtk::Orientation::Vertical, 0);
let icons_view = IconsView { widget };
icons_view.fill(&parent);
icons_view
}
fn fill(&self, parent: &gtk::ApplicationWindow) {
let legacy_contexts = vec!["Legacy"];
let theme = gtk::IconTheme::get_default().unwrap();
let mut icon_contexts = theme.list_contexts();
icon_contexts.sort_by(|a, b| a.as_str().cmp(&b.as_str()));
for context in icon_contexts.iter() {
let context_str = context.as_str();
if legacy_contexts.contains(&context_str) {
continue;
}
let icons_view_context = IconsViewContext::new(context_str.to_string(), &parent);
self.widget.pack_start(&icons_view_context.widget, true, true, 12);
}
}
pub fn filter(&self, search_str: String) {
let s = search_str.clone();
let filter_closure = move |flowboxchild: &gtk::FlowBoxChild| -> bool {
let row_container = &flowboxchild.get_children()[0];
let icon_name = &row_container.get_name().unwrap().as_str().to_string();
icon_name.contains(s.as_str())
};
for child in self.widget.get_children() {
let icons_view_context = child.downcast::<gtk::Container>().unwrap();
let flowbox_widget = &icons_view_context.get_children()[1];
let flowbox = flowbox_widget.clone().downcast::<gtk::FlowBox>().unwrap();
let search_str = search_str.clone();
flowbox.set_filter_func(Some(Box::new(filter_closure.clone())));
}
}
}
struct IconsViewContext {
pub widget: gtk::Box,
pub context: String,
icons_container: gtk::FlowBox,
}
impl IconsViewContext {
pub fn new(context: String, parent: &gtk::ApplicationWindow) -> IconsViewContext {
let widget = gtk::Box::new(gtk::Orientation::Vertical, 6);
widget.set_valign(gtk::Align::Fill);
widget.set_halign(gtk::Align::Fill);
let icons_view = IconsView { widget, context };
let icons_container = gtk::FlowBox::new();
let icons_view = IconsViewContext { widget, context, icons_container };
icons_view.init();
icons_view.fill(&parent);
......@@ -42,7 +89,7 @@ impl IconsView {
}
fn init(&self) {
let context_label = Label::new(Some(self.context.as_str()));
let context_label = gtk::Label::new(Some(self.context.as_str()));
context_label.set_halign(gtk::Align::Start);
context_label.get_style_context().add_class("icons-view-title");
......@@ -50,7 +97,7 @@ impl IconsView {
}
fn fill(&self, parent: &gtk::ApplicationWindow) {
let theme = IconTheme::get_default();
let theme = gtk::IconTheme::get_default();
let mut icons = theme.unwrap().list_icons(Some(self.context.as_str()));
icons.sort_by(|a, b| a.as_str().cmp(&b.as_str()));
......@@ -63,22 +110,20 @@ impl IconsView {
"gesture-rotate-anticlockwise-symbolic",
];
let icons_container = FlowBox::new();
icons_container.set_valign(gtk::Align::Fill);
icons_container.set_halign(gtk::Align::Fill);
icons_container.set_row_spacing(12);
icons_container.set_column_spacing(12);
icons_container.set_max_children_per_line(14);
icons_container.set_selection_mode(gtk::SelectionMode::None);
self.icons_container.set_valign(gtk::Align::Fill);
self.icons_container.set_halign(gtk::Align::Fill);
self.icons_container.set_row_spacing(12);
self.icons_container.set_column_spacing(12);
self.icons_container.set_max_children_per_line(14);
self.icons_container.set_selection_mode(gtk::SelectionMode::None);
let parent_window = parent.clone();
icons_container.connect_child_activated(move |_, child| {
self.icons_container.connect_child_activated(move |_, child| {
let child_container = &child.get_children()[0];
let icon_name = child_container.get_name().unwrap();
let export_dialog = ExportDialog::new(String::from(icon_name.as_str()));
export_dialog.widget.set_transient_for(&parent_window);
export_dialog.widget.show_all();
// TODO: set the export dialog as transient for the parent window
});
for icon in icons.iter() {
......@@ -88,9 +133,9 @@ impl IconsView {
}
if icon_name.ends_with("-symbolic") {
let icon_view = IconView::new(icon_name);
icons_container.add(&icon_view.widget);
self.icons_container.add(&icon_view.widget);
}
}
self.widget.add(&icons_container);
self.widget.add(&self.icons_container);
}
}
use gtk::prelude::*;
use libhandy::{Column, ColumnExt};
use crate::config::{APP_ID, PROFILE};
use crate::widgets::IconsView;
use crate::window_state;
use gtk::prelude::*;
use libhandy::{Column, ColumnExt};
pub struct Window {
pub widget: gtk::ApplicationWindow,
......@@ -44,36 +43,29 @@ impl Window {
Inhibit(false)
});
// Init the widgets
let legacy_contexts = vec!["Legacy"];
let container = gtk::Box::new(gtk::Orientation::Vertical, 0);
let theme = gtk::IconTheme::get_default().unwrap();
let mut icon_contexts = theme.list_contexts();
icon_contexts.sort_by(|a, b| a.as_str().cmp(&b.as_str()));
for context in icon_contexts.iter() {
let context_str = context.as_str();
if legacy_contexts.contains(&context_str) {
continue;
}
let icons_view = IconsView::new(context_str.to_string(), &self.widget);
container.pack_start(&icons_view.widget, true, true, 12);
}
let icons_view = IconsView::new(&self.widget);
let column = Column::new();
column.set_maximum_width(900);
let scrolled_window = gtk::ScrolledWindow::new(gtk::NONE_ADJUSTMENT, gtk::NONE_ADJUSTMENT);
scrolled_window.set_vexpand(true);
scrolled_window.add(&column);
// we can't call add as libhandy::Column is not seen as a gtkContainer
// Thanks to Jordan (Podcasts) for the tip :P
let column = column.upcast::<gtk::Widget>();
let column = column.downcast::<gtk::Container>().unwrap();
column.add(&container);
column.add(&icons_view.widget);
column.set_margin_bottom(24);
let scrolled_window = gtk::ScrolledWindow::new(gtk::NONE_ADJUSTMENT, gtk::NONE_ADJUSTMENT);
scrolled_window.set_vexpand(true);
scrolled_window.add(&column);
self.widget.add(&scrolled_window);
// Search
self.search_entry.connect_changed(move |entry| {
let search_text = entry.get_text().unwrap();
let search_str = search_text.as_str().to_string();
icons_view.filter(search_str);
});
self.widget.show_all();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment