Skip to content

Commit

Permalink
Lazy-load choose-readme panel and subcontrols
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Jul 8, 2019
1 parent 1512d1c commit 646a7f8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 197 deletions.
1 change: 1 addition & 0 deletions AngelLoader/AngelLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
</Compile>
<Compile Include="CustomControls\Static_LazyLoaded\AddTagLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\AltTitlesLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\ChooseReadmeLLPanel.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\ImportFromLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\PlayOriginalGameLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\TopRightLLMenu.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Drawing;
using System.Windows.Forms;
using AngelLoader.Common.DataClasses;
using AngelLoader.Common.Utility;
using AngelLoader.Forms;

namespace AngelLoader.CustomControls.Static_LazyLoaded
{
internal static class ChooseReadmeLLPanel
{
private static bool _constructed;

internal static Panel Panel;
internal static Button OKButton;
internal static ListBoxCustom ListBox;
internal static FlowLayoutPanel OKButtonFLP;

internal static void Construct(MainForm form, Control container)
{
if (_constructed) return;

OKButton = new Button
{
Anchor = AnchorStyles.Top | AnchorStyles.Right,
AutoSize = true,
Margin = new Padding(0),
Padding = new Padding(6, 0, 6, 0),
Height = 23,
TabIndex = 48,
UseVisualStyleBackColor = true
};
OKButton.Click += form.ChooseReadmeButton_Click;

OKButtonFLP = new FlowLayoutPanel
{
FlowDirection = FlowDirection.RightToLeft,
Location = new Point(1, 134),
Size = new Size(320, 24),
TabIndex = 3
};
OKButtonFLP.Controls.Add(OKButton);

ListBox = new ListBoxCustom
{
FormattingEnabled = true,
Size = new Size(320, 134),
TabIndex = 47
};

Panel = new Panel
{
Anchor = AnchorStyles.None,
TabIndex = 46,
Visible = false,
Size = new Size(324, 161)
};
Panel.Controls.Add(ListBox);
Panel.Controls.Add(OKButtonFLP);

Panel.CenterHV(container);
container.Controls.Add(Panel);

_constructed = true;

Localize();
}

internal static void Localize()
{
if (_constructed) OKButton.SetTextAutoSize(LText.Global.OK, 75);
}

internal static void SuspendPanelLayout()
{
if (_constructed) Panel.SuspendLayout();
}

internal static void ResumePanelLayout()
{
if (_constructed) Panel.ResumeLayout();
}

internal static void ShowPanel(bool value)
{
if (_constructed) Panel.Visible = value;
}
}
}
61 changes: 0 additions & 61 deletions AngelLoader/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 22 additions & 23 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ public void InitThreadable()

// Cheap 'n cheesy storage of initial size for minimum-width setting later
EditFMFinishedOnButton.Tag = new Size(138, 23);
ChooseReadmeButton.Tag = new Size(75, 23);
PatchOpenFMFolderButton.Tag = new Size(162, 23);

// EnsureValidity() guarantees selected tab will not be invisible
Expand All @@ -554,7 +553,6 @@ public void InitThreadable()

// Set these here because they depend on the splitter positions
SetUITextToLocalized(suspendResume: false);
ChooseReadmePanel.CenterHV(MainSplitContainer.Panel2);

if (Math.Abs(Config.FMsListFontSizeInPoints - FMsDGV.DefaultCellStyle.Font.SizeInPoints) >= 0.001)
{
Expand Down Expand Up @@ -792,7 +790,7 @@ public void SetUITextToLocalized(bool suspendResume = true)
AddRemoveTagFLP.SuspendLayout();
PatchMainPanel.SuspendLayout();
MainSplitContainer.Panel2.SuspendLayout();
ChooseReadmePanel.SuspendLayout();
ChooseReadmeLLPanel.SuspendPanelLayout();
#endif
}
try
Expand Down Expand Up @@ -975,7 +973,7 @@ public void SetUITextToLocalized(bool suspendResume = true)

ViewHTMLReadmeButton.SetTextAutoSize(LText.ReadmeArea.ViewHTMLReadme);

ChooseReadmeButton.SetTextAutoSize(LText.Global.OK, ((Size)ChooseReadmeButton.Tag).Width);
ChooseReadmeLLPanel.Localize();

#endregion

Expand Down Expand Up @@ -1037,7 +1035,7 @@ public void SetUITextToLocalized(bool suspendResume = true)
AddRemoveTagFLP.ResumeLayout();
PatchMainPanel.ResumeLayout();
MainSplitContainer.Panel2.ResumeLayout();
ChooseReadmePanel.ResumeLayout();
ChooseReadmeLLPanel.ResumePanelLayout();
}

