add convenient features to ICARUS script editor, like group/ungroup commands and lock/unlock parameters

This commit is contained in:
Michael Becker 2021-08-19 01:15:11 -04:00
parent 714ea0aa58
commit 452cbdc614
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C
9 changed files with 252 additions and 52 deletions

View File

@ -2,12 +2,15 @@
<Editors>
<Editor TypeName="UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus.IcarusScriptEditor">
<Commands>
<Command ID="Icarus_ContextMenu_Comment" Title="Comment Selected Items" />
<Command ID="Icarus_ContextMenu_Comment" Title="_Comment Selected Items" />
<Command ID="Icarus_ContextMenu_TEST_EXPRESSION_EDITOR" Title="Test E_xpression Editor" />
<Command ID="Icarus_ContextMenu_Insert_From_File" Title="Insert Commands from File..." />
<Command ID="Icarus_ContextMenu_Insert_From_File" Title="_Insert Commands from File..." />
<Command ID="Icarus_ContextMenu_Rename" Title="Rena_me" />
<Command ID="Icarus_ContextMenu_Group" Title="_Group" />
<Command ID="Icarus_ContextMenu_Ungroup" Title="_Ungroup" />
<Command ID="Icarus_ContextMenu">
<Items>
<CommandReference CommandID="EditCut" />
@ -23,6 +26,9 @@
<Separator />
<CommandReference CommandID="Icarus_ContextMenu_Rename" />
<Separator />
<CommandReference CommandID="Icarus_ContextMenu_Group" />
<CommandReference CommandID="Icarus_ContextMenu_Ungroup" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>

View File

@ -2,6 +2,11 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-dialog-authentication</property>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name text -->
@ -111,7 +116,7 @@
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
@ -132,6 +137,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
@ -143,7 +149,7 @@
<property name="use-underline">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">4</property>
</packing>
</child>
@ -164,6 +170,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="width">2</property>
</packing>
</child>
<child>
@ -175,7 +182,7 @@
<property name="use-underline">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">5</property>
</packing>
</child>
@ -223,6 +230,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
<property name="width">2</property>
</packing>
</child>
<child>
@ -239,7 +247,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
<property name="width">3</property>
</packing>
</child>
<child>
@ -251,7 +259,7 @@
<property name="use-underline">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">6</property>
</packing>
</child>
@ -272,6 +280,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
<property name="width">2</property>
</packing>
</child>
<child>
@ -309,7 +318,7 @@
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
@ -322,7 +331,7 @@
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="width">2</property>
<property name="width">3</property>
</packing>
</child>
<child>
@ -339,30 +348,21 @@
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
<object class="GtkToggleButton" id="cmdLock">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
</child>

View File

@ -35,7 +35,7 @@
-->
<IcarusCommands>
<IcarusCommand TypeCode="31" Name="flush" Icon="I_FLUSH" Description="clear all previous script commands on ent" />
<IcarusCommand Name="if" Icon="I_IF" Description="if condition true, execute block of commands">
<IcarusCommand Name="if" Type="Container" Icon="I_IF" Description="if condition true, execute block of commands">
<Parameters>
<Parameter Name="expr1">
</Parameter>
@ -46,12 +46,12 @@
</Parameters>
</IcarusCommand>
<IcarusCommand Name="else" Icon="I_IF" Description="must immediately follow and else, will execute if the if condition is false" />
<IcarusCommand TypeCode="27" Name="loop" Icon="I_LOOP" Description="execute block of commands any number of times (-1 = forever)">
<IcarusCommand TypeCode="27" Name="loop" Type="Container" Icon="I_LOOP" Description="execute block of commands any number of times (-1 = forever)">
<Parameters>
<Parameter Type="float" Name="count" Value="-1" />
</Parameters>
</IcarusCommand>
<IcarusCommand TypeCode="19" Name="affect" Description="switch script affect to ent with specified name, flush old commands or insert the new block of commands into current commands">
<IcarusCommand TypeCode="19" Name="affect" Type="Container" Description="switch script affect to ent with specified name, flush old commands or insert the new block of commands into current commands">
<Parameters>
<Parameter Name="Target" Value="DEFAULT" />
<Parameter Name="Type" Value="FLUSH" Enumeration="AFFECT_TYPE" />
@ -177,12 +177,12 @@
<Parameter Name="target" Type="string" Value="DEFAULT" />
</Parameters>
</IcarusCommand>
<IcarusCommand TypeCode="42" Name="do" Type="Container" Icon="I_DO">
<IcarusCommand TypeCode="42" Name="do" Icon="I_DO">
<Parameters>
<Parameter Name="target" Type="string" Value="DEFAULT" AutoCompleteCommandType="Task" AutoCompleteParameterIndex="0" />
</Parameters>
</IcarusCommand>
<IcarusCommand TypeCode="23" Name="wait" Type="Container" Icon="I_WAIT" Description="wait until task &quot;taskname&quot; is complete">
<IcarusCommand TypeCode="23" Name="wait" Icon="I_WAIT" Description="wait until task &quot;taskname&quot; is complete">
<Parameters>
<Parameter Name="target" Type="string" Value="DEFAULT" AutoCompleteCommandType="Task" AutoCompleteParameterIndex="0" />
</Parameters>

