Skip to content

Commit 73cbfd6

Browse files
committed
Merge pull request #989 from wise0704/CodeRefactor
Contextual Code Generation update
2 parents 84962f2 + 17b3f23 commit 73cbfd6

File tree

7 files changed

+168
-152
lines changed

7 files changed

+168
-152
lines changed

External/Plugins/ASCompletion/Completion/ASGenerator.cs

Lines changed: 91 additions & 98 deletions
Large diffs are not rendered by default.

External/Plugins/ASCompletion/PluginMain.cs

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
446446
// Actionscript context specific
447447
//
448448
if (ASContext.Context.IsFileValid)
449+
{
449450
switch (e.Type)
450451
{
451452
case EventType.ProcessArgs:
@@ -480,65 +481,67 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
480481
if (command.StartsWith("ASCompletion.", StringComparison.Ordinal))
481482
{
482483
string cmdData = de.Data as string;
483-
// run MTASC
484-
if (command == "ASCompletion.CustomBuild")
484+
switch (command)
485485
{
486-
if (cmdData != null) ASContext.Context.RunCMD(cmdData);
487-
else ASContext.Context.RunCMD("");
488-
e.Handled = true;
489-
}
486+
// run MTASC
487+
case "ASCompletion.CustomBuild":
488+
if (cmdData != null) ASContext.Context.RunCMD(cmdData);
489+
else ASContext.Context.RunCMD("");
490+
e.Handled = true;
491+
break;
490492

491-
// build the SWF using MTASC
492-
else if (command == "ASCompletion.QuickBuild")
493-
{
494-
ASContext.Context.BuildCMD(false);
495-
e.Handled = true;
496-
}
493+
// build the SWF using MTASC
494+
case "ASCompletion.QuickBuild":
495+
ASContext.Context.BuildCMD(false);
496+
e.Handled = true;
497+
break;
497498

498-
// resolve element under cursor and open declaration
499-
else if (command == "ASCompletion.GotoDeclaration")
500-
{
501-
ASComplete.DeclarationLookup(sci);
502-
e.Handled = true;
503-
}
499+
// resolve element under cursor and open declaration
500+
case "ASCompletion.GotoDeclaration":
501+
ASComplete.DeclarationLookup(sci);
502+
e.Handled = true;
503+
break;
504504

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-
}
505+
// resolve element under cursor and send a CustomData event
506+
case "ASCompletion.ResolveElement":
507+
ASComplete.ResolveElement(sci, cmdData);
508+
e.Handled = true;
509+
break;
516510

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")
524-
{
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-
var options = ASGenerator.ContextualGenerator(ASContext.CurSciControl);
538-
var dataEvent = new DataEvent(EventType.Command, "ASCompletion.ContextualGenerator.AddOptions", options);
539-
EventManager.DispatchEvent(this, dataEvent);
540-
CompletionList.Show(options, false);
541-
}
511+
case "ASCompletion.MakeIntrinsic":
512+
ASContext.Context.MakeIntrinsic(cmdData);
513+
e.Handled = true;
514+
break;
515+
516+
// alternative to default shortcuts
517+
case "ASCompletion.CtrlSpace":
518+
ASComplete.OnShortcut(Keys.Control | Keys.Space, ASContext.CurSciControl);
519+
e.Handled = true;
520+
break;
521+
522+
case "ASCompletion.CtrlShiftSpace":
523+
ASComplete.OnShortcut(Keys.Control | Keys.Shift | Keys.Space, ASContext.CurSciControl);
524+
e.Handled = true;
525+
break;
526+
527+
case "ASCompletion.CtrlAltSpace":
528+
ASComplete.OnShortcut(Keys.Control | Keys.Alt | Keys.Space, ASContext.CurSciControl);
529+
e.Handled = true;
530+
break;
531+
532+
case "ASCompletion.ContextualGenerator":
533+
if (ASContext.HasContext && ASContext.Context.IsFileValid)
534+
{
535+
var options = new List<ICompletionListItem>();
536+
ASGenerator.ContextualGenerator(ASContext.CurSciControl, options);
537+
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ASCompletion.ContextualGenerator.AddOptions", options));
538+
if (options.Count == 0)
539+
{
540+
PluginBase.MainForm.StatusLabel.Text = TextHelper.GetString("Info.NoContextGeneratorCode");
541+
}
542+
CompletionList.Show(options, false);
543+
}
544+
break;
542545
}
543546
}
544547
return;
@@ -548,6 +551,7 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
548551
ASContext.Context.OnProcessEnd(procResult);
549552
break;
550553
}
554+
}
551555
}
552556
catch(Exception ex)
553557
{

PluginCore/PluginCore/Resources/de_DE.resX

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5964,4 +5964,8 @@ Eigene Sprachumgebungen müssen eine Erweiterung der Standard-Sprachumgebung sei
59645964
<value>Highlight word:</value>
59655965
<comment>Added after 5.0.2</comment>
59665966
</data>
5967+
<data name="ASCompletion.Info.NoContextGeneratorCode" xml:space="preserve">
5968+
<value>No contextual code generation available.</value>
5969+
<comment>REQUIRES TRANSLATION</comment>
5970+
</data>
59675971
</root>

PluginCore/PluginCore/Resources/en_US.resX

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5980,4 +5980,7 @@ Custom locales must be an extension of a default locale, e.g. en-US.</value>
59805980
<value>Highlight word:</value>
59815981
<comment>Added after 5.0.2</comment>
59825982
</data>
5983+
<data name="ASCompletion.Info.NoContextGeneratorCode" xml:space="preserve">
5984+
<value>No contextual code generation available.</value>
5985+
</data>
59835986
</root>

PluginCore/PluginCore/Resources/eu_ES.resX

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5961,4 +5961,8 @@ Lokalizazio pertsonalizatuek lehenetsiaren luzapen bat izan behar dute, adb. en-
59615961
<value>Highlight word:</value>
59625962
<comment>Added after 5.0.2</comment>
59635963
</data>
5964+
<data name="ASCompletion.Info.NoContextGeneratorCode" xml:space="preserve">
5965+
<value>No contextual code generation available.</value>
5966+
<comment>REQUIRES TRANSLATION</comment>
5967+
</data>
59645968
</root>

PluginCore/PluginCore/Resources/ja_JP.resX

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6022,4 +6022,8 @@ UseData:"</value>
60226022
<value>Highlight word:</value>
60236023
<comment>Added after 5.0.2</comment>
60246024
</data>
6025+
<data name="ASCompletion.Info.NoContextGeneratorCode" xml:space="preserve">
6026+
<value>No contextual code generation available.</value>
6027+
<comment>REQUIRES TRANSLATION</comment>
6028+
</data>
60256029
</root>

PluginCore/PluginCore/Resources/zh_CN.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5974,4 +5974,8 @@
59745974
<value>Highlight word:</value>
59755975
<comment>Added after 5.0.2</comment>
59765976
</data>
5977+
<data name="ASCompletion.Info.NoContextGeneratorCode" xml:space="preserve">
5978+
<value>No contextual code generation available.</value>
5979+
<comment>REQUIRES TRANSLATION</comment>
5980+
</data>
59775981
</root>

0 commit comments

Comments
 (0)