Skip to content

Commit

Permalink
* fixed where the filter was being called multiple times on launch
Browse files Browse the repository at this point in the history
* simplified productsGrid init means a lot of defensive code is no longer needed
  • Loading branch information
rmcrackan committed May 12, 2022
1 parent 75c5f66 commit 360f077
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions Source/LibationWinForms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ public Form1()
{
InitializeComponent();

if (this.DesignMode)
return;

productsGrid = new ProductsGrid { Dock = DockStyle.Fill };
productsGrid.VisibleCountChanged += (_, qty) => visibleCountLbl.Text = string.Format("Visible: {0}", qty);
gridPanel.Controls.Add(productsGrid);
this.Load += (_, __) =>
{
productsGrid.Display();

// also applies filter. ONLY call AFTER loading grid
loadInitialQuickFilterState();
};

// back up string formats
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
Expand All @@ -39,13 +49,11 @@ public Form1()
liberateVisibleToolStripMenuItem_format = liberateVisibleToolStripMenuItem.Text;
liberateVisible2ToolStripMenuItem_format = liberateVisible2ToolStripMenuItem.Text;

if (this.DesignMode)
return;

// independent UI updates
this.Load += (_, _) => this.RestoreSizeAndLocation(Configuration.Instance);
this.FormClosing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance);
LibraryCommands.LibrarySizeChanged += reloadGridAndUpdateBottomNumbers;
this.Load += setBackupCounts;
LibraryCommands.BookUserDefinedItemCommitted += setBackupCounts;
QuickFilters.Updated += updateFiltersMenu;
LibraryCommands.ScanBegin += LibraryCommands_ScanBegin;
Expand All @@ -71,21 +79,12 @@ private void Form1_Load(object sender, EventArgs e)
if (this.DesignMode)
return;

// can't refactor into "this.Load => reloadGridAndUpdateBottomNumbers"
// because loadInitialQuickFilterState must follow it
reloadGridAndUpdateBottomNumbers();

// also applies filter. ONLY call AFTER loading grid
loadInitialQuickFilterState();
// I'm leaving this empty call here as a reminder that if we use this, it should probably be after DesignMode check
}

private void reloadGridAndUpdateBottomNumbers(object _ = null, object __ = null)
private void reloadGridAndUpdateBottomNumbers(object _, object __)
{
// suppressed filter while init'ing UI
var prev_isProcessingGridSelect = isProcessingGridSelect;
isProcessingGridSelect = true;
this.UIThreadSync(() => productsGrid.Display());
isProcessingGridSelect = prev_isProcessingGridSelect;

// UI init complete. now we can apply filter
this.UIThreadAsync(() => doFilter(lastGoodFilter));
Expand Down Expand Up @@ -198,7 +197,6 @@ private void filterSearchTb_KeyPress(object sender, KeyPressEventArgs e)
}
private void filterBtn_Click(object sender, EventArgs e) => doFilter();

private bool isProcessingGridSelect = false;
private string lastGoodFilter = "";
private void doFilter(string filterString)
{
Expand All @@ -207,9 +205,6 @@ private void doFilter(string filterString)
}
private void doFilter()
{
if (isProcessingGridSelect || productsGrid is null)
return;

try
{
productsGrid.Filter(filterSearchTb.Text);
Expand Down

0 comments on commit 360f077

Please sign in to comment.