View File

@ -53,9 +53,33 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Controls.Icarus
private Container ctFileChooser = null;
private Button cmdExecute;
private DefaultTreeModel lsGETName;
internal Button cmdLock;
public IcarusScriptObjectModel Script { get; set; } = null;
[EventHandler(nameof(cmdLock), nameof(Button.Click))]
private void cmdLock_Click(object sender, EventArgs e)
{
EnableDisableControls(!cmdLock.Checked);
}
private void EnableDisableControls(bool enable)
{
txtParameterValue.Enabled = enable;
cboExpressionType.Enabled = enable;
cboGETType.Enabled = enable;
cmdBrowse.Enabled = enable;
cmdExecute.Enabled = enable;
cboGETName.Enabled = enable;
cmdGET.Enabled = enable;
cboTAGType.Enabled = enable;
cmdTAG.Enabled = enable;
txtRangeStart.Enabled = enable;
lblRange.Enabled = enable;
txtRangeEnd.Enabled = enable;
cmdRND.Enabled = enable;
}
public void UpdateParameterValueChoices()
{
if (Parameter.AutoCompleteCommandType != IcarusCommandType.None)
@ -99,6 +123,7 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Controls.Icarus
lblParameterName.Text = _Parameter.Name;
lblParameterDescription.Text = _Parameter.Description;
cmdLock.Checked = _Parameter.ReadOnly;
string pval = _Parameter.Value?.ToString();
if (!String.IsNullOrEmpty(pval))
@ -149,6 +174,8 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Controls.Icarus
break;
}
}
EnableDisableControls(!_Parameter.ReadOnly);
}
protected override void OnCreated(EventArgs e)

View File

