@@ -446,104 +446,107 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
446
446
// Actionscript context specific
447
447
//
448
448
if ( ASContext . Context . IsFileValid )
449
- switch ( e . Type )
450
- {
451
- case EventType . ProcessArgs :
452
- TextEvent te = ( TextEvent ) e ;
453
- if ( reArgs . IsMatch ( te . Value ) )
454
- {
455
- // resolve current element
456
- Hashtable details = ASComplete . ResolveElement ( sci , null ) ;
457
- te . Value = ArgumentsProcessor . Process ( te . Value , details ) ;
458
-
459
- if ( te . Value . IndexOf ( "$" ) >= 0 && reCostlyArgs . IsMatch ( te . Value ) )
449
+ switch ( e . Type )
450
+ {
451
+ case EventType . ProcessArgs :
452
+ TextEvent te = ( TextEvent ) e ;
453
+ if ( reArgs . IsMatch ( te . Value ) )
460
454
{
461
- ASResult result = ASComplete . CurrentResolvedContext . Result ?? new ASResult ( ) ;
462
- details = new Hashtable ( ) ;
463
- // Get closest list (Array or Vector)
464
- string closestListName = "" , closestListItemType = "" ;
465
- ASComplete . FindClosestList ( ASContext . Context , result . Context , sci . CurrentLine , ref closestListName , ref closestListItemType ) ;
466
- details . Add ( "TypClosestListName" , closestListName ) ;
467
- details . Add ( "TypClosestListItemType" , closestListItemType ) ;
468
- // get free iterator index
469
- string iterator = ASComplete . FindFreeIterator ( ASContext . Context , ASContext . Context . CurrentClass , result . Context ) ;
470
- details . Add ( "ItmUniqueVar" , iterator ) ;
455
+ // resolve current element
456
+ Hashtable details = ASComplete . ResolveElement ( sci , null ) ;
471
457
te . Value = ArgumentsProcessor . Process ( te . Value , details ) ;
472
- }
473
- }
474
- break ;
475
458
476
- // menu commands
477
- case EventType . Command :
478
- string command = ( e as DataEvent ) . Action ?? "" ;
479
- if ( command . StartsWith ( "ASCompletion." ) )
480
- {
481
- string cmdData = ( e as DataEvent ) . Data as string ;
482
- // run MTASC
483
- if ( command == "ASCompletion.CustomBuild" )
484
- {
485
- if ( cmdData != null ) ASContext . Context . RunCMD ( cmdData ) ;
486
- else ASContext . Context . RunCMD ( "" ) ;
487
- e . Handled = true ;
459
+ if ( te . Value . IndexOf ( "$" ) >= 0 && reCostlyArgs . IsMatch ( te . Value ) )
460
+ {
461
+ ASResult result = ASComplete . CurrentResolvedContext . Result ?? new ASResult ( ) ;
462
+ details = new Hashtable ( ) ;
463
+ // Get closest list (Array or Vector)
464
+ string closestListName = "" , closestListItemType = "" ;
465
+ ASComplete . FindClosestList ( ASContext . Context , result . Context , sci . CurrentLine , ref closestListName , ref closestListItemType ) ;
466
+ details . Add ( "TypClosestListName" , closestListName ) ;
467
+ details . Add ( "TypClosestListItemType" , closestListItemType ) ;
468
+ // get free iterator index
469
+ string iterator = ASComplete . FindFreeIterator ( ASContext . Context , ASContext . Context . CurrentClass , result . Context ) ;
470
+ details . Add ( "ItmUniqueVar" , iterator ) ;
471
+ te . Value = ArgumentsProcessor . Process ( te . Value , details ) ;
472
+ }
488
473
}
474
+ break ;
489
475
490
- // build the SWF using MTASC
491
- else if ( command == "ASCompletion.QuickBuild" )
476
+ // menu commands
477
+ case EventType . Command :
478
+ de = e as DataEvent ;
479
+ string command = de . Action ?? "" ;
480
+ if ( command . StartsWith ( "ASCompletion." ) )
492
481
{
493
- ASContext . Context . BuildCMD ( false ) ;
494
- e . Handled = true ;
495
- }
482
+ string cmdData = de . Data as string ;
483
+ // run MTASC
484
+ if ( command == "ASCompletion.CustomBuild" )
485
+ {
486
+ if ( cmdData != null ) ASContext . Context . RunCMD ( cmdData ) ;
487
+ else ASContext . Context . RunCMD ( "" ) ;
488
+ e . Handled = true ;
489
+ }
496
490
497
- // resolve element under cusor and open declaration
498
- else if ( command == "ASCompletion.GotoDeclaration " )
499
- {
500
- ASComplete . DeclarationLookup ( sci ) ;
501
- e . Handled = true ;
502
- }
491
+ // build the SWF using MTASC
492
+ else if ( command == "ASCompletion.QuickBuild " )
493
+ {
494
+ ASContext . Context . BuildCMD ( false ) ;
495
+ e . Handled = true ;
496
+ }
503
497
504
- // resolve element under cursor and send a CustomData event
505
- else if ( command == "ASCompletion.ResolveElement" )
506
- {
507
- ASComplete . ResolveElement ( sci , cmdData ) ;
508
- e . Handled = true ;
509
- }
510
- else if ( command == "ASCompletion.MakeIntrinsic" )
511
- {
512
- ASContext . Context . MakeIntrinsic ( cmdData ) ;
513
- e . Handled = true ;
514
- }
498
+ // resolve element under cursor and open declaration
499
+ else if ( command == "ASCompletion.GotoDeclaration" )
500
+ {
501
+ ASComplete . DeclarationLookup ( sci ) ;
502
+ e . Handled = true ;
503
+ }
515
504
516
- // alternative to default shortcuts
517
- else if ( command == "ASCompletion.CtrlSpace " )
518
- {
519
- ASComplete . OnShortcut ( Keys . Control | Keys . Space , ASContext . CurSciControl ) ;
520
- e . Handled = true ;
521
- }
522
- else if ( command == "ASCompletion.CtrlShiftSpace " )
523
- {
524
- ASComplete . OnShortcut ( Keys . Control | Keys . Shift | Keys . Space , ASContext . CurSciControl ) ;
525
- e . Handled = true ;
526
- }
527
- else if ( command == "ASCompletion.CtrlAltSpace" )
528
- {
529
- ASComplete . OnShortcut ( Keys . Control | Keys . Alt | Keys . Space , ASContext . CurSciControl ) ;
530
- e . Handled = true ;
531
- }
532
- else if ( command == "ASCompletion.ContextualGenerator" )
533
- {
534
- if ( ASContext . HasContext && ASContext . Context . IsFileValid )
505
+ // resolve element under cursor and send a CustomData event
506
+ else if ( command == "ASCompletion.ResolveElement " )
507
+ {
508
+ ASComplete . ResolveElement ( sci , cmdData ) ;
509
+ e . Handled = true ;
510
+ }
511
+ else if ( command == "ASCompletion.MakeIntrinsic " )
512
+ {
513
+ ASContext . Context . MakeIntrinsic ( cmdData ) ;
514
+ e . Handled = true ;
515
+ }
516
+
517
+ // alternative to default shortcuts
518
+ else if ( command == "ASCompletion.CtrlSpace" )
519
+ {
520
+ ASComplete . OnShortcut ( Keys . Control | Keys . Space , ASContext . CurSciControl ) ;
521
+ e . Handled = true ;
522
+ }
523
+ else if ( command == "ASCompletion.CtrlShiftSpace" )
535
524
{
536
- ASGenerator . ContextualGenerator ( ASContext . CurSciControl ) ;
525
+ ASComplete . OnShortcut ( Keys . Control | Keys . Shift | Keys . Space , ASContext . CurSciControl ) ;
526
+ e . Handled = true ;
527
+ }
528
+ else if ( command == "ASCompletion.CtrlAltSpace" )
529
+ {
530
+ ASComplete . OnShortcut ( Keys . Control | Keys . Alt | Keys . Space , ASContext . CurSciControl ) ;
531
+ e . Handled = true ;
532
+ }
533
+ else if ( command == "ASCompletion.ContextualGenerator" )
534
+ {
535
+ if ( ASContext . HasContext && ASContext . Context . IsFileValid )
536
+ {
537
+ ASGenerator . ContextualGenerator ( ASContext . CurSciControl ) ;
538
+ AddRefactorMenus ( ASGenerator . KnownList , de . Data as ToolStripMenuItem ) ;
539
+ CompletionList . Show ( ASGenerator . KnownList , false ) ;
540
+ }
537
541
}
538
542
}
539
- }
540
- return ;
543
+ return ;
541
544
542
- case EventType . ProcessEnd :
543
- string procResult = ( e as TextEvent ) . Value ;
544
- ASContext . Context . OnProcessEnd ( procResult ) ;
545
- break ;
546
- }
545
+ case EventType . ProcessEnd :
546
+ string procResult = ( e as TextEvent ) . Value ;
547
+ ASContext . Context . OnProcessEnd ( procResult ) ;
548
+ break ;
549
+ }
547
550
}
548
551
catch ( Exception ex )
549
552
{
@@ -960,6 +963,59 @@ private void ContextChanged()
960
963
SetItemsEnabled ( enableItems , ASContext . Context . CanBuild ) ;
961
964
}
962
965
#endregion
966
+
967
+ #region Contextual Code Generation Utilities
968
+
969
+ void AddRefactorMenus ( List < ICompletionListItem > list , ToolStripMenuItem menu )
970
+ {
971
+ if ( list == null )
972
+ return ;
973
+
974
+ ASComplete . NotifyContextChanged ( ) ;
975
+ Type RefactorMenu = menu . GetType ( ) ;
976
+
977
+ var RenameMenuItem = GetItem ( RefactorMenu , menu , "RenameMenuItem" ) ;
978
+ var ExtractMethodMenuItem = GetItem ( RefactorMenu , menu , "ExtractMethodMenuItem" ) ;
979
+ var ExtractLocalVariableMenuItem = GetItem ( RefactorMenu , menu , "ExtractLocalVariableMenuItem" ) ;
980
+ var DelegateMenuItem = GetItem ( RefactorMenu , menu , "DelegateMenuItem" ) ;
981
+
982
+ if ( RenameMenuItem . Enabled ) list . Add ( new RefactorItem ( RenameMenuItem ) ) ;
983
+ if ( ExtractMethodMenuItem . Enabled ) list . Add ( new RefactorItem ( ExtractMethodMenuItem ) ) ;
984
+ if ( ExtractLocalVariableMenuItem . Enabled ) list . Add ( new RefactorItem ( ExtractLocalVariableMenuItem ) ) ;
985
+ if ( DelegateMenuItem . Enabled ) list . Add ( new RefactorItem ( DelegateMenuItem ) ) ;
986
+
987
+ var features = ASContext . Context . Features ;
988
+
989
+ if ( ! features . hasImports )
990
+ return ;
991
+
992
+ var sci = ASContext . CurSciControl ;
993
+ string line = sci . GetLine ( sci . CurrentLine ) . TrimStart ( ) ;
994
+
995
+ if ( line . StartsWith ( features . importKey , StringComparison . Ordinal )
996
+ || ! string . IsNullOrEmpty ( features . importKeyAlt ) && line . StartsWith ( features . importKeyAlt , StringComparison . Ordinal ) )
997
+ {
998
+ var OrganizeMenuItem = GetItem ( RefactorMenu , menu , "OrganizeMenuItem" ) ;
999
+
1000
+ if ( OrganizeMenuItem . Enabled )
1001
+ list . Add ( new RefactorItem ( OrganizeMenuItem ) ) ;
1002
+
1003
+ if ( features . hasImportsWildcard )
1004
+ {
1005
+ var TruncateMenuItem = GetItem ( RefactorMenu , menu , "TruncateMenuItem" ) ;
1006
+
1007
+ if ( TruncateMenuItem . Enabled )
1008
+ list . Add ( new RefactorItem ( TruncateMenuItem ) ) ;
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ ToolStripMenuItem GetItem ( Type type , ToolStripMenuItem menu , string item )
1014
+ {
1015
+ return type . GetProperty ( item ) . GetValue ( menu , null ) as ToolStripMenuItem ;
1016
+ }
1017
+
1018
+ #endregion
963
1019
}
964
1020
965
1021
}
0 commit comments