Skip to content

Commit

Permalink
generate Live metadatas
Browse files Browse the repository at this point in the history
  • Loading branch information
elsassph committed May 21, 2013
1 parent 13f26a2 commit 38897a4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ColtPlugin/ColtPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>..\..\..\FlashDevelop\Bin\Debug\Plugins\</OutputPath>
<OutputPath>..\..\svn\FlashDevelop\Bin\Debug\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
</PropertyGroup>
Expand Down Expand Up @@ -118,6 +118,10 @@
<EmbeddedResource Include="Resources\colt.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\svn\External\Plugins\ASCompletion\ASCompletion.csproj">
<Project>{4EBF2653-9654-4E40-880E-0046B3D6210E}</Project>
<Name>ASCompletion</Name>
</ProjectReference>
<ProjectReference Include="..\..\svn\External\Plugins\ProjectManager\ProjectManager.csproj">
<Project>{78101C01-E186-4954-B1DD-DEBB7905FAD8}</Project>
<Name>ProjectManager</Name>
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 38897a4

Please # to comment.