@@ -801,15 +801,22 @@ private static void ShowEventList(FoundDeclaration found, List<ICompletionListIt
801
801
string labelEvent = String . Format ( tmp , "Event" ) ;
802
802
string labelDataEvent = String . Format ( tmp , "DataEvent" ) ;
803
803
string labelContext = String . Format ( tmp , contextParam ) ;
804
- string [ ] choices = ( contextParam != "Event" ) ?
805
- new string [ ] { labelContext , labelEvent } :
806
- new string [ ] { labelEvent , labelDataEvent } ;
804
+ string [ ] choices ;
805
+ if ( contextParam != "Event" ) choices = new string [ ] { labelContext , labelEvent } ;
806
+ else if ( HasDataEvent ( ) ) choices = new string [ ] { labelEvent , labelDataEvent } ;
807
+ else choices = new string [ ] { labelEvent } ;
808
+
807
809
for ( int i = 0 ; i < choices . Length ; i ++ )
808
810
{
809
811
options . Add ( new GeneratorItem ( choices [ i ] ,
810
812
choices [ i ] == labelContext ? GeneratorJobType . ComplexEvent : GeneratorJobType . BasicEvent ,
811
813
found . member , found . inClass ) ) ;
812
814
}
815
+ }
816
+
817
+ private static bool HasDataEvent ( )
818
+ {
819
+ return ! ASContext . Context . ResolveType ( "flash.events.DataEvent" , ASContext . Context . CurrentModel ) . IsVoid ( ) ;
813
820
}
814
821
815
822
private static void ShowGetSetList ( FoundDeclaration found , List < ICompletionListItem > options )
@@ -3569,22 +3576,12 @@ private static void GenerateEventHandler(string name, string type, MemberModel a
3569
3576
ClassModel eventClass = ASContext . Context . ResolveType ( type , ASContext . Context . CurrentModel ) ;
3570
3577
if ( eventClass . IsVoid ( ) )
3571
3578
{
3572
- if ( type == "Event" )
3573
- {
3574
- List < string > typesUsed = new List < string > ( ) ;
3575
- typesUsed . Add ( "flash.events.Event" ) ;
3576
- delta = AddImportsByName ( typesUsed , sci . LineFromPosition ( position ) ) ;
3577
- position += delta ;
3578
- sci . SetSel ( position , position ) ;
3579
- }
3580
- else if ( type == "DataEvent" )
3581
- {
3582
- List < string > typesUsed = new List < string > ( ) ;
3583
- typesUsed . Add ( "flash.events.DataEvent" ) ;
3584
- delta = AddImportsByName ( typesUsed , sci . LineFromPosition ( position ) ) ;
3585
- position += delta ;
3586
- sci . SetSel ( position , position ) ;
3587
- }
3579
+ if ( TryImportType ( "flash.events." + type , ref delta , sci . LineFromPosition ( position ) ) )
3580
+ {
3581
+ position += delta ;
3582
+ sci . SetSel ( position , position ) ;
3583
+ }
3584
+ else type = null ;
3588
3585
}
3589
3586
lookupPosition += delta ;
3590
3587
string acc = GetPrivateAccessor ( afterMethod , inClass ) ;
@@ -3608,6 +3605,18 @@ private static void GenerateEventHandler(string name, string type, MemberModel a
3608
3605
{
3609
3606
sci . EndUndoAction ( ) ;
3610
3607
}
3608
+ }
3609
+
3610
+ private static bool TryImportType ( string type , ref int delta , int atLine )
3611
+ {
3612
+ ClassModel eventClass = ASContext . Context . ResolveType ( type , ASContext . Context . CurrentModel ) ;
3613
+ if ( eventClass . IsVoid ( ) )
3614
+ return false ;
3615
+
3616
+ List < string > typesUsed = new List < string > ( ) ;
3617
+ typesUsed . Add ( type ) ;
3618
+ delta += AddImportsByName ( typesUsed , atLine ) ;
3619
+ return true ;
3611
3620
}
3612
3621
3613
3622
static private string AddRemoveEvent ( string eventName )
0 commit comments