Skip to content

Commit

Permalink
Lazy-load add tag menu
Browse files Browse the repository at this point in the history
And that's the last of the menus. Onto higher hanging fruit.
  • Loading branch information
FenPhoenix committed Jul 8, 2019
1 parent bef027c commit 3ac9685
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 41 deletions.
1 change: 1 addition & 0 deletions AngelLoader/AngelLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
<Compile Include="CustomControls\SettingsForm\PathsPage.Designer.cs">
<DependentUpon>PathsPage.cs</DependentUpon>
</Compile>
<Compile Include="CustomControls\Static_LazyLoaded\AddTagLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\AltTitlesLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\ImportFromLLMenu.cs" />
<Compile Include="CustomControls\Static_LazyLoaded\PlayOriginalGameLLMenu.cs" />
Expand Down
22 changes: 22 additions & 0 deletions AngelLoader/CustomControls/Static_LazyLoaded/AddTagLLMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel;
using System.Windows.Forms;
using AngelLoader.Forms;

namespace AngelLoader.CustomControls.Static_LazyLoaded
{
internal static class AddTagLLMenu
{
private static bool _constructed;
internal static ContextMenuStrip Menu;

internal static void Construct(MainForm form, IContainer components)
{
if (_constructed) return;

Menu = new ContextMenuStrip(components);
Menu.Closed += form.AddTagMenu_Closed;

_constructed = true;
}
}
}
49 changes: 21 additions & 28 deletions AngelLoader/Forms/MainForm.Designer.cs

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

23 changes: 16 additions & 7 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,17 @@ public void InitThreadable()

#region Autosize menus

// NOTE: This region is now empty cause all the menus are now programmatically defined and lazy-loaded,
// but for future reference, this is how you gotta do it if you want to keep them designer-generated:

// --- old notes ---

// This is another hack to fix behavior caused by the UI designer. When you select a menu, it appears
// and adds an extra "Type Here" item to the bottom. This item counts as part of the height, and so
// the height ends up including an item that only actually appears in the designer, causing the menu
// to be shown in the wrong location when you call Show() with the height as a parameter. Setting a
// menu's size to empty causes it to autosize back to its actual proper size. I swear, this stuff.

AddTagMenu.Size = Size.Empty;

#endregion

// Cheap 'n cheesy storage of initial size for minimum-width setting later
Expand Down Expand Up @@ -3203,10 +3206,12 @@ private void AddTagOperation(FanMission fm, string catAndTag)

private void AddTagButton_Click(object sender, EventArgs e) => AddTagOperation(FMsDGV.GetSelectedFM(), AddTagTextBox.Text);

private void TagPresetsButton_Click(object sender, EventArgs e)
private void AddTagFromListButton_Click(object sender, EventArgs e)
{
GlobalTags.SortAndMoveMiscToEnd();
AddTagMenu.Items.Clear();

AddTagLLMenu.Construct(this, components);
AddTagLLMenu.Menu.Items.Clear();

var addTagMenuItems = new List<ToolStripItem>();
foreach (var catAndTag in GlobalTags)
Expand Down Expand Up @@ -3250,9 +3255,9 @@ private void TagPresetsButton_Click(object sender, EventArgs e)
}
}

AddTagMenu.Items.AddRange(addTagMenuItems.ToArray());
AddTagLLMenu.Menu.Items.AddRange(addTagMenuItems.ToArray());

ShowMenu(AddTagMenu, AddTagFromListButton, MenuPos.LeftDown);
ShowMenu(AddTagLLMenu.Menu, AddTagFromListButton, MenuPos.LeftDown);
}

private void AddTagMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -3282,7 +3287,11 @@ private void AddTagMenuCustomItem_Click(object sender, EventArgs e)

// Just to keep things in a known state (clearing items also removes their event hookups, which is
// convenient)
private void AddTagMenu_Closed(object sender, ToolStripDropDownClosedEventArgs e) => AddTagMenu.Items.Clear();
internal void AddTagMenu_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
// This handler will only be hooked up after construction, so we don't need to call Construct()
AddTagLLMenu.Menu.Items.Clear();
}

#endregion

Expand Down
7 changes: 1 addition & 6 deletions AngelLoader/Forms/MainForm_InitManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private void InitComponentManual()
ChooseReadmeListBox = new ListBoxCustom();
ReadmeRichTextBox = new RichTextBoxCustom();
MainToolTip = new ToolTip(components);
AddTagMenu = new ContextMenuStrip(components);

#endregion

Expand Down Expand Up @@ -1494,7 +1493,7 @@ private void InitComponentManual()
AddTagFromListButton.Height = 23;
AddTagFromListButton.TabIndex = 0;
AddTagFromListButton.UseVisualStyleBackColor = true;
AddTagFromListButton.Click += TagPresetsButton_Click;
AddTagFromListButton.Click += AddTagFromListButton_Click;
//
// TagsTreeView
//
Expand Down Expand Up @@ -1722,10 +1721,6 @@ private void InitComponentManual()
ReadmeRichTextBox.TabIndex = 0;
ReadmeRichTextBox.LinkClicked += ReadmeRichTextBox_LinkClicked;
//
// AddTagMenu
//
AddTagMenu.Closed += AddTagMenu_Closed;
//
// MainForm
//
AutoScaleDimensions = new SizeF(96F, 96F);
Expand Down

0 comments on commit 3ac9685

Please sign in to comment.