Skip to content

Commit ebc1b0b

Browse files
committed
cleanup
1 parent 5063a73 commit ebc1b0b

File tree

12 files changed

+568
-519
lines changed

12 files changed

+568
-519
lines changed

PdfFileType/Export/PdfExporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Threading;
1212
using PaintDotNet;
1313
using PaintDotNet.PropertySystem;
14+
using PaintDotNet.PropertySystem.Extensions;
1415
using PaintDotNet.Rendering;
1516

1617
namespace PdfFileTypePlugin.Export

PdfFileType/FodyWeavers.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2-
<ILMerge NamespacePrefix="" IncludeResources="\.icc$">
3-
<IncludeAssemblies>PDFiumSharp|UglyToad.PdfPig.*</IncludeAssemblies>
4-
<FullImport>false</FullImport>
5-
</ILMerge>
2+
<ILMerge NamespacePrefix="" IncludeResources="\.icc$" IncludeAssemblies="PDFiumSharp|UglyToad.PdfPig.*" FullImport="false" />
63
</Weavers>

PdfFileType/PaintDotNet/IndirectUI/ControlInfoExtensions.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

PdfFileType/PaintDotNet/IndirectUI/PropertyControlInfoExtensions.cs renamed to PdfFileType/PaintDotNet/IndirectUI/Extensions/PropertyControlInfoExtensions.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright 2022 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

4-
using System;
54
using PaintDotNet.PropertySystem;
5+
using System;
6+
using System.Drawing;
7+
using System.IO;
68

