Skip to content

Commit

Permalink
Reuse StashView when refreshing the stash.
Browse files Browse the repository at this point in the history
Recreating the StashView every time we want to refresh the stash is a
memory leak, and makes Procurement lag while it rebuilds the stash.  As
an added bonus, now the last-selected stash tab remains selected when
revisiting the stash.
  • Loading branch information
thailyn committed Jun 23, 2019
1 parent c76515c commit 0032521
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion Procurement/ViewModel/ScreenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void ReloadStash()
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(() =>
{
screens[STASH_VIEW] = new StashView();
SelectedView = screens[STASH_VIEW] as UserControl;
ButtonsVisible = true;
}));
Expand Down
5 changes: 3 additions & 2 deletions Procurement/ViewModel/TabViewModel/StashViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
var item = stashView.tabControl.SelectedItem as TabItem;
selectedTab = item;
Image i = item.Header as Image;
CroppedBitmap bm = (CroppedBitmap)i.Source;
Tab tab = (Tab)i.Tag;
item.Header = StashHelper.GenerateTabImage(tab, true);
}
Expand All @@ -266,6 +265,8 @@ private void unselectPreviousTab(TabItem selectedTab)

void ApplicationState_LeagueChanged(object sender, PropertyChangedEventArgs e)
{
tabsAndContent.Clear();

getAvailableItems();
stashView.tabControl.SelectionChanged -= new SelectionChangedEventHandler(tabControl_SelectionChanged);
stashView.tabControl.Items.Clear();
Expand Down Expand Up @@ -339,9 +340,9 @@ private void closeAndSelect(ContextMenu menu, MenuItem menuItem)

void stashView_Loaded(object sender, RoutedEventArgs e)
{
var stash = ApplicationState.Stash[ApplicationState.CurrentLeague];
for (var i = 1; i <= ApplicationState.Stash[ApplicationState.CurrentLeague].NumberOfTabs; i++)
{
var stash = ApplicationState.Stash[ApplicationState.CurrentLeague];
var currentTab = stash.Tabs[i - 1];

var item = new TabItem
Expand Down

0 comments on commit 0032521

Please sign in to comment.