1
1
using Microsoft . Extensions . Logging ;
2
2
using OnnxStack . StableDiffusion . Config ;
3
+ using OnnxStack . StableDiffusion . Enums ;
3
4
using OnnxStack . UI . Commands ;
4
5
using OnnxStack . UI . Models ;
5
6
using OnnxStack . UI . Services ;
6
- using OnnxStack . UI . Views ;
7
- using System ;
8
7
using System . Collections . Generic ;
9
8
using System . Collections . ObjectModel ;
10
9
using System . ComponentModel ;
@@ -28,34 +27,27 @@ public partial class AddModelDialog : Window, INotifyPropertyChanged
28
27
private string _modelName ;
29
28
private IModelFactory _modelFactory ;
30
29
private OnnxStackUIConfig _settings ;
31
- private ModelTemplateViewModel _modelTemplate ;
30
+ private StableDiffusionModelTemplate _modelTemplate ;
32
31
private StableDiffusionModelSet _modelSetResult ;
33
32
34
33
public AddModelDialog ( OnnxStackUIConfig settings , IModelFactory modelFactory , ILogger < AddModelDialog > logger )
35
34
{
36
35
_logger = logger ;
37
36
_settings = settings ;
38
37
_modelFactory = modelFactory ;
39
- WindowCloseCommand = new AsyncRelayCommand ( WindowClose ) ;
40
- WindowRestoreCommand = new AsyncRelayCommand ( WindowRestore ) ;
41
- WindowMinimizeCommand = new AsyncRelayCommand ( WindowMinimize ) ;
42
- WindowMaximizeCommand = new AsyncRelayCommand ( WindowMaximize ) ;
43
38
SaveCommand = new AsyncRelayCommand ( Save , CanExecuteSave ) ;
44
39
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 ( ) ;
47
42
InitializeComponent ( ) ;
48
43
}
49
- public AsyncRelayCommand WindowMinimizeCommand { get ; }
50
- public AsyncRelayCommand WindowRestoreCommand { get ; }
51
- public AsyncRelayCommand WindowMaximizeCommand { get ; }
52
- public AsyncRelayCommand WindowCloseCommand { get ; }
44
+
53
45
public AsyncRelayCommand SaveCommand { get ; }
54
46
public AsyncRelayCommand CancelCommand { get ; }
55
47
public ObservableCollection < ValidationResult > ValidationResults { get ; set ; } = new ObservableCollection < ValidationResult > ( ) ;
56
- public List < ModelTemplateViewModel > ModelTemplates { get ; set ; }
48
+ public List < StableDiffusionModelTemplate > ModelTemplates { get ; set ; }
57
49
58
- public ModelTemplateViewModel ModelTemplate
50
+ public StableDiffusionModelTemplate ModelTemplate
59
51
{
60
52
get { return _modelTemplate ; }
61
53
set { _modelTemplate = value ; NotifyPropertyChanged ( ) ; CreateModelSet ( ) ; }
@@ -78,7 +70,7 @@ public string ModelFolder
78
70
set
79
71
{
80
72
_modelFolder = value ;
81
- if ( _modelTemplate is not null && ! _modelTemplate . IsUserTemplate )
73
+ if ( _modelTemplate is not null )
82
74
_modelName = string . IsNullOrEmpty ( _modelFolder )
83
75
? string . Empty
84
76
: Path . GetFileName ( _modelFolder ) ;
@@ -94,31 +86,11 @@ public StableDiffusionModelSet ModelSetResult
94
86
get { return _modelSetResult ; }
95
87
}
96
88
97
- private bool _enableTemplateSelection = true ;
98
-
99
- public bool EnableTemplateSelection
100
- {
101
- get { return _enableTemplateSelection ; }
102
- set { _enableTemplateSelection = value ; NotifyPropertyChanged ( ) ; }
103
- }
104
89
105
- private bool _enableNameSelection = true ;
106
- public bool EnableNameSelection
107
- {
108
- get { return _enableNameSelection ; }
109
- set { _enableNameSelection = value ; NotifyPropertyChanged ( ) ; }
110
- }
111
90
112
91
113
- public bool ShowDialog ( ModelTemplateViewModel selectedTemplate = null )
92
+ public new bool ShowDialog ( )
114
93
{
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
- }
122
94
return base . ShowDialog ( ) ?? false ;
123
95
}
124
96
@@ -127,15 +99,15 @@ private void CreateModelSet()
127
99
{
128
100
_modelSetResult = null ;
129
101
ValidationResults . Clear ( ) ;
102
+ if ( _modelTemplate is null )
103
+ return ;
130
104
if ( string . IsNullOrEmpty ( _modelFolder ) )
131
105
return ;
132
106
133
- _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate . StableDiffusionTemplate ) ;
107
+ _modelSetResult = _modelFactory . CreateStableDiffusionModelSet ( ModelName . Trim ( ) , ModelFolder , _modelTemplate ) ;
134
108
135
109
// 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 ) ) ;
139
111
foreach ( var validationResult in _modelSetResult . ModelConfigurations . Select ( x => new ValidationResult ( x . Type . ToString ( ) , File . Exists ( x . OnnxModelPath ) ) ) )
140
112
{
141
113
ValidationResults . Add ( validationResult ) ;
@@ -168,41 +140,6 @@ private Task Cancel()
168
140
return Task . CompletedTask ;
169
141
}
170
142
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
-
206
143
#region INotifyPropertyChanged
207
144
public event PropertyChangedEventHandler PropertyChanged ;
208
145
public void NotifyPropertyChanged ( [ CallerMemberName ] string property = "" )
0 commit comments