/// <summary> /// Called if a FileModel needs filtering /// - modify parsed model /// </summary> /// <param name="model"></param> /// <returns></returns> static public void FilterSource(FileModel model, MxmlFilterContext ctx) { ctx.model = model; model.InlinedIn = "xml"; model.InlinedRanges = ctx.as3ranges; if (model.MetaDatas == null) { model.MetaDatas = new List <ASMetaData>(); } foreach (string key in ctx.namespaces.Keys) { ASMetaData meta = new ASMetaData("Namespace"); meta.Params = new Dictionary <string, string>(); meta.Params.Add(key, ctx.namespaces[key]); model.MetaDatas.Add(meta); } ClassModel aClass = model.GetPublicClass(); if (aClass == ClassModel.VoidClass) { return; } aClass.Comments = "<" + ctx.baseTag + "/>"; Dictionary <string, string> resolved = new Dictionary <string, string>(); foreach (MemberModel mxmember in ctx.mxmlMembers) { string tag = mxmember.Type; string type = null; if (resolved.ContainsKey(tag)) { type = resolved[tag]; } else { type = MxmlComplete.ResolveType(ctx, tag); resolved[tag] = type; } MemberModel member = aClass.Members.Search(mxmember.Name, FlagType.Variable, Visibility.Public); if (member != null) { member.Comments = "<" + tag + "/>"; member.Type = type; } } }
/// <summary> /// Handles the incoming events /// </summary> public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { if (priority == HandlingPriority.Low) { switch (e.Type) { case EventType.ProcessArgs: TextEvent te = e as TextEvent; if (te.Value.IndexOf("$(FlexSDK)") >= 0) { te.Value = te.Value.Replace("$(FlexSDK)", contextInstance.GetCompilerPath()); } break; case EventType.Command: DataEvent de = e as DataEvent; string action = de.Action; if (action == "ProjectManager.Project") { FlexShells.Instance.Stop(); // clear } else if (action == "ProjectManager.OpenVirtualFile") { if (PluginBase.CurrentProject != null && PluginBase.CurrentProject.Language == "as3") { e.Handled = OpenVirtualFileModel(de.Data as String); } } else if (!(settingObject as AS3Settings).DisableFDB && action == "AS3Context.StartDebugger") { string workDir = (PluginBase.CurrentProject != null) ? Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath) : Environment.CurrentDirectory; string flexSdk = (settingObject as AS3Settings).GetDefaultSDK().Path; // if the default sdk is not defined ask for project sdk if (String.IsNullOrEmpty(flexSdk)) { flexSdk = PluginBase.MainForm.ProcessArgString("$(CompilerPath)"); } e.Handled = FlexDebugger.Start(workDir, flexSdk, null); } else if (action == "AS3Context.StartProfiler") { if (profilerUI.AutoStart) { profilerUI.StartProfiling(); } } break; case EventType.Keys: if (inMXML) { KeyEvent ke = e as KeyEvent; if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("SearchMenu.GotoDeclaration")) { if (MxmlComplete.GotoDeclaration()) { ke.Handled = true; ke.ProcessKey = false; } } } break; } return; } else if (priority == HandlingPriority.Normal) { switch (e.Type) { case EventType.UIStarted: contextInstance = new Context(settingObject); ValidateSettings(); AddToolbarItems(); // Associate this context with AS3 language ASContext.RegisterLanguage(contextInstance, "as3"); ASContext.RegisterLanguage(contextInstance, "mxml"); break; case EventType.FileSave: case EventType.FileSwitch: if (contextInstance != null) { contextInstance.OnFileOperation(e); } if (PluginBase.MainForm.CurrentDocument.IsEditable) { string ext = Path.GetExtension(PluginBase.MainForm.CurrentDocument.FileName); inMXML = (ext.ToLower() == ".mxml"); MxmlComplete.IsDirty = true; } else { inMXML = false; } break; } return; } else if (priority == HandlingPriority.High) { if (e.Type == EventType.Command) { string action = (e as DataEvent).Action; if (action == "ProjectManager.Project") { FlexDebugger.Stop(); IProject project = PluginBase.CurrentProject; viewButton.Enabled = project == null || project.Language == "as3" || project.Language == "haxe"; } else if (action.StartsWith("FlashViewer.")) { if (action == "FlashViewer.Closed") { FlexDebugger.Stop(); } else if (action == "FlashViewer.External" || action == "FlashViewer.Default" || action == "FlashViewer.Popup" || action == "FlashViewer.Document") { if (PluginBase.CurrentProject != null && PluginBase.CurrentProject.EnableInteractiveDebugger) { DataEvent de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null); EventManager.DispatchEvent(this, de); if (PluginBase.CurrentProject.TraceEnabled) { de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", (e as DataEvent).Data); EventManager.DispatchEvent(this, de); } } } } else if (action == "FlashConnect") { ProfilerUI.HandleFlashConnect(sender, (e as DataEvent).Data); } else if (inMXML) { DataEvent de = e as DataEvent; if (de.Action == "XMLCompletion.Element") { de.Handled = MxmlComplete.HandleElement(de.Data); } if (de.Action == "XMLCompletion.Namespace") { de.Handled = MxmlComplete.HandleNamespace(de.Data); } else if (de.Action == "XMLCompletion.CloseElement") { de.Handled = MxmlComplete.HandleElementClose(de.Data); } else if (de.Action == "XMLCompletion.Attribute") { de.Handled = MxmlComplete.HandleAttribute(de.Data); } else if (de.Action == "XMLCompletion.AttributeValue") { de.Handled = MxmlComplete.HandleAttributeValue(de.Data); } } } } }
/// <summary> /// Called if a FileModel needs filtering /// - define inline AS3 ranges /// </summary> /// <param name="src"></param> /// <returns></returns> static public string FilterSource(string name, string src, MxmlFilterContext ctx) { List <InlineRange> as3ranges = ctx.as3ranges; MemberList mxmlMembers = ctx.mxmlMembers; StringBuilder sb = new StringBuilder(); sb.Append("package{"); int len = src.Length - 8; int rangeStart = -1; int nodeStart = -1; int nodeEnd = -1; int line = 0; bool firstNode = true; bool skip = true; bool hadNL = false; bool inComment = false; for (int i = 0; i < len; i++) { char c = src[i]; // keep newlines if (c == 10 || c == 13) { if (c == 13) { line++; } else if (i > 0 && src[i - 1] != 13) { line++; } sb.Append(c); hadNL = true; } // XML comment else if (inComment) { if (i < len - 3 && c == '-' && src[i + 1] == '-' && src[i + 2] == '>') { inComment = false; i += 3; } continue; } // in XML else if (skip) { if (c == '<' && i < len - 3) { if (src[i + 1] == '!') { if (src[i + 2] == '-' && src[i + 3] == '-') { inComment = true; i += 3; continue; } else if (src[i + 2] == '[' && src.Substring(i + 2, 7) == "[CDATA[") { i += 8; skip = false; hadNL = false; rangeStart = i; continue; } } else { nodeStart = i + 1; nodeEnd = -1; if (firstNode && src[i + 1] != '?') { int space = src.IndexOfAny(new char[] { ' ', '\n' }, i); string tag = GetXMLContextTag(src, space); if (tag != null && space > 0) { firstNode = false; ctx.baseTag = tag; ReadNamespaces(ctx, src, space); string type = MxmlComplete.ResolveType(ctx, tag); sb.Append("public class ").Append(name) .Append(" extends ").Append(type).Append('{'); } } } } else if (c == '=' && i > 4) // <node id="..." { int off = i - 1; while (src[off] == ' ' && off > 4) { off--; } if (src[off - 2] <= 32 && src[off - 1] == 'i' && src[off] == 'd') { string tag = GetXMLContextTag(src, i); if (tag != null) { string id = GetAttributeValue(src, ref i); if (id != null) { MemberModel member = new MemberModel(id, tag, FlagType.Variable | FlagType.Dynamic, Visibility.Public); member.LineTo = member.LineFrom = line; string type = MxmlComplete.ResolveType(ctx, tag); mxmlMembers.Add(member); sb.Append("public var ").Append(id) .Append(':').Append(type).Append(';'); } } } } else if (nodeEnd < 0) { if (nodeStart >= 0 && (c == ' ' || c == '>')) { nodeEnd = i; } } } // in script else { if (c == ']' && src[i] == ']' && src[i + 1] == '>') { skip = true; if (hadNL) { as3ranges.Add(new InlineRange("as3", rangeStart, i)); } rangeStart = -1; } else { sb.Append(c); } } } if (rangeStart >= 0 && hadNL) { as3ranges.Add(new InlineRange("as3", rangeStart, src.Length)); } sb.Append("}}"); return(sb.ToString()); }