Skip to content

Commit c866fb9

Browse files
committed
feat: remember expand status of data source group and keep the status next time run the app.
1 parent 7e21192 commit c866fb9

File tree

7 files changed

+84
-22
lines changed

7 files changed

+84
-22
lines changed

Ui/AppVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class AppVersion
88
public const uint Minor = 0;
99
public const uint Patch = 0;
1010
public const uint Build = 0;
11-
public const string PreRelease = "beta.02"; // e.g. "alpha" "beta.2"
11+
public const string PreRelease = "beta.03"; // e.g. "alpha" "beta.2"
1212

1313

1414
public static readonly VersionHelper.Version VersionData = new VersionHelper.Version(Major, Minor, Patch, Build, PreRelease);

Ui/Service/DataSource/Model/DataSourceBase.Source.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,13 @@ public void MarkAsNeedRead()
9898
/// <returns></returns>
9999
public IEnumerable<ProtocolBaseViewModel> GetServers(bool focus = false)
100100
{
101+
if (focus == false
102+
&& LastReadFromDataSourceMillisecondsTimestamp >= _dataSourceDataUpdateTimestamp)
103+
{
104+
return CachedProtocols;
105+
}
101106
lock (this)
102107
{
103-
if (focus == false
104-
&& LastReadFromDataSourceMillisecondsTimestamp >= _dataSourceDataUpdateTimestamp)
105-
{
106-
return CachedProtocols;
107-
}
108-
109108
var result = Database_GetServers();
110109
if (result.IsSuccess)
111110
{

Ui/Service/LocalityService.cs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Documents;
1010
using Newtonsoft.Json;
1111
using _1RM.Model.Protocol;
12+
using _1RM.Service.DataSource;
1213
using _1RM.View.Launcher;
1314
using Shawn.Utils;
1415
using _1RM.View;
@@ -23,6 +24,7 @@ public enum EnumServerOrderBy
2324
ProtocolDesc = 1,
2425
NameAsc = 2,
2526
NameDesc = 3,
27+
2628
//TagAsc = 4,
2729
//TagDesc = 5,
2830
AddressAsc = 6,
@@ -43,13 +45,13 @@ internal class LocalitySettings
4345
public EnumServerOrderBy ServerOrderBy = EnumServerOrderBy.IdAsc;
4446
public Dictionary<string, int> ServerCustomOrder = new Dictionary<string, int>();
4547
public Dictionary<string, int> ServerGroupedOrder = new Dictionary<string, int>();
48+
public Dictionary<string, bool> ServerGroupedIsExpanded = new Dictionary<string, bool>();
4649
public ConcurrentDictionary<string, RdpLocalSetting> RdpLocalities = new ConcurrentDictionary<string, RdpLocalSetting>();
4750
public List<QuickConnectionItem> QuickConnectionHistory = new List<QuickConnectionItem>();
4851
}
4952

5053
public sealed class LocalityService
5154
{
52-
5355
public double MainWindowWidth
5456
{
5557
get => _localitySettings.MainWindowWidth;
@@ -155,7 +157,6 @@ public WindowStyle TabWindowStyle
155157
}
156158

157159

158-
159160
public EnumServerOrderBy ServerOrderBy
160161
{
161162
get => _localitySettings.ServerOrderBy;
@@ -175,6 +176,7 @@ public EnumServerOrderBy ServerOrderBy
175176

176177
public Dictionary<string, int> ServerCustomOrder => _localitySettings.ServerCustomOrder;
177178
public Dictionary<string, int> ServerGroupedOrder => _localitySettings.ServerGroupedOrder;
179+
public Dictionary<string, bool> ServerGroupedIsExpanded => _localitySettings.ServerGroupedIsExpanded;
178180

179181
#region Interface
180182

@@ -186,6 +188,7 @@ public EnumServerOrderBy ServerOrderBy
186188
{
187189
return v;
188190
}
191+
189192
return null;
190193
}
191194

@@ -204,6 +207,7 @@ public void RdpLocalityUpdate(string key, bool isFullScreen, int fullScreenIndex
204207
{
205208
_localitySettings.RdpLocalities.TryRemove(obsolete, out _);
206209
}
210+
207211
Save();
208212
}
209213

@@ -219,6 +223,7 @@ public void QuickConnectionHistoryAdd(QuickConnectionItem item)
219223
{
220224
_localitySettings.QuickConnectionHistory.RemoveRange(50, _localitySettings.QuickConnectionHistory.Count - 50);
221225
}
226+
222227
Save();
223228
}
224229

@@ -232,6 +237,7 @@ public void QuickConnectionHistoryRemove(QuickConnectionItem item)
232237
{
233238
_localitySettings.QuickConnectionHistory.RemoveRange(50, _localitySettings.QuickConnectionHistory.Count - 50);
234239
}
240+
235241
Save();
236242
}
237243

@@ -244,8 +250,10 @@ public void ServerCustomOrderRebuild(IEnumerable<ProtocolBaseViewModel> servers)
244250
_localitySettings.ServerCustomOrder.Add(server.Id, i);
245251
++i;
246252
}
253+
247254
Save();
248255
}
256+
249257
public void ServerGroupedOrderRebuild(string?[] groupNames)
250258
{
251259
int i = 0;
@@ -258,7 +266,36 @@ public void ServerGroupedOrderRebuild(string?[] groupNames)
258266
Save();
259267
}
260268

