diff --git a/MCTG/ConsoleApp/Menu/Entry.EntryStep.cs b/MCTG/ConsoleApp/Menu/Entry.EntryStep.cs
index 06dfc88..ee9bdfb 100644
--- a/MCTG/ConsoleApp/Menu/Entry.EntryStep.cs
+++ b/MCTG/ConsoleApp/Menu/Entry.EntryStep.cs
@@ -8,20 +8,45 @@ namespace ConsoleApp.Menu
{
internal abstract partial class Entry
{
+ ///
+ /// Define a step of the Entry menu, or in other word, an entry itself.
+ ///
public class EntryStep
{
+ #region Attributes & Properties
private Type _entryType;
+ ///
+ /// The entry description. This text is generally placed before the input field.
+ ///
public string Description { get; private set; }
+
+ ///
+ /// Contain the input gave by the menu.
+ ///
public string Input { get; internal set; }
+ #endregion
- internal EntryStep(string description, Type type)
+ #region Constructors
+ ///
+ /// Constructor of the entry step.
+ ///
+ /// The text generally placed before the input in the menu.
+ /// The type of the returned input.
+ public EntryStep(string description, Type type)
{
Description = description;
Input = "";
_entryType = type;
}
+ #endregion
+ #region Methods
+ ///
+ /// Get the inputed string converted on this entry type.
+ ///
+ /// The converted string on the entry type.
+ /// Throw when the entry type converter does not exist here.
public object GetEntry()
{
try
@@ -40,6 +65,7 @@ namespace ConsoleApp.Menu
throw new NotImplementedException("Error: parse of this type is not implemented.");
}
+ #endregion
}
}
}
diff --git a/MCTG/ConsoleApp/Menu/Entry.cs b/MCTG/ConsoleApp/Menu/Entry.cs
index de4cd0d..cb08dbb 100644
--- a/MCTG/ConsoleApp/Menu/Entry.cs
+++ b/MCTG/ConsoleApp/Menu/Entry.cs
@@ -6,17 +6,31 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// Define an Entry menu.
+ ///
It allows you to navigate through the entries and completes them with a console input.
+ ///
internal abstract partial class Entry : Menu
{
+ #region Attributes & Properties
private List _steps = new List();
-
+ #endregion
+
+ #region Constructors
+ ///
+ /// Constructor of the entry menu, based on the Menu constructor.
+ ///
+ /// The title of this menu.
+ /// All the entries of this menu.
protected Entry(string title, params EntryStep[] entrySteps) : base(title)
{
_steps = entrySteps.ToList();
_allSelectors = ConvertEntryStepsInSelector();
_selectList = _allSelectors;
}
+ #endregion
+ #region Methods
private List> ConvertEntryStepsInSelector()
{
List> newSelectors = new List>();
@@ -26,7 +40,9 @@ namespace ConsoleApp.Menu
}
return newSelectors;
}
+ #endregion
+ #region IMenu implementation
public override void WriteMenuMode(ConsoleKeyInfo cki)
{
if (!WriteMode && cki.Key == ConsoleKey.R)
@@ -98,5 +114,6 @@ namespace ConsoleApp.Menu
"\n\nHint:\n^:previous, v:next, <:ret, -enter-:return, r:write, -escape-:exit search mode");
Console.WriteLine(_screenDisplay);
}
+ #endregion
}
}
diff --git a/MCTG/ConsoleApp/Menu/IMenu.cs b/MCTG/ConsoleApp/Menu/IMenu.cs
index a9e15fa..120a387 100644
--- a/MCTG/ConsoleApp/Menu/IMenu.cs
+++ b/MCTG/ConsoleApp/Menu/IMenu.cs
@@ -7,19 +7,66 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// Define a console menu with element selection.
+ ///
internal interface IMenu
{
+ ///
+ /// True when enable, False otherwise.
+ ///
bool WriteMode { get; set; }
+
+ ///
+ /// A string input. Used for search string or entry input.
+ ///
StringBuilder InputStr { get; set; }
+ ///
+ /// Refresh the console with the updated display. This function dose not call Update().
+ ///
void Display();
+
+ ///
+ /// Update the parameters of the menu. Generally called before Display() to refresh the informations.
+ ///
void Update();
+
+ ///
+ /// Select the next element in the selection list.
+ ///
void SelectNext();
+
+ ///
+ /// Select the previous element in the selection list.
+ ///
void SelectPrevious();
+
+ ///
+ /// Enable the write mode.
+ ///
void EnableWriteMode();
+
+ ///
+ /// Disable the write mode.
+ ///
void DisableWriteMode();
+
+ ///
+ /// Toogle the write mode.
+ ///
void ToggleWriteMode();
+
+ ///
+ /// Define the comportement of the write mode. For instence: in the standard menu, it is used for the research of a line.
+ ///
+ /// The key to deal with.
void WriteMenuMode(ConsoleKeyInfo cki);
+
+ ///
+ /// Execute some actions and then return.
+ ///
+ /// 'null' when there is no menu after this selection. Otherwise the next menu.
IMenu? Return();
}
}
diff --git a/MCTG/ConsoleApp/Menu/MainMenu.cs b/MCTG/ConsoleApp/Menu/MainMenu.cs
index b167526..f26bdf0 100644
--- a/MCTG/ConsoleApp/Menu/MainMenu.cs
+++ b/MCTG/ConsoleApp/Menu/MainMenu.cs
@@ -7,6 +7,9 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// Main menu of the console. Contain the first interaction menus.
+ ///
internal class MainMenu : Menu
{
public MainMenu(DataManager dataMgr)
@@ -16,10 +19,5 @@ namespace ConsoleApp.Menu
new Selector(
new ConnectionMenu(), "Connection"))
{ }
-
- public override IMenu? Return()
- {
- return CurrentSelected;
- }
}
}
diff --git a/MCTG/ConsoleApp/Menu/Menu.cs b/MCTG/ConsoleApp/Menu/Menu.cs
index bc8e7b1..5f59e16 100644
--- a/MCTG/ConsoleApp/Menu/Menu.cs
+++ b/MCTG/ConsoleApp/Menu/Menu.cs
@@ -9,18 +9,30 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// Define a selection menu.
+ ///
It allows you to navigate through the selections and search with a console input.
+ ///
+ /// The type (or the implementation) of the selection.
internal abstract class Menu : IMenu
where T : notnull
{
+ #region Attributes & Properties
protected StringBuilder _screenDisplay;
protected List> _allSelectors = new List>();
protected List> _selectList = new List>();
+ private int _currentLine;
+
+ ///
+ /// Title of the menu.
+ ///
public string Title { get; private set; }
- public StringBuilder InputStr { get; set; }
- private int _currentLine;
+ ///
+ /// The current line of the selection list.
+ ///
public int CurrentLine
{
get
@@ -36,9 +48,19 @@ namespace ConsoleApp.Menu
}
}
+ ///
+ /// The currently selected object.
+ ///
public T? CurrentSelected { get; protected set; }
- public bool WriteMode { get; set; }
-
+ #endregion
+
+ #region Constructors
+ ///
+ /// Base constructor of the Menu class.
+ ///
This one is incomplete and need to be completed in the inherited class constructors.
+ ///
Basically, the '_allSelection' and '_selectList' attribute initialization are missing.
+ ///
+ /// The title of the Menu.
protected Menu(string title)
{
Title = title;
@@ -48,6 +70,11 @@ namespace ConsoleApp.Menu
InputStr = new StringBuilder();
}
+ ///
+ /// Constructor of the Menu class. This constructor allows you to directly pass the selections.
+ ///
+ /// The title of the menu.
+ /// The selections of the menu.
protected Menu(string title, params Selector[] selections ) : this(title)
{
if (selections == null || selections.Length == 0)
@@ -60,8 +87,19 @@ namespace ConsoleApp.Menu
_selectList = _allSelectors;
CurrentSelected = _allSelectors[0].Item;
}
+ #endregion
- public abstract IMenu? Return();
+ #region IMenu implementation
+ public StringBuilder InputStr { get; set; }
+ public bool WriteMode { get; set; }
+
+ public virtual IMenu? Return()
+ {
+ if (CurrentSelected is null)
+ throw new Exception("Error: CurrentSelected is null.");
+
+ return (IMenu)CurrentSelected;
+ }
protected virtual List> SearchInSelection()
{
@@ -158,5 +196,6 @@ namespace ConsoleApp.Menu
else
EnableWriteMode();
}
+ #endregion
}
}
diff --git a/MCTG/ConsoleApp/Menu/PlainText.cs b/MCTG/ConsoleApp/Menu/PlainText.cs
index 3495ac7..f18379e 100644
--- a/MCTG/ConsoleApp/Menu/PlainText.cs
+++ b/MCTG/ConsoleApp/Menu/PlainText.cs
@@ -6,14 +6,25 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// Define a Plain text menu.
+ ///
This menu is a bit special. It display some text, and then, the only action that can be performed is the back return. Usefull for testing.
+ ///
internal class PlainText : IMenu
{
+ #region Constructors
+ ///
+ /// Constructor of the Plain text menu.
+ ///
+ /// The text buffer to display.
public PlainText(string text)
{
InputStr = new StringBuilder(text);
WriteMode = false;
}
+ #endregion
+ #region IMenu implementation
public IMenu? Return() { return null; }
public void Display()
{
@@ -30,5 +41,6 @@ namespace ConsoleApp.Menu
public void ToggleWriteMode() { return; }
public void Update() { return; }
public void WriteMenuMode(ConsoleKeyInfo cki) { return; }
+ #endregion
}
}
diff --git a/MCTG/ConsoleApp/Menu/SearcherRecipe.cs b/MCTG/ConsoleApp/Menu/SearcherRecipe.cs
index 68abaef..a04a041 100644
--- a/MCTG/ConsoleApp/Menu/SearcherRecipe.cs
+++ b/MCTG/ConsoleApp/Menu/SearcherRecipe.cs
@@ -23,7 +23,7 @@ namespace ConsoleApp.Menu
_selectList = _allSelectors;
}
- #region Methodes
+ #region Methods
private List> ConvertRecipeCollectionInSelectors()
{
List> newSelectors = new List>();
diff --git a/MCTG/ConsoleApp/Menu/Selector.cs b/MCTG/ConsoleApp/Menu/Selector.cs
index 7278db8..f8f71e0 100644
--- a/MCTG/ConsoleApp/Menu/Selector.cs
+++ b/MCTG/ConsoleApp/Menu/Selector.cs
@@ -9,11 +9,19 @@ using System.Threading.Tasks;
namespace ConsoleApp.Menu
{
+ ///
+ /// The selector of a menu.
+ ///
+ /// The type of the selector.
internal class Selector : IEquatable>
where T : notnull
{
+ #region Attributes & Properties
private string _line = "";
+ ///
+ /// The string that are displayed on the menu.
+ ///
public string Line {
get => _line;
private set
@@ -24,14 +32,27 @@ namespace ConsoleApp.Menu
_line = value;
}
}
+
+ ///
+ /// The item contained in the selector.
+ ///
public T Item { get; private set; }
+ #endregion
+ #region Constructors
+ ///
+ /// The constructor of the selector.
+ ///
+ /// The item to place inside.
+ /// The string to display in the menu.
public Selector(T item, string line = "")
{
Line = line;
Item = item;
}
+ #endregion
+ #region IEquatable implementation
public virtual bool Equals(Selector? other)
{
if (other == null) return false;
@@ -50,5 +71,6 @@ namespace ConsoleApp.Menu
{
return Line.GetHashCode();
}
+ #endregion
}
}
diff --git a/MCTG/ConsoleApp/MenuManager.cs b/MCTG/ConsoleApp/MenuManager.cs
index 4c47e0c..bbbf6d1 100644
--- a/MCTG/ConsoleApp/MenuManager.cs
+++ b/MCTG/ConsoleApp/MenuManager.cs
@@ -8,11 +8,29 @@ using System.Threading.Tasks;
namespace ConsoleApp
{
+ ///
+ /// Manage the menus of the console application.
+ ///
internal class MenuManager
{
+ #region Attributes & Properties
+ ///
+ /// The manager that contains usefull data taken from the model.
+ ///
public DataManager DataManager { get; private set; }
+
+ ///
+ /// Each menu called are push in this stack. Then, to return back, we pop this stack to retrive the previous menu.
+ ///
public Stack MenuCallStack { get; set; }
+ #endregion
+ #region Constructors
+ ///
+ /// Constructor of the MenuManager class. This constructor allows you to give the first menu of the call stack, wich is usefull for testing.
+ ///
+ /// The data manager needed by the menus inside.
+ /// The starting menu, the first that will be push on the call stack.
public MenuManager(DataManager dataManager, Menu.IMenu firstMenu)
{
DataManager = dataManager;
@@ -21,9 +39,18 @@ namespace ConsoleApp
MenuCallStack.Push(firstMenu);
}
+ ///
+ /// Constructor of the MenuManager class.
+ ///
+ /// The data manager needed by the menus inside.
public MenuManager(DataManager dataManager) : this(dataManager, new MainMenu(dataManager))
{ }
+ #endregion
+ #region Methods
+ ///
+ /// Main loop. Loop while the menu call stack is not empty.
+ ///
public void Loop()
{
ConsoleKeyInfo cki;
@@ -57,5 +84,6 @@ namespace ConsoleApp
}
} while (MenuCallStack.Count > 0);
}
+ #endregion
}
}
diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs
index 3b9b798..d6aedee 100644
--- a/MCTG/ConsoleApp/Program.cs
+++ b/MCTG/ConsoleApp/Program.cs
@@ -25,6 +25,3 @@ DataManager dataMgr = new DataManager(allRecipe);
MenuManager menuMgr = new MenuManager(dataMgr);
menuMgr.Loop();
-
-// press any key to quit
-Console.ReadKey();