Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
- Tabs.Manager.cs no longer attempts to fetch the text of an already closed tab.
- Tabs.Manager.cs now properly assigns names to duplicate default tabs.
  • Loading branch information
iSmokeDrow committed Oct 9, 2021
1 parent 789a95f commit 667e79b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.11.1")]
[assembly: AssemblyFileVersion("0.4.11.1")]
[assembly: AssemblyVersion("0.4.12.2")]
[assembly: AssemblyFileVersion("0.4.12.2")]
89 changes: 50 additions & 39 deletions Tabs/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Grimoire.Tabs
{
public class Manager
{
#region Properties

readonly GUI.Main main = null;
readonly TabControl tabs = null;
readonly TabControl.TabPageCollection pages = null;
Expand All @@ -26,15 +28,6 @@ public static Manager Instance

public int RightClick_TabIdx = 0;

public Manager()
{
main = GUI.Main.Instance;
tabs = main.TabControl;
pages = tabs.TabPages;

Log.Information("Tab Manager initialized!");
}

public string Text
{
get
Expand All @@ -46,7 +39,8 @@ public string Text

return ret;
}
set {
set
{
main.Invoke(new MethodInvoker(delegate {
Log.Information($"Tab {pages[tabs.SelectedIndex]?.Text} text set to: {value}");

Expand Down Expand Up @@ -76,24 +70,6 @@ public Style Style
}
}

public string[] GetKeysByStyle(Style style)
{
List<string> keys = new List<string>();

if (pages == null || pages.Count == 0)
return null;

foreach (TabPage page in pages)
{
Style cmpStyle = getStyle(page.Name);

if (style == cmpStyle)
keys.Add(page.Name);
}

return keys.ToArray();
}

public DataCore.Core DataCore
{
get
Expand Down Expand Up @@ -156,7 +132,7 @@ public Daedalus.Core RDBCoreByKey(string key)

Daedalus.Core ret = null;

GUI.Main.Instance.Invoke(new MethodInvoker(delegate {
GUI.Main.Instance.Invoke(new MethodInvoker(delegate {
ret = ((Styles.rdbTab)pages[key].Controls[0]).Core;
}));

Expand Down Expand Up @@ -215,7 +191,7 @@ public Styles.Hasher HashTab
Styles.Hasher ret = null;

if (Style == Style.HASHER)
{
{
main.Invoke(new MethodInvoker(delegate {
ret = (Styles.Hasher)pages[tabs.SelectedIndex].Controls[0];
}));
Expand All @@ -242,11 +218,42 @@ public Styles.Item ItemTab
}
}

//TODO: Tabs should not generate two like tabs with the same name. (duplicate tab should be like item (2), item (3) with unique keys
#endregion

public Manager()
{
main = GUI.Main.Instance;
tabs = main.TabControl;
pages = tabs.TabPages;

Log.Information("Tab Manager initialized!");
}

#region Methods (public)

public string[] GetKeysByStyle(Style style)
{
List<string> keys = new List<string>();

if (pages == null || pages.Count == 0)
return null;

foreach (TabPage page in pages)
{
Style cmpStyle = getStyle(page.Name);

if (style == cmpStyle)
keys.Add(page.Name);
}

return keys.ToArray();
}

public void Create(Style style)
{
string key = string.Format("{0}_{1}", pages.Count, (int)style);
string text = string.Empty;

TabPage tab = new TabPage() { Name = key };

switch (style)
Expand Down Expand Up @@ -275,13 +282,15 @@ public void Create(Style style)
tab.Controls.Add(new Styles.MarketEditor() { Dock = DockStyle.Fill });
text = "Market Utility";
break;
}

//case Style.DROPS:
// tab.Controls.Add(new Styles.DropEditor() { Dock = DockStyle.Fill });
// text = "Drop Utility";
// break;
int styleCnt = 0;
for (int i = 0; i < pages.Count; i++)
if (pages[i].Text == text || pages[i].Text.Contains(text))
styleCnt++;

}
if (styleCnt > 0)
text += $" ({styleCnt})";

pages.Add(tab);
SetText(key, text);
Expand Down Expand Up @@ -317,11 +326,11 @@ public void Clear()
}

public void Destroy()
{
{
Log.Information($"{Text} has been closed!");

pages.RemoveAt(RightClick_TabIdx);
tabs.SelectedIndex = pages.Count - 1;

Log.Information($"{Text} has been closed!");
}

public void SetText(string key, string text)
Expand All @@ -332,6 +341,8 @@ public void SetText(string key, string text)
Log.Error($"Could not set text because tab {key} does not exist!");
}

#endregion

private Style getStyle(string key)
{
if (string.IsNullOrEmpty(key))
Expand Down

0 comments on commit 667e79b

Please sign in to comment.