Skip to content

Commit 871b923

Browse files
authored
Added options to import/export settings (#6542)
1 parent 7da8156 commit 871b923

31 files changed

+286
-45
lines changed

Files/Extensions/EnumerableExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ internal static class EnumerableExtensions
1414
/// <param name="item">The item</param>
1515
/// <returns><see cref="IEnumerable{T}"/> with <paramref name="item"/></returns>
1616
internal static IEnumerable<T> CreateEnumerable<T>(this T item) =>
17+
CreateList<T>(item);
18+
19+
internal static List<T> CreateList<T>(this T item) =>
1720
new List<T>() { item };
1821

1922
/// <summary>

Files/Files.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
<Compile Include="Helpers\ZipHelpers.cs" />
236236
<Compile Include="Interacts\ItemManipulationModel.cs" />
237237
<Compile Include="ISearchBox.cs" />
238+
<Compile Include="Models\JsonSettings\BaseObservableJsonSettingsModel.cs" />
238239
<Compile Include="Models\JsonSettings\ISettingsSharingContext.cs" />
239240
<Compile Include="Models\JsonSettings\IJsonSettingsDatabase.cs" />
240241
<Compile Include="Models\JsonSettings\IJsonSettingsSerializer.cs" />

Files/Helpers/UIHelpers.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using System.Threading.Tasks;
77
using Windows.ApplicationModel.AppService;
88
using Windows.Foundation.Collections;
9+
using Windows.UI.Xaml;
910
using Windows.UI.Xaml.Controls;
11+
using Windows.UI.Xaml.Media;
1012
using Windows.UI.Xaml.Media.Imaging;
1113

1214
namespace Files.Helpers
@@ -25,6 +27,19 @@ public static async Task<ContentDialogResult> TryShowAsync(this ContentDialog di
2527
}
2628
}
2729

30+
public static void CloseAllDialogs()
31+
{
32+
var openedDialogs = VisualTreeHelper.GetOpenPopups(Window.Current);
33+
34+
foreach (var item in openedDialogs)
35+
{
36+
if (item.Child is ContentDialog dialog)
37+
{
38+
dialog.Hide();
39+
}
40+
}
41+
}
42+
2843
private static async Task<IList<IconFileInfo>> LoadSelectedIconsAsync(string filePath, IList<int> indexes, int iconSize = 48)
2944
{
3045
var connection = await AppServiceConnectionHelper.Instance;

Files/Models/JsonSettings/BaseJsonSettingsModel.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public virtual bool FlushSettings()
127127

128128
public virtual object ExportSettings()
129129
{
130-
return JsonSettingsDatabase.ExportSettings();
130+
return JsonSettingsDatabase.ExportSettings();
131131
}
132132

133133
public virtual bool ImportSettings(object import)
@@ -155,14 +155,8 @@ public ISettingsSharingContext GetSharingContext()
155155

156156
public virtual void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
157157
{
158-
if (settingsSharingContext != null)
159-
{
160-
settingsSharingContext.RaiseOnSettingChangedEvent(sender, e);
161-
}
162-
else
163-
{
164-
OnSettingChangedEvent?.Invoke(sender, e);
165-
}
158+
OnSettingChangedEvent?.Invoke(sender, e);
159+
settingsSharingContext?.RaiseOnSettingChangedEvent(sender, e);
166160
}
167161

168162
#endregion Helpers
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.ComponentModel;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Files.Models.JsonSettings
5+
{
6+
public abstract class BaseObservableJsonSettingsModel : BaseJsonSettingsModel, INotifyPropertyChanged
7+
{
8+
public event PropertyChangedEventHandler PropertyChanged;
9+
10+
public BaseObservableJsonSettingsModel()
11+
: base()
12+
{
13+
}
14+
15+
protected BaseObservableJsonSettingsModel(string filePath)
16+
: base(filePath)
17+
{
18+
}
19+
20+
protected BaseObservableJsonSettingsModel(string filePath, bool isCachingEnabled, IJsonSettingsSerializer jsonSettingsSerializer = null, ISettingsSerializer settingsSerializer = null)
21+
: base(filePath, isCachingEnabled, jsonSettingsSerializer, settingsSerializer)
22+
{
23+
}
24+
25+
protected override bool Set<TValue>(TValue value, [CallerMemberName] string propertyName = "")
26+
{
27+
if (base.Set(value, propertyName))
28+
{
29+
OnPropertyChanged(propertyName);
30+
return true;
31+
}
32+
33+
return false;
34+
}
35+
36+
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
37+
{
38+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
39+
}
40+
}
41+
}

Files/Models/JsonSettings/IJsonSettingsDatabase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Files.Models.JsonSettings
1+
using System.Collections.Generic;
2+
3+
namespace Files.Models.JsonSettings
24
{
35
public interface IJsonSettingsDatabase
46
{
@@ -15,5 +17,7 @@ public interface IJsonSettingsDatabase
1517
bool ImportSettings(object import);
1618

1719
object ExportSettings();
20+
21+
Dictionary<string, object> TakeDifferent(Dictionary<string, object> other);
1822
}
1923
}

Files/Models/JsonSettings/Implementation/DefaultJsonSettingsDatabase.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Linq;
45
using Files.Common;
56

67
namespace Files.Models.JsonSettings.Implementation
@@ -127,6 +128,13 @@ public virtual bool ImportSettings(object import)
127128
}
128129
}
129130

131+
public virtual object ExportSettings()
132+
{
133+
settingsCache = GetNewSettingsCache();
134+
135+
return settingsCache;
136+
}
137+
130138
public virtual bool FlushSettings()
131139
{
132140
try
@@ -148,11 +156,22 @@ public virtual bool FlushSettings()
148156
}
149157
}
150158

151-
public virtual object ExportSettings()
159+
public Dictionary<string, object> TakeDifferent(Dictionary<string, object> other)
152160
{
153-
settingsCache = GetNewSettingsCache();
161+
Dictionary<string, object> difference = new Dictionary<string, object>();
154162

155-
return settingsCache;
163+
foreach (var item in other)
164+
{
165+
foreach (var item2 in settingsCache)
166+
{
167+
if (item.Key == item2.Key && (!item.Value?.Equals(item2.Value) ?? false))
168+
{
169+
difference.Add(item.Key, item.Value);
170+
}
171+
}
172+
}
173+
174+
return difference;
156175
}
157176
}
158177
}

Files/Services/IAppearanceSettingsService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
namespace Files.Services
1+
using System.ComponentModel;
2+
3+
namespace Files.Services
24
{
3-
public interface IAppearanceSettingsService
5+
public interface IAppearanceSettingsService : INotifyPropertyChanged
46
{
57
/// <summary>
68
/// Gets or sets a value indicating whether or not to move overflow menu items into a sub menu.

Files/Services/IFilesAndFoldersSettingsService.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.ComponentModel;
62

73
namespace Files.Services
84
{
9-
public interface IFilesAndFoldersSettingsService
5+
public interface IFilesAndFoldersSettingsService : INotifyPropertyChanged
106
{
117
/// <summary>
128
/// Gets or sets a value indicating whether or not file extensions should be visible.

Files/Services/ILayoutSettingsService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using Files.Enums;
2+
using System.ComponentModel;
23

34
namespace Files.Services
45
{
5-
public interface ILayoutSettingsService
6+
public interface ILayoutSettingsService : INotifyPropertyChanged
67
{
78
/// <summary>
89
/// Gets or sets a value indicating whether or not the date column should be visible.

0 commit comments

Comments
 (0)