Skip to content

Commit bdd031c

Browse files
committed
Refresh tags and bundles on import
Refresh widgets on import Fix duplicate favorites section
1 parent a7de0c1 commit bdd031c

File tree

10 files changed

+50
-33
lines changed

10 files changed

+50
-33
lines changed

Files/DataModels/SidebarPinnedModel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class SidebarPinnedModel
2828

2929
private SidebarPinnedController controller;
3030

31-
private LocationItem favoriteSection, homeSection;
31+
private LocationItem favoriteSection;
3232

3333
[JsonIgnore]
3434
public MainViewModel MainViewModel => App.MainViewModel;
@@ -43,6 +43,7 @@ public void SetController(SidebarPinnedController controller)
4343

4444
public SidebarPinnedModel()
4545
{
46+
favoriteSection = SidebarControl.SideBarItems.FirstOrDefault(x => x.Text == "SidebarFavorites".GetLocalized()) as LocationItem;
4647
}
4748

4849
/// <summary>
@@ -282,7 +283,7 @@ public async Task AddItemToSidebarAsync(string path)
282283
}
283284
}
284285

285-
if (!favoriteSection.ChildItems.Contains(locationItem))
286+
if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path))
286287
{
287288
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem));
288289
}
@@ -303,7 +304,7 @@ private void AddItemToSidebarAsync(LocationItem section)
303304
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath));
304305
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
305306

