Skip to content

Commit

Permalink
Script Add/Remove Support and editor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltContainer committed Jan 16, 2023
1 parent d6a450b commit a724d88
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 3 deletions.
9 changes: 9 additions & 0 deletions BrilliantShiningScriptEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,20 @@
<Compile Include="Forms\FormMain.Designer.cs">
<DependentUpon>FormMain.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FormTextBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\FormTextBox.Designer.cs">
<DependentUpon>FormTextBox.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Forms\FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FormTextBox.resx">
<DependentUpon>FormTextBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
Expand Down
1 change: 1 addition & 0 deletions Forms/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void FormMain_Load(object sender, EventArgs e)
LoadPage();
}

private void webEditor_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
private void webEditor_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
stripMain.Enabled = true;
}
Expand All @@ -65,6 +65,7 @@ private string GetEditorValue()
string code = ExecuteEditorScript("editor.getValue()");
code = code.Replace("\"", "");
code = code.Replace("\\n", "\n");
code = code.Replace("\\r", "");
return code;
}

Expand Down Expand Up @@ -97,6 +98,11 @@ private static string EditorWait(Task<string> task)

return wait;
}

private void FormMain_SizeChanged(object sender, EventArgs e)
{
ExecuteEditorScript("editor.layout()");
}
#endregion

private void AddToolTips()
Expand All @@ -122,8 +128,9 @@ private void UpdateScriptList(List<Script> scripts)
}

private void UpdateScriptBox(Script script)
{
{
SetEditorValue(scriptEditorEngine.DecompileScript(script));
ExecuteEditorScript("editor.updateOptions({readOnly: false})");
}

private void UpdateCommandInfo(CommandInfo command)
Expand Down Expand Up @@ -163,11 +170,45 @@ private void comboScript_SelectedIndexChanged(object sender, EventArgs e)
private void btnScriptAdd_Click(object sender, EventArgs e)
{
// Add Script

FormTextBox newScriptForm = new FormTextBox("Add Script", "Enter the name for the script:", "Confirm", "Cancel");

if (newScriptForm.ShowDialog() == DialogResult.OK)
{
string result = newScriptForm.Result;
List<Script> list = ((ScriptFile)comboScriptFile.SelectedItem).Scripts;
if (string.IsNullOrWhiteSpace(result))
{
MessageBox.Show("The given Script name is empty.", "Invalid Script Name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (list.Select(s => s.Name).Contains(result))
{
MessageBox.Show("The given Script name already exists in this file.", "Invalid Script Name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
int endId = FileConstants.Commands.Where(c => c.Name == "_END").Select(c => c.Id).DefaultIfEmpty(0).First();
Argument endArgument = new Argument(ArgumentType.Command, endId);
Script script = new Script(result, new List<Command>() { new Command(new List<Argument>() { endArgument }) });
list.Add(script);
MessageBox.Show("Added the new script in memory successfully! Don't forget to export all your changes.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboScriptFile_SelectedIndexChanged(this, new EventArgs());
}
}
}

private void btnScriptRemove_Click(object sender, EventArgs e)
{
// Remove Script

if (MessageBox.Show("Are you sure you want to delete this script from memory? The script will be completely gone when you export your changes.", "Script Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
List<Script> list = ((ScriptFile)comboScriptFile.SelectedItem).Scripts;
Script script = (Script)comboScript.SelectedItem;
list.Remove(script);
MessageBox.Show("Removed the new script from memory successfully! Don't forget to export all your changes.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
comboScriptFile_SelectedIndexChanged(this, new EventArgs());
}
}

private void btnScriptCompile_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -237,7 +278,8 @@ private void tbtnOpen_Click(object sender, EventArgs e)
tbtnOpen.Enabled = false;
btnScriptCompile.Enabled = true;
btnScriptSave.Enabled = true;
ExecuteEditorScript("editor.updateOptions({readOnly: false})");
btnScriptAdd.Enabled = true;
btnScriptRemove.Enabled = true;
}
}
else
Expand Down
104 changes: 104 additions & 0 deletions Forms/FormTextBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Forms/FormTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BrilliantShiningScriptEditor.Forms
{
public partial class FormTextBox : Form
{
public string Result { get; set; }

public FormTextBox(string title, string description, string yesButton, string noButton)
{
InitializeComponent();

Name = title;
lbInfo.Text = description;
btnYes.Text = yesButton;
btnNo.Text = noButton;
}

private void btnYes_Click(object sender, EventArgs e)
{
Result = txtAnswer.Text;
DialogResult = DialogResult.OK;
Close();
}
}
}
120 changes: 120 additions & 0 deletions Forms/FormTextBox.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
6 changes: 6 additions & 0 deletions Monaco/editor_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
scrollBeyondLastLine: false,
readOnly: true,
theme: 'vs-dark'
});
var outputElem = document.getElementById('output');
var model = editor.getModel();
model.setEOL(monaco.editor.EndOfLineSequence.LF);
editor.onDidChangeModelContent(async (e) => {
outputElem.innerHTML = JSON.stringify(editor.getValue());
});

0 comments on commit a724d88

Please sign in to comment.