owo/src/Widgets/CommandRow.vala
2021-05-04 20:17:55 -05:00

101 lines
3.4 KiB
Vala

namespace Streamdeck.Widgets {
public class CommandRow : Gtk.ListBoxRow {
private string serial_number;
private Data.Command command;
private Dialogs.EditCommandDialog? edit_dialog;
public CommandRow (string serial_number, Data.Command command) {
this.serial_number = serial_number;
this.command = command;
var key = command.get_command_key ();
var row_key = new Gtk.Label (@"$(key)");
row_key.halign = Gtk.Align.START;
row_key.valign = Gtk.Align.START;
row_key.show_all ();
var row_command = new Gtk.Label (null);
row_command.halign = Gtk.Align.START;
row_command.valign = Gtk.Align.START;
row_command.show_all ();
var row_grid = new Gtk.Grid ();
row_grid.orientation = Gtk.Orientation.HORIZONTAL;
row_grid.margin = 6;
row_grid.margin_start = 3;
row_grid.column_spacing = 3;
row_grid.add (row_key);
row_grid.add (row_command);
switch (command.get_command_type ()) {
case Data.CommandType.SWITCH_SCENE:
row_command.label = _("Switch scene");
switch_scene_ui (row_grid);
break;
default:
row_command.label = _("Unknown Command");
break;
}
var row_edit = new Gtk.Button.from_icon_name (
"document-edit-symbolic",
Gtk.IconSize.BUTTON
);
row_edit.tooltip_text = _("Edit");
row_edit.halign = Gtk.Align.END;
row_edit.valign = Gtk.Align.END;
row_edit.expand = true;
row_edit.clicked.connect (() => {
if (edit_dialog == null) {
edit_dialog = new Dialogs.EditCommandDialog (serial_number, command);
edit_dialog.transient_for = (Gtk.Window) get_toplevel ();
edit_dialog.show_all ();
edit_dialog.response.connect ((response_id) => {
if (response_id == Gtk.ResponseType.REJECT) {
unowned var app = (MainWindow) get_toplevel ();
app.to_obs ();
}
edit_dialog.destroy ();
});
edit_dialog.destroy.connect (() => {
edit_dialog = null;
});
}
edit_dialog.present ();
});
row_grid.add (row_edit);
row_grid.show_all();
add (row_grid);
show_all ();
}
public uint8 get_key () {
return command.get_command_key ();
}
private void switch_scene_ui (Gtk.Grid row_grid) {
unowned var switch_scene = (Data.SwitchScene) command;
var to = new Gtk.Label (_("to"));
to.halign = Gtk.Align.START;
to.valign = Gtk.Align.START;
to.show_all ();
var scene_name = new Gtk.Label (switch_scene.scene_name);
scene_name.halign = Gtk.Align.START;
scene_name.valign = Gtk.Align.START;
scene_name.show_all ();
row_grid.add (to);
row_grid.add (scene_name);
}
}
}