diff options
author | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-17 21:50:38 +0300 |
---|---|---|
committer | JeffB42 <10328858+JeffB42@users.noreply.github.com> | 2021-04-17 21:50:38 +0300 |
commit | c87fc2af68d91ee43e545b9ac201bd783d8c4776 (patch) | |
tree | b1a728c14e25fd358036c318f4dfa445dd521bbd | |
parent | 9818157a8a6b90a00f8167cbc12890a48a396a28 (diff) |
added 'yellow bar' to scripts which display a confirmation
-rwxr-xr-x | uiWidgets/CommandButton.go | 15 | ||||
-rwxr-xr-x | uiWidgets/ControlButton.go | 17 |
2 files changed, 27 insertions, 5 deletions
diff --git a/uiWidgets/CommandButton.go b/uiWidgets/CommandButton.go index 030d4c8..3914897 100755 --- a/uiWidgets/CommandButton.go +++ b/uiWidgets/CommandButton.go @@ -4,12 +4,14 @@ import ( // "fmt" "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) + type CommandButton struct { *gtk.Button @@ -24,7 +26,12 @@ func CreateCommandButton( commandDefinition *dataModels.CommandDefinition, iconName string, ) *CommandButton { - base := utils.MustButtonImage(utils.StrEllipsisLen(commandDefinition.Name, 16), iconName + ".svg", nil) + style := "" + if commandRequiresConfirmation(commandDefinition) { + style = "color-warning-sign-yellow" + } + base := utils.MustButtonImageStyle(utils.StrEllipsisLen(commandDefinition.Name, 16), iconName + ".svg", style, nil) + instance := &CommandButton { Button: base, client: client, @@ -40,8 +47,12 @@ func CreateCommandButton( return instance } +func commandRequiresConfirmation(commandDefinition *dataModels.CommandDefinition) bool { + return commandDefinition != nil && len(commandDefinition.Confirm) > 0 +} + func (this *CommandButton) handleClicked() { - if len(this.commandDefinition.Confirm) != 0 { + if commandRequiresConfirmation(this.commandDefinition) { utils.MustConfirmDialogBox( this.parentWindow, this.commandDefinition.Confirm, diff --git a/uiWidgets/ControlButton.go b/uiWidgets/ControlButton.go index 232abed..53ae63e 100755 --- a/uiWidgets/ControlButton.go +++ b/uiWidgets/ControlButton.go @@ -4,12 +4,14 @@ import ( // "fmt" "github.com/gotk3/gotk3/gtk" + "github.com/Z-Bolt/OctoScreen/logger" "github.com/Z-Bolt/OctoScreen/octoprintApis" "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels" "github.com/Z-Bolt/OctoScreen/utils" ) + type ControlButton struct { *gtk.Button @@ -24,7 +26,12 @@ func CreateControlButton( controlDefinition *dataModels.ControlDefinition, iconName string, ) *ControlButton { - base := utils.MustButtonImage(utils.StrEllipsisLen(controlDefinition.Name, 16), iconName + ".svg", nil) + style := "" + if controlRequiresConfirmation(controlDefinition) { + style = "color-warning-sign-yellow" + } + base := utils.MustButtonImageStyle(utils.StrEllipsisLen(controlDefinition.Name, 16), iconName + ".svg", style, nil) + instance := &ControlButton { Button: base, client: client, @@ -40,8 +47,12 @@ func CreateControlButton( return instance } +func controlRequiresConfirmation(controlDefinition *dataModels.ControlDefinition) bool { + return controlDefinition != nil && len(controlDefinition.Confirm) > 0 +} + func (this *ControlButton) handleClicked() { - if len(this.controlDefinition.Confirm) != 0 { + if controlRequiresConfirmation(this.controlDefinition) { utils.MustConfirmDialogBox( this.parentWindow, this.controlDefinition.Confirm, @@ -54,7 +65,7 @@ func (this *ControlButton) handleClicked() { func (this *ControlButton) sendCommand() { logger.Infof("ControlButton.sendCommand(), now sending command %q", this.controlDefinition.Name) - + commandRequest := &octoprintApis.CommandRequest{ Commands: this.controlDefinition.Commands, } |