269+
public void ServerGroupedSetIsExpanded(string name, bool isExpanded)
270+
{
271+
try
272+
{
273+
if (ServerGroupedIsExpanded.ContainsKey(name))
274+
ServerGroupedIsExpanded[name] = isExpanded;
275+
else
276+
ServerGroupedIsExpanded.Add(name, isExpanded);
277+
var ds = IoC.TryGet<DataSourceService>();
278+
if (ds != null)
279+
{
280+
foreach (var key in ServerGroupedIsExpanded.Keys.ToArray())
281+
{
282+
if (ds.LocalDataSource?.Name != key && ds.AdditionalSources.All(x => x.Key != key))
283+
{
284+
ServerGroupedIsExpanded.Remove(key);
285+
}
286+
}
287+
}
288+
}
289+
catch (Exception e)
290+
{
291+
MsAppCenterHelper.Error(e);
292+
_localitySettings.ServerGroupedIsExpanded = new Dictionary<string, bool>();
293+
}
294+
Save();
295+
}
296+
261297
public bool CanSave = true;
298+
262299
private void Save()
263300
{
264301
if (!CanSave) return;
@@ -270,10 +307,8 @@ private void Save()
270307
if (fi?.Directory?.Exists == false)
271308
fi.Directory.Create();
272309

273-
RetryHelper.Try(() =>
274-
{
275-
File.WriteAllText(AppPathHelper.Instance.LocalityJsonPath, JsonConvert.SerializeObject(this._localitySettings, Formatting.Indented), Encoding.UTF8);
276-
}, actionOnError: exception => MsAppCenterHelper.Error(exception));
310+
RetryHelper.Try(() => { File.WriteAllText(AppPathHelper.Instance.LocalityJsonPath, JsonConvert.SerializeObject(this._localitySettings, Formatting.Indented), Encoding.UTF8); },
311+
actionOnError: exception => MsAppCenterHelper.Error(exception));
277312
CanSave = true;
278313
}
279314
}

Ui/View/Editor/DataSourceSelectorView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=DataContext.CmdSelect}"
132132
CommandParameter="{Binding}"
133133
>
134-
<!--<Button.Style>
134+
<Button.Style>
135135
<Style TargetType="Button" BasedOn="{StaticResource ButtonAccentStyle}">
136136
<Setter Property="IsEnabled" Value="False"></Setter>
137137
<Style.Triggers>
@@ -146,7 +146,7 @@
146146
</MultiDataTrigger>
147147
</Style.Triggers>
148148
</Style>
149-
</Button.Style>-->
149+
</Button.Style>
150150
</Button>
151151
</Grid>
152152
<DataTemplate.Triggers>

Ui/View/ProtocolBaseViewModel.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public int CustomOrder
3030
}
3131
}
3232

33-
33+
#region Grouped
3434
public string GroupedOrder
3535
{
3636
get
@@ -48,6 +48,39 @@ public string GroupedOrder
4848
}
4949

5050

51+
private readonly DebounceDispatcher _debounceDispatcher = new();
52+
private bool? _groupedIsExpanded = null;
53+
public bool GroupedIsExpanded
54+
{
55+
set
56+
{
57+
if (IoC.TryGet<LocalityService>() != null
58+
&& SetAndNotifyIfChanged(ref _groupedIsExpanded, value))
59+
{
60+
_debounceDispatcher.Debounce(1000, (_) =>
61+
{
62+
IoC.Get<LocalityService>().ServerGroupedSetIsExpanded(DataSourceName, value);
63+
});
64+
}
65+
}
66+
get
67+
{
68+
if (_groupedIsExpanded == null)
69+
{
70+
var ret = true;
71+
if (IoC.TryGet<LocalityService>() != null)
72+
{
73+
var tmp = IoC.Get<LocalityService>().ServerGroupedIsExpanded;
74+
if (tmp.ContainsKey(DataSourceName) == true)
75+
ret = tmp[DataSourceName];
76+
}
77+
_groupedIsExpanded = ret;
78+
}
79+
return _groupedIsExpanded.Value;
80+
}
81+
}
82+
#endregion
83+
5184
public bool IsEditable { get; private set; } = false;
5285
public bool IsViewable { get; private set; } = false;
5386

@@ -199,7 +232,6 @@ public DateTime LastConnectTime
199232
get => _lastConnectTime;
200233
set => SetAndNotifyIfChanged(ref _lastConnectTime, value);
201234
}
202-
203235
#region CMD
204236

205237
private RelayCommand? _cmdConnServer;

Ui/View/ServerList/ServerListPageView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@
486486
<Setter.Value>
487487
<ControlTemplate TargetType="{x:Type GroupItem}">
488488
<Grid>
489-
<Expander IsExpanded="True"
489+
<Expander IsExpanded="{Binding Items[0].GroupedIsExpanded}"
490490
Background="{DynamicResource BackgroundBrush}"
491491
Foreground="{DynamicResource BackgroundTextBrush}"
492492
BorderThickness="0">

Ui/View/ServerList/ServerListPageViewModel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
using System.Windows;
12-
using System.Windows.Controls;
1312
using System.Windows.Data;
1413
using _1RM.Model;
15-
using _1RM.Service.DataSource.DAO;
16-
using _1RM.Service.DataSource.DAO.Dapper;
1714
using _1RM.Model.Protocol;
1815
using _1RM.Model.Protocol.Base;
1916
using _1RM.Resources.Icons;
2017
using _1RM.Service;
2118
using _1RM.Service.DataSource;
22-
using _1RM.Service.DataSource.Model;
2319
using _1RM.Utils;
2420
using _1RM.Utils.mRemoteNG;
2521
using _1RM.Utils.RdpFile;

0 commit comments

Comments
 (0)