11using Microsoft . Extensions . Logging ;
22using OnnxStack . StableDiffusion . Config ;
3+ using OnnxStack . StableDiffusion . Enums ;
34using OnnxStack . UI . Commands ;
45using OnnxStack . UI . Models ;
56using OnnxStack . UI . Services ;
6- using OnnxStack . UI . Views ;
7- using System ;
87using System . Collections . Generic ;
98using System . Collections . ObjectModel ;
109using System . ComponentModel ;
@@ -28,34 +27,27 @@ public partial class AddModelDialog : Window, INotifyPropertyChanged
2827 private string _modelName ;
2928 private IModelFactory _modelFactory ;
3029 private OnnxStackUIConfig _settings ;
31- private ModelTemplateViewModel _modelTemplate ;
30+ private StableDiffusionModelTemplate _modelTemplate ;
3231 private StableDiffusionModelSet _modelSetResult ;
3332
3433 public AddModelDialog ( OnnxStackUIConfig settings , IModelFactory modelFactory , ILogger < AddModelDialog > logger )
3534 {
3635 _logger = logger ;
3736 _settings = settings ;
3837 _modelFactory = modelFactory ;
39- WindowCloseCommand = new AsyncRelayCommand ( WindowClose ) ;
40- WindowRestoreCommand = new AsyncRelayCommand ( WindowRestore ) ;
41- WindowMinimizeCommand = new AsyncRelayCommand ( WindowMinimize ) ;
42- WindowMaximizeCommand = new AsyncRelayCommand ( WindowMaximize ) ;
4338 SaveCommand = new AsyncRelayCommand ( Save , CanExecuteSave ) ;
4439 CancelCommand = new AsyncRelayCommand ( Cancel ) ;
45- ModelTemplates = _settings . Templates . Where ( x => ! x . IsUserTemplate ) . ToList ( ) ;
46- InvalidOptions = _settings . Templates . Where ( x => x . IsUserTemplate ) . Select ( x => x . Name . ToLower ( ) ) . ToList ( ) ;
40+ ModelTemplates = new List < StableDiffusionModelTemplate > ( _modelFactory . GetStableDiffusionModelTemplates ( ) ) ;
41+ InvalidOptions = _settings . StableDiffusionModelSets . Select ( x => x . Name . ToLower ( ) ) . ToList ( ) ;
4742 InitializeComponent ( ) ;
4843 }
49- public AsyncRelayCommand WindowMinimizeCommand { get ; }
50- public AsyncRelayCommand WindowRestoreCommand { get ; }
51- public AsyncRelayCommand WindowMaximizeCommand { get ; }
52- public AsyncRelayCommand WindowCloseCommand { get ; }
44+
5345 public AsyncRelayCommand SaveCommand { get ; }
5446 public AsyncRelayCommand CancelCommand { get ; }
5547 public ObservableCollection < ValidationResult > ValidationResults { get ; set ; } = new ObservableCollection < ValidationResult > ( ) ;
56- public List < ModelTemplateViewModel > ModelTemplates { get ; set ; }
48+ public List < StableDiffusionModelTemplate > ModelTemplates { get ; set ; }
5749
58- public ModelTemplateViewModel ModelTemplate
50+ public StableDiffusionModelTemplate ModelTemplate
5951 {
6052 get { return _modelTemplate ; }
6153 set { _modelTemplate = value ; NotifyPropertyChanged ( ) ; CreateModelSet ( ) ; }
@@ -78,7 +70,7 @@ public string ModelFolder
7870 set
7971 {
8072 _modelFolder = value ;
81- if ( _modelTemplate is not null && ! _modelTemplate . IsUserTemplate )
73+ if ( _modelTemplate is not null )
8274 _modelName = string . IsNullOrEmpty ( _modelFolder )
8375 ? string . Empty
8476 : Path . GetFileName ( _modelFolder ) ;
@@ -94,31 +86,11 @@ public StableDiffusionModelSet ModelSetResult
9486 get { return _modelSetResult ; }
9587 }
9688
97- private bool _enableTemplateSelection = true ;
98-
99- public bool EnableTemplateSelection
100- {
101- get { return _enableTemplateSelection ; }
102- set { _enableTemplateSelection = value ; NotifyPropertyChanged ( ) ; }
103- }
10489
105- private bool _enableNameSelection = true ;
106- public bool EnableNameSelection
107- {
108- get { return _enableNameSelection ; }
109- set { _enableNameSelection = value ; NotifyPropertyChanged ( ) ; }
110- }
11190
11291
113- public bool ShowDialog ( ModelTemplateViewModel selectedTemplate = null )
92+ public new bool ShowDialog ( )
11493 {
115- if ( selectedTemplate is not null )
116- {
117- EnableNameSelection = ! selectedTemplate . IsUserTemplate ;
118- EnableTemplateSelection = false ;
119- ModelTemplate = selectedTemplate ;
120- ModelName = selectedTemplate . IsUserTemplate ? selectedTemplate . Name : string . Empty ;
121- }
12294 return base . ShowDialog ( ) ?? false ;
12395 }
12496
@@ -127,15 +99,15 @@ private void CreateModelSet()
12799 {
128100 _modelSetResult = null ;
129101 ValidationResults . Clear ( ) ;
102+ if ( _modelTemplate is null )
103+ return ;
130104 if ( string . IsNullOrEmpty ( _modelFolder ) )
131105 return ;
132106
133- _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate . StableDiffusionTemplate ) ;
107+ _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate ) ;
134108
135109 // Validate
136- if ( _enableNameSelection )
137- ValidationResults . Add ( new ValidationResult ( "Name" , ! InvalidOptions . Contains ( _modelName . ToLower ( ) ) && _modelName . Length > 2 && _modelName . Length < 50 ) ) ;
138-
110+ ValidationResults . Add ( new ValidationResult ( "Name" , ! InvalidOptions . Contains ( _modelName . ToLower ( ) ) && _modelName . Length > 2 && _modelName . Length < 50 ) ) ;
139111 foreach ( var validationResult in _modelSetResult . ModelConfigurations . Select ( x => new ValidationResult ( x . Type . ToString ( ) , File . Exists ( x . OnnxModelPath ) ) ) )
140112 {
141113 ValidationResults . Add ( validationResult ) ;
@@ -168,41 +140,6 @@ private Task Cancel()
168140 return Task . CompletedTask ;
169141 }
170142
171- #region BaseWindow
172-
173- private Task WindowClose ( )
174- {
175- Close ( ) ;
176- return Task . CompletedTask ;
177- }
178-
179- private Task WindowRestore ( )
180- {
181- if ( WindowState == WindowState . Maximized )
182- WindowState = WindowState . Normal ;
183- else
184- WindowState = WindowState . Maximized ;
185- return Task . CompletedTask ;
186- }
187-
188- private Task WindowMinimize ( )
189- {
190- WindowState = WindowState . Minimized ;
191- return Task . CompletedTask ;
192- }
193-
194- private Task WindowMaximize ( )
195- {
196- WindowState = WindowState . Maximized ;
197- return Task . CompletedTask ;
198- }
199-
200- private void OnContentRendered ( object sender , EventArgs e )
201- {
202- InvalidateVisual ( ) ;
203- }
204- #endregion
205-
206143 #region INotifyPropertyChanged
207144 public event PropertyChangedEventHandler PropertyChanged ;
208145 public void NotifyPropertyChanged ( [ CallerMemberName ] string property = "" )
0 commit comments