99using System . Windows . Documents ;
1010using Newtonsoft . Json ;
1111using _1RM . Model . Protocol ;
12+ using _1RM . Service . DataSource ;
1213using _1RM . View . Launcher ;
1314using Shawn . Utils ;
1415using _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 }
0 commit comments