summaryrefslogtreecommitdiff
path: root/src/gui/iconSelectWindow.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/iconSelectWindow.vala')
-rw-r--r--src/gui/iconSelectWindow.vala428
1 files changed, 206 insertions, 222 deletions
diff --git a/src/gui/iconSelectWindow.vala b/src/gui/iconSelectWindow.vala
index 01a4a40..d66c654 100644
--- a/src/gui/iconSelectWindow.vala
+++ b/src/gui/iconSelectWindow.vala
@@ -23,45 +23,19 @@ namespace GnomePie {
/// happens in an extra thread and a spinner is displayed while loading.
/////////////////////////////////////////////////////////////////////////
-public class IconSelectWindow : Gtk.Dialog {
-
+public class IconSelectWindow : GLib.Object {
+
/////////////////////////////////////////////////////////////////////
- /// The currently selected icon. If set, this icon gets focused.
+ /// This signal gets emitted when the user selects a new icon.
/////////////////////////////////////////////////////////////////////
- private string _active_icon = "application-default-icon";
-
- public string active_icon {
- get {
- return _active_icon;
- }
- set {
- if (value.contains("/")) {
- this.file_chooser.set_filename(value);
- this.tabs.set_current_page(1);
- } else {
- this.icon_list_filtered.foreach((model, path, iter) => {
- string name = "";
- model.get(iter, 0, out name);
-
- if (name == value) {
- this.icon_view.select_path(path);
- this.icon_view.scroll_to_path(path, true, 0.5f, 0.0f);
- this.icon_view.set_cursor(path, null, false);
- }
- return (name == value);
- });
-
- this.tabs.set_current_page(0);
- }
- }
- }
+ public signal void on_ok(string icon_name);
/////////////////////////////////////////////////////////////////////
- /// This signal gets emitted when the user selects a new icon.
+ /// Stores the currently selected icon.
/////////////////////////////////////////////////////////////////////
- public signal void on_select(string icon_name);
+ private string active_icon = "";
/////////////////////////////////////////////////////////////////////
/// The ListStore storing all theme-icons.
@@ -121,6 +95,12 @@ public class IconSelectWindow : Gtk.Dialog {
private Gtk.Notebook tabs = null;
/////////////////////////////////////////////////////////////////////
+ /// The main window.
+ /////////////////////////////////////////////////////////////////////
+
+ private Gtk.Window window = null;
+
+ /////////////////////////////////////////////////////////////////////
/// A little structure containing data for one icon in the icon_view.
/////////////////////////////////////////////////////////////////////
@@ -156,217 +136,221 @@ public class IconSelectWindow : Gtk.Dialog {
/// C'tor, creates a new IconSelectWindow.
/////////////////////////////////////////////////////////////////////
- public IconSelectWindow() {
- this.title = _("Choose an Icon");
- this.set_size_request(520, 520);
- this.delete_event.connect(hide_on_delete);
- this.load_queue = new GLib.AsyncQueue<ListEntry?>();
+ public IconSelectWindow(Gtk.Window parent) {
+ try {
+ this.load_queue = new GLib.AsyncQueue<ListEntry?>();
- if (this.icon_list == null) {
- this.icon_list = new Gtk.ListStore(3, typeof(string), // icon name
- typeof(IconContext), // icon type
- typeof(Gdk.Pixbuf)); // the icon itself
-
- // disable sorting until all icons are loaded
- // else loading becomes horribly slow
- this.icon_list.set_default_sort_func(() => {return 0;});
+ if (this.icon_list == null) {
+ this.icon_list = new Gtk.ListStore(3, typeof(string), // icon name
+ typeof(IconContext), // icon type
+ typeof(Gdk.Pixbuf)); // the icon itself
+
+ // disable sorting until all icons are loaded
+ // else loading becomes horribly slow
+ this.icon_list.set_default_sort_func(() => {return 0;});
- // reload if icon theme changes
- Gtk.IconTheme.get_default().changed.connect(() => {
- if (this.visible) load_icons();
- else need_reload = true;
- });
- }
-
- // make the icon_view filterable
- this.icon_list_filtered = new Gtk.TreeModelFilter(this.icon_list, null);
-
- var container = new Gtk.VBox(false, 12);
- container.set_border_width(12);
+ // reload if icon theme changes
+ Gtk.IconTheme.get_default().changed.connect(() => {
+ if (this.window.visible) load_icons();
+ else need_reload = true;
+ });
+ }
+
+ // make the icon_view filterable
+ this.icon_list_filtered = new Gtk.TreeModelFilter(this.icon_list, null);
+
+ Gtk.Builder builder = new Gtk.Builder();
- // tab container
- this.tabs = new Gtk.Notebook();
+ builder.add_from_file (Paths.ui_files + "/icon_select.ui");
- // icon theme tab
- var theme_tab = new Gtk.VBox(false, 12);
- theme_tab.set_border_width(12);
+ this.window = builder.get_object("window") as Gtk.Window;
+ this.window.set_transient_for(parent);
+ this.window.set_modal(true);
+
+ this.tabs = builder.get_object("tabs") as Gtk.Notebook;
+
+ this.spinner = builder.get_object("spinner") as Gtk.Spinner;
+ this.spinner.start();
- // type chooser combo-box
- var context_combo = new Gtk.ComboBox.text();
- context_combo.append_text(_("All icons"));
- context_combo.append_text(_("Applications"));
- context_combo.append_text(_("Actions"));
- context_combo.append_text(_("Places"));
- context_combo.append_text(_("File types"));
- context_combo.append_text(_("Emotes"));
- context_combo.append_text(_("Miscellaneous"));
+ (builder.get_object("ok-button") as Gtk.Button).clicked.connect(on_ok_button_clicked);
+ (builder.get_object("cancel-button") as Gtk.Button).clicked.connect(on_cancel_button_clicked);
+
+ var combo_box = builder.get_object("combo-box") as Gtk.VBox;
+
+ // context combo
+ #if HAVE_GTK_3
+ var context_combo = new Gtk.ComboBoxText();
+ #else
+ var context_combo = new Gtk.ComboBox.text();
+ #endif
+ context_combo.append_text(_("All icons"));
+ context_combo.append_text(_("Applications"));
+ context_combo.append_text(_("Actions"));
+ context_combo.append_text(_("Places"));
+ context_combo.append_text(_("File types"));
+ context_combo.append_text(_("Emotes"));
+ context_combo.append_text(_("Miscellaneous"));
- context_combo.set_active(0);
-
- context_combo.changed.connect(() => {
- this.icon_list_filtered.refilter();
- });
-
- theme_tab.pack_start(context_combo, false, false);
+ context_combo.set_active(0);
+
+ context_combo.changed.connect(() => {
+ this.icon_list_filtered.refilter();
+ });
+
+ combo_box.pack_start(context_combo, false, false);
+
+ // string filter entry
+ var filter = builder.get_object("filter-entry") as Gtk.Entry;
+
+ // only display items which have the selected type
+ // and whose name contains the text entered in the entry
+ this.icon_list_filtered.set_visible_func((model, iter) => {
+ string name = "";
+ IconContext context = IconContext.ALL;
+ model.get(iter, 0, out name);
+ model.get(iter, 1, out context);
- // string filter entry
- var filter = new Gtk.Entry();
- filter.primary_icon_stock = Gtk.Stock.FIND;
- filter.primary_icon_activatable = false;
- filter.secondary_icon_stock = Gtk.Stock.CLEAR;
- theme_tab.pack_start(filter, false, false);
-
- // only display items which have the selected type
- // and whose name contains the text entered in the entry
- this.icon_list_filtered.set_visible_func((model, iter) => {
- string name = "";
- IconContext context = IconContext.ALL;
- model.get(iter, 0, out name);
- model.get(iter, 1, out context);
-
- if (name == null) return false;
-
- return (context_combo.get_active() == context ||
- context_combo.get_active() == IconContext.ALL) &&
- name.down().contains(filter.text.down());
- });
-
- // clear when the users clicks on the "clear" icon
- filter.icon_release.connect((pos, event) => {
- if (pos == Gtk.EntryIconPosition.SECONDARY)
- filter.text = "";
- });
-
- // refilter on input
- filter.notify["text"].connect(() => {
- this.icon_list_filtered.refilter();
- });
+ if (name == null) return false;
- // container for the icon_view
- var scroll = new Gtk.ScrolledWindow (null, null);
- scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
- scroll.set_shadow_type (Gtk.ShadowType.IN);
+ return (context_combo.get_active() == context ||
+ context_combo.get_active() == IconContext.ALL) &&
+ name.down().contains(filter.text.down());
+ });
+
+ // clear when the users clicks on the "clear" icon
+ filter.icon_release.connect((pos, event) => {
+ if (pos == Gtk.EntryIconPosition.SECONDARY)
+ filter.text = "";
+ });
+
+ // refilter on input
+ filter.notify["text"].connect(() => {
+ this.icon_list_filtered.refilter();
+ });
+
+ // container for the icon_view
+ var scroll = builder.get_object("icon-scrolledwindow") as Gtk.ScrolledWindow;
- // displays the filtered icons
- this.icon_view = new Gtk.IconView.with_model(this.icon_list_filtered);
- this.icon_view.item_width = 32;
- this.icon_view.item_padding = 3;
- this.icon_view.pixbuf_column = 2;
- this.icon_view.tooltip_column = 0;
-
- // set _active_icon if selection changes
- this.icon_view.selection_changed.connect(() => {
- foreach (var path in this.icon_view.get_selected_items()) {
- Gtk.TreeIter iter;
- this.icon_list_filtered.get_iter(out iter, path);
- this.icon_list_filtered.get(iter, 0, out this._active_icon);
- }
- });
-
- // hide this window when the user activates an icon
- this.icon_view.item_activated.connect((path) => {
- Gtk.TreeIter iter;
- this.icon_list_filtered.get_iter(out iter, path);
- this.icon_list_filtered.get(iter, 0, out this._active_icon);
- this.on_select(this._active_icon);
- this.hide();
- });
+ // displays the filtered icons
+ this.icon_view = new Gtk.IconView.with_model(this.icon_list_filtered);
+ this.icon_view.item_width = 32;
+ this.icon_view.item_padding = 3;
+ this.icon_view.pixbuf_column = 2;
+ this.icon_view.tooltip_column = 0;
- scroll.add(this.icon_view);
+ // set active_icon if selection changes
+ this.icon_view.selection_changed.connect(() => {
+ foreach (var path in this.icon_view.get_selected_items()) {
+ Gtk.TreeIter iter;
+ this.icon_list_filtered.get_iter(out iter, path);
+ this.icon_list_filtered.get(iter, 0, out this.active_icon);
+ }
+ });
- theme_tab.pack_start(scroll, true, true);
-
- tabs.append_page(theme_tab, new Gtk.Label(_("Icon Theme")));
+ // hide this window when the user activates an icon
+ this.icon_view.item_activated.connect((path) => {
+ Gtk.TreeIter iter;
+ this.icon_list_filtered.get_iter(out iter, path);
+ this.icon_list_filtered.get(iter, 0, out this.active_icon);
+ this.on_ok(this.active_icon);
+ this.window.hide();
+ });
+
+ scroll.add(this.icon_view);
- // tab containing the possibility to choose a custom icon
- var custom_tab = new Gtk.VBox(false, 6);
- custom_tab.border_width = 12;
+ // file chooser widget
+ this.file_chooser = builder.get_object("filechooser") as Gtk.FileChooserWidget;
+ var file_filter = new Gtk.FileFilter();
+ file_filter.add_pixbuf_formats();
- // file chooser widget
- this.file_chooser = new Gtk.FileChooserWidget(Gtk.FileChooserAction.OPEN);
- var file_filter = new Gtk.FileFilter();
- file_filter.add_pixbuf_formats();
+ #if HAVE_GTK_3
+ file_filter.set_filter_name(_("All supported image formats"));
+ #else
file_filter.set_name(_("All supported image formats"));
- file_chooser.add_filter(file_filter);
-
- // set _active_icon if the user selected a file
- file_chooser.selection_changed.connect(() => {
- if (file_chooser.get_filename() != null &&
- GLib.FileUtils.test(file_chooser.get_filename(),
- GLib.FileTest.IS_REGULAR))
-
- this._active_icon = file_chooser.get_filename();
- });
-
- // hide this window when the user activates a file
- file_chooser.file_activated.connect(() => {
- this._active_icon = file_chooser.get_filename();
- this.on_select(this._active_icon);
- this.hide();
- });
-
-
- custom_tab.pack_start(file_chooser, true, true);
-
- tabs.append_page(custom_tab, new Gtk.Label(_("Custom Icon")));
-
- container.pack_start(tabs, true, true);
-
- // button box --- this dialog has a custom button box at the bottom because it
- // should have a spinner there. Sadly that's impossible with the "normal"
- // action_area of Gtk.Dialog's
- var bottom_box = new Gtk.HBox(false, 0);
-
- var bbox = new Gtk.HButtonBox();
- bbox.set_spacing(6);
- bbox.set_layout(Gtk.ButtonBoxStyle.END);
-
- var cancel_button = new Gtk.Button.from_stock(Gtk.Stock.CANCEL);
- cancel_button.clicked.connect(() => {
- this.hide();
- });
- bbox.pack_start(cancel_button);
-
- var ok_button = new Gtk.Button.from_stock(Gtk.Stock.OK);
- ok_button.clicked.connect(() => {
- this.on_select(this._active_icon);
- this.hide();
- });
- bbox.pack_start(ok_button);
-
- bottom_box.pack_end(bbox, false);
+ #endif
- this.spinner = new Gtk.Spinner();
- this.spinner.set_size_request(16, 16);
- this.spinner.start();
+ file_chooser.add_filter(file_filter);
+
+ // set active_icon if the user selected a file
+ file_chooser.selection_changed.connect(() => {
+ if (file_chooser.get_filename() != null &&
+ GLib.FileUtils.test(file_chooser.get_filename(),
+ GLib.FileTest.IS_REGULAR))
- bottom_box.pack_start(this.spinner, false, false);
+ this.active_icon = file_chooser.get_filename();
+ });
+
+ // hide this window when the user activates a file
+ file_chooser.file_activated.connect(() => {
+ this.active_icon = file_chooser.get_filename();
+ this.on_ok(this.active_icon);
+ this.window.hide();
+ });
- container.pack_start(bottom_box, false, false);
-
- this.vbox.pack_start(container, true, true);
-
- this.vbox.show_all();
-
- this.set_focus(this.icon_view);
+ this.window.set_focus(this.icon_view);
+ this.window.delete_event.connect(this.window.hide_on_delete);
+
+ } catch (GLib.Error e) {
+ error("Could not load UI: %s\n", e.message);
+ }
}
/////////////////////////////////////////////////////////////////////
- /// Hide the "normal" action_area when this window is shown. Reload
- /// all icons if necessary.
+ /// Displays the window. The icons are reloaded if neccessary.
/////////////////////////////////////////////////////////////////////
-
- public override void show() {
- base.show();
-
- // hide the "normal" action_area --- this Dialog has a custom set of
- // buttons containg the spinner
- this.action_area.hide();
+
+ public void show() {
+ this.window.show_all();
+ this.spinner.hide();
if (this.need_reload) {
this.need_reload = false;
this.load_icons();
}
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Makes the window select the icon of the given Pie.
+ /////////////////////////////////////////////////////////////////////
+
+ public void set_pie(string id) {
+ string icon = PieManager.all_pies[id].icon;
+
+ if (icon.contains("/")) {
+ this.file_chooser.set_filename(icon);
+ this.tabs.set_current_page(1);
+ } else {
+ this.icon_list_filtered.foreach((model, path, iter) => {
+ string name = "";
+ model.get(iter, 0, out name);
+
+ if (name == icon) {
+ this.icon_view.select_path(path);
+ this.icon_view.scroll_to_path(path, true, 0.5f, 0.0f);
+ this.icon_view.set_cursor(path, null, false);
+ }
+ return (name == icon);
+ });
+
+ this.tabs.set_current_page(0);
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the user clicks the ok button.
+ /////////////////////////////////////////////////////////////////////
+
+ private void on_ok_button_clicked() {
+ this.on_ok(this.active_icon);
+ this.window.hide();
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ /// Called when the user clicks the cancel button.
+ /////////////////////////////////////////////////////////////////////
+
+ private void on_cancel_button_clicked() {
+ this.window.hide();
}
/////////////////////////////////////////////////////////////////////
@@ -400,13 +384,13 @@ public class IconSelectWindow : Gtk.Dialog {
var new_entry = this.load_queue.pop();
Gtk.TreeIter current;
this.icon_list.append(out current);
- this.icon_list.set(current, 0, new_entry.name,
+ this.icon_list.set(current, 0, new_entry.name,
1, new_entry.context,
2, new_entry.pixbuf);
}
// enable sorting of the icon_view if loading finished
- if (!this.loading) this.icon_list.set_sort_column_id(0, Gtk.SortType.ASCENDING);
+ if (!this.loading) this.icon_list.set_sort_column_id(0, Gtk.SortType.ASCENDING);
return loading;
});
@@ -439,12 +423,12 @@ public class IconSelectWindow : Gtk.Dialog {
default: break;
}
- try {
+ try {
// create a new entry for the queue
var new_entry = new ListEntry();
new_entry.name = icon;
new_entry.context = icon_context;
- new_entry.pixbuf = icon_theme.load_icon(icon, 32, 0);
+ new_entry.pixbuf = icon_theme.load_icon(icon, 32, 0);
// some icons have only weird sizes... do not include them
if (new_entry.pixbuf.width == 32)
@@ -462,7 +446,7 @@ public class IconSelectWindow : Gtk.Dialog {
// hide the spinner
if (spinner != null)
- spinner.visible = this.loading;
+ spinner.visible = false;
return null;
}