@ -89,6 +89,7 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Dialogs.Icarus
for (int i = 0; i < _Command.Parameters.Count; i++)
{
IcarusExpressionEditor ed = ct.Controls[i] as IcarusExpressionEditor;
_Command.Parameters[i].ReadOnly = ed.cmdLock.Checked;
if (ed.cboExpressionType.SelectedItem == (ed.cboExpressionType.Model as DefaultTreeModel).Rows[0])
{
// constant

View File

@ -77,15 +77,29 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
BeginEdit();
IcarusCommand omcmd = ScriptEditorCommandToOMCommand(cmd);
RecursiveAddCommand(omcmd);
(ObjectModel as IcarusScriptObjectModel).Commands.Add(omcmd);
IcarusCommand selectedCommand = tv.SelectedRows.Count == 1 ? tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd") : null;
if (selectedCommand != null && selectedCommand.IsContainer)
{
RecursiveAddCommand(omcmd, tv.SelectedRows[0]);
tv.SelectedRows[0].Expanded = true;
selectedCommand.Commands.Add(omcmd);
tv.SelectedRows[0].RowColumns[0].Value = GetCommandText(selectedCommand);
}
else
{
RecursiveAddCommand(omcmd);
(ObjectModel as IcarusScriptObjectModel).Commands.Add(omcmd);
}
EndEdit();
}
private IcarusCommand ScriptEditorCommandToOMCommand(IcarusScriptEditorCommand cmd)
{
IcarusCommand command = new IcarusCommand(cmd.Name, cmd.TypeCode);
IcarusCommand command = new IcarusCommand(cmd.Name, cmd.TypeCode, cmd.IsContainer);
command.Description = cmd.Description;
for (int i = 0; i < cmd.Parameters.Count; i++)
{
@ -177,6 +191,12 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
cmd.TypeCode = Int32.Parse(attTypeCode.Value);
}
MarkupAttribute attType = tagCommand.Attributes["Type"];
if (attType != null)
{
cmd.IsContainer = "container".Equals(attType.Value?.ToLower());
}
MarkupAttribute attIcon = tagCommand.Attributes["Icon"];
if (attIcon != null)
{
@ -205,6 +225,11 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
MarkupAttribute attParameterValue = tagParameter.Attributes["Value"];
MarkupAttribute attParameterEnumeration = tagParameter.Attributes["Enumeration"];
MarkupAttribute attParameterReadOnly = tagParameter.Attributes["ReadOnly"];
if (attParameterReadOnly != null)
{
parm.ReadOnly = "true".Equals(attParameterReadOnly.Value.ToLower());
}
MarkupAttribute attAutoCompleteCommandType = tagParameter.Attributes["AutoCompleteCommandType"];
MarkupAttribute attAutoCompleteParameterIndex = tagParameter.Attributes["AutoCompleteParameterIndex"];
@ -308,6 +333,9 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
Context.AttachCommandEventHandler("Icarus_ContextMenu_Insert_From_File", Icarus_ContextMenu_Insert_From_File);
Context.AttachCommandEventHandler("Icarus_ContextMenu_Rename", Icarus_ContextMenu_Rename);
Context.AttachCommandEventHandler("Icarus_ContextMenu_Group", Icarus_ContextMenu_Group);
Context.AttachCommandEventHandler("Icarus_ContextMenu_Ungroup", Icarus_ContextMenu_Ungroup);
// Commands["Icarus_Debug_BreakExecution"].Visible = false;
// Commands["Icarus_Debug_BreakExecution"].Visible = false;
// Commands["Icarus_Debug_StopDebugging"].Visible = false;
@ -328,10 +356,19 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
Application.Instance.Commands["EditCopy"].Enabled = hasSelectedItems;
Application.Instance.Commands["EditDelete"].Enabled = hasSelectedItems;
Application.Instance.Commands["FileProperties"].Enabled = hasSelectedItems;
Context.Commands["Icarus_ContextMenu_Comment"].Enabled = hasSelectedItems;
if (tv.SelectedRows.Count > 0)
{
Context.Commands["Icarus_ContextMenu_Group"].Enabled = tv.SelectedRows[0].ParentRow == null;
Context.Commands["Icarus_ContextMenu_Ungroup"].Enabled = tv.SelectedRows[0].ParentRow != null || (tv.SelectedRows[0].ParentRow == null && tv.SelectedRows.Count == 1 && tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd").IsContainer);
}
else
{
Context.Commands["Icarus_ContextMenu_Group"].Enabled = false;
Context.Commands["Icarus_ContextMenu_Ungroup"].Enabled = false;
}
if (tv.SelectedRows.Count == 1)
{
Context.Commands["Icarus_ContextMenu_Rename"].Enabled = tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd").IsMacro;
@ -419,6 +456,91 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
}
}
private void Icarus_ContextMenu_Group(object sender, EventArgs e)
{
IcarusScriptObjectModel script = (ObjectModel as IcarusScriptObjectModel);
IcarusCommand container = new IcarusCommand(String.Empty, 0, true);
TreeModelRow rowParent = null;
while (tv.SelectedRows.Count > 0)
{
IcarusCommand cmdChild = tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd");
container.Commands.Add(cmdChild);
if (tv.SelectedRows[0].ParentRow != null)
{
rowParent = tv.SelectedRows[0].ParentRow;
rowParent.Rows.Remove(tv.SelectedRows[0]);
}
else
{
tv.Model.Rows.Remove(tv.SelectedRows[0]);
}
treeNodesForCommands.Remove(cmdChild);
}
IcarusCommand cmdParent = null;
if (rowParent != null)
cmdParent = rowParent.GetExtraData<IcarusCommand>("cmd");
if (cmdParent != null)
{
cmdParent.Commands.Add(container);
}
else
{
script.Commands.Add(container);
}
RecursiveAddCommand(container, rowParent);
}
private void Icarus_ContextMenu_Ungroup(object sender, EventArgs e)
{
IcarusScriptObjectModel script = (ObjectModel as IcarusScriptObjectModel);
if (tv.SelectedRows.Count == 1)
{
// ungroup every command in this IcarusCommand (container)
// and put it in the current command's parent
IcarusCommand cmdParent = tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd");
TreeModelRow rowParent = tv.SelectedRows[0].ParentRow;
foreach (IcarusCommand command in cmdParent.Commands)
{
treeNodesForCommands.Remove(command);
RecursiveAddCommand(command, rowParent);
if (rowParent != null)
{
IcarusCommand cmdParent2 = rowParent.GetExtraData<IcarusCommand>("cmd");
cmdParent2.Commands.Add(command);
}
else
{
script.Commands.Add(command);
}
}
if (rowParent != null)
{
IcarusCommand cmdParent2 = rowParent.GetExtraData<IcarusCommand>("cmd");
cmdParent2.Commands.Remove(cmdParent);
rowParent.Rows.Remove(tv.SelectedRows[0]);
}
else
{
script.Commands.Remove(cmdParent);
tv.Model.Rows.Remove(tv.SelectedRows[0]);
}
}
}
private void Icarus_ContextMenu_Rename(object sender, EventArgs e)
{
IcarusCommand cmd = tv.SelectedRows[0].GetExtraData<IcarusCommand>("cmd");
@ -821,14 +943,7 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
sb.Append(" ( ");
for (int i = 0; i < command.Parameters.Count; i++)
{
if (command.Parameters[i].Value != null)
{
sb.Append(command.Parameters[i].Value);
}
else
{
sb.Append("null");
}
sb.Append(GetParameterText(command.Parameters[i]));
if (i < command.Parameters.Count - 1)
sb.Append(", ");
@ -843,6 +958,22 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
return sb.ToString();
}
private string GetParameterText(IcarusParameter param)
{
StringBuilder sb = new StringBuilder();
if (param.ReadOnly)
sb.Append("(R)");
if (param.Value != null)
{
sb.Append(param.Value);
}
else
{
sb.Append("null");
}
return sb.ToString();
}
[EventHandler(nameof(tv), "RowActivated")]
private void tv_RowActivated(object sender, ListViewRowActivatedEventArgs e)
{
@ -884,5 +1015,27 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
}
return base.ShowDocumentPropertiesDialogInternal();
}
private static SettingsProvider[] _sp = null;
protected override SettingsProvider[] GetDocumentPropertiesSettingsProvidersInternal()
{
if (_sp == null)
{
_sp = new SettingsProvider[]
{
new CustomSettingsProvider(new SettingsGroup[]
{
new SettingsGroup("General", new Setting[]
{
new CollectionSetting("", "Entity definitions", new SettingsGroup("Entity Definition Settings Group", new Setting[]
{
new TextSetting("", "Entity name")
}), "Entity Definition")
})
})
};
}
return _sp;
}
}
}

View File

@ -65,6 +65,7 @@ namespace UniversalEditor.Plugins.RavenSoftware.UserInterface.Editors.Icarus
public string IconName { get; set; } = null;
public int TypeCode { get; set; } = 0;
public bool IsContainer { get; set; } = false;
public IcarusParameter.IcarusParameterCollection Parameters { get; } = new IcarusParameter.IcarusParameterCollection();
public IcarusScriptEditorCommandCollection Commands { get; } = new IcarusScriptEditorCommandCollection();

View File

@ -36,6 +36,7 @@ namespace UniversalEditor.ObjectModels.Icarus
public string Name { get; set; } = null;
public string Description { get; set; } = null;
public bool IsContainer { get; } = false;
public int CommandType { get; set; } = 0;
@ -47,19 +48,30 @@ namespace UniversalEditor.ObjectModels.Icarus
/// </summary>
/// <value><c>true</c> if is commented; otherwise, <c>false</c>.</value>
public bool IsCommented { get; set; } = false;
public bool IsMacro { get { return (Commands.Count > 0 && CommandType == 0); } }
public bool IsMacro { get { return (IsContainer && Commands.Count > 0 && CommandType == 0); } }
public IcarusCommand.IcarusCommandCollection Commands { get; } = new IcarusCommandCollection();
public IcarusCommand(string name, int commandType)
public IcarusCommand(string name, int commandType, bool isContainer = false)
{
Name = name;
CommandType = commandType;
IsContainer = isContainer;
}
public virtual object Clone()
public object Clone()
{
return null;
IcarusCommand clone = new IcarusCommand(Name?.Clone() as string, CommandType, IsContainer);
clone.Description = Description?.Clone() as string;
foreach (IcarusParameter parameter in Parameters)
{
clone.Parameters.Add(parameter.Clone() as IcarusParameter);
}
foreach (IcarusCommand command in Commands)
{
clone.Commands.Add(command.Clone() as IcarusCommand);
}
return clone;
}
/*
private static Dictionary<string, Type> _cmdsByName = null;

View File

@ -45,7 +45,7 @@ namespace UniversalEditor.ObjectModels.Icarus.Parameters
clone.Description = Description?.Clone() as string;
clone.EnumerationName = EnumerationName?.Clone() as string;
clone.ReadOnly = ReadOnly;
clone.Value = Value.Clone() as IcarusExpression;
clone.Value = Value?.Clone() as IcarusExpression;
clone.AutoCompleteCommandType = AutoCompleteCommandType;
clone.AutoCompleteParameterIndex = AutoCompleteParameterIndex;