306-
if (!favoriteSection.ChildItems.Contains(section))
307+
if (!favoriteSection.ChildItems.Any(x => x.Section == section.Section))
307308
{
308309
favoriteSection.ChildItems.Insert(insertIndex, section);
309310
}
@@ -322,7 +323,7 @@ public async Task AddAllItemsToSidebar()
322323
await SidebarControl.SideBarItemsSemaphore.WaitAsync();
323324
try
324325
{
325-
homeSection = new LocationItem()
326+
var homeSection = new LocationItem()
326327
{
327328
Text = "SidebarHome".GetLocalized(),
328329
Section = SectionType.Home,
@@ -332,7 +333,7 @@ public async Task AddAllItemsToSidebar()
332333
Path = "Home".GetLocalized(),
333334
ChildItems = new ObservableCollection<INavigationControlItem>()
334335
};
335-
favoriteSection = new LocationItem()
336+
favoriteSection ??= new LocationItem()
336337
{
337338
Text = "SidebarFavorites".GetLocalized(),
338339
Section = SectionType.Favorites,
@@ -347,7 +348,7 @@ public async Task AddAllItemsToSidebar()
347348
AddItemToSidebarAsync(homeSection);
348349
}
349350

350-
if (!SidebarControl.SideBarItems.Contains(favoriteSection))
351+
if (!SidebarControl.SideBarItems.Any(x => x.Text == "SidebarFavorites".GetLocalized()))
351352
{
352353
SidebarControl.SideBarItems.BeginBulkOperation();
353354
var index = 0; // First section

Files/Helpers/RegistryToJsonSettingsMerger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void MergeSettings()
4545
userSettingsService.MultitaskingSettingsService.AlwaysOpenDualPaneInNewTab = appSettings.Get(false, "AlwaysOpenDualPaneInNewTab");
4646

4747
// Widgets
48-
userSettingsService.WidgetsSettingsService.ShowFoldersWidget = appSettings.Get(true, "ShowFolderWidgetWidget");
48+
userSettingsService.WidgetsSettingsService.ShowFoldersWidget = appSettings.Get(true, "ShowFoldersWidget");
4949
userSettingsService.WidgetsSettingsService.ShowRecentFilesWidget = appSettings.Get(true, "ShowRecentFilesWidget");
5050
userSettingsService.WidgetsSettingsService.ShowDrivesWidget = appSettings.Get(true, "ShowDrivesWidget");
5151
userSettingsService.WidgetsSettingsService.ShowBundlesWidget = appSettings.Get(false, "ShowBundlesWidget");

Files/Services/IBundlesSettingsService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using Files.EventArguments;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43

54
namespace Files.Services
65
{
76
public interface IBundlesSettingsService
87
{
9-
event EventHandler<SettingChangedEventArgs> OnSettingChangedEvent;
8+
event EventHandler OnSettingImportedEvent;
109

1110
bool FlushSettings();
1211

Files/Services/IFileTagsSettingsService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using Files.EventArguments;
2-
using Files.Filesystem;
1+
using Files.Filesystem;
32
using System;
43
using System.Collections.Generic;
54

65
namespace Files.Services
76
{
87
public interface IFileTagsSettingsService
98
{
10-
event EventHandler<SettingChangedEventArgs> OnSettingChangedEvent;
9+
event EventHandler OnSettingImportedEvent;
1110

1211
IList<FileTag> FileTagList { get; set; }
1312

Files/Services/Implementation/BundlesSettingsService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using Files.Extensions;
22
using Files.Models.JsonSettings;
3+
using System;
34
using System.Collections.Generic;
45
using Windows.Storage;
56

67
namespace Files.Services.Implementation
78
{
89
public sealed class BundlesSettingsService : BaseObservableJsonSettingsModel, IBundlesSettingsService
910
{
11+
public event EventHandler OnSettingImportedEvent;
12+
1013
public BundlesSettingsService()
1114
: base(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, Constants.LocalSettings.SettingsFolderName, Constants.LocalSettings.BundlesSettingsFileName),
1215
isCachingEnabled: true)
@@ -33,6 +36,7 @@ public override bool ImportSettings(object import)
3336
if (SavedBundles != null)
3437
{
3538
FlushSettings();
39+
OnSettingImportedEvent?.Invoke(this, null);
3640
return true;
3741
}
3842

Files/Services/Implementation/FileTagsSettingsService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Files.Services.Implementation
1010
{
1111
public sealed class FileTagsSettingsService : BaseJsonSettingsModel, IFileTagsSettingsService
1212
{
13+
public event EventHandler OnSettingImportedEvent;
14+
1315
private static readonly List<FileTag> s_defaultFileTags = new List<FileTag>()
1416
{
1517
new FileTag("Blue", "#0072BD"),
@@ -68,6 +70,7 @@ public override bool ImportSettings(object import)
6870
if (FileTagList != null)
6971
{
7072
FlushSettings();
73+
OnSettingImportedEvent?.Invoke(this, null);
7174
return true;
7275
}
7376

Files/UserControls/InnerNavigationToolbar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
<ToggleSwitch
232232
x:Uid="NavToolbarShowFolderWidget"
233233
Header="Show Folders widget"
234-
IsOn="{x:Bind ViewModel.ShowFolderWidgetWidget, Mode=TwoWay}" />
234+
IsOn="{x:Bind ViewModel.ShowFoldersWidget, Mode=TwoWay}" />
235235
<ToggleSwitch
236236
x:Uid="NavToolbarShowDrivesWidget"
237237
Header="Show Drives widget"

Files/ViewModels/ItemViewModel.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,19 @@ public ItemViewModel(FolderSettingsViewModel folderSettingsViewModel)
360360
shouldDisplayFileExtensions = UserSettingsService.PreferencesSettingsService.ShowFileExtensions;
361361

362362
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
363-
FileTagsSettingsService.OnSettingChangedEvent += FileTagsSettingsService_OnSettingChangedEvent;
363+
FileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingImportedEvent;
364364
AppServiceConnectionHelper.ConnectionChanged += AppServiceConnectionHelper_ConnectionChanged;
365365
}
366366

367-
private void FileTagsSettingsService_OnSettingChangedEvent(object sender, SettingChangedEventArgs e)
367+
private async void FileTagsSettingsService_OnSettingImportedEvent(object sender, EventArgs e)
368368
{
369-
switch (e.settingName)
369+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() =>
370370
{
371-
case nameof(FileTagsSettingsService.FileTagList):
372-
// Reload tags
373-
break;
374-
}
371+
if (WorkingDirectory != "Home".GetLocalized())
372+
{
373+
RefreshItems(null);
374+
}
375+
});
375376
}
376377

377378
private async void UserSettingsService_OnSettingChangedEvent(object sender, SettingChangedEventArgs e)
@@ -2263,7 +2264,7 @@ public void Dispose()
22632264
Connection.RequestReceived -= Connection_RequestReceived;
22642265
}
22652266
UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent;
2266-
FileTagsSettingsService.OnSettingChangedEvent -= FileTagsSettingsService_OnSettingChangedEvent;
2267+
FileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingImportedEvent;
22672268
AppServiceConnectionHelper.ConnectionChanged -= AppServiceConnectionHelper_ConnectionChanged;
22682269
DefaultIcons.Clear();
22692270
}

Files/ViewModels/NavToolbarViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ public NavToolbarViewModel()
328328
dragOverTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
329329
SearchBox.SuggestionChosen += SearchRegion_SuggestionChosen;
330330
SearchBox.Escaped += SearchRegion_Escaped;
331+
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
332+
}
333+
334+
private void UserSettingsService_OnSettingChangedEvent(object sender, EventArguments.SettingChangedEventArgs e)
335+
{
336+
switch (e.settingName)
337+
{
338+
case nameof(ShowFoldersWidget):
339+
case nameof(ShowDrivesWidget):
340+
case nameof(ShowBundlesWidget):
341+
case nameof(ShowRecentFilesWidget):
342+
RefreshWidgetsRequested?.Invoke(this, EventArgs.Empty);
343+
OnPropertyChanged(e.settingName);
344+
break;
345+
}
331346
}
332347

333348
private DispatcherQueueTimer dragOverTimer;
@@ -642,7 +657,7 @@ public void UpdateAdditionnalActions()
642657

643658
#region WidgetsPage Widgets
644659

645-
public bool ShowFolderWidgetWidget
660+
public bool ShowFoldersWidget
646661
{
647662
get => UserSettingsService.WidgetsSettingsService.ShowFoldersWidget;
648663
set
@@ -1050,6 +1065,7 @@ public void Dispose()
10501065
{
10511066
SearchBox.SuggestionChosen -= SearchRegion_SuggestionChosen;
10521067
SearchBox.Escaped -= SearchRegion_Escaped;
1068+
UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent;
10531069

10541070
InstanceViewModel.FolderSettings.SortDirectionPreferenceUpdated -= FolderSettings_SortDirectionPreferenceUpdated;
10551071
InstanceViewModel.FolderSettings.SortOptionPreferenceUpdated -= FolderSettings_SortOptionPreferenceUpdated;

Files/ViewModels/Widgets/Bundles/BundlesViewModel.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public BundlesViewModel()
105105
ImportBundlesCommand = new AsyncRelayCommand(ImportBundles);
106106
ExportBundlesCommand = new AsyncRelayCommand(ExportBundles);
107107

108-
BundlesSettingsService.OnSettingChangedEvent += BundlesSettingsService_OnSettingChangedEvent;
108+
BundlesSettingsService.OnSettingImportedEvent += BundlesSettingsService_OnSettingImportedEvent;
109109
}
110110

111111
#endregion Constructor
@@ -259,14 +259,9 @@ private async Task ExportBundles()
259259

260260
#region Handlers
261261

262-
private async void BundlesSettingsService_OnSettingChangedEvent(object sender, EventArguments.SettingChangedEventArgs e)
262+
private async void BundlesSettingsService_OnSettingImportedEvent(object sender, EventArgs e)
263263
{
264-
switch (e.settingName)
265-
{
266-
case nameof(BundlesSettingsService.SavedBundles):
267-
await Load();
268-
break;
269-
}
264+
await Load();
270265
}
271266

272267
private void OpenPathHandle(string path, FilesystemItemType itemType, bool openSilent, bool openViaApplicationPicker, IEnumerable<string> selectItems)
@@ -285,8 +280,6 @@ private void OpenPathInNewPaneHandle(string path)
285280
/// <param name="item"></param>
286281
private void NotifyItemRemovedHandle(BundleContainerViewModel item)
287282
{
288-
BundlesSettingsService.OnSettingChangedEvent -= BundlesSettingsService_OnSettingChangedEvent;
289-
290283
Items.Remove(item);
291284
item?.Dispose();
292285

@@ -464,6 +457,7 @@ public void Dispose()
464457
}
465458

466459
Items.CollectionChanged -= Items_CollectionChanged;
460+
BundlesSettingsService.OnSettingImportedEvent -= BundlesSettingsService_OnSettingImportedEvent;
467461
}
468462

469463
#endregion IDisposable

0 commit comments

Comments
 (0)