2626
2727using System ;
2828using System . Collections . Immutable ;
29+ using System . Diagnostics . CodeAnalysis ;
2930using Pinta . Core ;
3031
3132namespace Pinta ;
3233
33- public sealed class LayerPropertiesDialog : Gtk . Dialog
34+ [ GObject . Subclass < Gtk . Dialog > ]
35+ public sealed partial class LayerPropertiesDialog
3436{
35- private readonly LayerProperties initial_properties ;
37+ private LayerProperties initial_properties = new ( string . Empty , false , 0.0 , BlendMode . Normal ) ;
3638
3739 private double current_layer_opacity ;
3840 private bool current_layer_hidden ;
39- private string current_layer_name ;
41+ private string current_layer_name = string . Empty ;
4042 private BlendMode current_layer_blend_mode ;
4143
42- private readonly Gtk . Entry layer_name_entry ;
43- private readonly Gtk . CheckButton visibility_checkbox ;
44- private readonly Gtk . SpinButton opacity_spinner ;
45- private readonly Gtk . Scale opacity_slider ;
46- private readonly Gtk . ComboBoxText blend_combo_box ;
44+ private Gtk . Entry layer_name_entry ;
45+ private Gtk . CheckButton visibility_checkbox ;
46+ private Gtk . SpinButton opacity_spinner ;
47+ private Gtk . Scale opacity_slider ;
48+ private Gtk . ComboBoxText blend_combo_box ;
4749
48- private readonly WorkspaceManager workspace ;
50+ private WorkspaceManager workspace = null ! ; // NRT - set by factory method
4951
50- public LayerPropertiesDialog ( ChromeManager chrome , WorkspaceManager workspace )
52+ [ MemberNotNull ( nameof ( layer_name_entry ) ) ]
53+ [ MemberNotNull ( nameof ( visibility_checkbox ) ) ]
54+ [ MemberNotNull ( nameof ( opacity_slider ) ) ]
55+ [ MemberNotNull ( nameof ( opacity_spinner ) ) ]
56+ [ MemberNotNull ( nameof ( blend_combo_box ) ) ]
57+ partial void Initialize ( )
5158 {
5259 const int spacing = 6 ;
5360
54- Document doc = workspace . ActiveDocument ;
55-
56- string currentLayerName = doc . Layers . CurrentUserLayer . Name ;
57- bool currentLayerHidden = doc . Layers . CurrentUserLayer . Hidden ;
58- double currentLayerOpacity = doc . Layers . CurrentUserLayer . Opacity ;
59- BlendMode currentLayerBlendMode = doc . Layers . CurrentUserLayer . BlendMode ;
60-
61- LayerProperties initialProperties = new (
62- currentLayerName ,
63- currentLayerHidden ,
64- currentLayerOpacity ,
65- currentLayerBlendMode ) ;
66-
6761 Gtk . Label nameLabel = Gtk . Label . New ( Translations . GetString ( "Name:" ) ) ;
6862 nameLabel . Halign = Gtk . Align . End ;
6963
7064 Gtk . Entry layerNameEntry = Gtk . Entry . New ( ) ;
7165 layerNameEntry . Hexpand = true ;
7266 layerNameEntry . Halign = Gtk . Align . Fill ;
73- layerNameEntry . SetText ( initialProperties . Name ) ;
7467 layerNameEntry . OnChanged += OnLayerNameChanged ;
7568 layerNameEntry . SetActivatesDefault ( true ) ;
7669
7770 Gtk . CheckButton visibilityCheckbox = Gtk . CheckButton . NewWithLabel ( Translations . GetString ( "Visible" ) ) ;
78- visibilityCheckbox . Active = ! initialProperties . Hidden ;
7971 visibilityCheckbox . OnToggled += OnVisibilityToggled ;
8072
8173 Gtk . Label blendLabel = Gtk . Label . New ( Translations . GetString ( "Blend Mode" ) + ":" ) ;
8274 blendLabel . Halign = Gtk . Align . End ;
8375
84- var allBlendmodes = UserBlendOps . GetAllBlendModeNames ( ) . ToImmutableArray ( ) ;
85- var index = allBlendmodes . IndexOf ( UserBlendOps . GetBlendModeName ( currentLayerBlendMode ) ) ;
86-
8776 Gtk . ComboBoxText blendComboBox = Gtk . ComboBoxText . New ( ) ;
8877
8978 foreach ( string name in UserBlendOps . GetAllBlendModeNames ( ) )
9079 blendComboBox . AppendText ( name ) ;
9180
9281 blendComboBox . Hexpand = true ;
9382 blendComboBox . Halign = Gtk . Align . Fill ;
94- blendComboBox . Active = index ;
9583 blendComboBox . OnChanged += OnBlendModeChanged ;
9684
9785 Gtk . Label opacityLabel = Gtk . Label . New ( Translations . GetString ( "Opacity:" ) ) ;
@@ -100,7 +88,6 @@ public LayerPropertiesDialog (ChromeManager chrome, WorkspaceManager workspace)
10088 Gtk . SpinButton opacitySpinner = Gtk . SpinButton . NewWithRange ( 0 , 100 , 1 ) ;
10189 opacitySpinner . Adjustment ! . PageIncrement = 10 ;
10290 opacitySpinner . ClimbRate = 1 ;
103- opacitySpinner . Value = Math . Round ( initialProperties . Opacity * 100 ) ;
10491 opacitySpinner . OnValueChanged += OnOpacitySpinnerChanged ;
10592 opacitySpinner . SetActivatesDefaultImmediate ( true ) ;
10693
@@ -109,7 +96,6 @@ public LayerPropertiesDialog (ChromeManager chrome, WorkspaceManager workspace)
10996 opacitySlider . Adjustment ! . PageIncrement = 10 ;
11097 opacitySlider . Hexpand = true ;
11198 opacitySlider . Halign = Gtk . Align . Fill ;
112- opacitySlider . SetValue ( Math . Round ( initialProperties . Opacity * 100 ) ) ;
11399 opacitySlider . OnValueChanged += OnOpacitySliderChanged ;
114100
115101 Gtk . Box opacityBox = Gtk . Box . New ( Gtk . Orientation . Horizontal , spacing ) ;
@@ -131,7 +117,6 @@ public LayerPropertiesDialog (ChromeManager chrome, WorkspaceManager workspace)
131117 // --- Initialization (Gtk.Window)
132118
133119 Title = Translations . GetString ( "Layer Properties" ) ;
134- TransientFor = chrome . MainWindow ;
135120 Modal = true ;
136121 DefaultWidth = 349 ;
137122 DefaultHeight = 224 ;
@@ -156,15 +141,48 @@ public LayerPropertiesDialog (ChromeManager chrome, WorkspaceManager workspace)
156141 blend_combo_box = blendComboBox ;
157142 opacity_spinner = opacitySpinner ;
158143 opacity_slider = opacitySlider ;
144+ }
145+
146+ public static LayerPropertiesDialog New ( IChromeService chrome , WorkspaceManager workspace )
147+ {
148+ LayerPropertiesDialog dialog = NewWithProperties ( [ ] ) ;
149+ dialog . Configure ( chrome , workspace ) ;
150+ return dialog ;
151+ }
152+
153+ private void Configure ( IChromeService chrome , WorkspaceManager workspace )
154+ {
155+ this . workspace = workspace ;
156+ TransientFor = chrome . MainWindow ;
157+
158+ Document doc = workspace . ActiveDocument ;
159+
160+ string currentLayerName = doc . Layers . CurrentUserLayer . Name ;
161+ bool currentLayerHidden = doc . Layers . CurrentUserLayer . Hidden ;
162+ double currentLayerOpacity = doc . Layers . CurrentUserLayer . Opacity ;
163+ BlendMode currentLayerBlendMode = doc . Layers . CurrentUserLayer . BlendMode ;
164+
165+ LayerProperties initialProperties = new (
166+ currentLayerName ,
167+ currentLayerHidden ,
168+ currentLayerOpacity ,
169+ currentLayerBlendMode ) ;
170+
171+ layer_name_entry . SetText ( initialProperties . Name ) ;
172+ visibility_checkbox . Active = ! initialProperties . Hidden ;
173+ opacity_spinner . Value = Math . Round ( initialProperties . Opacity * 100 ) ;
174+ opacity_slider . SetValue ( Math . Round ( initialProperties . Opacity * 100 ) ) ;
175+
176+ var allBlendmodes = UserBlendOps . GetAllBlendModeNames ( ) . ToImmutableArray ( ) ;
177+ var index = allBlendmodes . IndexOf ( UserBlendOps . GetBlendModeName ( currentLayerBlendMode ) ) ;
178+ blend_combo_box . Active = index ;
159179
160180 current_layer_name = currentLayerName ;
161181 current_layer_hidden = currentLayerHidden ;
162182 current_layer_opacity = currentLayerOpacity ;
163183 current_layer_blend_mode = currentLayerBlendMode ;
164184
165185 initial_properties = initialProperties ;
166-
167- this . workspace = workspace ;
168186 }
169187
170188 public bool AreLayerPropertiesUpdated =>
0 commit comments