Commit 0c63b14b authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

minor cleaning

parent 105844d3
Pipeline #98183 passed with stages
in 22 minutes and 23 seconds
use crate::icon::Icon; use crate::icon::Icon;
use gdk; use gdk;
use gettextrs::gettext;
use gio::prelude::*; use gio::prelude::*;
use gtk; use gtk;
use gtk::prelude::*; use gtk::prelude::*;
...@@ -16,7 +16,7 @@ pub struct ExportDialog { ...@@ -16,7 +16,7 @@ pub struct ExportDialog {
} }
impl ExportDialog { impl ExportDialog {
pub fn new(icon: Icon) -> ExportDialog { pub fn new(icon: &Icon) -> ExportDialog {
let builder = gtk::Builder::new_from_resource("/org/gnome/design/IconLibrary/export_dialog.ui"); let builder = gtk::Builder::new_from_resource("/org/gnome/design/IconLibrary/export_dialog.ui");
let widget: libhandy::Dialog = builder.get_object("export_dialog").unwrap(); let widget: libhandy::Dialog = builder.get_object("export_dialog").unwrap();
...@@ -68,7 +68,13 @@ impl ExportDialog { ...@@ -68,7 +68,13 @@ impl ExportDialog {
let save_as = gio::SimpleAction::new("save-as", None); let save_as = gio::SimpleAction::new("save-as", None);
let window = self.widget.clone(); let window = self.widget.clone();
save_as.connect_activate(move |_, _| { save_as.connect_activate(move |_, _| {
let export_dialog = gtk::FileChooserNative::new(Some("Export a symbolic icon"), Some(&window), gtk::FileChooserAction::Save, Some("Export"), Some("Cancel")); let export_dialog = gtk::FileChooserNative::new(
Some(gettext("Export a symbolic icon").as_str()),
Some(&window),
gtk::FileChooserAction::Save,
Some(gettext("Export").as_str()),
Some(gettext("Cancel").as_str()),
);
let file_name = format!("{}.svg", icon_name.clone()); let file_name = format!("{}.svg", icon_name.clone());
export_dialog.set_current_name(Path::new(&file_name)); export_dialog.set_current_name(Path::new(&file_name));
let icon_name = icon_name.clone(); let icon_name = icon_name.clone();
......
...@@ -175,14 +175,10 @@ impl IconsViewContext { ...@@ -175,14 +175,10 @@ impl IconsViewContext {
} }
fn init(&self) { fn init(&self) {
self.widget.set_valign(gtk::Align::Fill);
self.widget.set_halign(gtk::Align::Fill);
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_row_spacing(12);
self.icons_container.set_column_spacing(12); self.icons_container.set_column_spacing(12);
self.icons_container.set_max_children_per_line(14); self.icons_container.set_max_children_per_line(14);
self.icons_container.set_min_children_per_line(6);
self.icons_container.set_selection_mode(gtk::SelectionMode::None); self.icons_container.set_selection_mode(gtk::SelectionMode::None);
let context_label = gtk::Label::new(Some(self.context.as_str())); let context_label = gtk::Label::new(Some(self.context.as_str()));
...@@ -203,13 +199,15 @@ impl IconsViewContext { ...@@ -203,13 +199,15 @@ impl IconsViewContext {
fn connect_signals(&self, parent: &gtk::ApplicationWindow) { fn connect_signals(&self, parent: &gtk::ApplicationWindow) {
let parent_window = parent.clone(); let parent_window = parent.clone();
let icons_views = self.icons_views.clone(); let icons_views = self.icons_views.clone();
self.icons_container.connect_child_activated(move |_, child| match icons_views.get(child) { self.icons_container.connect_child_activated(move |_, child| {
Some(icon) => { match icons_views.get(child) {
let export_dialog = ExportDialog::new(icon.clone()); Some(icon) => {
export_dialog.widget.set_transient_for(Some(&parent_window)); let export_dialog = ExportDialog::new(icon);
export_dialog.widget.show_all(); export_dialog.widget.set_transient_for(Some(&parent_window));
} export_dialog.widget.show_all();
None => println!("Couldn't find the icon"), }
None => error!("Export Dialog: Couldn't find the icon"),
};
}); });
} }
...@@ -219,7 +217,10 @@ impl IconsViewContext { ...@@ -219,7 +217,10 @@ impl IconsViewContext {
let filter_closure = move |child: &gtk::FlowBoxChild| -> bool { let filter_closure = move |child: &gtk::FlowBoxChild| -> bool {
match icons_views.get(child) { match icons_views.get(child) {
Some(icon) => icon.should_display(&search_str), Some(icon) => icon.should_display(&search_str),
None => false, None => {
error!("Search: couldn't find the icon");
false
}
} }
}; };
self.icons_container.set_filter_func(Some(Box::new(filter_closure))); self.icons_container.set_filter_func(Some(Box::new(filter_closure)));
...@@ -231,10 +232,9 @@ impl IconsViewContext { ...@@ -231,10 +232,9 @@ impl IconsViewContext {
self.widget.set_visible(self.n_last_search_results != 0); self.widget.set_visible(self.n_last_search_results != 0);
} }
} }
#[derive(Clone)]
struct IconView { struct IconView {
pub widget: gtk::FlowBoxChild, pub widget: gtk::FlowBoxChild,
icon: Icon,
} }
impl IconView { impl IconView {
...@@ -247,7 +247,7 @@ impl IconView { ...@@ -247,7 +247,7 @@ impl IconView {
widget.set_tooltip_text(Some(icon_name)); widget.set_tooltip_text(Some(icon_name));
widget.add(&icon_img); widget.add(&icon_img);
let icon_view = IconView { widget, icon }; let icon_view = IconView { widget };
icon_view icon_view
} }
} }
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