66using Microsoft . VisualStudio . Designer . Interfaces ;
77using System ;
88using System . Collections ;
9+ using System . Collections . Generic ;
910using System . ComponentModel ;
1011using System . Drawing ;
1112using System . Globalization ;
1213using System . IO ;
14+ using System . Linq ;
1315using System . Runtime . InteropServices ;
1416using System . Windows . Forms ;
1517using System . Xml ;
@@ -464,7 +466,7 @@ public VSLangProj.prjBuildAction BuildAction
464466{
465467get
466468{
467- var res = BuildActionTypeConverter . Instance . ConvertFromString ( this . Node . ItemNode . ItemName ) ;
469+ var res = BuildActionTypeConverter . Instance . ConvertFromString ( this . Node . ProjectMgr . BuildActionConverter , this . Node . ItemNode . ItemName ) ;
468470if ( res is VSLangProj . prjBuildAction )
469471{
470472return ( VSLangProj . prjBuildAction ) res ;
@@ -473,7 +475,7 @@ public VSLangProj.prjBuildAction BuildAction
473475}
474476set
475477{
476- this . Node . ItemNode . ItemName = BuildActionTypeConverter . Instance . ConvertToString ( value ) ;
478+ this . Node . ItemNode . ItemName = BuildActionTypeConverter . Instance . ConvertToString ( this . Node . ProjectMgr . BuildActionConverter , value ) ;
477479}
478480}
479481
@@ -483,11 +485,11 @@ public virtual string ItemType
483485{
484486get
485487{
486- return BuildActionTypeConverter . Instance . ConvertToString ( this . BuildAction ) ;
488+ return BuildActionTypeConverter . Instance . ConvertToString ( this . Node . ProjectMgr . BuildActionConverter , this . BuildAction ) ;
487489}
488490set
489491{
490- var res = BuildActionTypeConverter . Instance . ConvertFromString ( value ) ;
492+ var res = BuildActionTypeConverter . Instance . ConvertFromString ( this . Node . ProjectMgr . BuildActionConverter , value ) ;
491493if ( res is VSLangProj . prjBuildAction )
492494{
493495this . BuildAction = ( VSLangProj . prjBuildAction ) res ;
@@ -527,65 +529,123 @@ public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
527529
528530public override bool CanConvertFrom ( ITypeDescriptorContext context , Type sourceType )
529531{
530- if ( sourceType == typeof ( string ) )
531- {
532- return true ;
533- }
534- return base . CanConvertFrom ( context , sourceType ) ;
532+ return ( sourceType == typeof ( string ) ) ? true : base . CanConvertFrom ( context , sourceType ) ;
535533}
536534
537535public override bool CanConvertTo ( ITypeDescriptorContext context , Type destinationType )
538536{
539- return base . CanConvertTo ( context , destinationType ) ;
537+ return ( destinationType == typeof ( string ) ) ? true : base . CanConvertTo ( context , destinationType ) ;
540538}
541539
542540public override object ConvertTo ( ITypeDescriptorContext context , CultureInfo culture , object value , Type destinationType )
543541{
544542if ( destinationType == typeof ( string ) )
545543{
546- switch ( ( VSLangProj . prjBuildAction ) value )
547- {
548- case VSLangProj . prjBuildAction . prjBuildActionCompile :
549- return "Compile" ;
550- case VSLangProj . prjBuildAction . prjBuildActionContent :
551- return "Content" ;
552- case VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource :
553- return "EmbeddedResource" ;
554- case VSLangProj . prjBuildAction . prjBuildActionNone :
555- return "None" ;
556- }
544+ var reply = ConvertToString ( GetBuildActionConverter ( context ) , value ) ;
545+ if ( reply != null ) return reply ;
557546}
558547return base . ConvertTo ( context , culture , value , destinationType ) ;
559548}
560549
561- public override object ConvertFrom ( ITypeDescriptorContext context , CultureInfo culture , object value )
550+ public string ConvertToString ( BuildActionConverter buildActionConverter , object value )
562551{
563- if ( value is string )
552+ switch ( ( VSLangProj . prjBuildAction ) value )
564553{
565- string strVal = ( string ) value ;
566- if ( strVal . Equals ( "Compile" , StringComparison . OrdinalIgnoreCase ) )
554+ case VSLangProj . prjBuildAction . prjBuildActionCompile :
555+ return "Compile" ;
556+ case VSLangProj . prjBuildAction . prjBuildActionContent :
557+ return "Content" ;
558+ case VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource :
559+ return "EmbeddedResource" ;
560+ case VSLangProj . prjBuildAction . prjBuildActionNone :
561+ return "None" ;
562+ default :
563+ if ( buildActionConverter != null )
567564{
568- return VSLangProj . prjBuildAction . prjBuildActionCompile ;
569- }
570- else if ( strVal . Equals ( "Content" , StringComparison . OrdinalIgnoreCase ) )
571- {
572- return VSLangProj . prjBuildAction . prjBuildActionContent ;
565+ // Not standard buildAction, so must have been registered.
566+ // Convert it to the name of the BuildAction at position index in the StandardValues from the BuildActionConverter
567+ int index = ( int ) value ;
568+ var actions = buildActionConverter . RegisteredBuildActions ;
569+ if ( index >= 0 && index < actions . Count )
570+ {
571+ return actions [ index ] . Name ;
572+ }
573573}
574- else if ( strVal . Equals ( "EmbeddedResource" , StringComparison . OrdinalIgnoreCase ) )
574+ return "None" ;
575+ }
576+ }
577+
578+ public override object ConvertFrom ( ITypeDescriptorContext context , CultureInfo culture , object value )
579+ {
580+ if ( value is string )
581+ {
582+ var reply = ConvertFromString ( GetBuildActionConverter ( context ) , ( string ) value ) ;
583+ if ( reply != null ) return reply ;
584+ }
585+ return base . ConvertFrom ( context , culture , value ) ;
586+ }
587+
588+ public object ConvertFromString ( BuildActionConverter buildActionConverter , string value )
589+ {
590+ if ( value . Equals ( "Compile" , StringComparison . OrdinalIgnoreCase ) )
591+ {
592+ return VSLangProj . prjBuildAction . prjBuildActionCompile ;
593+ }
594+ else if ( value . Equals ( "Content" , StringComparison . OrdinalIgnoreCase ) )
595+ {
596+ return VSLangProj . prjBuildAction . prjBuildActionContent ;
597+ }
598+ else if ( value . Equals ( "EmbeddedResource" , StringComparison . OrdinalIgnoreCase ) )
599+ {
600+ return VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource ;
601+ }
602+ else if ( value . Equals ( "None" , StringComparison . OrdinalIgnoreCase ) )
603+ {
604+ return VSLangProj . prjBuildAction . prjBuildActionNone ;
605+ }
606+ else
607+ {
608+ if ( buildActionConverter != null )
575609{
576- return VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource ;
610+ // Not standard buildAction, so must have been registered.
611+ // Convert it to the index in the StandardValues from the BuildActionConverter.
612+ var actions = buildActionConverter . RegisteredBuildActions ;
613+ var reply = actions . ToList ( ) . FindIndex ( i=> value . Equals ( i . Name , StringComparison . OrdinalIgnoreCase ) ) ;
614+ if ( reply != - 1 ) return ( VSLangProj . prjBuildAction ) reply ;
577615}
578- else if ( strVal . Equals ( "None" , StringComparison . OrdinalIgnoreCase ) )
616+ }
617+ return VSLangProj . prjBuildAction . prjBuildActionNone ;
618+ }
619+
620+ public override StandardValuesCollection GetStandardValues ( ITypeDescriptorContext context )
621+ {
622+ var buildActionConverter = GetBuildActionConverter ( context ) ;
623+ if ( buildActionConverter != null )
624+ {
625+ var results = new List < VSLangProj . prjBuildAction > ( ) ;
626+ foreach ( var a in buildActionConverter . RegisteredBuildActions )
579627{
580- return VSLangProj . prjBuildAction . prjBuildActionNone ;
628+ results . Add ( ( VSLangProj . prjBuildAction ) this . ConvertFrom ( context , CultureInfo . CurrentUICulture , a . Name ) ) ;
581629}
630+ return new StandardValuesCollection ( results ) ;
631+ }
632+ else
633+ {
634+ return new StandardValuesCollection ( new [ ] { VSLangProj . prjBuildAction . prjBuildActionNone , VSLangProj . prjBuildAction . prjBuildActionCompile , VSLangProj . prjBuildAction . prjBuildActionContent , VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource } ) ;
582635}
583- return base . ConvertFrom ( context , culture , value ) ;
584636}
585637
586- public override StandardValuesCollection GetStandardValues ( ITypeDescriptorContext context )
638+ private static BuildActionConverter GetBuildActionConverter ( ITypeDescriptorContext context )
587639{
588- return new StandardValuesCollection ( new [ ] { VSLangProj . prjBuildAction . prjBuildActionNone , VSLangProj . prjBuildAction . prjBuildActionCompile , VSLangProj . prjBuildAction . prjBuildActionContent , VSLangProj . prjBuildAction . prjBuildActionEmbeddedResource } ) ;
640+ if ( context != null )
641+ {
642+ BuildableNodeProperties nodeProperties = context . Instance as BuildableNodeProperties ;
643+ if ( nodeProperties != null )
644+ {
645+ return nodeProperties . Node . ProjectMgr . BuildActionConverter ;
646+ }
647+ }
648+ return null ;
589649}
590650}
591651
@@ -1553,4 +1613,4 @@ public override string FullPath
15531613}
15541614 #endregion
15551615}
1556- }
1616+ }