diff --git a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs index 09d672d..08ce86c 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs @@ -13,6 +13,7 @@ namespace Advanced_Software_Engineering { Graphics graphics; List commands = new List(); Drawer drawer; + bool commands_ok = true; /// /// This command updates the graphics element (usually) when the page repaints. @@ -60,7 +61,7 @@ namespace Advanced_Software_Engineering { /// /// Adds a verb to the command list to be executed. /// - /// Verb to be added + /// Verb to be added. public void AddCommand(Verb command) { commands.Add(command); } @@ -69,12 +70,13 @@ namespace Advanced_Software_Engineering { /// processes commands. Removes all commands if it fails parsing the raw commands. /// /// Processes commands seperated by \n or \r\n - public void ProcessCommands(string rawCommands) { + /// If the command is wrong, don't remove all of the commands + public void ProcessCommands(string rawCommands, bool pardonCommands=false) { //ignore case rawCommands = rawCommands.ToLower(); Console.WriteLine("Processing:\n" + rawCommands); - //remove windows \r if they exist + //remove windows' \r if they exist rawCommands = rawCommands.Replace("\r", ""); //isolate commands @@ -98,7 +100,12 @@ namespace Advanced_Software_Engineering { } } - if (failed) RemoveAllCommands(); + if (failed) { + if(!pardonCommands) RemoveAllCommands(); + commands_ok = false; + } else { + commands_ok = true; + } Console.WriteLine("\n\nHere is what the program is going to do:"); Console.WriteLine("Set origin to 0, 0"); @@ -112,9 +119,10 @@ namespace Advanced_Software_Engineering { /// Processes the commands and executes them at the same time. It's the same as /// /// Processes commands seperated by \n or \r\n - public void ProcessCommandsAndExecute(string rawCommands) { + /// If the command is wrong, don't remove all of the commands + public void ProcessCommandsAndExecute(string rawCommands, bool pardonCommands = false) { int start = commands.Count; - ProcessCommands(rawCommands); + ProcessCommands(rawCommands, pardonCommands); for (; start < commands.Count; start++) { commands[start].ExecuteVerb(); @@ -142,13 +150,12 @@ namespace Advanced_Software_Engineering { } /// - /// Get the numder of commands inside the Commader + /// Gets the status of the code that was processed /// - /// Integer number of commands - public int GetNumberOfCommands() { - return commands.Count; + /// False if there was no error. True if there was an error + public bool GetLastStatus() { + return commands_ok; } - } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs index c5ab264..1f9c9e4 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs @@ -153,6 +153,7 @@ namespace Advanced_Software_Engineering { } else throw new Exception("Command doesn't take parameters"); case "reset": + case "resetpen": if (parameters.Length == 0) { return new ResetPen(drawer); } else throw new Exception("Command doesn't take parameters"); diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.Designer.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.Designer.cs index 941f857..df175f3 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.Designer.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.Designer.cs @@ -55,6 +55,7 @@ this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(449, 20); this.textBox1.TabIndex = 1; + this.textBox1.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.textBox1_PreviewKeyDown); // // panel1 // diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs index 8ea6d1a..146a903 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs @@ -15,6 +15,7 @@ namespace Advanced_Software_Engineering Graphics graphics; Commander commander; + bool pardonCommands; /// /// The draw preview window. Spawns the basic DrawPreview. @@ -29,6 +30,7 @@ namespace Advanced_Software_Engineering graphics = panel1.CreateGraphics(); graphics.ResetClip(); commander = new Commander(graphics); + pardonCommands = true; } /// @@ -43,7 +45,7 @@ namespace Advanced_Software_Engineering graphics = panel1.CreateGraphics(); graphics.ResetClip(); commander = new Commander(graphics, commands); - + pardonCommands = false; //disable components textBox1.Enabled = false; button1.Enabled = false; @@ -67,7 +69,7 @@ namespace Advanced_Software_Engineering private void SubmitCommand(object sender, EventArgs e) { - commander.ProcessCommandsAndExecute(textBox1.Text); + commander.ProcessCommandsAndExecute(textBox1.Text, pardonCommands); textBox1.Text = ""; } @@ -76,7 +78,7 @@ namespace Advanced_Software_Engineering /// /// Commands seperated by new lines public void SubmitCommands(string comamnds) { - commander.ProcessCommandsAndExecute(comamnds); + commander.ProcessCommandsAndExecute(comamnds, pardonCommands); } /// @@ -92,6 +94,7 @@ namespace Advanced_Software_Engineering public void ReleaseCommandLock() { textBox1.Enabled = true; button1.Enabled = true; + pardonCommands = true; } /// @@ -103,12 +106,22 @@ namespace Advanced_Software_Engineering } /// - /// Returns weather there were any errors in the commander. Commander will have 0 commands if there is one bad command. + /// Returns weather there were any errors in the commander. /// /// A boolean describing the success of command phrasing public bool IsSuccess() { - return commander.GetNumberOfCommands() > 0; + return commander.GetLastStatus(); } + /// + /// Submits the form + /// + /// + /// + private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { + if (e.KeyCode == Keys.Enter && textBox1.Enabled) { + button1.PerformClick(); + } + } } } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.Designer.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.Designer.cs index 813b268..30cb327 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.Designer.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.Designer.cs @@ -180,7 +180,7 @@ namespace Advanced_Software_Engineering // this.label1.AutoSize = true; this.label1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.label1.Location = new System.Drawing.Point(0, 548); + this.label1.Location = new System.Drawing.Point(0, 535); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 13); this.label1.TabIndex = 2;