Text_Editor now describes the code

This commit is contained in:
Lukasz Baldyga committed 2020-10-23 11:25:36 +01:00
1 parent 2a3857d942
commit b888088f0b
8 files changed
+95 -52

No files matched your search

@@ -80,11 +80,11 @@
<Compile Include="DrawPreview.Designer.cs"> <Compile Include="DrawPreview.Designer.cs">
<DependentUpon>DrawPreview.cs</DependentUpon> <DependentUpon>DrawPreview.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="ErrorDetailWindow.cs"> <Compile Include="DetailsWindow.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="ErrorDetailWindow.Designer.cs"> <Compile Include="DetailsWindow.Designer.cs">
<DependentUpon>ErrorDetailWindow.cs</DependentUpon> <DependentUpon>DetailsWindow.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="ErrorWindow.cs"> <Compile Include="ErrorWindow.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@@ -113,8 +113,8 @@
<EmbeddedResource Include="DrawPreview.resx"> <EmbeddedResource Include="DrawPreview.resx">
<DependentUpon>DrawPreview.cs</DependentUpon> <DependentUpon>DrawPreview.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="ErrorDetailWindow.resx"> <EmbeddedResource Include="DetailsWindow.resx">
<DependentUpon>ErrorDetailWindow.cs</DependentUpon> <DependentUpon>DetailsWindow.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="ErrorWindow.resx"> <EmbeddedResource Include="ErrorWindow.resx">
<DependentUpon>ErrorWindow.cs</DependentUpon> <DependentUpon>ErrorWindow.cs</DependentUpon>
@@ -1,5 +1,5 @@
namespace Advanced_Software_Engineering { namespace Advanced_Software_Engineering {
partial class ErrorDetailWindow { partial class DetailsWindow {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
@@ -38,7 +38,7 @@
this.textBox1.Size = new System.Drawing.Size(365, 405); this.textBox1.Size = new System.Drawing.Size(365, 405);
this.textBox1.TabIndex = 0; this.textBox1.TabIndex = 0;
// //
// ErrorDetailWindow // DetailsWindow
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@@ -47,8 +47,8 @@
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "ErrorDetailWindow"; this.Name = "DetailsWindow";
this.Text = "Error Details"; this.Text = "Details";
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -9,14 +9,20 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace Advanced_Software_Engineering { namespace Advanced_Software_Engineering {
public partial class ErrorDetailWindow : Form { public partial class DetailsWindow : Form {
public ErrorDetailWindow() { public DetailsWindow() {
InitializeComponent(); InitializeComponent();
} }
public ErrorDetailWindow(string errorText) { public DetailsWindow(string errorText) {
InitializeComponent(); InitializeComponent();
textBox1.Text = errorText; textBox1.Text = errorText;
} }
public DetailsWindow(string errorText, string title) {
InitializeComponent();
textBox1.Text = errorText;
Text = title;
}
} }
} }
@@ -78,5 +78,9 @@ namespace Advanced_Software_Engineering
button1.Enabled = true; button1.Enabled = true;
} }
public string DescribeAllCommands() {
return commander.ExplainCommands();
}
} }
} }
@@ -55,7 +55,7 @@ namespace Advanced_Software_Engineering {
} }
private void button2_Click(object sender, EventArgs e) { private void button2_Click(object sender, EventArgs e) {
new ErrorDetailWindow(desc).Show(); new DetailsWindow(desc).Show();
} }
} }
} }
@@ -100,57 +100,58 @@ namespace Advanced_Software_Engineering
// newFileToolStripMenuItem // newFileToolStripMenuItem
// //
this.newFileToolStripMenuItem.Name = "newFileToolStripMenuItem"; this.newFileToolStripMenuItem.Name = "newFileToolStripMenuItem";
this.newFileToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.newFileToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.newFileToolStripMenuItem.Text = "New File"; this.newFileToolStripMenuItem.Text = "New File (Ctrl + N)";
this.newFileToolStripMenuItem.Click += new System.EventHandler(this.newFileToolStripMenuItem_Click); this.newFileToolStripMenuItem.Click += new System.EventHandler(this.newFileToolStripMenuItem_Click);
// //
// openToolStripMenuItem // openToolStripMenuItem
// //
this.openToolStripMenuItem.Name = "openToolStripMenuItem"; this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.openToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.openToolStripMenuItem.Text = "Open"; this.openToolStripMenuItem.Text = "Open (Ctrl + O)";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
// //
// saveToolStripMenuItem // saveToolStripMenuItem
// //
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.saveToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Text = "Save (Ctrl + S)";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
// //
// saveAsToolStripMenuItem // saveAsToolStripMenuItem
// //
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.saveAsToolStripMenuItem.Text = "Save As"; this.saveAsToolStripMenuItem.Text = "Save As (Ctrl + Shift + S)";
this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click); this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.saveAsToolStripMenuItem_Click);
// //
// exitToolStripMenuItem // exitToolStripMenuItem
// //
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.exitToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Text = "Exit (Alt + F4)";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
// //
// runToolStripMenuItem // runToolStripMenuItem
// //
this.runToolStripMenuItem.Name = "runToolStripMenuItem"; this.runToolStripMenuItem.Name = "runToolStripMenuItem";
this.runToolStripMenuItem.Size = new System.Drawing.Size(40, 20); this.runToolStripMenuItem.Size = new System.Drawing.Size(63, 20);
this.runToolStripMenuItem.Text = "Run"; this.runToolStripMenuItem.Text = "Run (F5)";
this.runToolStripMenuItem.Click += new System.EventHandler(this.runToolStripMenuItem_Click); this.runToolStripMenuItem.Click += new System.EventHandler(this.runToolStripMenuItem_Click);
// //
// checkSyntaxToolStripMenuItem // checkSyntaxToolStripMenuItem
// //
this.checkSyntaxToolStripMenuItem.Name = "checkSyntaxToolStripMenuItem"; this.checkSyntaxToolStripMenuItem.Name = "checkSyntaxToolStripMenuItem";
this.checkSyntaxToolStripMenuItem.Size = new System.Drawing.Size(90, 20); this.checkSyntaxToolStripMenuItem.Size = new System.Drawing.Size(151, 20);
this.checkSyntaxToolStripMenuItem.Text = "Check Syntax"; this.checkSyntaxToolStripMenuItem.Text = "Check Syntax (Shift + F5)";
this.checkSyntaxToolStripMenuItem.Click += new System.EventHandler(this.checkSyntaxToolStripMenuItem_Click); this.checkSyntaxToolStripMenuItem.Click += new System.EventHandler(this.checkSyntaxToolStripMenuItem_Click);
// //
// describeToolStripMenuItem // describeToolStripMenuItem
// //
this.describeToolStripMenuItem.Name = "describeToolStripMenuItem"; this.describeToolStripMenuItem.Name = "describeToolStripMenuItem";
this.describeToolStripMenuItem.Size = new System.Drawing.Size(64, 20); this.describeToolStripMenuItem.Size = new System.Drawing.Size(125, 20);
this.describeToolStripMenuItem.Text = "Describe"; this.describeToolStripMenuItem.Text = "Describe (Shift + F1)";
this.describeToolStripMenuItem.Click += new System.EventHandler(this.describeToolStripMenuItem_Click);
// //
// helpToolStripMenuItem // helpToolStripMenuItem
// //
@@ -134,20 +134,7 @@ namespace Advanced_Software_Engineering {
} }
} }
private void handleExit(FormClosingEventArgs e) { private void RunCode() {
if (unsavedChanges) {
DialogResult dialogResult = MessageBox.Show("You have unsaved work. Would you like to discard your work?", "Unsaved work!", MessageBoxButtons.YesNo, MessageBoxIcon.None);
if (e != null) e.Cancel = dialogResult != DialogResult.Yes;
}
}
private void Console_FormClosed(object sender, FormClosedEventArgs e) {
if (DisplayForm != null && !DisplayForm.IsDisposed) DisplayForm.ReleaseCommandLock();
SettingsAndHelperFunctions.WindowClosed();
Dispose();
}
private void runToolStripMenuItem_Click(object sender, EventArgs e) {
if (DisplayForm == null || DisplayForm.IsDisposed) { if (DisplayForm == null || DisplayForm.IsDisposed) {
DisplayForm = new Draw_Preview(textBox1.Text); DisplayForm = new Draw_Preview(textBox1.Text);
} else { } else {
@@ -159,10 +146,48 @@ namespace Advanced_Software_Engineering {
DisplayForm.Focus(); DisplayForm.Focus();
} }
private void createNewInstance() { public void CheckCode() {
new Text_Editor().Show(); Draw_Preview tmpDrawPreview = new Draw_Preview();
tmpDrawPreview.Hide();
tmpDrawPreview.SubmitCommands(textBox1.Text);
tmpDrawPreview.Close();
SettingsAndHelperFunctions.WindowClosed();
tmpDrawPreview.Dispose();
} }
private void handleExit(FormClosingEventArgs e) {
if (unsavedChanges) {
DialogResult dialogResult = MessageBox.Show("You have unsaved work. Would you like to discard your work?", "Unsaved work!", MessageBoxButtons.YesNo, MessageBoxIcon.None);
if (e != null) e.Cancel = dialogResult != DialogResult.Yes;
}
}
private void DescribeCode() {
Draw_Preview tmpDrawPreview = new Draw_Preview();
tmpDrawPreview.Hide();
tmpDrawPreview.SubmitCommands(textBox1.Text);
string commandDesc = tmpDrawPreview.DescribeAllCommands();
Console.WriteLine(commandDesc);
tmpDrawPreview.Close();
SettingsAndHelperFunctions.WindowClosed();
tmpDrawPreview.Dispose();
new DetailsWindow(commandDesc, "Command explanation").Show();
}
private void Console_FormClosed(object sender, FormClosedEventArgs e) {
if (DisplayForm != null && !DisplayForm.IsDisposed) DisplayForm.ReleaseCommandLock();
SettingsAndHelperFunctions.WindowClosed();
Dispose();
}
private void runToolStripMenuItem_Click(object sender, EventArgs e) => RunCode();
private void createNewInstance() => new Text_Editor().Show();
private void handleKeypress(object sender, EventArgs e) => handleKeypress(); private void handleKeypress(object sender, EventArgs e) => handleKeypress();
private void textBox1_Click(object sender, EventArgs e) => updateRowCol(); private void textBox1_Click(object sender, EventArgs e) => updateRowCol();
@@ -192,15 +217,22 @@ namespace Advanced_Software_Engineering {
} else if (e.Control && e.KeyCode == Keys.O) { } else if (e.Control && e.KeyCode == Keys.O) {
openFile(); openFile();
e.Handled = true; e.Handled = true;
} else if(e.KeyCode == Keys.F5) {
RunCode();
e.Handled = true;
} else if(e.KeyCode == Keys.F5 && e.Shift) {
CheckCode();
e.Handled = true;
} else if(e.KeyCode == Keys.F1 && e.Shift) {
DescribeCode();
e.Handled = true;
} }
} }
private void checkSyntaxToolStripMenuItem_Click(object sender, EventArgs e) { private void checkSyntaxToolStripMenuItem_Click(object sender, EventArgs e) => CheckCode();
Draw_Preview tmpDrawPreview = new Draw_Preview();
tmpDrawPreview.Hide(); private void describeToolStripMenuItem_Click(object sender, EventArgs e) => DescribeCode();
tmpDrawPreview.SubmitCommands(textBox1.Text);
tmpDrawPreview.Close();
SettingsAndHelperFunctions.WindowClosed();
}
} }
} }