From 60560a030fda3c539ff9dc1563b9926414a193da Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Sat, 21 Jan 2012 19:07:09 +0100 Subject: Imported Upstream version 0.4.0 --- src/pies/load.vala | 31 ++++++--------------------- src/pies/pie.vala | 38 ++++++++++++++++++++++++++++------ src/pies/pieManager.vala | 54 ++++++++++++++++++++++++++++++++++++++++++------ src/pies/save.vala | 8 +++---- 4 files changed, 90 insertions(+), 41 deletions(-) (limited to 'src/pies') diff --git a/src/pies/load.vala b/src/pies/load.vala index 98fd72f..b606cf5 100644 --- a/src/pies/load.vala +++ b/src/pies/load.vala @@ -80,7 +80,7 @@ namespace Pies { string name = ""; string icon = ""; string id = ""; - int quick_action = -1; + int quickaction = -1; // parse all attributes of this node for (Xml.Attr* attribute = node->properties; attribute != null; attribute = attribute->next) { @@ -92,7 +92,7 @@ namespace Pies { hotkey = attr_content; break; case "quickaction": - quick_action = int.parse(attr_content); + quickaction = int.parse(attr_content); break; case "name": name = attr_content; @@ -145,7 +145,7 @@ namespace Pies { string icon=""; string command=""; string type=""; - bool quick_action = false; + bool quickaction = false; // parse all attributes of this node for (Xml.Attr* attribute = slice->properties; attribute != null; attribute = attribute->next) { @@ -166,7 +166,7 @@ namespace Pies { type = attr_content; break; case "quickaction": - quick_action = bool.parse(attr_content); + quickaction = bool.parse(attr_content); break; default: warning("Invalid attribute \"" + attr_name + "\" in element in pies.conf!"); @@ -174,19 +174,8 @@ namespace Pies { } } - Action action = null; - // create a new Action according to the loaded type - foreach (var action_type in ActionRegistry.types) { - if (ActionRegistry.settings_names[action_type] == type) { - - action = GLib.Object.new(action_type, "name", name, - "icon", icon, - "real_command", command, - "is_quick_action", quick_action) as Action; - break; - } - } + Action action = ActionRegistry.create_action(type, name, icon, command, quickaction); if (action != null) pie.add_action(action); } @@ -213,15 +202,7 @@ namespace Pies { } } - ActionGroup group = null; - - // create a new ActionGroup according to the loaded type - foreach (var group_type in GroupRegistry.types) { - if (GroupRegistry.settings_names[group_type] == type) { - group = GLib.Object.new(group_type, "parent_id", pie.id) as ActionGroup; - break; - } - } + ActionGroup group = GroupRegistry.create_group(type, pie.id); if (group != null) pie.add_group(group); } diff --git a/src/pies/pie.vala b/src/pies/pie.vala index 0f87d8f..fa205c7 100644 --- a/src/pies/pie.vala +++ b/src/pies/pie.vala @@ -29,14 +29,14 @@ public class Pie : GLib.Object { /// The name of this Pie. It has not to be unique. ///////////////////////////////////////////////////////////////////// - public string name { get; construct; } + public string name { get; set; } ///////////////////////////////////////////////////////////////////// /// The name of the icon to be used for this Pie. It should exist in /// the users current icon theme, else a standard icon will be used. ///////////////////////////////////////////////////////////////////// - public string icon { get; construct; } + public string icon { get; set; } ///////////////////////////////////////////////////////////////////// /// The ID of this Pie. It has to be unique among all Pies. This ID @@ -77,18 +77,44 @@ public class Pie : GLib.Object { /// Adds an Action to this Pie. ///////////////////////////////////////////////////////////////////// - public void add_action(Action action) { + public void add_action(Action action, int at_position = -1) { var group = new ActionGroup(this.id); group.add_action(action); - this.add_group(group); + this.add_group(group, at_position); } ///////////////////////////////////////////////////////////////////// /// Adds an ActionGroup to this Pie. ///////////////////////////////////////////////////////////////////// - public void add_group(ActionGroup group) { - this.action_groups.add(group); + public void add_group(ActionGroup group, int at_position = -1) { + if (group.has_quickaction()) { + foreach (var action_group in action_groups) + action_group.disable_quickactions(); + } + + if (at_position < 0 || at_position >= this.action_groups.size) + this.action_groups.add(group); + else + this.action_groups.insert(at_position, group); + } + + public void remove_group(int index) { + if (this.action_groups.size > index) + this.action_groups.remove_at(index); + } + + public void move_group(int from, int to) { + if (this.action_groups.size > from && this.action_groups.size > to) { + var tmp = this.action_groups[from]; + this.remove_group(from); + this.add_group(tmp, to); + } + } + + public void update_group(ActionGroup group, int index) { + if (this.action_groups.size > index) + this.action_groups.set(index, group); } } diff --git a/src/pies/pieManager.vala b/src/pies/pieManager.vala index 5f84ea0..0263d23 100644 --- a/src/pies/pieManager.vala +++ b/src/pies/pieManager.vala @@ -31,6 +31,13 @@ public class PieManager : GLib.Object { public static Gee.HashMap all_pies { get; private set; } + ///////////////////////////////////////////////////////////////////// + /// Stores all PieWindows which are currently opened. Should be + /// rarely more than two... + ///////////////////////////////////////////////////////////////////// + + public static Gee.HashSet opened_windows { get; private set; } + ///////////////////////////////////////////////////////////////////// /// Stores all global hotkeys. ///////////////////////////////////////////////////////////////////// @@ -42,7 +49,7 @@ public class PieManager : GLib.Object { /// will be false already. ///////////////////////////////////////////////////////////////////// - private static bool a_pie_is_opened = false; + private static bool a_pie_is_active = false; ///////////////////////////////////////////////////////////////////// /// Initializes all Pies. They are loaded from the pies.conf file. @@ -50,6 +57,7 @@ public class PieManager : GLib.Object { public static void init() { all_pies = new Gee.HashMap(); + opened_windows = new Gee.HashSet(); bindings = new BindingManager(); // load all Pies from th pies.conf file @@ -66,19 +74,27 @@ public class PieManager : GLib.Object { ///////////////////////////////////////////////////////////////////// public static void open_pie(string id) { - if (!a_pie_is_opened) { + if (!a_pie_is_active) { Pie? pie = all_pies[id]; if (pie != null) { - a_pie_is_opened = true; + a_pie_is_active = true; var window = new PieWindow(); window.load_pie(pie); window.open(); + opened_windows.add(window); + + window.on_closed.connect(() => { + opened_windows.remove(window); + }); + window.on_closing.connect(() => { - a_pie_is_opened = false; + a_pie_is_active = false; }); + + } else { warning("Failed to open pie with ID \"" + id + "\": ID does not exist!"); } @@ -102,6 +118,15 @@ public class PieManager : GLib.Object { return bindings.get_accelerator_label_of(id); } + ///////////////////////////////////////////////////////////////////// + /// Bind the Pie with the given ID to the given trigger. + ///////////////////////////////////////////////////////////////////// + + public static void bind_trigger(Trigger trigger, string id) { + bindings.unbind(id); + bindings.bind(trigger, id); + } + ///////////////////////////////////////////////////////////////////// /// Returns true if the pie with the given id is in turbo mode. ///////////////////////////////////////////////////////////////////// @@ -110,6 +135,15 @@ public class PieManager : GLib.Object { return bindings.get_is_turbo(id); } + ///////////////////////////////////////////////////////////////////// + /// Returns true if the pie with the given id opens in the middle of + /// the screen. + ///////////////////////////////////////////////////////////////////// + + public static bool get_is_centered(string id) { + return bindings.get_is_centered(id); + } + ///////////////////////////////////////////////////////////////////// /// Returns the name of the Pie with the given ID. ///////////////////////////////////////////////////////////////////// @@ -212,7 +246,11 @@ public class PieManager : GLib.Object { } } - private static void create_launcher(string id) { + ///////////////////////////////////////////////////////////////////// + /// Creates a desktop file for which opens the Pie with given ID. + ///////////////////////////////////////////////////////////////////// + + public static void create_launcher(string id) { if (all_pies.has_key(id)) { Pie? pie = all_pies[id]; @@ -220,7 +258,7 @@ public class PieManager : GLib.Object { "#!/usr/bin/env xdg-open\n" + "[Desktop Entry]\n" + "Name=%s\n".printf(pie.name) + - "Exec=gnome-pie -o %s\n".printf(pie.id) + + "Exec=%s -o %s\n".printf(Paths.executable, pie.id) + "Encoding=UTF-8\n" + "Type=Application\n" + "Icon=%s\n".printf(pie.icon); @@ -237,6 +275,10 @@ public class PieManager : GLib.Object { } } + ///////////////////////////////////////////////////////////////////// + /// Deletes the desktop file for the Pie with the given ID. + ///////////////////////////////////////////////////////////////////// + private static void remove_launcher(string id) { string launcher = Paths.launchers + "/%s.desktop".printf(id); if (FileUtils.test(launcher, FileTest.EXISTS)) { diff --git a/src/pies/save.vala b/src/pies/save.vala index d691a95..c940e5a 100644 --- a/src/pies/save.vala +++ b/src/pies/save.vala @@ -55,18 +55,18 @@ namespace Pies { if (group.get_type().depth() == 2) { foreach (var action in group.actions) { writer.start_element("slice"); - writer.write_attribute("type", ActionRegistry.settings_names[action.get_type()]); - if (ActionRegistry.icon_name_editables[action.get_type()]) { + writer.write_attribute("type", ActionRegistry.descriptions[action.get_type().name()].id); + if (ActionRegistry.descriptions[action.get_type().name()].icon_name_editable) { writer.write_attribute("name", action.name); writer.write_attribute("icon", action.icon); } writer.write_attribute("command", action.real_command); - writer.write_attribute("quickAction", action.is_quick_action ? "true" : "false"); + writer.write_attribute("quickAction", action.is_quickaction ? "true" : "false"); writer.end_element(); } } else { writer.start_element("group"); - writer.write_attribute("type", GroupRegistry.settings_names[group.get_type()]); + writer.write_attribute("type", GroupRegistry.descriptions[group.get_type().name()].id); writer.end_element(); } } -- cgit v1.2.3