11using Avalonia . Controls ;
22using CommunityToolkit . Mvvm . ComponentModel ;
33using CommunityToolkit . Mvvm . DependencyInjection ;
4- // using SnapX.Avalonia.ViewModels.Settings;
54using SnapX . Core ;
5+ using SnapX . Core . Upload ;
66
77namespace SnapX . Avalonia . ViewModels ;
88
@@ -14,6 +14,7 @@ public partial class SettingsMainViewVM : ViewModelBase
1414 [ ObservableProperty ]
1515 private ViewModelBase _currentPage = new SettingsHomePageViewVM ( ) ;
1616 private readonly Stack < ViewModelBase > _history = new ( ) ;
17+ [ ObservableProperty ] private string _pageTitle = string . Empty ;
1718 public bool CanGoBack => _history . Count > 0 ;
1819 private readonly Dictionary < string , Type > _pageFactory = [ ] ;
1920
@@ -23,7 +24,20 @@ public SettingsMainViewVM()
2324 RegisterPage < CustomUploaderVM > ( "CustomUploader" ) ;
2425 RegisterPage < ImportExportVM > ( "ImportExport" ) ;
2526 // RegisterPage<ScreenRecordOptionsVM>("ScreenRecordOptions");
27+ RegisterPage < DatabaseVM > ( "Database" ) ;
28+ RegisterPage < CoreUploaderVM > ( "BuiltInUploader" ) ;
29+ foreach ( var category in Enum . GetValues < UploaderCategory > ( ) )
30+ {
31+ var pageKey = category . ToString ( ) ;
32+
33+ RegisterPage < CoreUploaderVM > ( pageKey ) ;
34+ }
35+ foreach ( var UploaderService in UploaderFactory . AllServices )
36+ {
37+ var pageKey = UploaderService . EnumValueObject . ToString ( ) ;
2638
39+ RegisterPage < CoreUploaderVM > ( "!" + pageKey ) ;
40+ }
2741 }
2842
2943 private void RegisterPage < T > ( string key )
@@ -48,7 +62,7 @@ private void RegisterPage<T>(string key)
4862 _pageFactory [ variant ] = type ;
4963 }
5064 }
51- public void Navigate ( string destinationTag )
65+ public void Navigate ( string ? categoryTag , string destinationTag )
5266 {
5367 DebugHelper . WriteLine ( "SettingsMainViewVM.Navigate: " + destinationTag ) ;
5468 if ( _pageFactory . TryGetValue ( destinationTag , out var factory ) )
@@ -63,15 +77,38 @@ public void Navigate(string destinationTag)
6377 DebugHelper . WriteLine ( $ "Can't get ViewModelBase on { type } . Did you register it in ViewLocator & IoC?") ;
6478 return ;
6579 }
80+ if ( destinationTag . StartsWith ( "!" ) )
81+ {
82+ var uploaderName = destinationTag . TrimStart ( '!' ) ;
83+
84+ var foundCategory = Enum . Parse < UploaderCategory > ( categoryTag ) ;
85+
86+ if ( vmb is CoreUploaderVM coreVM )
87+ {
88+ coreVM . NavigateToCategory ( foundCategory ) ;
89+ coreVM . SelectUploader ( uploaderName ) ;
90+ }
91+ }
92+ if ( Enum . TryParse < UploaderCategory > ( destinationTag , out var category ) )
93+ {
94+ if ( vmb is CoreUploaderVM coreVM )
95+ {
96+ coreVM . NavigateToCategory ( category ) ;
97+ }
98+ }
99+
66100 _history . Push ( CurrentPage ) ;
101+ PageTitle = $ "Settings for { Core . SnapXL . AppName } : { categoryTag ?? destinationTag } ";
67102 CurrentPage = vmb ;
68103 }
69104 else
70105 {
71106 DebugHelper . WriteLine ( $ "SettingsMainViewVM.Navigate: Unknown destination, defaulting to home page") ;
72107 // fallback, e.g. Home page
73108 _history . Push ( CurrentPage ) ;
74- CurrentPage = new SettingsHomePageViewVM ( ) ;
109+ CurrentPage = ( Design . IsDesignMode
110+ ? Activator . CreateInstance < SettingsHomePageViewVM > ( )
111+ : Ioc . Default . GetService < SettingsHomePageViewVM > ( ) ) ! ;
75112 }
76113 }
77114 public bool TryGetPage ( string tag , out Type type )
0 commit comments