Skip to content

Commit

Permalink
Merge pull request #5 from elsassph/master
Browse files Browse the repository at this point in the history
Shortcut to generate Live metadatas
  • Loading branch information
makc committed May 28, 2013
2 parents e74a545 + c6d00b3 commit 92527fa
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 6 deletions.
14 changes: 14 additions & 0 deletions ColtPlugin/ColtPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,18 @@
<ItemGroup>
<EmbeddedResource Include="Resources\colt.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ASCompletion\ASCompletion.csproj">
<Project>{4EBF2653-9654-4E40-880E-0046B3D6210E}</Project>
<Name>ASCompletion</Name>
</ProjectReference>
<ProjectReference Include="..\ProjectManager\ProjectManager.csproj">
<Project>{78101C01-E186-4954-B1DD-DEBB7905FAD8}</Project>
<Name>ProjectManager</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\PluginCore\PluginCore.csproj">
<Project>{61885F70-B4DC-4B44-852D-5D6D03F2A734}</Project>
<Name>PluginCore</Name>
</ProjectReference>
</ItemGroup>
</Project>
20 changes: 15 additions & 5 deletions ColtPlugin/ColtPlugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginCore", "..\..\..\Plug
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColtPlugin", "ColtPlugin.csproj", "{78101C02-E186-4954-B1DD-DEBB7905FAD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectManager", "..\ProjectManager\ProjectManager.csproj", "{E57AC379-B0A0-4D6F-BFB2-88639B280205}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectManager", "..\ProjectManager\ProjectManager.csproj", "{78101C01-E186-4954-B1DD-DEBB7905FAD8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASCompletion", "..\ASCompletion\ASCompletion.csproj", "{4EBF2653-9654-4E40-880E-0046B3D6210E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -29,10 +31,18 @@ Global
{78101C02-E186-4954-B1DD-DEBB7905FAD8}.Debug|x86.ActiveCfg = Debug|x86
{78101C02-E186-4954-B1DD-DEBB7905FAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78101C02-E186-4954-B1DD-DEBB7905FAD8}.Release|x86.ActiveCfg = Release|x86
{E57AC379-B0A0-4D6F-BFB2-88639B280205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E57AC379-B0A0-4D6F-BFB2-88639B280205}.Debug|x86.ActiveCfg = Debug|x86
{E57AC379-B0A0-4D6F-BFB2-88639B280205}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E57AC379-B0A0-4D6F-BFB2-88639B280205}.Release|x86.ActiveCfg = Release|x86
{78101C01-E186-4954-B1DD-DEBB7905FAD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78101C01-E186-4954-B1DD-DEBB7905FAD8}.Debug|x86.ActiveCfg = Debug|x86
{78101C01-E186-4954-B1DD-DEBB7905FAD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78101C01-E186-4954-B1DD-DEBB7905FAD8}.Release|x86.ActiveCfg = Release|x86
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Debug|x86.ActiveCfg = Debug|x86
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Debug|x86.Build.0 = Debug|x86
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Release|Any CPU.Build.0 = Release|Any CPU
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Release|x86.ActiveCfg = Release|x86
{4EBF2653-9654-4E40-880E-0046B3D6210E}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
80 changes: 79 additions & 1 deletion ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using PluginCore.Helpers;
using PluginCore;
using ProjectManager.Projects.AS3;
using ASCompletion.Context;
using System.Text.RegularExpressions;
using ASCompletion.Model;

namespace ColtPlugin
{
Expand All @@ -32,6 +35,7 @@ public class PluginMain : IPlugin
private FileSystemWatcher watcher;
private String pathToLog;
private System.Timers.Timer timer;
private Keys MakeItLiveKeys = Keys.Control | Keys.Shift | Keys.L;

#region Required Properties

Expand Down Expand Up @@ -155,6 +159,24 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
case EventType.FileSave:
if (active) ClearErrors();
break;

case EventType.Keys: // shortcut pressed
KeyEvent ke = (KeyEvent)e;
if (ke.Value == MakeItLiveKeys)
{
ke.Handled = true;
MakeItLive();
}
break;

case EventType.Shortcut: // shortcut changed
DataEvent de = (DataEvent)e;
if (de.Action == "ColtPlugin.MakeItLive")
{
MakeItLiveKeys = (Keys)de.Data;
}
break;

}
}

Expand Down Expand Up @@ -200,11 +222,13 @@ public void InitLocalization()
/// </summary>
public void AddEventHandlers()
{
EventManager.AddEventHandler(this, EventType.Command | EventType.FileSave);
EventManager.AddEventHandler(this, EventType.Command | EventType.FileSave | EventType.Keys | EventType.Shortcut);

watcher = new FileSystemWatcher();
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(OnFileChange);

PluginBase.MainForm.RegisterShortcutItem("ColtPlugin.MakeItLive", MakeItLiveKeys);
}

#endregion
Expand Down Expand Up @@ -350,6 +374,60 @@ private void ShowErrors()

#endregion

/// <summary>
/// Generate meta tags
/// </summary>
private void MakeItLive()
{
ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;
if (sci == null)
return;

IASContext context = ASCompletion.Context.ASContext.Context;
if (context.CurrentClass == null || context.CurrentClass.IsVoid() || context.CurrentClass.LineFrom == 0)
return;

// make member live
int originalPos = sci.CurrentPos;
int pos;
int line;
string indent;
MemberModel member = context.CurrentMember;
FlagType mask = FlagType.Function | FlagType.Dynamic;
if (member != null && (member.Flags & mask) == mask)
{
line = context.CurrentMember.LineFrom;
indent = LineIndentPosition(sci, line);
pos = sci.PositionFromLine(line) + indent.Length;
string insert = "[LiveCodeUpdateListener(method=\"" + member.Name + "\")]\n" + indent;
sci.SetSel(pos, pos);
sci.ReplaceSel(insert);
originalPos += insert.Length;
}

// make class live
if (!Regex.IsMatch(sci.Text, "\\[Live\\]"))
{
line = context.CurrentClass.LineFrom;
indent = LineIndentPosition(sci, line);
pos = sci.PositionFromLine(line) + indent.Length;
string insert = "[Live]\n" + indent;
sci.SetSel(pos, pos);
sci.ReplaceSel(insert);
originalPos += insert.Length;
}

sci.SetSel(originalPos, originalPos);
}

private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
{
string txt = sci.GetLine(line);
for (int i = 0; i < txt.Length; i++)
if (txt[i] > 32) return txt.Substring(0, i);
return "";
}

/// <summary>
/// Opens the project in COLT
/// </summary>
Expand Down
Binary file modified ColtPlugin/obj/Debug/ColtPlugin.dll
Binary file not shown.

0 comments on commit 92527fa

Please # to comment.