aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Editors/ParameterizedEditor.xaml.cs
blob: 30f1974d7985347e0b752418902d82875beaa970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Core;
using Tango.DragAndDrop;
using Tango.SharedUI;

namespace Tango.SharedUI.Editors
{
    /// <summary>
    /// Represents a scrollable list of auto generated editable controls for objects which inherits from <see cref="IParameterized"/>.
    /// </summary>
    public partial class ParameterizedEditor : UserControl
    {
        public class GeneratingItemsEventArgs : EventArgs
        {
            public IEnumerable<ParameterItem> Source { get; set; }
            public IEnumerable<ParameterItem> Result { get; set; }
        }

        public event EventHandler<GeneratingItemsEventArgs> GeneratingItems;

        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterizedEditor"/> class.
        /// </summary>
        public ParameterizedEditor()
        {
            InitializeComponent();

            DraggingSurface = draggingSurface;
        }


        /// <summary>
        /// Gets or sets the parameters.
        /// </summary>
        public List<ParameterItem> Parameters
        {
            get { return (List<ParameterItem>)GetValue(ParametersProperty); }
            set { SetValue(ParametersProperty, value); }
        }
        public static readonly DependencyProperty ParametersProperty =
            DependencyProperty.Register("Parameters", typeof(List<ParameterItem>), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the dragging surface.
        /// </summary>
        public DraggingSurface DraggingSurface
        {
            get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); }
            set { SetValue(DraggingSurfaceProperty, value); }
        }
        public static readonly DependencyProperty DraggingSurfaceProperty =
            DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(ParameterizedEditor), new PropertyMetadata(null));


        /// <summary>
        /// Gets or sets the items panel.
        /// </summary>
        public ItemsPanelTemplate ItemsPanel
        {
            get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); }
            set { SetValue(ItemsPanelProperty, value); }
        }
        public static readonly DependencyProperty ItemsPanelProperty =
            DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the parameterized object.
        /// </summary>
        public IParameterized ParameterizedObject
        {
            get { return (IParameterized)GetValue(ParameterizedObjectProperty); }
            set { SetValue(ParameterizedObjectProperty, value); }
        }
        public static readonly DependencyProperty ParameterizedObjectProperty =
            DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterizedEditor), new PropertyMetadata(null,(d,e) => (d as ParameterizedEditor).OnParameterizedObjectChanged()));

        /// <summary>
        /// Gets or sets a single item padding.
        /// </summary>
        public Thickness ItemPadding
        {
            get { return (Thickness)GetValue(ItemPaddingProperty); }
            set { SetValue(ItemPaddingProperty, value); }
        }
        public static readonly DependencyProperty ItemPaddingProperty =
            DependencyProperty.Register("ItemPadding", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));

        /// <summary>
        /// Gets or sets a single item margin.
        /// </summary>
        public Thickness ItemMargin
        {
            get { return (Thickness)GetValue(ItemMarginProperty); }
            set { SetValue(ItemMarginProperty, value); }
        }
        public static readonly DependencyProperty ItemMarginProperty =
            DependencyProperty.Register("ItemMargin", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));

        /// <summary>
        /// Gets or sets a single item minimum height.
        /// </summary>
        public double ItemMinHeight
        {
            get { return (double)GetValue(ItemMinHeightProperty); }
            set { SetValue(ItemMinHeightProperty, value); }
        }
        public static readonly DependencyProperty ItemMinHeightProperty =
            DependencyProperty.Register("ItemMinHeight", typeof(double), typeof(ParameterizedEditor), new PropertyMetadata(0.0));

        /// <summary>
        /// Gets or sets a single item label margin.
        /// </summary>
        public Thickness ItemLabelMargin
        {
            get { return (Thickness)GetValue(ItemLabelMarginProperty); }
            set { SetValue(ItemLabelMarginProperty, value); }
        }
        public static readonly DependencyProperty ItemLabelMarginProperty =
            DependencyProperty.Register("ItemLabelMargin", typeof(Thickness), typeof(ParameterizedEditor), new PropertyMetadata(new Thickness()));

        #region Templates

        /// <summary>
        /// Gets or sets the double template.
        /// </summary>
        public DataTemplate DoubleTemplate
        {
            get { return (DataTemplate)GetValue(DoubleTemplateProperty); }
            set { SetValue(DoubleTemplateProperty, value); }
        }
        public static readonly DependencyProperty DoubleTemplateProperty =
            DependencyProperty.Register("DoubleTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the int32 template.
        /// </summary>
        public DataTemplate Int32Template
        {
            get { return (DataTemplate)GetValue(Int32TemplateProperty); }
            set { SetValue(Int32TemplateProperty, value); }
        }
        public static readonly DependencyProperty Int32TemplateProperty =
            DependencyProperty.Register("Int32Template", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the single template.
        /// </summary>
        public DataTemplate SingleTemplate
        {
            get { return (DataTemplate)GetValue(SingleTemplateProperty); }
            set { SetValue(SingleTemplateProperty, value); }
        }
        public static readonly DependencyProperty SingleTemplateProperty =
            DependencyProperty.Register("SingleTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the double up down template.
        /// </summary>
        public DataTemplate DoubleUpDownTemplate
        {
            get { return (DataTemplate)GetValue(DoubleUpDownTemplateProperty); }
            set { SetValue(DoubleUpDownTemplateProperty, value); }
        }
        public static readonly DependencyProperty DoubleUpDownTemplateProperty =
            DependencyProperty.Register("DoubleUpDownTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the boolean template.
        /// </summary>
        public DataTemplate BooleanTemplate
        {
            get { return (DataTemplate)GetValue(BooleanTemplateProperty); }
            set { SetValue(BooleanTemplateProperty, value); }
        }
        public static readonly DependencyProperty BooleanTemplateProperty =
            DependencyProperty.Register("BooleanTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the enum template.
        /// </summary>
        public DataTemplate EnumTemplate
        {
            get { return (DataTemplate)GetValue(EnumTemplateProperty); }
            set { SetValue(EnumTemplateProperty, value); }
        }
        public static readonly DependencyProperty EnumTemplateProperty =
            DependencyProperty.Register("EnumTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the color template.
        /// </summary>
        public DataTemplate ColorTemplate
        {
            get { return (DataTemplate)GetValue(ColorTemplateProperty); }
            set { SetValue(ColorTemplateProperty, value); }
        }
        public static readonly DependencyProperty ColorTemplateProperty =
            DependencyProperty.Register("ColorTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the brush template.
        /// </summary>
        public DataTemplate BrushTemplate
        {
            get { return (DataTemplate)GetValue(BrushTemplateProperty); }
            set { SetValue(BrushTemplateProperty, value); }
        }
        public static readonly DependencyProperty BrushTemplateProperty =
            DependencyProperty.Register("BrushTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));

        /// <summary>
        /// Gets or sets the string template.
        /// </summary>
        public DataTemplate StringTemplate
        {
            get { return (DataTemplate)GetValue(StringTemplateProperty); }
            set { SetValue(StringTemplateProperty, value); }
        }
        public static readonly DependencyProperty StringTemplateProperty =
            DependencyProperty.Register("StringTemplate", typeof(DataTemplate), typeof(ParameterizedEditor), new PropertyMetadata(null));


        #endregion

        private void OnParameterizedObjectChanged()
        {
            if (ParameterizedObject != null)
            {
                GeneratingItemsEventArgs e = new GeneratingItemsEventArgs();
                e.Source = ParameterizedObject.Parameters;
                e.Result = ParameterizedObject.Parameters;

                GeneratingItems?.Invoke(this, e);

                Parameters = e.Result.ToList();
            }
            else
            {
                Parameters = null;
            }
        }
    }
}