From b290848034bc472f897698dbfb1b3e258e7505ce Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Sun, 29 Nov 2020 08:21:27 +0000 Subject: [PATCH] Refactored Menu controls from Settings And HelperFunctions a --- .../Advanced Software Engineering.csproj | 1 + .../MenuManager.cs | 25 +++++++++++++++++++ .../SettingsAndHelperFunctions.cs | 16 ------------ .../Verbs/VerbFactory.cs | 11 ++++++-- .../Windows/AboutWindow.cs | 6 ++--- .../Windows/DrawPreview.cs | 6 ++--- .../Windows/TextEditor.cs | 10 ++++---- 7 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 Advanced Software Engineering/Advanced Software Engineering/MenuManager.cs diff --git a/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj b/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj index e21f97c..42021c6 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj +++ b/Advanced Software Engineering/Advanced Software Engineering/Advanced Software Engineering.csproj @@ -69,6 +69,7 @@ + True True diff --git a/Advanced Software Engineering/Advanced Software Engineering/MenuManager.cs b/Advanced Software Engineering/Advanced Software Engineering/MenuManager.cs new file mode 100644 index 0000000..8d12864 --- /dev/null +++ b/Advanced Software Engineering/Advanced Software Engineering/MenuManager.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Advanced_Software_Engineering { + public static partial class MenuManager { + /// + /// The variable simply keep track of the windows that are currently shown (excluding ). + /// + public static int NumberOfWindows = 0; + + /// + /// This helper function is executed when a window is closed. It shows the when the count is 0 + /// + public static void WindowClosed() { + NumberOfWindows--; + if (NumberOfWindows == 0) { + Console.WriteLine("Showing MainMenu"); + Program.MainMenu.Show(); + } + } + } +} diff --git a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs index 60d7c79..bd5e9b2 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs @@ -26,22 +26,6 @@ namespace Advanced_Software_Engineering { /// public class SettingsAndHelperFunctions { - /// - /// The variable simply keep track of the windows that are currently shown (excluding ). - /// - public static int NumberOfWindows = 0; - - /// - /// This helper function is executed when a window is closed. It shows the when the count is 0 - /// - public static void WindowClosed() { - NumberOfWindows--; - if (NumberOfWindows == 0) { - System.Console.WriteLine("Showing MainMenu"); - Program.MainMenu.Show(); - } - } - /// /// This function removes spaces from the start and the end of the text. This should be unit tested. /// diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs index f775541..f6979b1 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs @@ -28,8 +28,15 @@ namespace Advanced_Software_Engineering { string[] commandParameters = result.getParameters(); if (command == null) throw new Exception("There is no command to process"); - //process declarations first + //check for names in directory + if (drawer.CheckVariableExists(command)) { + if (commandParameters.Length == 1) { + //return new UpdateVariable(drawer, ); + } else throw new Exception(command + "needs something to be assigned to it"); + } + + //process declarations if (!(commandParameters == null)) switch (command) { case "int": @@ -56,7 +63,7 @@ namespace Advanced_Software_Engineering { } int parameterLength = parameters.Count; - //process drawing commands and extras second + //process drawing commands and extras switch (command) { //Drawing commands case "move": diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/AboutWindow.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/AboutWindow.cs index d9f3a63..5c5b00f 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/AboutWindow.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/AboutWindow.cs @@ -2,14 +2,14 @@ namespace Advanced_Software_Engineering { - public partial class About_Window : Form { + partial class About_Window : Form { /// ///Creates an About Window which shows details about the program. /// public About_Window() { InitializeComponent(); - SettingsAndHelperFunctions.NumberOfWindows++; + MenuManager.NumberOfWindows++; } /// @@ -18,7 +18,7 @@ namespace Advanced_Software_Engineering { /// /// private void About_Window_FormClosed(object sender, FormClosedEventArgs e) { - SettingsAndHelperFunctions.WindowClosed(); + MenuManager.WindowClosed(); } } } \ No newline at end of file diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs index b0deb50..3e3c308 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/DrawPreview.cs @@ -17,7 +17,7 @@ namespace Advanced_Software_Engineering { /// public Draw_Preview() { InitializeComponent(); - SettingsAndHelperFunctions.NumberOfWindows++; + MenuManager.NumberOfWindows++; graphics = panel1.CreateGraphics(); graphics.ResetClip(); commander = new Commander(graphics); @@ -32,7 +32,7 @@ namespace Advanced_Software_Engineering { /// public Draw_Preview(string commands) { InitializeComponent(); - SettingsAndHelperFunctions.NumberOfWindows++; + MenuManager.NumberOfWindows++; graphics = panel1.CreateGraphics(); graphics.ResetClip(); commander = new Commander(graphics, commands); @@ -43,7 +43,7 @@ namespace Advanced_Software_Engineering { } private void DrawPreview_FormClosed(object sender, FormClosedEventArgs e) { - SettingsAndHelperFunctions.WindowClosed(); + MenuManager.WindowClosed(); Dispose(); } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.cs b/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.cs index e5f4dda..08c0938 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Windows/TextEditor.cs @@ -17,7 +17,7 @@ namespace Advanced_Software_Engineering { /// The text editor is the main window that the user will be using for writing code. /// public TextEditor() { - SettingsAndHelperFunctions.NumberOfWindows++; + MenuManager.NumberOfWindows++; InitializeComponent(); UpdateTitle(); } @@ -27,7 +27,7 @@ namespace Advanced_Software_Engineering { /// /// File dialog which points to the file to open public TextEditor(OpenFileDialog openFile) { - SettingsAndHelperFunctions.NumberOfWindows++; + MenuManager.NumberOfWindows++; InitializeComponent(); StreamReader fileStream = new StreamReader(openFile.OpenFile()); @@ -159,7 +159,7 @@ namespace Advanced_Software_Engineering { tmpDrawPreview.SubmitCommands(TextBox.Text); if (tmpDrawPreview.IsSuccess()) new ErrorWindow("No errors", "No errors found in the program", "There have been no errors found", ErrorWindow.INFO_MESSAGE).Show(); tmpDrawPreview.Close(); - SettingsAndHelperFunctions.WindowClosed(); + MenuManager.WindowClosed(); tmpDrawPreview.Dispose(); } @@ -179,7 +179,7 @@ namespace Advanced_Software_Engineering { Console.WriteLine(commandDesc); tmpDrawPreview.Close(); - SettingsAndHelperFunctions.WindowClosed(); + MenuManager.WindowClosed(); tmpDrawPreview.Dispose(); new DetailsWindow(commandDesc, "Command explanation").Show(); @@ -187,7 +187,7 @@ namespace Advanced_Software_Engineering { private void Console_FormClosed(object sender, FormClosedEventArgs e) { if (DisplayForm != null && !DisplayForm.IsDisposed) DisplayForm.ReleaseCommandLock(); - SettingsAndHelperFunctions.WindowClosed(); + MenuManager.WindowClosed(); Dispose(); }