From 452cbdc614d906935ee4b3d16ef926fd0516a04a Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 19 Aug 2021 01:15:11 -0400 Subject: [PATCH] add convenient features to ICARUS script editor, like group/ungroup commands and lock/unlock parameters --- .../RavenSoftware/Icarus/ContextMenu.uexml | 10 +- .../Icarus/Controls/ExpressionEditor.glade | 54 +++--- .../RavenSoftware/Icarus/IcarusCommands.uexml | 10 +- .../Controls/Icarus/IcarusExpressionEditor.cs | 27 +++ .../Icarus/IcarusExpressionHelperDialog.cs | 1 + .../Editors/Icarus/IcarusScriptEditor.cs | 179 ++++++++++++++++-- .../Icarus/IcarusScriptEditorCommand.cs | 1 + .../ObjectModels/Icarus/IcarusCommand.cs | 20 +- .../Parameters/IcarusGenericParameter.cs | 2 +- 9 files changed, 252 insertions(+), 52 deletions(-) diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/ContextMenu.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/ContextMenu.uexml index 1a2dcd48..8207e650 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/ContextMenu.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/ContextMenu.uexml @@ -2,12 +2,15 @@ - + - + + + + @@ -23,6 +26,9 @@ + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/Controls/ExpressionEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/Controls/ExpressionEditor.glade index fcdaf8a9..43c03ae5 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/Controls/ExpressionEditor.glade +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/Controls/ExpressionEditor.glade @@ -2,6 +2,11 @@ + + True + False + gtk-dialog-authentication + @@ -111,7 +116,7 @@ - 1 + 2 2 @@ -132,6 +137,7 @@ 0 4 + 2 @@ -143,7 +149,7 @@ True - 1 + 2 4 @@ -164,6 +170,7 @@ 0 5 + 2 @@ -175,7 +182,7 @@ True - 1 + 2 5 @@ -223,6 +230,7 @@ 0 6 + 2 @@ -239,7 +247,7 @@ 0 0 - 2 + 3 @@ -251,7 +259,7 @@ True - 1 + 2 6 @@ -272,6 +280,7 @@ 0 3 + 2 @@ -309,7 +318,7 @@ - 1 + 2 3 @@ -322,7 +331,7 @@ 0 1 - 2 + 3 @@ -339,30 +348,21 @@ - 0 + 1 2 - - - - - - - - - - - - - - - - - - - + + True + True + True + image1 + + + 0 + 2 + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/IcarusCommands.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/IcarusCommands.uexml index 06f15d0e..d4b68282 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/IcarusCommands.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/RavenSoftware/Icarus/IcarusCommands.uexml @@ -35,7 +35,7 @@ --> - + @@ -46,12 +46,12 @@ - + - + @@ -177,12 +177,12 @@ - + - + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Controls/Icarus/IcarusExpressionEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Controls/Icarus/IcarusExpressionEditor.cs index f60ed8e8..0a1528d1 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Controls/Icarus/IcarusExpressionEditor.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Controls/Icarus/IcarusExpressionEditor.cs @@ -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) diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Dialogs/Icarus/IcarusExpressionHelperDialog.cs b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Dialogs/Icarus/IcarusExpressionHelperDialog.cs index f113da8a..6c2fab93 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Dialogs/Icarus/IcarusExpressionHelperDialog.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Dialogs/Icarus/IcarusExpressionHelperDialog.cs @@ -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 diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditor.cs index 8476aa0d..51e02870 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditor.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditor.cs @@ -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("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("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("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("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("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("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("cmd"); + cmdParent2.Commands.Add(command); + } + else + { + script.Commands.Add(command); + } + } + + if (rowParent != null) + { + IcarusCommand cmdParent2 = rowParent.GetExtraData("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("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; + } } } diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditorCommand.cs b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditorCommand.cs index a22a84db..481b8806 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditorCommand.cs +++ b/Plugins.UserInterface/UniversalEditor.Plugins.RavenSoftware.UserInterface/Editors/Icarus/IcarusScriptEditorCommand.cs @@ -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(); diff --git a/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/IcarusCommand.cs b/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/IcarusCommand.cs index 2e070c3f..da0c5cde 100644 --- a/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/IcarusCommand.cs +++ b/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/IcarusCommand.cs @@ -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 /// /// true if is commented; otherwise, false. 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 _cmdsByName = null; diff --git a/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/Parameters/IcarusGenericParameter.cs b/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/Parameters/IcarusGenericParameter.cs index 6f49cc32..2a3a1dfd 100644 --- a/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/Parameters/IcarusGenericParameter.cs +++ b/Plugins/UniversalEditor.Plugins.RavenSoftware/ObjectModels/Icarus/Parameters/IcarusGenericParameter.cs @@ -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;