forked from dotnet/project-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationPropPageVBWinForms.vb
1664 lines (1414 loc) · 84 KB
/
ApplicationPropPageVBWinForms.vb
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
' Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
Imports System.ComponentModel
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.ApplicationServices
Imports Microsoft.VisualStudio.Editors.Common
Imports Microsoft.VisualStudio.Editors.MyApplication
Imports Microsoft.VisualStudio.Shell
Imports Microsoft.VisualStudio.Shell.Interop
Imports VSLangProj110
Imports VSLangProj158
Imports VSLangProj80
Imports VslangProj90
Namespace Microsoft.VisualStudio.Editors.PropertyPages
''' <summary>
''' The application property page for VB WinForms apps
''' - see comments in proppage.vb: "Application property pages (VB and C#)"
''' </summary>
Friend Class ApplicationPropPageVBWinForms
Inherits ApplicationPropPageVBBase
'Backing storage for the current MainForm value (without the root namespace)
Protected MainFormTextboxNoRootNS As New TextBox
Protected Const Const_SubMain As String = "Sub Main"
Protected Const Const_MyApplicationEntryPoint As String = "My.MyApplication"
Protected Const Const_MyApplication As String = "MyApplication"
Private ReadOnly _shutdownModeStringValues As String()
Private ReadOnly _authenticationModeStringValues As String()
Private ReadOnly _noneText As String
Private _myType As String
Private ReadOnly _startupObjectLabelText As String 'This one is in the form's resx when initialized
Private ReadOnly _startupFormLabelText As String 'This one we pull from resources
'This is the (cached) MyApplication.MyApplicationProperties object returned by the project system
Private _myApplicationPropertiesCache As IMyApplicationPropertiesInternal
Private WithEvents _myApplicationPropertiesNotifyPropertyChanged As INotifyPropertyChanged
'Set to true if we have tried to cache the MyApplication properties value. If this is True and
' _myApplicationPropertiesCache is Nothing, it indicates that the MyApplication property is not
' supported in this project system (which may mean the project flavor has turned off this support)
Private _isMyApplicationPropertiesCached As Boolean
'Cache whether MyType is one of the disabled values so we don't have to fetch it constantly
' from the project properties
Private _isMyTypeDisabled As Boolean
Private _isMyTypeDisabledCached As Boolean
' If set, we are using my application types as the 'output type'. Otherwise, we are using
' output types provided by the project system
Private _usingMyApplicationTypes As Boolean = True
Protected Const Const_EnableVisualStyles As String = "EnableVisualStyles"
Protected Const Const_AuthenticationMode As String = "AuthenticationMode"
Protected Const Const_SingleInstance As String = "SingleInstance"
Protected Const Const_ShutdownMode As String = "ShutdownMode"
Protected Const Const_SplashScreenNoRootNS As String = "SplashScreen" 'we persist this without the root namespace
Protected Const Const_CustomSubMain As String = "CustomSubMain"
Protected Const Const_MainFormNoRootNS As String = "MainForm" 'we persist this without the root namespace
Protected Const Const_MyType As String = "MyType"
Protected Const Const_SaveMySettingsOnExit As String = "SaveMySettingsOnExit"
' Shared list of all known application types and their properties...
Private Shared ReadOnly s_applicationTypes As New List(Of ApplicationTypeInfo)
Private _settingApplicationType As Boolean
''' <summary>
''' Set up shared state...
''' </summary>
Shared Sub New()
' Populate shared list of all known application types allowed on this page
s_applicationTypes.Add(New ApplicationTypeInfo(ApplicationTypes.WindowsApp, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_WindowsFormsApp, True))
s_applicationTypes.Add(New ApplicationTypeInfo(ApplicationTypes.WindowsClassLib, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_WindowsClassLib, True))
s_applicationTypes.Add(New ApplicationTypeInfo(ApplicationTypes.CommandLineApp, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_CommandLineApp, True))
s_applicationTypes.Add(New ApplicationTypeInfo(ApplicationTypes.WindowsService, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_WindowsService, False))
s_applicationTypes.Add(New ApplicationTypeInfo(ApplicationTypes.WebControl, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_WebControlLib, False))
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
SetCommonControls()
AddChangeHandlers()
'Remember original text of the Start-up object label text
_startupObjectLabelText = StartupObjectLabel.Text
'Get text for the forms case from resources
_startupFormLabelText = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Application_StartupFormLabelText
_noneText = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_ComboBoxSelect_None
'Ordering of strings here determines value stored in MyApplication.myapp
_shutdownModeStringValues = New String() {My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_MyApplication_StartupMode_FormCloses, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_MyApplication_StartupMode_AppExits}
_authenticationModeStringValues = New String() {My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_MyApplication_AuthenMode_Windows, My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_MyApplication_AuthenMode_ApplicationDefined}
PageRequiresScaling = False
End Sub
''' <summary>
''' Let the base class know which control instances correspond to shared controls
''' between this inherited class and the base vb application property page class.
''' </summary>
Private Sub SetCommonControls()
CommonControls = New CommonPageControls(
IconCombobox, IconLabel, IconPicturebox)
End Sub
Protected Overrides ReadOnly Property ControlData As PropertyControlData()
Get
Dim ControlsThatDependOnStartupObjectProperty As Control() = {
StartupObjectLabel, UseApplicationFrameworkCheckBox, WindowsAppGroupBox
}
Dim ControlsThatDependOnOutputTypeProperty As Control() = {
ApplicationTypeComboBox, ApplicationTypeLabel
}
If m_ControlData Is Nothing Then
'StartupObject must be kept after OutputType because it depends on the initialization of "OutputType" values
' Custom sub main must come before MainForm, because it will ASSERT on the enable frameowrk checkbox
' StartupObject must be kept after MainForm, because it needs the main form name...
' MyApplication should be kept before all other MyAppDISPIDs properties to make sure that everyting in there
' is initialized correctly...
Dim datalist As List(Of PropertyControlData) = New List(Of PropertyControlData)
Dim data As PropertyControlData = New PropertyControlData(VBProjPropId.VBPROJPROPID_MyApplication, Const_MyApplication, Nothing, AddressOf MyApplicationSet, AddressOf MyApplicationGet, ControlDataFlags.UserHandledEvents Or ControlDataFlags.UserPersisted)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.CustomSubMain, Const_CustomSubMain, UseApplicationFrameworkCheckBox, AddressOf CustomSubMainSet, AddressOf CustomSubMainGet, ControlDataFlags.UserPersisted Or ControlDataFlags.UserHandledEvents, AddressOf MyApplicationGet)
datalist.Add(data)
data = New PropertyControlData(VsProjPropId.VBPROJPROPID_RootNamespace, Const_RootNamespace, RootNamespaceTextBox, New Control() {RootNamespaceLabel}) With {
.DisplayPropertyName = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Property_RootNamespace
}
datalist.Add(data)
data = New PropertyControlData(VsProjPropId110.VBPROJPROPID_OutputTypeEx, Const_OutputTypeEx, Nothing, AddressOf OutputTypeSet, AddressOf OutputTypeGet, ControlDataFlags.None, ControlsThatDependOnOutputTypeProperty)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.MainForm, Const_MainFormNoRootNS, MainFormTextboxNoRootNS, AddressOf MainFormNoRootNSSet, Nothing, ControlDataFlags.UserPersisted, AddressOf MyApplicationGet)
datalist.Add(data)
data = New PropertyControlData(VsProjPropId.VBPROJPROPID_StartupObject, Const_StartupObject, StartupObjectComboBox, AddressOf StartupObjectSet, AddressOf StartupObjectGet, ControlDataFlags.UserHandledEvents, ControlsThatDependOnStartupObjectProperty) With {
.DisplayPropertyName = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Property_StartupObject
}
datalist.Add(data)
data = New PropertyControlData(VsProjPropId.VBPROJPROPID_AssemblyName, "AssemblyName", AssemblyNameTextBox, New Control() {AssemblyNameLabel}) With {
.DisplayPropertyName = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Property_AssemblyName
}
datalist.Add(data)
data = New PropertyControlData(VsProjPropId.VBPROJPROPID_ApplicationIcon, "ApplicationIcon", IconCombobox, AddressOf ApplicationIconSet, AddressOf ApplicationIconGet, ControlDataFlags.UserHandledEvents, New Control() {IconLabel, IconPicturebox}) With {
.DisplayPropertyName = My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Property_ApplicationIcon
}
datalist.Add(data)
data = New PropertyControlData(VBProjPropId.VBPROJPROPID_MyType, Const_MyType, Nothing, AddressOf MyTypeSet, AddressOf MyTypeGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.EnableVisualStyles, Const_EnableVisualStyles, EnableXPThemesCheckBox, ControlDataFlags.UserPersisted, AddressOf MyApplicationGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.AuthenticationMode, Const_AuthenticationMode, AuthenticationModeComboBox, ControlDataFlags.UserPersisted, AddressOf MyApplicationGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.SingleInstance, Const_SingleInstance, SingleInstanceCheckBox, ControlDataFlags.UserPersisted, AddressOf MyApplicationGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.ShutdownMode, Const_ShutdownMode, ShutdownModeComboBox, ControlDataFlags.UserPersisted, New Control() {ShutdownModeLabel}, AddressOf MyApplicationGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.SplashScreen, Const_SplashScreenNoRootNS, SplashScreenComboBox, ControlDataFlags.UserPersisted, New Control() {SplashScreenLabel}, AddressOf MyApplicationGet)
datalist.Add(data)
data = New MyApplicationPersistedPropertyControlData(MyAppDISPIDs.SaveMySettingsOnExit, Const_SaveMySettingsOnExit, SaveMySettingsCheckbox, ControlDataFlags.UserPersisted, AddressOf MyApplicationGet)
datalist.Add(data)
data = New PropertyControlData(VsProjPropId90.VBPROJPROPID_ApplicationManifest, "ApplicationManifest", Nothing, ControlDataFlags.Hidden)
datalist.Add(data)
data = New PropertyControlData(VsProjPropId158.VBPROJPROPID_AutoGenerateBindingRedirects, "AutoGenerateBindingRedirects", AutoGenerateBindingRedirectsCheckBox)
datalist.Add(data)
TargetFrameworkPropertyControlData = New TargetFrameworkPropertyControlData(
VsProjPropId100.VBPROJPROPID_TargetFrameworkMoniker,
ApplicationPropPage.Const_TargetFrameworkMoniker,
TargetFrameworkComboBox,
AddressOf SetTargetFrameworkMoniker,
AddressOf GetTargetFrameworkMoniker,
ControlDataFlags.ProjectMayBeReloadedDuringPropertySet Or ControlDataFlags.NoOptimisticFileCheckout,
New Control() {TargetFrameworkLabel})
datalist.Add(TargetFrameworkPropertyControlData)
m_ControlData = datalist.ToArray()
End If
Return m_ControlData
End Get
End Property
''' <summary>
''' Removes references to anything that was passed in to SetObjects
''' </summary>
Protected Overrides Sub CleanupCOMReferences()
MyBase.CleanupCOMReferences()
_myApplicationPropertiesCache = Nothing
_myApplicationPropertiesNotifyPropertyChanged = Nothing
_isMyApplicationPropertiesCached = False
End Sub
Private ReadOnly Property MyApplicationPropertiesSupported As Boolean
Get
Return MyApplicationProperties IsNot Nothing
End Get
End Property
''' <summary>
''' Gets the MyApplication.MyApplicationProperties object returned by the project system (which the project system creates by calling into us)
''' </summary>
''' <value>The value of the MyApplication property, or else Nothing if it is not supported.</value>
Private ReadOnly Property MyApplicationProperties As IMyApplicationPropertiesInternal
Get
Debug.Assert(Implies(_myApplicationPropertiesCache IsNot Nothing, _isMyApplicationPropertiesCached))
Debug.Assert(Implies(_myApplicationPropertiesNotifyPropertyChanged IsNot Nothing, _isMyApplicationPropertiesCached))
If Not _isMyApplicationPropertiesCached Then
'Set a flag so we don't keep trying to query for this property
_isMyApplicationPropertiesCached = True
' TODO: Remove this condition once VB property pages are fully supported on CPS
If Not ProjectHierarchy.IsCapabilityMatch("PreventAutomaticMyApplication") Then
_myApplicationPropertiesCache = MyApplicationProjectLifetimeTracker.Track(ProjectHierarchy)
_myApplicationPropertiesNotifyPropertyChanged = TryCast(_myApplicationPropertiesCache, INotifyPropertyChanged)
Else
'MyApplication property is not supported in this project system
_myApplicationPropertiesCache = Nothing
_myApplicationPropertiesNotifyPropertyChanged = Nothing
End If
End If
Return _myApplicationPropertiesCache
End Get
End Property
''' <summary>
''' Attempts to run the custom tool for the .myapp file. If an exception
''' is thrown, it is displayed to the user and swallowed.
''' </summary>
''' <returns>True on success.</returns>
Private Function TryRunCustomToolForMyApplication() As Boolean
If MyApplicationProperties IsNot Nothing Then
Try
MyApplicationProperties.RunCustomTool()
Catch ex As Exception When ReportWithoutCrash(ex, NameOf(TryRunCustomToolForMyApplication), NameOf(ApplicationPropPageInternalBase))
ShowErrorMessage(ex)
End Try
End If
Return True
End Function
''' <summary>
''' This is a readonly property, so don't return anything
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function MyApplicationGet(control As Control, prop As PropertyDescriptor, ByRef value As Object) As Boolean
value = MyApplicationProperties
Return True
End Function
''' <summary>
''' Value given us for "MyApplication" property
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function MyApplicationSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
'Nothing for us to do
Return True
End Function
''' <summary>
''' Returns the value stored in the UI for the MyType property.
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function MyTypeGet(control As Control, prop As PropertyDescriptor, ByRef value As Object) As Boolean
value = _myType
Return True
End Function
''' <summary>
''' Value given us for "MyType" property
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function MyTypeSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
Dim stValue As String = CType(value, String)
If (stValue IsNot Nothing) AndAlso (stValue.Trim().Length > 0) Then
_myType = stValue
Else
_myType = Nothing
End If
UpdateApplicationTypeUI()
If Not m_fInsideInit Then
' We've got to make sure that we run the custom tool whenever we change
' the "application type"
TryRunCustomToolForMyApplication()
End If
Return True
End Function
''' <summary>
''' Gets the output type from the UI fields
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
''' <remarks>OutputType is obtained from the value in the Application Type field</remarks>
Protected Function OutputTypeGet(control As Control, prop As PropertyDescriptor, ByRef value As Object) As Boolean
If _usingMyApplicationTypes Then
Dim AppType As ApplicationTypes
If ApplicationTypeComboBox.SelectedItem IsNot Nothing Then
AppType = DirectCast(ApplicationTypeComboBox.SelectedItem, ApplicationTypeInfo).ApplicationType
Else
AppType = ApplicationTypes.WindowsApp
End If
value = MyApplication.MyApplicationProperties.OutputTypeFromApplicationType(AppType)
Else
If ApplicationTypeComboBox.SelectedItem IsNot Nothing Then
value = DirectCast(ApplicationTypeComboBox.SelectedItem, OutputTypeComboBoxValue).Value
Else
value = prjOutputTypeEx.prjOutputTypeEx_WinExe
End If
End If
Return True
End Function
Protected Function OutputTypeSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
If _usingMyApplicationTypes Then
'No UI for OutputType, ApplicationType provides our UI selection
UpdateApplicationTypeUI()
If Not m_fInsideInit Then
' We've got to make sure that we run the custom tool whenever we change
' the "application type"
TryRunCustomToolForMyApplication()
End If
Else
Dim uIntValue As UInteger = CUInt(value)
If SelectItemInOutputTypeComboBox(ApplicationTypeComboBox, uIntValue) Then
PopulateStartupObject(StartUpObjectSupported(uIntValue), PopulateDropdown:=False)
End If
End If
Return True
End Function
''' <summary>
''' Make sure the application type combobox is showing the appropriate
''' value
''' </summary>
Private Sub UpdateApplicationTypeUI()
If _settingApplicationType Then
Return
End If
Dim oOutputType As Object = Nothing
Dim oMyType As Object = Nothing
If GetProperty(VBProjPropId.VBPROJPROPID_MyType, oMyType) AndAlso oMyType IsNot Nothing AndAlso Not PropertyControlData.IsSpecialValue(oMyType) _
AndAlso GetProperty(VsProjPropId110.VBPROJPROPID_OutputTypeEx, oOutputType) AndAlso oOutputType IsNot Nothing AndAlso Not PropertyControlData.IsSpecialValue(oOutputType) _
Then
Dim AppType As ApplicationTypes = MyApplication.MyApplicationProperties.ApplicationTypeFromOutputType(CUInt(oOutputType), CStr(oMyType))
ApplicationTypeComboBox.SelectedItem = s_applicationTypes.Find(ApplicationTypeInfo.ApplicationTypePredicate(AppType))
EnableControlSet(AppType)
PopulateControlSet(AppType)
Else
ApplicationTypeComboBox.SelectedIndex = -1
EnableIconComboBox(False)
EnableUseApplicationFrameworkCheckBox(False)
End If
End Sub
''' <summary>
''' Getter for the "CustSubMain" property.
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
''' <remarks>
''' The UI checkbox's logic is reversed from the property ("Enable application frameworks" = Not CustomSubMain). However, because the property
''' is specified as CustomSubMain and I don't want to change it at this point, and the property change notification is based on the
''' CustomSubMain property ID, I didn't want to change the PropertyControlData to use a custom property. So we reverse the logic in
''' a custom getter/setter
''' </remarks>
Protected Function CustomSubMainGet(control As Control, prop As PropertyDescriptor, ByRef value As Object) As Boolean
If UseApplicationFrameworkCheckBox.CheckState <> CheckState.Indeterminate Then
value = Not UseApplicationFrameworkCheckBox.Checked 'reversed
Return True
End If
Return False
End Function
''' <summary>
''' Setter for the "CustSubMain" property.
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
''' <remarks>
''' The UI checkbox's logic is reversed from the property ("Enable application frameworks" = Not CustomSubMain). However, because the property
''' is specified as CustomSubMain and I don't want to change it at this point, and the property change notification is based on the
''' CustomSubMain property ID, I didn't want to change the PropertyControlData to use a custom property. So we reverse the logic in
''' a custom getter/setter
''' </remarks>
Protected Function CustomSubMainSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
If PropertyControlData.IsSpecialValue(value) Then
UseApplicationFrameworkCheckBox.CheckState = CheckState.Indeterminate
Else
UseApplicationFrameworkCheckBox.CheckState = IIf(Not CBool(value), CheckState.Checked, CheckState.Unchecked) 'reversed
End If
'Toggle whether the application framework properties are enabled
WindowsAppGroupBox.Enabled = MyApplicationFrameworkEnabled()
Return True
End Function
Private Shared Function IsClassLibrary(AppType As ApplicationTypes) As Boolean
If AppType = ApplicationTypes.WindowsClassLib OrElse AppType = ApplicationTypes.WebControl Then
Return True
End If
Return False
End Function
''' <summary>
''' Enables the "Enable application framework" checkbox (if Enable=True), but only if it is supported in this project with current settings
''' </summary>
''' <param name="Enable"></param>
Private Sub EnableUseApplicationFrameworkCheckBox(Enable As Boolean)
If Enable Then
Dim useApplicationFrameworkEnabled As Boolean = MyApplicationFrameworkSupported()
UseApplicationFrameworkCheckBox.Enabled = useApplicationFrameworkEnabled
Debug.Assert(Not MyApplicationPropertiesSupported OrElse UseApplicationFrameworkCheckBox.Checked = Not MyApplicationProperties.CustomSubMainRaw)
'The groupbox with My-related properties on the page should only be
' enabled if the custom sub main checkbox is enabled but not
' checked.
Debug.Assert(Implies(useApplicationFrameworkEnabled, MyApplicationProperties IsNot Nothing))
WindowsAppGroupBox.Enabled = useApplicationFrameworkEnabled AndAlso Not MyApplicationProperties.CustomSubMainRaw 'Be sure to use CustomSubMainRaw instead of CustomSubMain - application type might not be set correctly yet
Else
UseApplicationFrameworkCheckBox.Enabled = False
WindowsAppGroupBox.Enabled = False
End If
End Sub
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function StartupObjectGet(control As Control, prop As PropertyDescriptor, ByRef value As Object) As Boolean
If Not StartUpObjectSupported() Then
value = ""
Return True
End If
Dim StringValue As String
'Value in the combobox does not contain the root namespace
StringValue = NothingToEmptyString(DirectCast(StartupObjectComboBox.SelectedItem, String))
If MyApplicationFrameworkEnabled() Then
'Check that the main form is actually a form
Dim IsAForm As Boolean = False
Dim FormEntryPoints() As String = GetFormEntryPoints(IncludeSplashScreen:=False)
If IsNoneText(StringValue) OrElse Const_SubMain.Equals(StringValue, StringComparison.OrdinalIgnoreCase) Then
'Not a form
Else
Dim StringValueWithNamespace As String = AddCurrentRootNamespace(StringValue)
For Each FormName As String In FormEntryPoints
If String.Equals(FormName, StringValueWithNamespace, StringComparison.OrdinalIgnoreCase) Then
IsAForm = True
Exit For
End If
Next
End If
If Not IsAForm Then
If StringValue <> "" AndAlso StringValue.Equals(MyApplicationProperties.SplashScreenNoRootNS, StringComparison.OrdinalIgnoreCase) Then
'We couldn't find it because it's the same as the splash screen. That's not allowed.
ShowErrorMessage(My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Application_SplashSameAsStart)
Else
'When the application framework is enabled, there must be a start-up form selected (MainForm) or there will
' be a compile error or run-time error. We avoid this when possible by picking the first available
' form. Also show a messagebox to let the user know about the problem (but don't throw an exception, because
' that would cause problems in applying the other properties on the page).
ShowErrorMessage(My.Resources.Microsoft_VisualStudio_Editors_Designer.PPG_Application_InvalidSubMainStartup)
End If
If FormEntryPoints IsNot Nothing AndAlso FormEntryPoints.Length() > 0 Then
'Change to an arbitrary start-up form and continue...
StringValue = RemoveCurrentRootNamespace(FormEntryPoints(0))
Else
'There is no start-up form available. To keep from getting a compile or run-time error, we need to turn
' off the application framework.
UseApplicationFrameworkCheckBox.CheckState = CheckState.Unchecked
SetDirty(MyAppDISPIDs.CustomSubMain, False)
value = ""
MainFormTextboxNoRootNS.Text = ""
SetDirty(MyAppDISPIDs.MainForm, False)
Return True
End If
End If
End If
'If this is a WindowsApplication with My, then the value in the combobox is what we want
' to be the main form - this gets placed into MainFormTextboxNoRootNS and will get persisted
' out to MyApplicationProperties.MainFormNoRootNS. The start-up object must be returned
' as a pointer to the start-up method in the My application framework stuff.
If MyApplicationFrameworkEnabled() Then
Debug.Assert(Not IsNoneText(StringValue), "None should not have been supported with the My stuff enabled")
MainFormTextboxNoRootNS.Text = StringValue
SetDirty(MyAppDISPIDs.MainForm, False)
'Start-up object needs the root namespace
value = AddCurrentRootNamespace(Const_MyApplicationEntryPoint)
Else
'My framework not enabled, add the root namespace to the raw value in the combobox, and that's the
' start-up object (unless it's (None)).
If Not IsNoneText(StringValue) And Not Const_SubMain.Equals(StringValue, StringComparison.OrdinalIgnoreCase) Then
StringValue = AddCurrentRootNamespace(StringValue)
End If
value = StringValue
End If
Return True
End Function
''' <summary>
''' Called by base to set update the UI
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function StartupObjectSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
'This is handled by the ApplicationType set, so do nothing here
'CONSIDER: The start-up object/MainForm-handling code needs to be reworked - it makes undo/redo/external property changes
' more difficult than they should be. Get code should not be changing the value of other properties.
If Not m_fInsideInit Then
'Property has been changed, refresh.
PopulateStartupObject(StartUpObjectSupported(), False)
End If
Return True
End Function
''' <summary>
''' Setter for MainForm. We handle this so that we also get notified when the property
''' has changed.
''' </summary>
''' <param name="control"></param>
''' <param name="prop"></param>
''' <param name="value"></param>
Protected Function MainFormNoRootNSSet(control As Control, prop As PropertyDescriptor, value As Object) As Boolean
If Not PropertyControlData.IsSpecialValue(value) Then
MainFormTextboxNoRootNS.Text = DirectCast(value, String)
'When this changes, we need to update the start-up object combobox
If Not m_fInsideInit Then
PopulateStartupObject(StartUpObjectSupported(), PopulateDropdown:=False)
End If
Else
MainFormTextboxNoRootNS.Text = ""
End If
Return True
End Function
''' <param name="OutputType"></param>
Private Sub PopulateControlSet(OutputType As UInteger)
Debug.Assert(m_Objects.Length <= 1, "Multiple project updates not supported")
PopulateStartupObject(StartUpObjectSupported(OutputType), False)
End Sub
Private Sub PopulateControlSet(AppType As ApplicationTypes)
Debug.Assert(m_Objects.Length <= 1, "Multiple project updates not supported")
PopulateStartupObject(StartUpObjectSupportedForApplicationType(AppType), False)
End Sub
''' <summary>
''' Populates the splash screen combobox's text and optionally dropdown entries
''' </summary>
''' <param name="PopulateDropdown">If false, only the current text in the combobox is set. If true, the entire dropdown list is populated. For performance reasons, False should be used until the user actually drops down the list.</param>
Protected Sub PopulateSplashScreenList(PopulateDropdown As Boolean)
'Use the same list as StartupObject, but no sub main
Dim StartupObjectControlData As PropertyControlData = GetPropertyControlData(Const_StartupObject)
Dim SplashScreenControlData As PropertyControlData = GetPropertyControlData(Const_SplashScreenNoRootNS)
If Not MyApplicationPropertiesSupported OrElse StartupObjectControlData.IsMissing OrElse SplashScreenControlData.IsMissing Then
Debug.Assert(SplashScreenComboBox.Enabled = False) 'Should have been disabled via PropertyControlData mechanism
Debug.Assert(SplashScreenLabel.Enabled = False) 'Should have been disabled via PropertyControlData mechanism
Else
With SplashScreenComboBox
.Items.Clear()
.Items.Add(_noneText)
If PopulateDropdown Then
Switches.TracePDPerf("*** Populating splash screen list from the project [may be slow for a large project]")
Debug.Assert(Not m_fInsideInit, "PERFORMANCE ALERT: We shouldn't be populating the splash screen dropdown list during page initialization, it should be done later if needed.")
Using New WaitCursor
Dim CurrentMainForm As String = MyApplicationProperties.MainFormNoRootNamespace
For Each SplashForm As String In GetFormEntryPoints(IncludeSplashScreen:=True) _
.Select(Function(e) RemoveCurrentRootNamespace(e)) _
.OrderBy(Function(n) n)
'Only add forms to this list, skip 'Sub Main'
If (Not SplashForm.Equals(Const_MyApplicationEntryPoint, StringComparison.OrdinalIgnoreCase)) AndAlso
(Not SplashForm.Equals(Const_SubMain, StringComparison.OrdinalIgnoreCase)) Then
'We don't allow the splash form and main form to be the same, so don't
' put the main into the splash form list
If Not SplashForm.Equals(CurrentMainForm, StringComparison.OrdinalIgnoreCase) Then
.Items.Add(SplashForm)
End If
End If
Next
End Using
End If
If MyApplicationProperties.SplashScreenNoRootNS = "" Then
'Set to (None)
.SelectedIndex = 0
Else
.SelectedItem = MyApplicationProperties.SplashScreenNoRootNS
If .SelectedItem Is Nothing Then
'Not in the list - add it
.SelectedIndex = .Items.Add(MyApplicationProperties.SplashScreenNoRootNS)
End If
End If
End With
End If
End Sub
''' <summary>
''' Returns True iff the My Application framework should be supportable
''' in this project. It does not necessarily mean that it's turned on,
''' just that it can be supported.
''' </summary>
Private Function MyApplicationFrameworkSupported() As Boolean
If Not MyApplicationPropertiesSupported Then
Return False
End If
Dim StartupObjectControlData As PropertyControlData = GetPropertyControlData(Const_StartupObject)
If StartupObjectControlData.IsMissing Then
'This project type does not support the Startup-Object property, therefore it can't
' support the My application framework.
Return False
End If
If MyTypeDisabled() Then
Return False
End If
Return True
End Function
''' <summary>
''' Returns True iff the My Application framework stuff is supported
''' in this project system *and* it is currently turned on by the
''' user.
''' This means, among other things, that we have a list of start-up *forms*
''' instead of objects.
''' </summary>
Private Function MyApplicationFrameworkEnabled() As Boolean
If Not MyApplicationFrameworkSupported() Then
Return False
End If
If Not _usingMyApplicationTypes Then
Return False
End If
Dim appType As ApplicationTypeInfo = DirectCast(ApplicationTypeComboBox.SelectedItem, ApplicationTypeInfo)
If appType IsNot Nothing _
AndAlso appType.ApplicationType = ApplicationTypes.WindowsApp _
AndAlso UseApplicationFrameworkCheckBox.CheckState = CheckState.Checked _
Then
Return True
Else
Return False
End If
End Function
''' <summary>
''' Retrieve the list of start-up forms (not start-up objects) from the VB compiler
''' </summary>
Private Function GetFormEntryPoints(IncludeSplashScreen As Boolean) As String()
Try
Dim EntryPointProvider As Interop.IVBEntryPointProvider = CType(ServiceProvider.GetService(Interop.NativeMethods.VBCompilerGuid), Interop.IVBEntryPointProvider)
If EntryPointProvider IsNot Nothing Then
Dim EntryPoints() As String = Array.Empty(Of String)()
Dim cEntryPointsAvailable As UInteger
'First call gets estimated number of entrypoints
Dim hr As Integer = EntryPointProvider.GetFormEntryPointsList(ProjectHierarchy, 0, Nothing, cEntryPointsAvailable)
If VSErrorHandler.Failed(hr) Then
Debug.Fail("Failed to get VB Form entry points, hr=0x" & Hex(hr))
ElseIf cEntryPointsAvailable > 0 Then
'Keep repeating until we give them a large enough array (it's possible the
' number of entry points available has increased since we made our first call)
While EntryPoints.Length < cEntryPointsAvailable
ReDim EntryPoints(CInt(cEntryPointsAvailable) - 1)
EntryPointProvider.GetFormEntryPointsList(ProjectHierarchy, CUInt(EntryPoints.Length), EntryPoints, cEntryPointsAvailable)
End While
'We might have ended up with fewer than originally estimated...
ReDim Preserve EntryPoints(CInt(cEntryPointsAvailable) - 1)
If Not IncludeSplashScreen Then
'Filter out the splash screen
Dim SplashScreen As String = MyApplicationProperties.SplashScreen
For i As Integer = 0 To EntryPoints.Length - 1
If EntryPoints(i).Equals(SplashScreen, StringComparison.OrdinalIgnoreCase) Then
'Found it - remove it
For j As Integer = i + 1 To EntryPoints.Length - 1
EntryPoints(i) = EntryPoints(j)
Next
ReDim Preserve EntryPoints(EntryPoints.Length - 1 - 1) 'Reduce allocated number by one
Return EntryPoints
End If
Next
End If
'And return 'em...
Return EntryPoints
End If
Else
Debug.Fail("Failed to get IVBEntryPointProvider")
End If
Catch ex As Exception When ReportWithoutCrash(ex, "An exception occurred in GetStartupForms() - using empty list", NameOf(ApplicationPropPageVBWinForms))
End Try
Return Array.Empty(Of String)
End Function
''' <summary>
''' Populates the start-up object combobox box dropdown
''' </summary>
''' <param name="StartUpObjectSupported">If false, (None) will be the only entry in the list.</param>
''' <param name="PopulateDropdown">If false, only the current text in the combobox is set. If true, the entire dropdown list is populated. For performance reasons, False should be used until the user actually drops down the list.</param>
Protected Sub PopulateStartupObject(StartUpObjectSupported As Boolean, PopulateDropdown As Boolean)
'overridable to support the csharpapplication page (Sub Main isn't used by C#)
Dim InsideInitSave As Boolean = m_fInsideInit
m_fInsideInit = True
Try
Dim StartupObjectPropertyControlData As PropertyControlData = GetPropertyControlData(Const_StartupObject)
If Not StartUpObjectSupported OrElse StartupObjectPropertyControlData.IsMissing Then
With StartupObjectComboBox
.DropDownStyle = ComboBoxStyle.DropDownList
.Items.Clear()
.SelectedIndex = .Items.Add(_noneText)
End With
If StartupObjectPropertyControlData.IsMissing Then
StartupObjectComboBox.Enabled = False
StartupObjectLabel.Enabled = False
End If
Else
Dim prop As PropertyDescriptor = StartupObjectPropertyControlData.PropDesc
Dim SwapWithMyAppData As Boolean = MyApplicationFrameworkEnabled()
With StartupObjectComboBox
.Items.Clear()
If PopulateDropdown Then
Using New WaitCursor
Switches.TracePDPerf("*** Populating start-up object list from the project [may be slow for a large project]")
Debug.Assert(Not InsideInitSave, "PERFORMANCE ALERT: We shouldn't be populating the start-up object dropdown list during page initialization, it should be done later if needed.")
Dim StartupObjects As ICollection = Nothing
If MyApplicationFrameworkEnabled() Then
StartupObjects = GetFormEntryPoints(IncludeSplashScreen:=False)
Else
RefreshPropertyStandardValues() 'Force us to see any new start-up objects in the project
'Certain project types may not support standard values
If prop.Converter.GetStandardValuesSupported() Then
StartupObjects = prop.Converter.GetStandardValues()
End If
End If
If StartupObjects IsNot Nothing Then
For Each o As Object In StartupObjects
Dim EntryPoint As String = RemoveCurrentRootNamespace(TryCast(o, String))
'Remove "My.MyApplication" from the list
If SwapWithMyAppData AndAlso Const_SubMain.Equals(EntryPoint, StringComparison.OrdinalIgnoreCase) Then
'Do not add 'Sub Main' for MY applications
ElseIf Not Const_MyApplicationEntryPoint.Equals(EntryPoint, StringComparison.OrdinalIgnoreCase) Then
.Items.Add(EntryPoint)
End If
Next
End If
End Using
End If
'(Okay to use StartupObject's InitialValue because we checked it against IsMissing up above)
Dim SelectedItemText As String = RemoveCurrentRootNamespace(CStr(StartupObjectPropertyControlData.InitialValue))
If SwapWithMyAppData Then
'We're using the My application framework for start-up, so that means we need to show the MainForm from
' our my application stuff instead of what's in the start-up object (which would set to the My application
' start-up).
SelectedItemText = MainFormTextboxNoRootNS.Text
End If
.SelectedItem = SelectedItemText
If .SelectedItem Is Nothing AndAlso SelectedItemText <> "" Then
.SelectedIndex = .Items.Add(SelectedItemText)
End If
If .SelectedItem Is Nothing AndAlso SelectedItemText = "" Then
.SelectedIndex = .Items.Add(_noneText)
End If
If PopulateDropdown Then
'If "Sub Main" is not in the list and this isn't a WindowsApplication with My, then add it.
Dim SubMainIndex As Integer = .Items.IndexOf(Const_SubMain)
If SwapWithMyAppData Then
'Remove "Sub Main" if this is a MY app
If SubMainIndex > 0 Then
.Items.RemoveAt(SubMainIndex)
End If
ElseIf .Items.IndexOf(Const_SubMain) < 0 Then
.Items.Add(Const_SubMain)
End If
End If
End With
End If
Finally
'Restore previous state
m_fInsideInit = InsideInitSave
End Try
End Sub
Private Sub EnableControlSet(AppType As ApplicationTypes)
Select Case AppType
Case ApplicationTypes.CommandLineApp, ApplicationTypes.WindowsService
EnableIconComboBox(True)
EnableUseApplicationFrameworkCheckBox(False)
Case ApplicationTypes.WindowsApp
EnableIconComboBox(True)
EnableUseApplicationFrameworkCheckBox(True)
Case ApplicationTypes.WindowsClassLib
EnableIconComboBox(False)
EnableUseApplicationFrameworkCheckBox(False)
Case ApplicationTypes.WebControl
EnableIconComboBox(False)
EnableUseApplicationFrameworkCheckBox(False)
Case Else
Debug.Fail("Unexpected ApplicationType")
EnableIconComboBox(False)
EnableUseApplicationFrameworkCheckBox(False)
End Select
EnableMyApplicationControlSet()
EnableControl(ViewUACSettingsButton, UACSettingsButtonSupported(AppType))
End Sub
''' <param name="OutputType"></param>
Private Sub EnableControlSet(OutputType As VSLangProj.prjOutputType)
EnableIconComboBox(OutputType <> VSLangProj.prjOutputType.prjOutputTypeLibrary)
EnableMyApplicationControlSet()
EnableControl(ViewUACSettingsButton, UACSettingsButtonSupported(OutputType))
End Sub
''' <summary>
''' Sets the visibility of the MyApplication-related properties
''' </summary>
Private Sub EnableMyApplicationControlSet()
If Not MyApplicationPropertiesSupported Then
'If MyApplication property not supported at all, then this project system flavor has disabled it,
' and we want to completely hide all my-related controls, so we don't confuse users.
WindowsAppGroupBox.Visible = False
UseApplicationFrameworkCheckBox.Visible = False
Else
WindowsAppGroupBox.Visible = True
UseApplicationFrameworkCheckBox.Visible = True
SaveMySettingsCheckbox.Enabled = MySettingsSupported()
End If
End Sub
Protected Overrides Function GetF1HelpKeyword() As String
Return HelpKeywords.VBProjPropApplication
End Function
''' <summary>
''' Customizable processing done before the class has populated controls in the ControlData array
''' </summary>
''' <remarks>
''' Override this to implement custom processing.
''' IMPORTANT NOTE: this method can be called multiple times on the same page. In particular,
''' it is called on every SetObjects call, which means that when the user changes the
''' selected configuration, it is called again.
''' </remarks>
Protected Overrides Sub PreInitPage()
MyBase.PreInitPage()
If Not SupportsOutputTypeProperty() Then
ApplicationTypeComboBox.Enabled = False
ApplicationTypeLabel.Enabled = False
Else
' If the project specifies the output types, use the output types instead of the my application types
_usingMyApplicationTypes = Not PopulateOutputTypeComboBoxFromProjectProperty(ApplicationTypeComboBox)
If _usingMyApplicationTypes Then
PopulateApplicationTypes(ApplicationTypeComboBox, s_applicationTypes)
End If
End If
ShutdownModeComboBox.Items.Clear()
ShutdownModeComboBox.Items.AddRange(_shutdownModeStringValues)
AuthenticationModeComboBox.Items.Clear()
AuthenticationModeComboBox.Items.AddRange(_authenticationModeStringValues)
PopulateTargetFrameworkComboBox(TargetFrameworkComboBox)
' Hide the AssemblyInformation button if project supports Pack capability, and hence has a Package property page with assembly info properties.
EnableControl(AssemblyInfoButton, Not ProjectHierarchy.IsCapabilityMatch(Pack))
End Sub
''' <summary>
''' Customizable processing done after base class has populated controls in the ControlData array
''' </summary>
''' <remarks>
''' Override this to implement custom processing.
''' IMPORTANT NOTE: this method can be called multiple times on the same page. In particular,
''' it is called on every SetObjects call, which means that when the user changes the
''' selected configuration, it is called again.
''' </remarks>
Protected Overrides Sub PostInitPage()
MyBase.PostInitPage()
If MyTypeDisabled() Then
'If the MyType is disabled, we should turn on Custom Sub Main. This will ensure we don't write any
' code for Application.Designer.vb, which would not compile for ApplicationType=WindowsForms.
If MyApplicationProperties IsNot Nothing Then
Try
MyApplicationProperties.CustomSubMain = True
UseApplicationFrameworkCheckBox.CheckState = CheckState.Unchecked
Catch ex As Exception When ReportWithoutCrash(ex, NameOf(PostInitPage), NameOf(ApplicationPropPageVBWinForms))
End Try
End If
End If
' enable/disable controls based upon the current value of the project's
' OutputType (.exe, .dll...)
EnableControlSet(ProjectProperties.OutputType)
PopulateIconList(False)
UpdateIconImage(False)
SetStartupObjectLabelText()
PopulateSplashScreenList(False)
End Sub
''' <summary>
''' Shows or hides the Auto-generate Binding Redirects checkbox depending on the new target
''' framework.
''' </summary>
Protected Overrides Sub TargetFrameworkMonikerChanged()
ShowAutoGeneratedBindingRedirectsCheckBox(TargetFrameworkComboBox, AutoGenerateBindingRedirectsCheckBox)
End Sub
Public Overrides Function GetUserDefinedPropertyDescriptor(PropertyName As String) As PropertyDescriptor
If PropertyName = Const_MyApplication Then
Return New UserPropertyDescriptor(PropertyName, GetType(MyApplicationProperties))
ElseIf PropertyName = Const_EnableVisualStyles Then
Return New UserPropertyDescriptor(PropertyName, GetType(Boolean))