Refactored Menu controls from Settings And HelperFunctions

a
This commit is contained in:
Lukasz Baldyga committed 2020-11-29 08:21:27 +00:00
1 parent 38a40994cf
commit b290848034
7 files changed
+46 -29

No files matched your search

@@ -69,6 +69,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MenuManager.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -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 {
/// <summary>
/// The variable simply keep track of the windows that are currently shown (excluding <see cref="Menu"/>).
/// </summary>
public static int NumberOfWindows = 0;
/// <summary>
/// This helper function is executed when a window is closed. It shows the <see cref="Menu"/> when the count is 0
/// </summary>
public static void WindowClosed() {
NumberOfWindows--;
if (NumberOfWindows == 0) {
Console.WriteLine("Showing MainMenu");
Program.MainMenu.Show();
}
}
}
}
@@ -26,22 +26,6 @@ namespace Advanced_Software_Engineering {
/// </summary>
public class SettingsAndHelperFunctions {
/// <summary>
/// The variable simply keep track of the windows that are currently shown (excluding <see cref="MainMenu"/>).
/// </summary>
public static int NumberOfWindows = 0;
/// <summary>
/// This helper function is executed when a window is closed. It shows the <see cref="MainMenu"/> when the count is 0
/// </summary>
public static void WindowClosed() {
NumberOfWindows--;
if (NumberOfWindows == 0) {
System.Console.WriteLine("Showing MainMenu");
Program.MainMenu.Show();
}
}
/// <summary>
/// This function removes spaces from the start and the end of the text. This should be unit tested.
/// </summary>
@@ -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":
@@ -2,14 +2,14 @@
namespace Advanced_Software_Engineering {
public partial class About_Window : Form {
partial class About_Window : Form {
///<summary>
///Creates an About Window which shows details about the program.
///</summary>
public About_Window() {
InitializeComponent();
SettingsAndHelperFunctions.NumberOfWindows++;
MenuManager.NumberOfWindows++;
}
/// <summary>
@@ -18,7 +18,7 @@ namespace Advanced_Software_Engineering {
/// <param name="sender"></param>
/// <param name="e"></param>
private void About_Window_FormClosed(object sender, FormClosedEventArgs e) {
SettingsAndHelperFunctions.WindowClosed();
MenuManager.WindowClosed();
}
}
}
@@ -17,7 +17,7 @@ namespace Advanced_Software_Engineering {
/// </remarks>
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 {
/// </remarks>
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();
}
@@ -17,7 +17,7 @@ namespace Advanced_Software_Engineering {
/// The text editor is the main window that the user will be using for writing code.
/// </summary>
public TextEditor() {
SettingsAndHelperFunctions.NumberOfWindows++;
MenuManager.NumberOfWindows++;
InitializeComponent();
UpdateTitle();
}
@@ -27,7 +27,7 @@ namespace Advanced_Software_Engineering {
/// </summary>
/// <param name="openFile">File dialog which points to the file to open</param>
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();
}