Skip to content

Commit

Permalink
Fix: Save tabs when path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 committed Mar 1, 2024
1 parent 48829c4 commit c6415f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e
if (e.PropertyName is nameof(AppModel.TabStripSelectedIndex))
UpdateCurrentTabIndex();
}

private void BaseMultitaskingControl_OnLoaded(object? sender, ITabBar control)
{
SetProperty(ref this.control, control, nameof(Control));
UpdateTabCount();
UpdateCurrentTabIndex();
}

private void HorizontalMultitaskingControl_SelectedTabItemChanged(object? sender, TabBarItem? e)
{
isPopupOpen = e is not null;
int newSelectedIndex = e is null ? currentTabIndex : MainPageViewModel.AppInstances.IndexOf(e);
UpdateSelectedTabIndex(newSelectedIndex);
}

private void FocusManager_GotFocus(object? sender, FocusManagerGotFocusEventArgs e)
{
if (isPopupOpen)
Expand All @@ -68,6 +71,7 @@ private void FocusManager_GotFocus(object? sender, FocusManagerGotFocusEventArgs
UpdateSelectedTabIndex(newSelectedIndex);
}
}

private void FocusManager_LosingFocus(object? sender, LosingFocusEventArgs e)
{
if (isPopupOpen)
Expand All @@ -83,13 +87,15 @@ private void UpdateTabCount()
{
SetProperty(ref tabCount, (ushort)MainPageViewModel.AppInstances.Count, nameof(TabCount));
}

private void UpdateCurrentTabIndex()
{
if (SetProperty(ref currentTabIndex, (ushort)App.AppModel.TabStripSelectedIndex, nameof(CurrentTabIndex)))
{
OnPropertyChanged(nameof(CurrentTabItem));
}
}

private void UpdateSelectedTabIndex(int index)
{
if (SetProperty(ref selectedTabIndex, (ushort)index, nameof(SelectedTabIndex)))
Expand Down
6 changes: 0 additions & 6 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public static async Task AddNewTabByPathAsync(Type type, string? path, int atInd
MainPageViewModel.AppInstances.Insert(index, tabItem);

App.AppModel.TabStripSelectedIndex = index;

// Save the updated tab list
AppLifecycleHelper.SaveSessionTabs();
}

public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs, int atIndex = -1)
Expand All @@ -89,9 +86,6 @@ public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs
var index = atIndex == -1 ? MainPageViewModel.AppInstances.Count : atIndex;
MainPageViewModel.AppInstances.Insert(index, tabItem);
App.AppModel.TabStripSelectedIndex = index;

// Save the updated tab list
AppLifecycleHelper.SaveSessionTabs();
}

private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigationArg)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public async void TabItemContent_ContentChanged(object? sender, CustomTabViewIte
LoadPaneChanged();
UpdateNavToolbarProperties();
await NavigationHelpers.UpdateInstancePropertiesAsync(paneArgs);

// Save the updated tab list
AppLifecycleHelper.SaveSessionTabs();
}

public async void MultitaskingControl_CurrentInstanceChanged(object? sender, CurrentInstanceChangedEventArgs e)
Expand Down

0 comments on commit c6415f7

Please sign in to comment.