-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperties.cs
1290 lines (1139 loc) · 43.8 KB
/
Properties.cs
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using DynamicTypeDescriptor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using WinAGI.Engine;
using static WinAGI.Editor.Base;
using static WinAGI.Engine.Base;
namespace WinAGI.Editor {
/// <summary>
/// Property accessors for the AGI Game object. Used on the main form to display
/// properties, and allows them to be edited.
/// </summary>
public class GameProperties {
//string _GameID;
public GameProperties() {
}
public string GameID {
get
{
return EditGame.GameID;
}
set
{
if (ChangeGameID(value)) {
// mark any logics that use the gameID token as changed
UpdateReservedToken(EditGame.ReservedDefines.GameInfo[0].Name);
EditGame.ReservedDefines.GameInfo[0].Value = '"' + EditGame.GameID + '"';
}
}
}
public string Author {
get => EditGame.GameAuthor;
set => EditGame.GameAuthor = value;
}
public string GameDir {
get => EditGame.GameDir;
}
public string ResDir {
get => EditGame.ResDirName;
set {
// validate and change resource directory
ChangeResDir(value);
}
}
[TypeConverter(typeof(IntVerConverter))]
public string IntVer {
get => EditGame?.InterpreterVersion;
set {
// determine if a change was made:
if (EditGame.InterpreterVersion != value) {
ChangeIntVersion(value);
}
}
}
[ReadOnly(true)]
[Editor(typeof(AGIPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Description {
get => EditGame.GameDescription;
set { }
}
//[Editor(typeof(AGIPropertyEditor),
// typeof(System.Drawing.Design.UITypeEditor))]
public string GameVer {
get => EditGame.GameVersion;
set {
EditGame.GameVersion = value;
UpdateReservedToken(EditGame.ReservedDefines.GameInfo[1].Name);
EditGame.ReservedDefines.GameInfo[1].Value = '"' + EditGame.GameVersion + '"';
}
}
//[Editor(typeof(AGIPropertyEditor),
// typeof(System.Drawing.Design.UITypeEditor))]
public string GameAbout {
get => EditGame.GameAbout;
set {
EditGame.GameAbout = value;
UpdateReservedToken(EditGame.ReservedDefines.GameInfo[2].Name);
EditGame.ReservedDefines.GameInfo[2].Value = '"' + EditGame.GameAbout + '"';
}
}
public bool LayoutEditor {
get => EditGame.UseLE;
set {
EditGame.UseLE = value;
UpdateLEStatus();
}
}
public DateTime LastEdit {
get => EditGame.LastEdit; }
}
public class LogicHdrProperties {
public DynamicCustomTypeDescriptor m_dctd = null;
public LogicHdrProperties() {
GlobalDef = "(List)";
m_dctd = ProviderInstaller.Install(this);
CustomPropertyDescriptor cpd = m_dctd.GetProperty("GlobalDef");
cpd.SetIsBrowsable(EditGame.IncludeGlobals);
}
public int Count {
get => EditGame.Logics.Count;
}
public bool IncludeIDs {
get => EditGame.IncludeIDs;
set {
EditGame.IncludeIDs = value;
MDIMain.UseWaitCursor = true;
RefreshLogicIncludes();
MDIMain.UseWaitCursor = false;
}
}
public bool IncludeReserved {
get => EditGame.IncludeReserved;
set {
EditGame.IncludeReserved = value;
MDIMain.UseWaitCursor = true;
RefreshLogicIncludes();
MDIMain.UseWaitCursor = false;
}
}
public bool IncludeGlobals {
get => EditGame.IncludeGlobals;
set {
EditGame.IncludeGlobals = value;
MDIMain.UseWaitCursor = true;
RefreshLogicIncludes();
MDIMain.UseWaitCursor = false;
MDIMain.propertyGrid1.SelectedObject = new LogicHdrProperties();
}
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string GlobalDef {
get => "(List)"; set { }
}
}
public class LogicProperties {
Logic pLogic;
public LogicProperties(Logic logic) {
pLogic = logic;
}
[Editor(typeof(AGIPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public byte Number {
get => pLogic.Number;
set {
if (value != pLogic.Number) {
RenumberResource(AGIResType.Logic, pLogic.Number, value);
}
}
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string ID {
get => pLogic.ID;
set { }
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description {
get => pLogic.Description;
set { }
}
[ReadOnlyAttribute(false)]
public bool IsRoom {
get {
return pLogic.IsRoom;
}
set {
if (value != pLogic.IsRoom) {
pLogic.IsRoom = value;
pLogic.SaveProps();
if (EditGame.UseLE) {
UpdateReason reason;
if (pLogic.IsRoom) {
reason = UpdateReason.ShowRoom;
}
else {
reason = UpdateReason.RemoveRoom;
}
// update layout editor to show new room status
UpdateExitInfo(reason, SelResNum, pLogic);
}
}
// update editor
foreach (frmLogicEdit frm in LogicEditors) {
if (frm.LogicNumber == SelResNum) {
frm.EditLogic.IsRoom = value;
break;
}
}
}
}
public bool Compiled {
get => pLogic.Compiled;
}
public int Volume {
get => pLogic.Volume;
}
public int LOC {
get => pLogic.Loc;
}
public int Size {
get => pLogic.Size;
}
public int CodeSize {
get {
bool unload = !pLogic.Loaded;
if (unload) {
pLogic.Load();
}
int retval = pLogic.CodeSize;
if (unload) {
pLogic.Unload();
}
return retval;
}
}
}
public class PictureHdrProperties {
public int Count { get => EditGame.Pictures.Count; }
}
public class PictureProperties {
Picture pPicture;
public PictureProperties(Picture picture) {
pPicture = picture;
}
[Editor(typeof(AGIPropertyEditor), typeof(System.Drawing.Design.UITypeEditor))]
public byte Number {
get => pPicture.Number;
set {
if (value != pPicture.Number) {
RenumberResource(AGIResType.Picture, pPicture.Number, value);
}
}
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string ID {
get => pPicture.ID;
set { }
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description {
get => pPicture.Description;
set { }
}
public int Volume {
get => pPicture.Volume;
}
public int LOC {
get => pPicture.Loc;
}
public int Size {
get => pPicture.Size;
}
}
public class SoundHdrProperties {
public int Count { get => EditGame.Sounds.Count; }
}
public class SoundProperties {
Sound pSound;
public SoundProperties(Sound sound) {
pSound = sound;
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public byte Number {
get => pSound.Number;
set {
if (value != pSound.Number) {
RenumberResource(AGIResType.Sound, pSound.Number, value);
}
}
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string ID {
get => pSound.ID;
set { }
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description {
get => pSound.Description;
set { }
}
public int Volume {
get => pSound.Volume;
}
public int LOC {
get => pSound.Loc;
}
public int Size {
get => pSound.Size;
}
}
public class ViewHdrProperties {
public int Count { get => EditGame.Views.Count; }
}
public class ViewProperties {
Engine.View pView;
public ViewProperties(Engine.View view) {
pView = view;
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public byte Number {
get => pView.Number;
set {
if (value != pView.Number) {
RenumberResource(AGIResType.View, pView.Number, value);
}
}
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string ID {
get => pView.ID;
set { }
}
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description {
get => pView.Description;
set { }
}
public string ViewDesc {
get => pView.ViewDescription;
set { }
}
public int Volume {
get => pView.Volume;
}
public int LOC {
get => pView.Loc;
}
public int Size {
get => pView.Size;
}
}
public class InvObjProperties {
public InvObjProperties(InventoryList pInvObj) {
ItemCount = pInvObj.Count;
Description = pInvObj.Description;
Encrypted = pInvObj.Encrypted;
MaxScreenObj = pInvObj.MaxScreenObjects;
}
public int ItemCount { get; }
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description { get; set; }
public bool Encrypted { get; }
public int MaxScreenObj { get; }
}
public class WordListProperties {
public WordListProperties(WordList pWordList) {
WordCount = pWordList.WordCount;
GroupCount = pWordList.GroupCount;
Description = pWordList.Description;
}
public int GroupCount { get; }
public int WordCount { get; }
[Editor(typeof(AGIPropertyEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Description { get; set; }
}
internal class PropIntVersions {
internal static string[] _Versions = IntVersions;
}
public class IntVerConverter : StringConverter {
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
// true means show a combobox
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
// true will limit to list. false will show the list,
// but allow free-form entry
return true;
}
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
return new StandardValuesCollection(PropIntVersions._Versions);
}
}
public class AGIPropertyEditor : UITypeEditor {
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value) {
AGIResType restype = 0;
byte resnum = 0;
AGIResource thisres = null;
frmGetResourceNum _frmGetResNum;
switch (context.PropertyDescriptor.Name) {
case "Number":
bool isroom = false;
switch (context.Instance.ToString()) {
case "WinAGI.Editor.LogicProperties":
restype = AGIResType.Logic;
resnum = ((LogicProperties)context.Instance).Number;
isroom = ((LogicProperties)context.Instance).IsRoom;
break;
case "WinAGI.Editor.PictureProperties":
restype = AGIResType.Picture;
resnum = ((PictureProperties)context.Instance).Number;
break;
case "WinAGI.Editor.SoundProperties":
restype = AGIResType.Sound;
resnum = ((SoundProperties)context.Instance).Number;
break;
case "WinAGI.Editor.ViewProperties":
restype = AGIResType.View;
resnum = ((ViewProperties)context.Instance).Number;
break;
}
_frmGetResNum = new(isroom ? GetRes.RenumberRoom : GetRes.Renumber, restype, resnum);
if (_frmGetResNum.ShowDialog(MDIMain) != DialogResult.Cancel) {
value = _frmGetResNum.NewResNum;
}
else {
value = (byte)SelResNum;
}
// need to unbox the value object before converting to byte
return (byte)value;
case "ID":
switch (context.Instance.ToString()) {
case "WinAGI.Editor.LogicProperties":
restype = AGIResType.Logic;
resnum = ((LogicProperties)context.Instance).Number;
thisres = EditGame.Logics[resnum];
break;
case "WinAGI.Editor.PictureProperties":
restype = AGIResType.Picture;
resnum = ((PictureProperties)context.Instance).Number;
thisres = EditGame.Pictures[resnum];
break;
case "WinAGI.Editor.SoundProperties":
restype = AGIResType.Sound;
resnum = ((SoundProperties)context.Instance).Number;
thisres = EditGame.Sounds[resnum];
break;
case "WinAGI.Editor.ViewProperties":
restype = AGIResType.View;
resnum = ((ViewProperties)context.Instance).Number;
thisres = EditGame.Views[resnum];
break;
}
MDIMain.EditSelectedItemProperties(1);
return thisres.ID;
case "Description":
switch (context.Instance.ToString()) {
case "WinAGI.Editor.GameProperties":
MDIMain.ShowProperties(false, "Version", nameof(frmGameProperties.txtGameDescription));
return EditGame.GameDescription;
case "WinAGI.Editor.LogicProperties":
restype = AGIResType.Logic;
resnum = ((LogicProperties)context.Instance).Number;
thisres = EditGame.Logics[resnum];
break;
case "WinAGI.Editor.PictureProperties":
restype = AGIResType.Picture;
resnum = ((PictureProperties)context.Instance).Number;
thisres = EditGame.Pictures[resnum];
break;
case "WinAGI.Editor.SoundProperties":
restype = AGIResType.Sound;
resnum = ((SoundProperties)context.Instance).Number;
thisres = EditGame.Sounds[resnum];
break;
case "WinAGI.Editor.ViewProperties":
restype = AGIResType.View;
resnum = ((ViewProperties)context.Instance).Number;
thisres = EditGame.Views[resnum];
break;
case "WinAGI.Editor.InvObjProperties":
break;
case "WinAGI.Editor.WordListProperties":
break;
}
MDIMain.EditSelectedItemProperties(1);
switch (context.Instance.ToString()) {
case "WinAGI.Editor.InvObjProperties":
return EditGame.InvObjects.Description;
case "WinAGI.Editor.WordListProperties":
return EditGame.WordList.Description;
default:
return thisres.Description;
}
case "GlobalDef":
if (EditGame.IncludeGlobals) {
// same as clicking globals menu item
OpenGlobals(GEInUse);
}
return value;
default:
// to avoid compile error, need a default case
// even though it will never be reached
return value;
}
}
}
}
namespace DynamicTypeDescriptor {
[Flags]
public enum PropertyFlags {
[StandardValue("None", "None of the flags should be applied to this property.")]
None = 0,
[StandardValue("Display name", "Display name should be retrieved from resource if possible for this property.")]
LocalizeDisplayName = 1,
[StandardValue("Category name", "Category name should be retrieved from resource if possible for this property.")]
LocalizeCategoryName = 2,
[StandardValue("Description", "Description string should be retrieved from resource if possible for this property.")]
LocalizeDescription = 4,
[StandardValue("Enumeration", "Enumerations' display strings should be retrieved from resource if possible for this property if it is an enumeration type.")]
LocalizeEnumerations = 8,
[StandardValue("Exclusive", "Values can only be selected from a list and user are not allowed to type in the value for this property.")]
ExclusiveStandardValues = 16,
[StandardValue("Use resource for all string", "Use resource for all string for this property.")]
LocalizeAllString = PropertyFlags.LocalizeDisplayName | PropertyFlags.LocalizeDescription |
PropertyFlags.LocalizeCategoryName | PropertyFlags.LocalizeEnumerations,
[StandardValue("Expandable", "Make property expandlabe if property type is IEnemerable")]
ExpandIEnumerable = 32,
[StandardValue("Supports standard values", "Property supports standard values.")]
SupportStandardValues = 64,
[StandardValue("All flags", "All of the flags should be applied to this property.")]
All = PropertyFlags.LocalizeAllString | PropertyFlags.ExclusiveStandardValues | PropertyFlags.ExpandIEnumerable | PropertyFlags.SupportStandardValues,
Default = PropertyFlags.LocalizeAllString | PropertyFlags.SupportStandardValues,
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class PropertyStateFlagsAttribute : Attribute {
public PropertyStateFlagsAttribute()
: base() {
}
public PropertyStateFlagsAttribute(PropertyFlags flags)
: base() {
m_Flags = flags;
}
private PropertyFlags m_Flags = PropertyFlags.All & ~PropertyFlags.ExclusiveStandardValues;
public PropertyFlags Flags {
get {
return m_Flags;
}
set {
m_Flags = value;
}
}
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class IdAttribute : Attribute {
public IdAttribute()
: base() {
}
public IdAttribute(int propertyId, int categoryId)
: base() {
PropertyId = propertyId;
CategoryId = categoryId;
}
private int m_PropertyId = 0;
public int PropertyId {
get {
return m_PropertyId;
}
set {
m_PropertyId = value;
}
}
private int m_CategoryId = 0;
public int CategoryId {
get {
return m_CategoryId;
}
set {
m_CategoryId = value;
}
}
}
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class StandardValueAttribute : Attribute {
public StandardValueAttribute() {
}
public StandardValueAttribute(object value) {
m_Value = value;
}
public StandardValueAttribute(object value, string displayName) {
m_DisplayName = displayName;
m_Value = value;
}
public StandardValueAttribute(string displayName, string description) {
m_DisplayName = displayName;
m_Description = description;
}
private string m_DisplayName = String.Empty;
public string DisplayName {
get {
if (String.IsNullOrEmpty(m_DisplayName)) {
if (Value != null) {
return Value.ToString();
}
}
return m_DisplayName;
}
set {
m_DisplayName = value;
}
}
private bool m_Visible = true;
public bool Visible {
get {
return m_Visible;
}
set {
m_Visible = value;
}
}
private bool m_Enabled = true;
public bool Enabled {
get {
return m_Enabled;
}
set {
m_Enabled = value;
}
}
private string m_Description = String.Empty;
public string Description {
get {
return m_Description;
}
set {
m_Description = value;
}
}
internal object m_Value = null;
public object Value {
get {
return m_Value;
}
}
public override string ToString() {
return DisplayName;
}
internal static StandardValueAttribute[] GetEnumItems(Type enumType) {
if (enumType == null) {
throw new ArgumentNullException("'enumInstance' is null.");
}
if (!enumType.IsEnum) {
throw new ArgumentException("'enumInstance' is not Enum type.");
}
ArrayList arrAttr = new ArrayList();
FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo fi in fields) {
StandardValueAttribute[] attr = fi.GetCustomAttributes(typeof(StandardValueAttribute), false) as StandardValueAttribute[];
if (attr != null && attr.Length > 0) {
attr[0].m_Value = fi.GetValue(null);
arrAttr.Add(attr[0]);
}
else {
StandardValueAttribute atr = new StandardValueAttribute(fi.GetValue(null));
arrAttr.Add(atr);
}
}
StandardValueAttribute[] retAttr = arrAttr.ToArray(typeof(StandardValueAttribute)) as StandardValueAttribute[];
return retAttr;
}
}
internal class PropertyDescriptorList : List<CustomPropertyDescriptor> {
public PropertyDescriptorList() {
}
}
internal class AttributeList : List<Attribute> {
public AttributeList() {
}
public AttributeList(AttributeCollection ac) {
foreach (Attribute attr in ac) {
this.Add(attr);
}
}
public AttributeList(Attribute[] aa) {
foreach (Attribute attr in aa) {
this.Add(attr);
}
}
}
public class DynamicCustomTypeDescriptor : CustomTypeDescriptor {
private PropertyDescriptorList m_pdl = new PropertyDescriptorList();
private object m_instance = null;
private Hashtable m_hashRM = new Hashtable();
public DynamicCustomTypeDescriptor(ICustomTypeDescriptor ctd, object instance)
: base(ctd) {
m_instance = instance;
GetProperties();
}
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
List<CustomPropertyDescriptor> pdl = m_pdl.FindAll(pd => pd.Attributes.Contains(attributes));
PreProcess(pdl);
PropertyDescriptorCollection pdcReturn = new PropertyDescriptorCollection(pdl.ToArray());
return pdcReturn;
}
public override PropertyDescriptorCollection GetProperties() {
if (m_pdl.Count == 0) {
PropertyDescriptorCollection pdc = base.GetProperties(); // this gives us a readonly collection, no good
foreach (PropertyDescriptor pd in pdc) {
if (!(pd is CustomPropertyDescriptor)) {
CustomPropertyDescriptor cpd = new CustomPropertyDescriptor(base.GetPropertyOwner(pd), pd);
m_pdl.Add(cpd);
}
}
}
List<CustomPropertyDescriptor> pdl = m_pdl.FindAll(pd => pd != null);
PreProcess(pdl);
PropertyDescriptorCollection pdcReturn = new PropertyDescriptorCollection(m_pdl.ToArray());
return pdcReturn;
}
private void PreProcess(List<CustomPropertyDescriptor> pdl) {
//if (m_PropertySortOrder != CustomSortOrder.None && pdl.Count > 0) {
// PropertySorter propSorter = new PropertySorter();
// propSorter.SortOrder = m_PropertySortOrder;
// pdl.Sort(propSorter);
//}
//UpdateCategoryTabAppendCount();
//UpdateResourceManager();
}
public CustomPropertyDescriptor GetProperty(string propertyName) {
CustomPropertyDescriptor cpd = m_pdl.FirstOrDefault(a => String.Compare(a.Name, propertyName, true) == 0);
return cpd;
}
}
internal class CustomTypeDescriptionProvider : TypeDescriptionProvider {
private TypeDescriptionProvider m_parent = null;
private ICustomTypeDescriptor m_ctd = null;
public CustomTypeDescriptionProvider()
: base() {
}
public CustomTypeDescriptionProvider(TypeDescriptionProvider parent)
: base(parent) {
m_parent = parent;
}
public CustomTypeDescriptionProvider(TypeDescriptionProvider parent, ICustomTypeDescriptor ctd)
: base(parent) {
m_parent = parent;
m_ctd = ctd;
}
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) {
return m_ctd;
}
}
public static class ProviderInstaller {
public static DynamicCustomTypeDescriptor Install(object instance) {
TypeDescriptionProvider parentProvider = TypeDescriptor.GetProvider(instance);
ICustomTypeDescriptor parentCtd = parentProvider.GetTypeDescriptor(instance);
DynamicCustomTypeDescriptor ourCtd = new DynamicCustomTypeDescriptor(parentCtd, instance);
CustomTypeDescriptionProvider ourProvider = new CustomTypeDescriptionProvider(parentProvider, ourCtd);
TypeDescriptor.AddProvider(ourProvider, instance);
return ourCtd;
}
}
public class CustomPropertyDescriptor : PropertyDescriptor {
private static Hashtable m_hashRM = new Hashtable();
internal object m_owner = null;
private Type m_PropType = Type.Missing.GetType();
private AttributeList m_Attributes = new AttributeList();
private PropertyDescriptor m_pd = null;
private Collection<PropertyValueUIItem> m_colUIItem = new Collection<PropertyValueUIItem>();
internal CustomPropertyDescriptor(object owner, string sName, Type type, object value, params Attribute[] attributes)
: base(sName, attributes) {
this.m_owner = owner;
this.m_value = value;
m_PropType = type;
m_Attributes.AddRange(attributes);
UpdateMemberData();
}
internal CustomPropertyDescriptor(object owner, PropertyDescriptor pd)
: base(pd) {
m_pd = pd;
m_owner = owner;
m_Attributes = new AttributeList(pd.Attributes);
UpdateMemberData();
}
private void UpdateMemberData() {
if (m_pd != null) {
m_value = m_pd.GetValue(m_owner);
}
if (PropertyType.IsEnum) {
StandardValueAttribute[] sva = StandardValueAttribute.GetEnumItems(PropertyType);
this.m_StatandardValues.AddRange(sva);
}
else if (PropertyType == typeof(bool)) {
this.m_StatandardValues.Add(new StandardValueAttribute(true));
this.m_StatandardValues.Add(new StandardValueAttribute(false));
}
}
public override Type ComponentType {
get {
return m_owner.GetType();
}
}
public override Type PropertyType {
get {
if (m_pd != null) {
return this.m_pd.PropertyType;
}
return m_PropType;
}
}
protected override Attribute[] AttributeArray {
get {
return m_Attributes.ToArray();
}
set {
m_Attributes.Clear();
m_Attributes.AddRange(value);
}
}
public override AttributeCollection Attributes {
get {
AttributeCollection ac = new AttributeCollection(m_Attributes.ToArray());
return ac;
}
}
protected override void FillAttributes(IList attributeList) {
foreach (Attribute attr in m_Attributes) {
attributeList.Add(attr);
}
}
public IList<Attribute> AllAttributes {
get {
return m_Attributes;
}
}
/// <summary>
/// Must override abstract properties.
/// </summary>
///
public override bool IsLocalizable {
get {
LocalizableAttribute attr = (LocalizableAttribute)m_Attributes.FirstOrDefault(a => a is LocalizableAttribute);
if (attr != null) {
return attr.IsLocalizable;
}
return base.IsLocalizable;
}
}
public void SetIsLocalizable(bool isLocalizable) {
LocalizableAttribute attr = (LocalizableAttribute)m_Attributes.FirstOrDefault(a => a is LocalizableAttribute);
if (attr != null) {
m_Attributes.RemoveAll(a => a is LocalizableAttribute);
}
attr = new LocalizableAttribute(isLocalizable);
m_Attributes.Add(attr);
}
public override bool IsReadOnly {
get {
ReadOnlyAttribute attr = (ReadOnlyAttribute)m_Attributes.FirstOrDefault(a => a is ReadOnlyAttribute);
if (attr != null) {
return attr.IsReadOnly;
}
return false;
}
}
public void SetIsReadOnly(bool isReadOnly) {
ReadOnlyAttribute attr = (ReadOnlyAttribute)m_Attributes.FirstOrDefault(a => a is ReadOnlyAttribute);
if (attr != null) {
m_Attributes.RemoveAll(a => a is ReadOnlyAttribute);