diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/commandComboList.vala | 120 | ||||
-rw-r--r-- | src/gui/newSliceWindow.vala | 17 | ||||
-rw-r--r-- | src/gui/piePreview.vala | 13 |
3 files changed, 144 insertions, 6 deletions
diff --git a/src/gui/commandComboList.vala b/src/gui/commandComboList.vala new file mode 100644 index 0000000..3f157ce --- /dev/null +++ b/src/gui/commandComboList.vala @@ -0,0 +1,120 @@ +///////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011-2016 by Simon Schneegans +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +///////////////////////////////////////////////////////////////////////// + +namespace GnomePie { + +///////////////////////////////////////////////////////////////////////// +/// A drop-down list, containing one entry for each +/// installed application. +///////////////////////////////////////////////////////////////////////// + +class CommandComboList : Gtk.ComboBox { + + ///////////////////////////////////////////////////////////////////// + /// Called when something is selected from the drop down. + ///////////////////////////////////////////////////////////////////// + + public signal void on_select(string name, string command, string icon); + + ///////////////////////////////////////////////////////////////////// + /// The currently selected item. + ///////////////////////////////////////////////////////////////////// + + public string text { + get { return (this.get_child() as Gtk.Entry).get_text();} + set { (this.get_child() as Gtk.Entry).set_text(value);} + } + + ///////////////////////////////////////////////////////////////////// + /// Stores the data internally. + ///////////////////////////////////////////////////////////////////// + + private Gtk.ListStore data; + private enum DataPos {ICON, NAME, COMMAND} + + ///////////////////////////////////////////////////////////////////// + /// C'tor, constructs the Widget. + ///////////////////////////////////////////////////////////////////// + + public CommandComboList() { + GLib.Object(has_entry : true); + + this.data = new Gtk.ListStore(3, typeof(string), + typeof(string), + typeof(string)); + + this.data.set_sort_column_id(1, Gtk.SortType.ASCENDING); + this.entry_text_column = 2; + this.id_column = 2; + + base.set_model(this.data); + + // hide default renderer + this.get_cells().nth_data(0).visible = false; + + var icon_render = new Gtk.CellRendererPixbuf(); + icon_render.xpad = 4; + this.pack_start(icon_render, false); + + var name_render = new Gtk.CellRendererText(); + this.pack_start(name_render, true); + + this.add_attribute(icon_render, "icon_name", DataPos.ICON); + this.add_attribute(name_render, "text", DataPos.NAME); + + this.changed.connect(() => { + Gtk.TreeIter active; + if (this.get_active_iter(out active)) { + string name = ""; + string command = ""; + string icon = ""; + this.data.get(active, DataPos.NAME, out name); + this.data.get(active, DataPos.COMMAND, out command); + this.data.get(active, DataPos.ICON, out icon); + on_select(name, command, icon); + } + }); + + reload(); + } + + ///////////////////////////////////////////////////////////////////// + /// Loads all existing applications to the list. + ///////////////////////////////////////////////////////////////////// + + public void reload() { + var apps = GLib.AppInfo.get_all(); + foreach (var app in apps) { + if (app.should_show()) { + Gtk.TreeIter last; + var icon_name = "application-x-executable"; + var icon = app.get_icon(); + + if (icon != null) { + icon_name = icon.to_string(); + } + + this.data.append(out last); + this.data.set(last, DataPos.ICON, icon_name, + DataPos.NAME, app.get_display_name(), + DataPos.COMMAND, app.get_commandline()); + } + } + } +} + +} diff --git a/src/gui/newSliceWindow.vala b/src/gui/newSliceWindow.vala index d719213..3133e34 100644 --- a/src/gui/newSliceWindow.vala +++ b/src/gui/newSliceWindow.vala @@ -61,7 +61,7 @@ public class NewSliceWindow : GLib.Object { private Gtk.Box workspace_only_box = null; private Gtk.Image icon = null; private Gtk.Entry name_entry = null; - private Gtk.Entry command_entry = null; + private CommandComboList command_list = null; private Gtk.Entry uri_entry = null; private Gtk.Switch quickaction_checkbutton = null; private Gtk.Switch workspace_only_checkbutton = null; @@ -195,11 +195,18 @@ public class NewSliceWindow : GLib.Object { this.name_entry = builder.get_object("name-entry") as Gtk.Entry; this.uri_entry = builder.get_object("uri-entry") as Gtk.Entry; - this.command_entry = builder.get_object("command-entry") as Gtk.Entry; this.quickaction_checkbutton = builder.get_object("quick-action-checkbutton") as Gtk.Switch; this.quickaction_box = builder.get_object("quickaction-box") as Gtk.Box; this.icon = builder.get_object("icon") as Gtk.Image; + this.command_list = new CommandComboList(); + this.command_list.on_select.connect((name, command, icon) => { + this.set_icon(icon); + this.name_entry.text = name; + }); + + this.command_box.pack_start(this.command_list, true, true); + this.workspace_only_checkbutton = builder.get_object("workspace-only-checkbutton") as Gtk.Switch; this.workspace_only_box = builder.get_object("workspace-only-box") as Gtk.Box; @@ -275,7 +282,7 @@ public class NewSliceWindow : GLib.Object { switch (type) { case "app": this.current_custom_icon = action.icon; - this.command_entry.text = action.real_command; + this.command_list.text = action.real_command; break; case "key": this.current_custom_icon = action.icon; @@ -319,7 +326,7 @@ public class NewSliceWindow : GLib.Object { this.key_select.set_trigger(new Trigger()); this.pie_select.select_first(); this.name_entry.text = _("Rename me!"); - this.command_entry.text = ""; + this.command_list.text = ""; this.uri_entry.text = ""; } @@ -359,7 +366,7 @@ public class NewSliceWindow : GLib.Object { case "app": group = new ActionGroup(this.current_id); group.add_action(new AppAction(this.name_entry.text, this.current_icon, - this.command_entry.text, + this.command_list.text, this.quickaction_checkbutton.active)); break; case "key": diff --git a/src/gui/piePreview.vala b/src/gui/piePreview.vala index eadaa8e..540ab51 100644 --- a/src/gui/piePreview.vala +++ b/src/gui/piePreview.vala @@ -87,8 +87,9 @@ class PiePreview : Gtk.DrawingArea { this.enable_drag_source(); Gtk.TargetEntry uri_dest = {"text/uri-list", 0, 0}; + Gtk.TargetEntry text_dest = {"text/plain", 0, 0}; Gtk.TargetEntry slice_dest = {"text/plain", Gtk.TargetFlags.SAME_WIDGET, 0}; - Gtk.TargetEntry[] destinations = { uri_dest, slice_dest }; + Gtk.TargetEntry[] destinations = { uri_dest, text_dest, slice_dest }; Gtk.drag_dest_set(this, Gtk.DestDefaults.ALL, destinations, Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK); this.drag_begin.connect(this.on_start_drag); @@ -349,6 +350,16 @@ class PiePreview : Gtk.DrawingArea { int position = this.renderer.get_active_slice(); this.renderer.set_dnd_mode(false); + var text = selection_data.get_text(); + if (text != null && GLib.Uri.parse_scheme(text) != null) { + pie.add_action(ActionRegistry.new_for_uri(text), position); + this.renderer.add_group(pie.action_groups[position], position); + + if (this.renderer.slices.size == 1) + this.on_first_slice_added(); + } + + foreach (var uri in selection_data.get_uris()) { pie.add_action(ActionRegistry.new_for_uri(uri), position); this.renderer.add_group(pie.action_groups[position], position); |