// We can't do this while the layout is suspended, because then it won't have the right dimensions
Expand Down Expand Up @@ -2507,7 +2505,7 @@ private void ClearShownData()
// Hide instead of clear to avoid zoom factor pain
ShowReadme(false);

ChooseReadmePanel.Hide();
ChooseReadmeLLPanel.ShowPanel(false);
ViewHTMLReadmeButton.Hide();
WebSearchButton.Enabled = false;

Expand Down Expand Up @@ -2777,9 +2775,6 @@ private async Task DisplaySelectedFM(bool refreshReadme = false)

using (new DisableEvents(this)) ChooseReadmeComboBox.ClearFullItems();

// Debug
fm.SelectedReadme = "";

if (!fm.SelectedReadme.IsEmpty())
{
if (readmeFiles.Count > 1)
Expand All @@ -2797,7 +2792,7 @@ private async Task DisplaySelectedFM(bool refreshReadme = false)
{
ReadmeRichTextBox.SetText(LText.ReadmeArea.NoReadmeFound);

ChooseReadmePanel.Hide();
ChooseReadmeLLPanel.ShowPanel(false);
ChooseReadmeComboBox.Hide();
ViewHTMLReadmeButton.Hide();
ShowReadme(true);
Expand All @@ -2808,9 +2803,6 @@ private async Task DisplaySelectedFM(bool refreshReadme = false)
{
var safeReadme = Core.DetectSafeReadme(readmeFiles, fm.Title);

// Debug
safeReadme = "";

if (!safeReadme.IsEmpty())
{
fm.SelectedReadme = safeReadme;
Expand All @@ -2821,12 +2813,14 @@ private async Task DisplaySelectedFM(bool refreshReadme = false)
ShowReadme(false);
ViewHTMLReadmeButton.Hide();

ChooseReadmeListBox.ClearFullItems();
foreach (var f in readmeFiles) ChooseReadmeListBox.AddFullItem(f, f.GetFileNameFastBothDSC());
ChooseReadmeLLPanel.Construct(this, MainSplitContainer.Panel2);

ChooseReadmeLLPanel.ListBox.ClearFullItems();
foreach (var f in readmeFiles) ChooseReadmeLLPanel.ListBox.AddFullItem(f, f.GetFileNameFastBothDSC());

ShowReadmeControls(false);

ChooseReadmePanel.Show();
ChooseReadmeLLPanel.ShowPanel(true);

return;
}
Expand All @@ -2839,7 +2833,7 @@ private async Task DisplaySelectedFM(bool refreshReadme = false)
}
}

ChooseReadmePanel.Hide();
ChooseReadmeLLPanel.ShowPanel(false);

LoadReadme(fm);

Expand Down Expand Up @@ -3305,13 +3299,18 @@ internal void AddTagMenu_Closed(object sender, ToolStripDropDownClosedEventArgs

#region Choose readme

private void ChooseReadmeButton_Click(object sender, EventArgs e)
internal void ChooseReadmeButton_Click(object sender, EventArgs e)
{
if (ChooseReadmeListBox.Items.Count == 0 || ChooseReadmeListBox.SelectedIndex == -1) return;
// This is only hooked up after construction, so no Construct() call needed

if (ChooseReadmeLLPanel.ListBox.Items.Count == 0 || ChooseReadmeLLPanel.ListBox.SelectedIndex == -1)
{
return;
}

var fm = FMsDGV.GetSelectedFM();
fm.SelectedReadme = ChooseReadmeListBox.SelectedBackingItem();
ChooseReadmePanel.Hide();
fm.SelectedReadme = ChooseReadmeLLPanel.ListBox.SelectedBackingItem();
ChooseReadmeLLPanel.ShowPanel(false);

if (fm.SelectedReadme.ExtIsHtml())
{
Expand All @@ -3322,9 +3321,9 @@ private void ChooseReadmeButton_Click(object sender, EventArgs e)
ShowReadme(true);
}

if (ChooseReadmeListBox.Items.Count > 1)
if (ChooseReadmeLLPanel.ListBox.Items.Count > 1)
{
ReadmeCB_FillAndSelect(ChooseReadmeListBox.BackingItems, fm.SelectedReadme);
ReadmeCB_FillAndSelect(ChooseReadmeLLPanel.ListBox.BackingItems, fm.SelectedReadme);
ShowReadmeControls(CursorOverReadmeArea());
}
else
Expand Down
Loading

0 comments on commit 646a7f8

Please sign in to comment.