7-
namespace PaintDotNet.IndirectUI
9+
namespace PaintDotNet.IndirectUI.Extensions
810
{
9-
internal static class PropertyControlInfoExtensions
11+
public static class PropertyControlInfoExtensions
1012
{
1113
private static PropertyControlInfo SetPropertyControlValue(this PropertyControlInfo pci, ControlInfoPropertyNames controlPropertyName, object controlPropertyValue)
1214
{
@@ -20,7 +22,7 @@ private static PropertyControlInfo SetPropertyControlValue(this PropertyControlI
2022
/// <strong>Supported Controls</strong>:
2123
/// <see cref="PropertyControlType.FileChooser" />
2224
/// </remarks>
23-
public static PropertyControlInfo AllowAllFiles(this PropertyControlInfo pci, bool value)
25+
public static PropertyControlInfo AllowAllFiles(this PropertyControlInfo pci, bool value = true)
2426
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.AllowAllFiles, value);
2527

2628
/// <remarks>
@@ -81,14 +83,14 @@ public static PropertyControlInfo Footnote(this PropertyControlInfo pci, string
8183
/// <strong>Supported Controls</strong>:
8284
/// <see cref="PropertyControlType.TextBox" />
8385
/// </remarks>
84-
public static PropertyControlInfo Multiline(this PropertyControlInfo pci, bool value)
86+
public static PropertyControlInfo Multiline(this PropertyControlInfo pci, bool value = true)
8587
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.Multiline, value);
8688

8789
/// <remarks>
8890
/// <strong>Supported Controls</strong>:
8991
/// <see cref="PropertyControlType.Slider" /> using <see cref="Int32Property"/> or <see cref="DoubleProperty"/>
9092
/// </remarks>
91-
public static PropertyControlInfo RangeWraps(this PropertyControlInfo pci, bool value)
93+
public static PropertyControlInfo RangeWraps(this PropertyControlInfo pci, bool value = true)
9294
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.RangeWraps, value);
9395

9496
/// <remarks>
@@ -99,7 +101,7 @@ public static PropertyControlInfo RangeWraps(this PropertyControlInfo pci, bool
99101
/// <see cref="PropertyControlType.RollBallAndSliders" />,
100102
/// <see cref="PropertyControlType.ColorWheel" />
101103
/// </remarks>
102-
public static PropertyControlInfo ShowResetButton(this PropertyControlInfo pci, bool value)
104+
public static PropertyControlInfo ShowResetButton(this PropertyControlInfo pci, bool value = true)
103105
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.ShowResetButton, value);
104106

105107
/// <remarks>
@@ -139,7 +141,7 @@ public static PropertyControlInfo SliderLargeChangeZ(this PropertyControlInfo pc
139141
/// <strong>Supported Controls</strong>:
140142
/// <see cref="PropertyControlType.Slider" /> using <see cref="Int32Property"/>
141143
/// </remarks>
142-
public static PropertyControlInfo SliderShowTickMarks(this PropertyControlInfo pci, bool value)
144+
public static PropertyControlInfo SliderShowTickMarks(this PropertyControlInfo pci, bool value = true)
143145
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.SliderShowTickMarks, value);
144146

145147
/// <remarks>
@@ -148,7 +150,7 @@ public static PropertyControlInfo SliderShowTickMarks(this PropertyControlInfo p
148150
/// <see cref="PropertyControlType.PanAndSlider" />,
149151
/// <see cref="PropertyControlType.RollBallAndSliders" />
150152
/// </remarks>
151-
public static PropertyControlInfo SliderShowTickMarksX(this PropertyControlInfo pci, bool value)
153+
public static PropertyControlInfo SliderShowTickMarksX(this PropertyControlInfo pci, bool value = true)
152154
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.SliderShowTickMarksX, value);
153155

154156
/// <remarks>
@@ -157,15 +159,15 @@ public static PropertyControlInfo SliderShowTickMarksX(this PropertyControlInfo
157159
/// <see cref="PropertyControlType.PanAndSlider" />,
158160
/// <see cref="PropertyControlType.RollBallAndSliders" />
159161
/// </remarks>
160-
public static PropertyControlInfo SliderShowTickMarksY(this PropertyControlInfo pci, bool value)
162+
public static PropertyControlInfo SliderShowTickMarksY(this PropertyControlInfo pci, bool value = true)
161163
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.SliderShowTickMarksY, value);
162164

163165
/// <remarks>
164166
/// <strong>Supported Controls</strong>:
165167
/// <see cref="PropertyControlType.Slider" /> using <see cref="DoubleVector3Property"/>,
166168
/// <see cref="PropertyControlType.RollBallAndSliders" />
167169
/// </remarks>
168-
public static PropertyControlInfo SliderShowTickMarksZ(this PropertyControlInfo pci, bool value)
170+
public static PropertyControlInfo SliderShowTickMarksZ(this PropertyControlInfo pci, bool value = true)
169171
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.SliderShowTickMarksZ, value);
170172

171173
/// <remarks>
@@ -207,6 +209,26 @@ public static PropertyControlInfo SliderSmallChangeZ(this PropertyControlInfo pc
207209
public static PropertyControlInfo StaticImageUnderlay(this PropertyControlInfo pci, ImageResource value)
208210
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.StaticImageUnderlay, value);
209211

212+
/// <remarks>
213+
/// <strong>Supported Controls</strong>:
214+
/// <see cref="DoubleVectorProperty"/>,
215+
/// </remarks>
216+
public static PropertyControlInfo StaticImageUnderlay(this PropertyControlInfo pci, byte[] bytes)
217+
{
218+
using (var ms = new MemoryStream(bytes))
219+
{
220+
pci.StaticImageUnderlay(ImageResource.FromImage(Image.FromStream(ms)));
221+
}
222+
return pci;
223+
}
224+
225+
/// <remarks>
226+
/// <strong>Supported Controls</strong>:
227+
/// <see cref="DoubleVectorProperty"/>,
228+
/// </remarks>
229+
public static PropertyControlInfo StaticImageUnderlay(this PropertyControlInfo pci, string base64string)
230+
=> pci.StaticImageUnderlay(Convert.FromBase64String(base64string));
231+
210232
/// <remarks>
211233
/// <strong>Supported Controls</strong>:
212234
/// <see cref="PropertyControlType.Slider" /> using <see cref="Int32Property"/> or <see cref="DoubleProperty"/>,
@@ -245,7 +267,7 @@ public static PropertyControlInfo UpDownIncrementZ(this PropertyControlInfo pci,
245267
/// <strong>Supported Controls</strong>:
246268
/// <see cref="PropertyControlType.Slider" /> using <see cref="DoubleProperty"/> or <see cref="DoubleVectorProperty"/>
247269
/// </remarks>
248-
public static PropertyControlInfo UseExponentialScale(this PropertyControlInfo pci, bool value)
270+
public static PropertyControlInfo UseExponentialScale(this PropertyControlInfo pci, bool value = true)
249271
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.UseExponentialScale, value);
250272

251273
public static PropertyControlInfo WindowHelpContent(this PropertyControlInfo pci, string value)
@@ -254,7 +276,7 @@ public static PropertyControlInfo WindowHelpContent(this PropertyControlInfo pci
254276
public static PropertyControlInfo WindowHelpContentType(this PropertyControlInfo pci, WindowHelpContentType value)
255277
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.WindowHelpContentType, value);
256278

257-
public static PropertyControlInfo WindowIsSizable(this PropertyControlInfo pci, bool value)
279+
public static PropertyControlInfo WindowIsSizable(this PropertyControlInfo pci, bool value = true)
258280
=> pci.SetPropertyControlValue(ControlInfoPropertyNames.WindowIsSizable, value);
259281

260282
public static PropertyControlInfo WindowTitle(this PropertyControlInfo pci, string value)
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2022 Osman Tunçelli. All rights reserved.
2+
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
3+
4+
using PaintDotNet.IndirectUI.Extensions;
5+
using PaintDotNet.PropertySystem;
6+
using System;
7+
using System.Collections;
8+
using System.Collections.Generic;
9+
using System.Collections.ObjectModel;
10+
using System.Linq;
11+
12+
namespace PaintDotNet.IndirectUI
13+
{
14+
public sealed class PropertyControlInfoCollection : IEnumerable<PropertyControlInfo>, IEnumerable
15+
{
16+
#region Fields
17+
18+
private readonly HashSet<PropertyName> addedToPanel = new HashSet<PropertyName>();
19+
20+
private readonly KeyedPropertyControlInfoCollection items = new KeyedPropertyControlInfoCollection();
21+
22+
#endregion
23+
24+
#region Properties
25+
26+
public IReadOnlyList<Property> Properties => items.Select(pci => pci.Property).ToList();
27+
28+
public IReadOnlyList<PropertyName> PropertyNames => Properties.Select(p => (PropertyName)p.Name).ToList();
29+
30+
public PropertyControlInfo this[PropertyName propertyName] => items[propertyName];
31+
32+
public int Count => items.Count;
33+
34+
PropertyControlInfo this[int index] => GetPropertyControlInfoAt(index);
35+
36+
#endregion
37+
38+
#region Constructors
39+
40+
public PropertyControlInfoCollection(IEnumerable<Property> props)
41+
{
42+
foreach (Property prop in props)
43+
{
44+
PropertyControlInfo pci = PropertyControlInfo.CreateFor(prop);
45+
pci.DisplayName(prop.Name);
46+
items.Add(pci);
47+
}
48+
}
49+
50+
#endregion
51+
52+
#region Methods
53+
54+
public PropertyControlInfoCollection Configure(PropertyName propertyName, Func<PropertyControlInfo, PropertyControlInfo> selector)
55+
{
56+
PropertyControlInfo pci = items[propertyName];
57+
_ = selector(pci);
58+
return this;
59+
}
60+
61+
public PropertyControlInfoCollection Configure(PropertyName propertyName, string displayName, Func<PropertyControlInfo, PropertyControlInfo> selector = null)
62+
{
63+
return Configure(propertyName, p =>
64+
{
65+
PropertyControlInfo pci = p.DisplayName(displayName);
66+
return selector?.Invoke(pci) ?? pci;
67+
});
68+
}
69+
70+
public PropertyControlInfoCollection Configure(PropertyName propertyName, string displayName, string description, Func<PropertyControlInfo, PropertyControlInfo> selector = null)
71+
{
72+
return Configure(propertyName, displayName, p =>
73+
{
74+
PropertyControlInfo pci = p.Description(description);
75+
return selector?.Invoke(pci) ?? pci;
76+
});
77+
}
78+
79+
public bool TryGetControl(PropertyName propertyName, out PropertyControlInfo pci)
80+
{
81+
#if NETCOREAPP
82+
return items.TryGetValue(propertyName, out pci);
83+
#else
84+
pci = default;
85+
if (!items.Contains(propertyName)) { return false; }
86+
pci = items[propertyName];
87+
return true;
88+
#endif
89+
}
90+
91+
public PropertyControlInfo GetPropertyControlInfoAt(int index) => ((Collection<PropertyControlInfo>)items)[index];
92+
93+
public PanelControlInfo CreatePanelControlInfo(params PropertyName[] propertyNames)
94+
{
95+
if (propertyNames == null || propertyNames.Length == 0)
96+
{
97+
propertyNames = PropertyNames.ToArray();
98+
}
99+
100+
PanelControlInfo panel = new PanelControlInfo();
101+
foreach (PropertyName propertyName in PropertyNames)
102+
{
103+
if (addedToPanel.Contains(propertyName)) { continue; }
104+
if (!propertyNames.Contains(propertyName)) { continue; }
105+
PropertyControlInfo pci = items[propertyName];
106+
panel.AddChildControl(pci);
107+
addedToPanel.Add(propertyName);
108+
}
109+
if (panel.ChildControls.Count == 0) { return null; }
110+
return panel;
111+
}
112+
113+
#endregion
114+
115+
#region IEnumerable
116+
117+
public IEnumerator<PropertyControlInfo> GetEnumerator()
118+
=> items.GetEnumerator();
119+
120+
IEnumerator IEnumerable.GetEnumerator()
121+
=> GetEnumerator();
122+
123+
#endregion
124+
125+
#region KeyedPropertyControlInfoCollection
126+
127+
private sealed class KeyedPropertyControlInfoCollection : KeyedCollection<PropertyName, PropertyControlInfo>
128+
{
129+
protected override PropertyName GetKeyForItem(PropertyControlInfo item) => (PropertyName)item.Property.Name;
130+
}
131+
132+
#endregion
133+
}
134+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Copyright 2022 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

4-
namespace PaintDotNet.PropertySystem
4+
using System;
5+
6+
namespace PaintDotNet.PropertySystem.Extensions
57
{
6-
internal static class PropertyCollectionExtensions
8+
public static class PropertyCollectionExtensions
79
{
8-
public static T GetPropertyValue<T>(this PropertyCollection collection, object propertyName)
9-
=> (T)collection.GetPropertyValue(propertyName);
10+
public static T GetPropertyValue<T>(this PropertyCollection collection, PropertyName propertyName)
11+
=> (T)Convert.ChangeType(collection.GetPropertyValue(propertyName), typeof(T));
1012

11-
public static object GetPropertyValue(this PropertyCollection collection, object propertyName)
13+
public static object GetPropertyValue(this PropertyCollection collection, PropertyName propertyName)
1214
=> collection[propertyName].Value;
1315
}
1416
}

0 commit comments

Comments
 (0)