Skip to content

Commit 9022ff5

Browse files
committed
Include available Refactor menus in Contextual Code Generation list
This makes FD feel more like Visual Studio, especially when you set the keyboard shortcut to Ctrl+OemPeriod. Rename, Extract Method, Extract Local Variable, Generate Delegate Methods, Organise Imports and Truncate Imports can be available using the context code generator list.
1 parent 9e1bdec commit 9022ff5

File tree

11 files changed

+229
-162
lines changed

11 files changed

+229
-162
lines changed

External/Plugins/AS2Context/Context.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public Context(AS2Settings initSettings)
9999
features.objectKey = "Object";
100100
features.booleanKey = "Boolean";
101101
features.numberKey = "Number";
102+
features.stringKey = "String";
102103
features.arrayKey = "Array";
104+
features.dynamicKey = "*";
103105
features.importKey = "import";
104106
features.typesPreKeys = new string[] { "import", "new", "instanceof", "extends", "implements" };
105107
features.codeKeywords = new string[] {

External/Plugins/AS3Context/Context.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ public Context(AS3Settings initSettings)
101101
features.objectKey = "Object";
102102
features.booleanKey = "Boolean";
103103
features.numberKey = "Number";
104+
features.stringKey = "String";
104105
features.arrayKey = "Array";
106+
features.dynamicKey = "*";
105107
features.importKey = "import";
106108
features.typesPreKeys = new string[] { "import", "new", "typeof", "is", "as", "extends", "implements" };
107109
features.codeKeywords = new string[] {

External/Plugins/ASCompletion/Completion/ASComplete.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,9 @@ private static void ClearResolvedContext()
860860
NotifyContextChanged();
861861
}
862862

863-
private static void NotifyContextChanged()
863+
public static void NotifyContextChanged()
864864
{
865-
if (OnResolvedContextChanged != null)
866-
OnResolvedContextChanged(CurrentResolvedContext);
865+
OnResolvedContextChanged?.Invoke(CurrentResolvedContext);
867866
}
868867

869868
/// <summary>

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 74 additions & 71 deletions
Large diffs are not rendered by default.

External/Plugins/ASCompletion/Completion/ContextFeatures.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public class ContextFeatures
7272
public string objectKey;
7373
public string booleanKey;
7474
public string numberKey;
75+
public string stringKey;
7576
public string arrayKey;
77+
public string dynamicKey;
7678
public string importKey;
7779
public string importKeyAlt;
7880
public string[] typesPreKeys = new string[] { };

External/Plugins/ASCompletion/PluginMain.cs

Lines changed: 141 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -446,104 +446,107 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
446446
// Actionscript context specific
447447
//
448448
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))
460454
{
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);
471457
te.Value = ArgumentsProcessor.Process(te.Value, details);
472-
}
473-
}
474-
break;
475458

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+
}
488473
}
474+
break;
489475

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."))
492481
{
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+
}
496490

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+
}
503497

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+
}
515504

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")
535524
{
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+
}
537541
}
538542
}
539-
}
540-
return;
543+
return;
541544

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+
}
547550
}
548551
catch(Exception ex)
549552
{
@@ -960,6 +963,59 @@ private void ContextChanged()
960963
SetItemsEnabled(enableItems, ASContext.Context.CanBuild);
961964
}
962965
#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
9631019
}
9641020

9651021
}

External/Plugins/CodeRefactor/Commands/RefactorCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace CodeRefactor.Commands
55
{
66
/// <summary>
7-
/// Basic underyling Refactoring command. Refactoring commands can derive from this.
7+
/// Basic underlying Refactoring command. Refactoring commands can derive from this.
88
/// </summary>
99
/// <typeparam name="RefactorResultType">The refactoring results return type</typeparam>
1010
public abstract class RefactorCommand<RefactorResultType>

External/Plugins/CodeRefactor/PluginMain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ private void BatchMenuItemClicked(Object sender, EventArgs e)
629629
/// </summary>
630630
private void CodeGeneratorMenuItemClicked(Object sender, EventArgs e)
631631
{
632-
DataEvent de = new DataEvent(EventType.Command, "ASCompletion.ContextualGenerator", null);
632+
DataEvent de = new DataEvent(EventType.Command, "ASCompletion.ContextualGenerator", refactorContextMenu);
633633
EventManager.DispatchEvent(this, de);
634634
}
635635

External/Plugins/HaXeContext/Context.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public Context(HaXeSettings initSettings)
115115
features.objectKey = "Dynamic";
116116
features.booleanKey = "Bool";
117117
features.numberKey = "Float";
118+
features.stringKey = "String";
118119
features.arrayKey = "Array<T>";
120+
features.dynamicKey = "Dynamic";
119121
features.importKey = "import";
120122
features.importKeyAlt = "using";
121123
features.typesPreKeys = new string[] { "import", "new", "extends", "implements", "using" };

External/Plugins/LoomContext/Context.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public Context(LoomSettings initSettings)
7373
features.objectKey = "Object";
7474
features.booleanKey = "Boolean";
7575
features.numberKey = "Number";
76+
features.stringKey = "String";
7677
features.arrayKey = "Array";
7778
features.importKey = "import";
7879
features.typesPreKeys = new string[] { "import", "new", "typeof", "is", "as", "extends", "implements" };

0 commit comments

Comments
 (0)