/** * Handles the incoming events */ public void HandleEvent(object sender, NotifyEvent e) { try { if (e.Type != EventType.UIRefresh) { DebugConsole.Trace("*** " + e.Type.ToString()); } // context busy? if (ASContext.Locked) { DebugConsole.Trace("ASContext is busy"); if (e.Type == EventType.Command) { string command = ((TextEvent)e).Text; // add a custom classpath if (command.StartsWith("ASCompletion;ClassPath;")) { int p = command.IndexOf(';', 15); ASContext.SetExternalClassPathWanted(command.Substring(p + 1)); e.Handled = true; } } return; } // editor ready? ScintillaNet.ScintillaControl sci = ASContext.MainForm.CurSciControl; if (sci == null) { return; } /** * Other events always handled */ bool isValid; switch (e.Type) { // key combinations case EventType.Shortcut: DebugConsole.Trace("Key " + ((KeyEvent)e).Value); e.Handled = ASComplete.OnShortcut(((KeyEvent)e).Value, sci); return; // // File management // case EventType.FileSave: // update view if needed ASContext.Context.CurrentClass.IsVoid(); // toolbar isValid = ASContext.Context.IsFileValid(); this.SetItemsEnabled(isValid); if (isValid) { if (ASContext.Context.CheckOnSave) { AutoCheckActionScript(); } ASContext.Context.RemoveClassCompilerCache(); } return; case EventType.LanguageChange: case EventType.FileSwitch: DebugConsole.Trace("Switch to " + ASContext.MainForm.CurFile); // check file if (sci.ConfigurationLanguage == "as2" && !ASContext.MainForm.CurDocIsUntitled()) { ASContext.Context.SetCurrentFile(ASContext.MainForm.CurFile); } else { ASContext.Context.SetCurrentFile(""); } // toolbar isValid = ASContext.Context.IsFileValid(); DebugConsole.Trace("Valid? " + isValid); return; case EventType.FileClose: DebugConsole.Trace("Close " + ASContext.MainForm.CurFile); return; case EventType.SettingUpdate: ASContext.UpdateSettings(); break; // some commands work all the time case EventType.Command: string command = ((TextEvent)e).Text; // add a custom classpath if (command.StartsWith("ASCompletion;ClassPath;")) { int p = command.IndexOf(';', 15); ASContext.SetExternalClassPath(command.Substring(p + 1)); e.Handled = true; } // clear the classes cache else if (command.StartsWith("ASCompletion;ClearClassCache")) { ClearClassCache(null, null); e.Handled = true; } else if (command.StartsWith("ASCompletion;SendContext")) { int p = command.IndexOf(';', 15); string wanted = command.Substring(p + 1); if (wanted == "as2") { DataEvent de = new DataEvent(EventType.CustomData, "ASCompletion.Context", ASContext.Context); MainForm.DispatchEvent(de); e.Handled = true; } } // call the Flash IDE else if (command.StartsWith("CallFlashIDE")) { string flashexe = MainForm.MainSettings.GetValue(SETTING_MACROMEDIA_FLASHIDE); if ((flashexe.Length == 0) || !System.IO.File.Exists(flashexe)) { ErrorHandler.ShowInfo("The path to Flash.exe is not configured properly."); } // save modified files this.mainForm.CallCommand("SaveAllModified", null); // run the Flash IDE if (command.IndexOf(';') > 0) { string args = MainForm.ProcessArgString(command.Substring(command.IndexOf(';') + 1)); if (args.IndexOf('"') < 0) { args = '"' + args + '"'; } System.Diagnostics.Process.Start(flashexe, args); } else { System.Diagnostics.Process.Start(flashexe); } e.Handled = true; } break; } /** * Actionscript context specific */ if ((sci.Lexer == 3) && ASContext.Context.IsFileValid()) { switch (e.Type) { case EventType.ProcessArgs: TextEvent te = (TextEvent)e; string cmd = te.Text; if (cmd.IndexOf("@") > 0) { // resolve current element Hashtable details = ASComplete.ResolveElement(sci, null); // resolve current class details if (details == null) { ClassModel oClass = ASContext.Context.CurrentClass; details = new Hashtable(); details.Add("@CLASSDECL", ClassModel.MemberDeclaration(oClass.ToMemberModel())); int p = oClass.ClassName.LastIndexOf('.'); if (p > 0) { details.Add("@CLASSPACKAGE", oClass.ClassName.Substring(0, p)); details.Add("@CLASSNAME", oClass.ClassName.Substring(p + 1)); } else { details.Add("@CLASSPACKAGE", ""); details.Add("@CLASSNAME", oClass.ClassName); } details.Add("@CLASSFULLNAME", oClass.ClassName); details.Add("@MEMBERKIND", ""); details.Add("@MEMBERNAME", ""); details.Add("@MEMBERDECL", ""); details.Add("@MEMBERCLASSPACKAGE", ""); details.Add("@MEMBERCLASSNAME", ""); details.Add("@MEMBERCLASSFILE", ""); details.Add("@MEMBERCLASSDECL", ""); } // complete command foreach (string key in details.Keys) { cmd = cmd.Replace(key, (string)details[key]); } te.Text = cmd; } break; // menu commands case EventType.Command: string command = ((TextEvent)e).Text; DebugConsole.Trace(command); if (command.StartsWith("ASCompletion;")) { // run MTASC if (command.StartsWith("ASCompletion;MtascRun")) { int p = command.IndexOf(';', 15); if (p > 15) { ASContext.Context.RunCMD(command.Substring(p + 1)); } else { ASContext.Context.RunCMD(""); } e.Handled = true; } // build the SWF using MTASC else if (command.StartsWith("ASCompletion;MtascBuild")) { ASContext.Context.BuildCMD(false); e.Handled = true; } // resolve element under cusor and open declaration else if (command.StartsWith("ASCompletion;GotoDeclaration")) { ASComplete.DeclarationLookup(sci); e.Handled = true; } // resolve element under cursor and send a CustomData event else if (command.StartsWith("ASCompletion;ResolveElement;")) { int p = command.IndexOf(';', 15); ASComplete.ResolveElement(sci, command.Substring(p + 1)); e.Handled = true; } else if (command.StartsWith("ASCompletion;MakeIntrinsic")) { int p = command.IndexOf(';', 15); if (p > 15) { ASContext.Context.MakeIntrinsic(command.Substring(p + 1)); } else { ASContext.Context.MakeIntrinsic(null); } e.Handled = true; } } return; case EventType.ProcessEnd: string result = ((TextEvent)e).Text; ASContext.Context.OnProcessEnd(result); break; } } } catch (Exception ex) { ErrorHandler.ShowError(ex.Message, ex); } }
public string GenerateIntrinsic() { StringBuilder sb = new StringBuilder(); string nl = "\r\n"; char semi = ';'; char tab = '\t'; // header if (Version > 2) { sb.Append("package"); if (Package.Length > 0) { sb.Append(" ").Append(Package); } if (haXe) { sb.Append(semi).Append(nl).Append(nl); } else { sb.Append(nl).Append("{").Append(nl).Append(nl); } } // imports if (Imports.Count > 0) { foreach (MemberModel import in Imports) { sb.Append("import ").Append(import.Type).Append(semi).Append(nl); } sb.Append(nl); } // members string decl; foreach (MemberModel member in Members) { if ((member.Flags & FlagType.Variable) > 0) { sb.Append(ClassModel.CommentDeclaration(member.Comments, true)); sb.Append(tab).Append(ClassModel.MemberDeclaration(member)).Append(semi).Append(nl); sb.Append(nl); } else if ((member.Flags & FlagType.Function) > 0) { decl = ClassModel.MemberDeclaration(member); if ((member.Flags & FlagType.Constructor) > 0) { decl = decl.Replace(" : constructor", ""); } sb.Append(ClassModel.CommentDeclaration(member.Comments, true)); sb.Append(tab).Append(decl).Append(semi).Append(nl).Append(nl); sb.Append(nl); } } foreach (ClassModel aClass in Classes) { sb.Append(aClass.GenerateIntrinsic()); sb.Append(nl).Append(nl); } if (Version == 3) { sb.Append('}'); } return(sb.ToString()); }