15
15
using Windows . Security . Authentication . Web . Provider ;
16
16
using Microsoft . UI ;
17
17
using WinRT . Interop ;
18
+ using System . Collections . Generic ;
19
+ using Microsoft . Extensions . DependencyInjection ;
20
+ using ICSharpCode . Decompiler . CSharp . Syntax ;
21
+ using AtlasToolbox . ViewModels ;
22
+ using System . Runtime . CompilerServices ;
18
23
19
24
namespace AtlasToolbox
20
25
{
21
26
public sealed partial class MainWindow : Window
22
27
{
28
+ public List < IConfigurationItem > RootList { get ; set ; }
23
29
public MainWindow ( )
24
30
{
25
31
this . InitializeComponent ( ) ;
@@ -31,14 +37,34 @@ public MainWindow()
31
37
WindowManager . Get ( this ) . Height = 850 ;
32
38
WindowManager . Get ( this ) . MinHeight = 850 ;
33
39
34
- WindowManager . Get ( this ) . IsResizable = false ;
35
- WindowManager . Get ( this ) . IsMaximizable = false ;
36
-
37
40
CenterWindowOnScreen ( ) ;
38
41
ExtendsContentIntoTitleBar = true ;
39
42
40
43
LoadText ( ) ;
41
44
45
+ // Setup root list
46
+ RootList = new List < IConfigurationItem > ( ) ;
47
+ foreach ( IConfigurationItem item in App . _host . Services . GetServices < LinksViewModel > ( ) )
48
+ {
49
+ /*if (!item.Type.ToString().Contains("SubMenu"))*/ RootList . Add ( item ) ;
50
+ }
51
+ foreach ( IConfigurationItem item in App . _host . Services . GetServices < ConfigurationItemViewModel > ( ) )
52
+ {
53
+ /*if (!item.Type.ToString().Contains("SubMenu"))*/ RootList . Add ( item ) ;
54
+ }
55
+ foreach ( IConfigurationItem item in App . _host . Services . GetServices < MultiOptionConfigurationItemViewModel > ( ) )
56
+ {
57
+ /*if (!item.Type.ToString().Contains("SubMenu"))*/ RootList . Add ( item ) ;
58
+ }
59
+ foreach ( IConfigurationItem item in App . _host . Services . GetServices < ConfigurationSubMenuViewModel > ( ) )
60
+ {
61
+ /*if (!item.Type.ToString().Contains("SubMenu"))*/ RootList . Add ( item ) ;
62
+ }
63
+ foreach ( IConfigurationItem item in App . _host . Services . GetServices < ConfigurationButtonViewModel > ( ) )
64
+ {
65
+ /*if (!item.Type.ToString().Contains("SubMenu"))*/ RootList . Add ( item ) ;
66
+ }
67
+ App . RootList = this . RootList ;
42
68
NavigationViewControl . SelectedItem = NavigationViewControl . MenuItems . OfType < NavigationViewItem > ( ) . First ( ) ;
43
69
ContentFrame . Navigate (
44
70
typeof ( Views . HomePage ) ,
@@ -48,7 +74,7 @@ public MainWindow()
48
74
SetTitleBar ( AppTitleBar ) ;
49
75
50
76
if ( RegistryHelper . IsMatch ( "HKLM\\ SOFTWARE\\ AtlasOS\\ Toolbox" , "OnStartup" , 1 ) ) this . Closed += AppBehaviorHelper . HideApp ;
51
- else this . Closed += AppBehaviorHelper . CloseApp ;
77
+ else this . Closed += AppBehaviorHelper . CloseApp ;
52
78
}
53
79
54
80
public void LoadText ( )
@@ -89,7 +115,8 @@ private void NavigationViewControl_ItemInvoked(NavigationView sender,
89
115
//var NavView = sender as NavigationView;
90
116
//if (NavView.SelectedItem == args.InvokedItemContainer) { return; };
91
117
92
- if ( App . CurrentCategory == args . InvokedItemContainer . Tag . ToString ( ) || ( App . CurrentCategory == "SettingsItem" && args . IsSettingsInvoked == true ) ) { return ; } ;
118
+ if ( App . CurrentCategory == args . InvokedItemContainer . Tag . ToString ( ) || ( App . CurrentCategory == "SettingsItem" && args . IsSettingsInvoked == true ) ) { return ; }
119
+ ;
93
120
94
121
App . CurrentCategory = args . InvokedItemContainer . Tag . ToString ( ) ;
95
122
if ( args . IsSettingsInvoked == true )
@@ -99,7 +126,13 @@ private void NavigationViewControl_ItemInvoked(NavigationView sender,
99
126
return ;
100
127
}
101
128
102
- switch ( args . InvokedItemContainer . Tag . ToString ( ) )
129
+ Navigate ( args . InvokedItemContainer . Tag . ToString ( ) ) ;
130
+ App . XamlRoot = this . Content . XamlRoot ;
131
+ }
132
+
133
+ private void Navigate ( string tag )
134
+ {
135
+ switch ( tag )
103
136
{
104
137
case "SettingsPage" :
105
138
App . CurrentCategory = "SettingsItem" ;
@@ -113,7 +146,7 @@ private void NavigationViewControl_ItemInvoked(NavigationView sender,
113
146
) ;
114
147
break ;
115
148
case "AtlasToolbox.Views.HomePage" :
116
- Type newPage = Type . GetType ( args . InvokedItemContainer . Tag . ToString ( ) ) ;
149
+ Type newPage = Type . GetType ( tag ) ;
117
150
ContentFrame . Navigate (
118
151
newPage ,
119
152
null ,
@@ -126,7 +159,6 @@ private void NavigationViewControl_ItemInvoked(NavigationView sender,
126
159
new DrillInNavigationTransitionInfo ( ) ) ;
127
160
break ;
128
161
}
129
- App . XamlRoot = this . Content . XamlRoot ;
130
162
}
131
163
132
164
public void GoBack ( )
@@ -175,6 +207,7 @@ private void NavigateTo()
175
207
}
176
208
}
177
209
210
+
178
211
/// <summary>
179
212
/// Creates a ContentDialog with the required type
180
213
/// </summary>
@@ -279,5 +312,47 @@ private void AtlasButton_Click(object sender, RoutedEventArgs e)
279
312
timesClicked ++ ;
280
313
}
281
314
}
315
+
316
+ private void AutoSuggestBox_SuggestionChosen ( AutoSuggestBox sender , AutoSuggestBoxSuggestionChosenEventArgs args )
317
+ {
318
+ var configItem = RootList . Where ( item => item . Name == args . SelectedItem . ToString ( ) ) . FirstOrDefault ( ) ;
319
+ string type = configItem . Type . ToString ( ) ;
320
+
321
+ if ( configItem is not null )
322
+ {
323
+ NavigationViewControl . SelectedItem = NavigationViewControl . MenuItems
324
+ . OfType < NavigationViewItem > ( )
325
+ . First ( n => n . Tag . Equals ( configItem . Type . ToString ( ) ) ) ;
326
+ App . CurrentCategory = configItem . Type . ToString ( ) ;
327
+ Navigate ( configItem . Type . ToString ( ) ) ;
328
+ }
329
+ }
330
+
331
+ private void AutoSuggestBox_TextChanged ( AutoSuggestBox sender , AutoSuggestBoxTextChangedEventArgs args )
332
+ {
333
+ // Since selecting an item will also change the text,
334
+ // only listen to changes caused by user entering text.
335
+ if ( args . Reason == AutoSuggestionBoxTextChangeReason . UserInput )
336
+ {
337
+ var suitableItems = new List < string > ( ) ;
338
+ var splitText = sender . Text . ToLower ( ) . Split ( " " ) ;
339
+ foreach ( var viewModel in RootList )
340
+ {
341
+ var found = splitText . All ( ( key ) =>
342
+ {
343
+ return viewModel . Name . ToLower ( ) . Contains ( key ) ;
344
+ } ) ;
345
+ if ( found )
346
+ {
347
+ suitableItems . Add ( viewModel . Name ) ;
348
+ }
349
+ }
350
+ if ( suitableItems . Count == 0 )
351
+ {
352
+ suitableItems . Add ( "No results found" ) ;
353
+ }
354
+ sender . ItemsSource = suitableItems ;
355
+ }
356
+ }
282
357
}
283
358
}
0 commit comments