summaryrefslogtreecommitdiff
path: root/src/gui/triggerSelectWindow.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/triggerSelectWindow.vala')
-rw-r--r--src/gui/triggerSelectWindow.vala257
1 files changed, 94 insertions, 163 deletions
diff --git a/src/gui/triggerSelectWindow.vala b/src/gui/triggerSelectWindow.vala
index e003a84..23eea3c 100644
--- a/src/gui/triggerSelectWindow.vala
+++ b/src/gui/triggerSelectWindow.vala
@@ -23,21 +23,23 @@ namespace GnomePie {
/// a mouse based hotkey.
/////////////////////////////////////////////////////////////////////////
-public class TriggerSelectWindow : Gtk.Dialog {
+public class TriggerSelectWindow : GLib.Object {
/////////////////////////////////////////////////////////////////////
/// This signal is emitted when the user selects a new hot key.
/////////////////////////////////////////////////////////////////////
- public signal void on_select(Trigger trigger);
+ public signal void on_ok(Trigger trigger);
/////////////////////////////////////////////////////////////////////
/// Some private members which are needed by other methods.
/////////////////////////////////////////////////////////////////////
+ private Gtk.Dialog window;
private Gtk.CheckButton turbo;
private Gtk.CheckButton delayed;
- private Gtk.Label preview;
+ private Gtk.CheckButton centered;
+ private TriggerSelectButton button;
/////////////////////////////////////////////////////////////////////
/// The currently configured trigger.
@@ -54,204 +56,133 @@ public class TriggerSelectWindow : Gtk.Dialog {
private Trigger original_trigger = null;
/////////////////////////////////////////////////////////////////////
- /// These modifiers are ignored.
- /////////////////////////////////////////////////////////////////////
-
- private Gdk.ModifierType lock_modifiers = Gdk.ModifierType.MOD2_MASK
- |Gdk.ModifierType.LOCK_MASK
- |Gdk.ModifierType.MOD5_MASK;
-
- /////////////////////////////////////////////////////////////////////
/// C'tor, constructs a new TriggerSelectWindow.
/////////////////////////////////////////////////////////////////////
public TriggerSelectWindow() {
- this.title = _("Define an open-command");
- this.resizable = false;
- this.delete_event.connect(hide_on_delete);
- this.key_press_event.connect(on_key_press);
- this.button_press_event.connect(on_button_press);
-
- this.show.connect_after(() => {
- FocusGrabber.grab(this);
- });
+ try {
- this.hide.connect(() => {
- FocusGrabber.ungrab(this);
- });
+ Gtk.Builder builder = new Gtk.Builder();
+
+ builder.add_from_file (Paths.ui_files + "/trigger_select.ui");
- var container = new Gtk.VBox(false, 6);
- container.set_border_width(6);
-
- // click area
- var click_frame = new Gtk.Frame(_("Click here if you want to bind a mouse button!"));
+ this.window = builder.get_object("window") as Gtk.Dialog;
+ this.button = new TriggerSelectButton(true);
+ this.button.show();
- var click_box = new Gtk.EventBox();
- click_box.height_request = 100;
- click_box.button_press_event.connect(on_area_clicked);
-
- this.preview = new Gtk.Label(null);
-
- click_box.add(this.preview);
-
- click_frame.add(click_box);
-
- container.pack_start(click_frame, false);
+ this.button.on_select.connect((trigger) => {
+ this.trigger = new Trigger.from_values(trigger.key_sym,
+ trigger.modifiers,
+ trigger.with_mouse,
+ this.turbo.active,
+ this.delayed.active,
+ this.centered.active);
+ });
- // turbo checkbox
- this.turbo = new Gtk.CheckButton.with_label (_("Turbo mode"));
- this.turbo.tooltip_text = _("If checked, the Pie will close when you " +
- "release the chosen hot key.");
- this.turbo.active = false;
- this.turbo.toggled.connect(() => {
- if (this.trigger != null)
- this.update_trigger(new Trigger.from_values(
- this.trigger.key_sym, this.trigger.modifiers,
- this.trigger.with_mouse, this.turbo.active,
- this.delayed.active));
- });
-
- container.pack_start(turbo, false);
+ (builder.get_object("trigger-box") as Gtk.VBox).pack_start(this.button, true, true);
+
+ (builder.get_object("ok-button") as Gtk.Button).clicked.connect(this.on_ok_button_clicked);
+ (builder.get_object("cancel-button") as Gtk.Button).clicked.connect(this.on_cancel_button_clicked);
+
+ this.turbo = builder.get_object("turbo-check") as Gtk.CheckButton;
+ this.turbo.toggled.connect(this.on_check_toggled);
- // delayed checkbox
- this.delayed = new Gtk.CheckButton.with_label (_("Long press for activation"));
- this.delayed.tooltip_text = _("If checked, the Pie will only open if you " +
- "press this hot key a bit longer.");
- this.delayed.active = false;
- this.delayed.toggled.connect(() => {
- if (this.trigger != null)
- this.update_trigger(new Trigger.from_values(
- this.trigger.key_sym, this.trigger.modifiers,
- this.trigger.with_mouse, this.turbo.active,
- this.delayed.active));
- });
+ this.delayed = builder.get_object("delay-check") as Gtk.CheckButton;
+ this.delayed.toggled.connect(this.on_check_toggled);
+
+ this.centered = builder.get_object("center-check") as Gtk.CheckButton;
+ this.centered.toggled.connect(this.on_check_toggled);
+
+ this.window.delete_event.connect(this.window.hide_on_delete);
- container.pack_start(delayed, false);
-
- container.show_all();
-
- this.vbox.pack_start(container, true, true);
-
- this.add_button(Gtk.Stock.CANCEL, 1);
- this.add_button(Gtk.Stock.OK, 0);
-
- // select a new trigger on OK, hide on CANCEL
- this.response.connect((id) => {
- if (id == 1)
- this.hide();
- else if (id == 0) {
- var assigned_id = PieManager.get_assigned_id(this.trigger);
+ } catch (GLib.Error e) {
+ error("Could not load UI: %s\n", e.message);
+ }
+ }
- if (this.trigger == this.original_trigger) {
- // nothing did change
- this.hide();
- } else if (this.trigger.key_code == this.original_trigger.key_code
- && this.trigger.modifiers == this.original_trigger.modifiers
- && this.trigger.with_mouse == this.original_trigger.with_mouse) {
- // only turbo and/or delayed mode changed, no need to check for double assignment
- this.on_select(this.trigger);
- this.hide();
- } else if (assigned_id != "") {
- // it's already assigned
- var error = _("This hotkey is already assigned to the pie \"%s\"! \n\nPlease select " +
- "another one or cancel your selection.").printf(PieManager.get_name_of(assigned_id));
- var dialog = new Gtk.MessageDialog((Gtk.Window)this.get_toplevel(),
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.ERROR,
- Gtk.ButtonsType.CANCEL,
- error);
- dialog.run();
- dialog.destroy();
- } else {
- // a unused hot key has been chosen, great!
- this.on_select(this.trigger);
- this.hide();
- }
- }
- });
+ /////////////////////////////////////////////////////////////////////
+ /// Sets the parent window, in order to make this window stay in
+ /// front.
+ /////////////////////////////////////////////////////////////////////
+
+ public void set_parent(Gtk.Window parent) {
+ this.window.set_transient_for(parent);
}
/////////////////////////////////////////////////////////////////////
- /// Used to set the currently selected trigger on opening.
+ /// Displays the window on the screen.
/////////////////////////////////////////////////////////////////////
- public void set_trigger(Trigger trigger) {
- this.turbo.active = trigger.turbo;
- this.delayed.active = trigger.delayed;
- this.original_trigger = trigger;
- this.update_trigger(trigger);
+ public void show() {
+ this.window.show_all();
}
/////////////////////////////////////////////////////////////////////
- /// Called when the user clicks in the click area.
+ /// Initilizes all members to match the Trigger of the Pie with the
+ /// given ID.
/////////////////////////////////////////////////////////////////////
- private bool on_area_clicked(Gdk.EventButton event) {
- Gdk.ModifierType state = event.state & ~ this.lock_modifiers;
+ public void set_pie(string id) {
+ var trigger = new Trigger.from_string(PieManager.get_accelerator_of(id));
- var new_trigger = new Trigger.from_values((int)event.button, state, true,
- this.turbo.active, this.delayed.active);
- if (new_trigger.key_code == 1) {
- var dialog = new Gtk.MessageDialog((Gtk.Window)this.get_toplevel(), Gtk.DialogFlags.MODAL,
- Gtk.MessageType.WARNING,
- Gtk.ButtonsType.YES_NO,
- _("It possible to make your system unusable if " +
- "you bind a Pie to your left mouse button. Do " +
- "you really want to do this?"));
-
- dialog.response.connect((response) => {
- if (response == Gtk.ResponseType.YES) {
- this.update_trigger(new_trigger);
- }
- });
-
- dialog.run();
- dialog.destroy();
- } else {
- this.update_trigger(new_trigger);
- }
+ this.turbo.active = trigger.turbo;
+ this.delayed.active = trigger.delayed;
+ this.centered.active = trigger.centered;
+ this.original_trigger = trigger;
+ this.trigger = trigger;
- return true;
+ this.button.set_trigger(trigger);
}
/////////////////////////////////////////////////////////////////////
- /// Called when the user presses a keyboard key.
+ /// Called when one of the three checkoxes is toggled.
/////////////////////////////////////////////////////////////////////
- private bool on_key_press(Gdk.EventKey event) {
- if (Gdk.keyval_name(event.keyval) == "Escape") {
- this.hide();
- } else if (Gdk.keyval_name(event.keyval) == "BackSpace") {
- this.update_trigger(new Trigger());
- } else if (event.is_modifier == 0) {
- Gdk.ModifierType state = event.state & ~ this.lock_modifiers;
- this.update_trigger(new Trigger.from_values((int)event.keyval, state, false,
- this.turbo.active, this.delayed.active));
- }
-
- return true;
+ private void on_check_toggled() {
+ if (this.trigger != null)
+ this.trigger = new Trigger.from_values(this.trigger.key_sym, this.trigger.modifiers,
+ this.trigger.with_mouse, this.turbo.active,
+ this.delayed.active, this.centered.active);
}
/////////////////////////////////////////////////////////////////////
- /// Called when the user presses a mouse button.
+ /// Called when the OK-button is pressed.
/////////////////////////////////////////////////////////////////////
- private bool on_button_press(Gdk.EventButton event) {
- int width = 0, height = 0;
- this.window.get_geometry(null, null, out width, out height, null);
- if (event.x < 0 || event.x > width || event.y < 0 || event.y > height)
- this.hide();
- return true;
+ private void on_ok_button_clicked() {
+ var assigned_id = PieManager.get_assigned_id(this.trigger);
+
+ if (this.trigger == this.original_trigger) {
+ // nothing did change
+ this.window.hide();
+ } else if (this.trigger.key_code == this.original_trigger.key_code
+ && this.trigger.modifiers == this.original_trigger.modifiers
+ && this.trigger.with_mouse == this.original_trigger.with_mouse) {
+ // only turbo and/or delayed mode changed, no need to check for double assignment
+ this.on_ok(this.trigger);
+ this.window.hide();
+ } else if (assigned_id != "") {
+ // it's already assigned
+ var error = _("This hotkey is already assigned to the pie \"%s\"! \n\nPlease select " +
+ "another one or cancel your selection.").printf(PieManager.get_name_of(assigned_id));
+ var dialog = new Gtk.MessageDialog((Gtk.Window)this.window.get_toplevel(), Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, error);
+ dialog.run();
+ dialog.destroy();
+ } else {
+ // a unused hot key has been chosen, great!
+ this.on_ok(this.trigger);
+ this.window.hide();
+ }
}
/////////////////////////////////////////////////////////////////////
- /// Helper method to update the content of the trigger preview label.
+ /// Called when the cancel button is pressed.
/////////////////////////////////////////////////////////////////////
- private void update_trigger(Trigger new_trigger) {
- this.trigger = new_trigger;
- this.preview.set_markup("<big><b>" + this.trigger.label + "</b></big>");
- }
+ private void on_cancel_button_clicked() {
+ this.window.hide();
+ }
}
}