Skip to content

Commit

Permalink
SetEnginePreference command support variable marker etc
Browse files Browse the repository at this point in the history
  • Loading branch information
rcktrncn committed Jul 24, 2021
1 parent adb72a6 commit faf3ff6
Showing 1 changed file with 84 additions and 2 deletions.
86 changes: 84 additions & 2 deletions taskt/Core/Automation/Commands/SetEnginePreferenceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;
using System.Linq;

namespace taskt.Core.Automation.Commands
{
Expand All @@ -19,10 +20,29 @@ public class SetEnginePreferenceCommand : ScriptCommand
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Enable Automatic Calculations")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Disable Automatic Calculations")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Start Variable Marker")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("End Variable Marker")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Engine Delay")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Current Window Keyword")]
[Attributes.PropertyAttributes.InputSpecification("")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_PreferenceType { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Specify Parameter Value")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_ParameterValue { get; set; }

[XmlIgnore]
[NonSerialized]
private ComboBox PreferenceTypeCombobox;

[XmlIgnore]
[NonSerialized]
private List<Control> ElementParameterControls;

public SetEnginePreferenceCommand()
{
this.CommandName = "SetEnginePreferenceCommand";
Expand All @@ -37,6 +57,8 @@ public override void RunCommand(object sender)

var preference = v_PreferenceType.ConvertToUserVariable(sender);

var parameterValue = v_ParameterValue.ConvertToUserVariable(sender);

switch (preference)
{
case "Enable Automatic Calculations":
Expand All @@ -45,6 +67,20 @@ public override void RunCommand(object sender)
case "Disable Automatic Calculations":
engine.AutoCalculateVariables = false;
break;

case "Start Variable Marker":
engine.engineSettings.VariableStartMarker = parameterValue;
break;
case "End Variable Marker":
engine.engineSettings.VariableEndMarker = parameterValue;
break;
case "Engine Delay":
engine.engineSettings.DelayBetweenCommands = int.Parse(parameterValue);
break;
case "Current Window Keyword":
engine.engineSettings.CurrentWindowKeyword = parameterValue;
break;

default:
throw new NotImplementedException($"The preference '{preference}' is not implemented.");
}
Expand All @@ -55,13 +91,59 @@ public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_PreferenceType", this, editor));
var preference = CommandControls.CreateDefaultDropdownGroupFor("v_PreferenceType", this, editor);
RenderedControls.AddRange(preference);

PreferenceTypeCombobox = (ComboBox)preference.Where(t => t is ComboBox).FirstOrDefault();
PreferenceTypeCombobox.SelectedValueChanged += (sender, e) => PreferenceCombobox_SelectedChanged(sender, e);

ElementParameterControls = CommandControls.CreateDefaultInputGroupFor("v_ParameterValue", this, editor);
RenderedControls.AddRange(this.ElementParameterControls);

return RenderedControls;
}
public override string GetDisplayValue()
{
return base.GetDisplayValue() + $" [{v_PreferenceType}]";
switch (this.v_PreferenceType)
{
case "Enable Automatic Calculations":
case "Disable Automatic Calculations":
return base.GetDisplayValue() + $" [{v_PreferenceType}]";
break;

case "Start Variable Marker":
case "End Variable Marker":
case "Engine Delay":
case "Current Window Keyword":
return base.GetDisplayValue() + " [" + v_PreferenceType +" set '" + (String.IsNullOrEmpty(v_ParameterValue) ? "" : v_ParameterValue) + "']";
break;

default:
return base.GetDisplayValue() + $" [{v_PreferenceType}]";
break;
}

}

private void PreferenceCombobox_SelectedChanged(object sender, System.EventArgs e)
{
switch (PreferenceTypeCombobox.Text)
{
case "Enable Automatic Calculations":
case "Disable Automatic Calculations":
foreach(var ctl in ElementParameterControls)
{
ctl.Visible = false;
}
break;

default:
foreach (var ctl in ElementParameterControls)
{
ctl.Visible = true;
}
break;
}
}

public override bool IsValidate(frmCommandEditor editor)
Expand Down

0 comments on commit faf3ff6

Please sign in to comment.