Introduce 'already mapped' messaging for new commands
This commit is contained in:
parent
2394996d04
commit
99533be690
1 changed files with 45 additions and 11 deletions
|
@ -1,5 +1,7 @@
|
|||
namespace Streamdeck.Dialogs {
|
||||
public class NewCommandDialog : Granite.Dialog {
|
||||
private Gtk.Stack stack;
|
||||
private Views.ConfigCommand command_page;
|
||||
private string serial_number;
|
||||
private ReadInput key_info;
|
||||
|
||||
|
@ -24,11 +26,26 @@ namespace Streamdeck.Dialogs {
|
|||
|
||||
press_page.attach (press_label, 0, 0);
|
||||
|
||||
var command_page = new Views.ConfigCommand (serial_number);
|
||||
var existing_key_label = new Gtk.Label (
|
||||
_("Key already mapped, try pressing a new key")
|
||||
);
|
||||
existing_key_label.valign = Gtk.Align.CENTER;
|
||||
existing_key_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
|
||||
|
||||
var stack = new Gtk.Stack ();
|
||||
var existing_key_page = new Gtk.Grid ();
|
||||
existing_key_page.column_spacing = 12;
|
||||
existing_key_page.row_spacing = 12;
|
||||
existing_key_page.halign = Gtk.Align.CENTER;
|
||||
existing_key_page.margin = 24;
|
||||
|
||||
existing_key_page.attach (existing_key_label, 0, 0);
|
||||
|
||||
command_page = new Views.ConfigCommand (serial_number);
|
||||
|
||||
stack = new Gtk.Stack ();
|
||||
stack.add_named (disconnected_page, "disconnected");
|
||||
stack.add_named (press_page, "keypress");
|
||||
stack.add_named (existing_key_page, "existing");
|
||||
stack.add_named (command_page, "command");
|
||||
|
||||
get_content_area ().add (stack);
|
||||
|
@ -41,15 +58,7 @@ namespace Streamdeck.Dialogs {
|
|||
|
||||
show_all ();
|
||||
|
||||
key_press.connect ((_obj, key_info) => {
|
||||
if (serial_number == key_info.serial_number) {
|
||||
this.key_info = key_info;
|
||||
command_page.set_key (key_info.key);
|
||||
stack.set_visible_child_name ("command");
|
||||
} else {
|
||||
Daemon.instance.key_press.begin ();
|
||||
}
|
||||
});
|
||||
key_press.connect (handle_key_press);
|
||||
|
||||
if (Daemon.instance.get_obs_state () != "Connected") {
|
||||
stack.set_visible_child_name ("disconnected");
|
||||
|
@ -58,5 +67,30 @@ namespace Streamdeck.Dialogs {
|
|||
Daemon.instance.key_press.begin ();
|
||||
}
|
||||
}
|
||||
|
||||
private void handle_key_press (ReadInput key_info) {
|
||||
if (serial_number == key_info.serial_number) {
|
||||
if (already_pressed (key_info.key)) {
|
||||
stack.set_visible_child_name ("existing");
|
||||
Daemon.instance.key_press.begin ();
|
||||
} else {
|
||||
this.key_info = key_info;
|
||||
command_page.set_key (key_info.key);
|
||||
stack.set_visible_child_name ("command");
|
||||
}
|
||||
} else {
|
||||
Daemon.instance.key_press.begin ();
|
||||
}
|
||||
}
|
||||
|
||||
private bool already_pressed (uint8 key) {
|
||||
foreach (CommandInfo cmd in Daemon.instance.get_commands (serial_number)) {
|
||||
if (cmd.key == key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue