/// <summary> /// Entry point to execute renaming. /// </summary> protected override void ExecutionImplementation() { var sci = PluginBase.MainForm.CurrentDocument.SciControl; var fileModel = ASContext.Context.CurrentModel; var parser = new ASFileParser(); parser.ParseSrc(fileModel, sci.Text); var search = new FRSearch(sci.SelText) { SourceFile = sci.FileName }; var mathes = search.Matches(sci.Text); var currentMember = fileModel.Context.CurrentMember; var lineFrom = currentMember.LineFrom; var lineTo = currentMember.LineTo; mathes.RemoveAll(it => it.Line <lineFrom || it.Line> lineTo); var target = mathes.FindAll(it => sci.MBSafePosition(it.Index) == sci.SelectionStart); if (mathes.Count > 1) { CompletionList = new List <ICompletionListItem> { new CompletionListItem(target, sci, OnItemClick) }; CompletionList.Insert(0, new CompletionListItem(mathes, sci, OnItemClick)); sci.DisableAllSciEvents = true; PluginCore.Controls.CompletionList.Show(CompletionList, true); } else { GenerateExtractVariable(target); } }
private void ExtractFilesFromArchive() { string[] masks = context.GetExplorerMask(); for (int i = 0; i < masks.Length; i++) { masks[i] = masks[i].Substring(masks[i].IndexOf('*') + 1); } Stream fileStream = File.OpenRead(pathModel.Path); ZipFile zipFile = new ZipFile(fileStream); ASFileParser parser = new ASFileParser(); Dictionary <string, FileModel> models = new Dictionary <string, FileModel>(); foreach (ZipEntry entry in zipFile) { string ext = Path.GetExtension(entry.Name).ToLower(); foreach (string mask in masks) { if (ext == mask) { string src = UnzipFile(zipFile, entry); FileModel model = new FileModel(Path.Combine(pathModel.Path, entry.Name)); model.Context = pathModel.Owner; parser.ParseSrc(model, src); models.Add(model.FileName, model); } } } zipFile.Close(); fileStream.Close(); pathModel.SetFiles(models); }
private static FileModel ParseInclude(FileModel fileModel, ASMetaData meta) { Match m = reIncPath.Match(meta.RawParams); if (m.Success) { string path = m.Groups[2].Value; if (path.Length == 0) { return(null); } // retrieve from cache if (includesCache.ContainsKey(path)) { return(includesCache[path]); } // relative path? string fileName = path; if (!Path.IsPathRooted(fileName)) { if (fileName[0] == '/' || fileName[0] == '\\') { fileName = Path.Combine(fileModel.BasePath, fileName); } else { fileName = Path.Combine(Path.GetDirectoryName(fileModel.FileName), fileName); } } // parse & cache if (!File.Exists(fileName)) { return(null); } string src = File.ReadAllText(fileName); if (src.IndexOf("package") < 0) { src = "package {" + src + "}"; } ASFileParser parser = new ASFileParser(); FileModel model = new FileModel(path); parser.ParseSrc(model, src); includesCache[path] = model; return(model); } return(null); }
/// <summary> /// Refresh the file model /// </summary> /// <param name="updateUI">Update outline view</param> public override void UpdateCurrentFile(bool updateUI) { if (cFile == null || CurSciControl == null) { return; } ASFileParser parser = new ASFileParser(); parser.ParseSrc(cFile, CurSciControl.Text); ScriptToClass(cFile); cLine = CurSciControl.LineFromPosition(CurSciControl.CurrentPos); UpdateContext(cLine); // update outline if (updateUI) { ASContext.Context = this; } }
/// <summary> /// Build the file DOM /// </summary> /// <param name="filename">File path</param> protected override void GetCurrentFileModel(string fileName) { string ext = Path.GetExtension(fileName); if (!re_PHPext.IsMatch(ext)) { cFile = FileModel.Ignore; UpdateContext(cLine); } else { cFile = new FileModel(fileName); cFile.Context = this; cFile.HasFiltering = true; ASFileParser parser = new ASFileParser(); parser.ParseSrc(cFile, CurSciControl.Text); cLine = CurSciControl.CurrentLine; UpdateContext(cLine); } }
/// <summary> /// AS2/AS3 detection /// </summary> /// <param name="doc">Document to check</param> /// <returns>Detected language</returns> private string DetectActionscriptVersion(ITabbedDocument doc) { ASFileParser parser = new ASFileParser(); FileModel model = new FileModel(doc.FileName); parser.ParseSrc(model, doc.SciControl.Text); if (model.Version == 1 && PluginBase.CurrentProject != null) { String lang = PluginBase.CurrentProject.Language; if (lang == "*") return "as2"; else return lang; } else if (model.Version > 2) return "as3"; else if (model.Version > 1) return "as2"; else if (settingObject.LastASVersion != null && settingObject.LastASVersion.StartsWithOrdinal("as")) { return settingObject.LastASVersion; } else return "as2"; }
public void Execute() { Sci = PluginBase.MainForm.CurrentDocument.SciControl; Sci.BeginUndoAction(); try { IASContext context = ASContext.Context; string selection = Sci.SelText; if (selection == null || selection.Length == 0) { return; } if (selection.TrimStart().Length == 0) { return; } Sci.SetSel(Sci.SelectionStart + selection.Length - selection.TrimStart().Length, Sci.SelectionEnd); Sci.CurrentPos = Sci.SelectionEnd; Int32 pos = Sci.CurrentPos; int lineStart = Sci.LineFromPosition(Sci.SelectionStart); int lineEnd = Sci.LineFromPosition(Sci.SelectionEnd); int firstLineIndent = Sci.GetLineIndentation(lineStart); int entryPointIndent = Sci.Indent; for (int i = lineStart; i <= lineEnd; i++) { int indent = Sci.GetLineIndentation(i); if (i > lineStart) { Sci.SetLineIndentation(i, indent - firstLineIndent + entryPointIndent); } } string selText = Sci.SelText; Sci.ReplaceSel(NewName + "();"); cFile = ASContext.Context.CurrentModel; ASFileParser parser = new ASFileParser(); parser.ParseSrc(cFile, Sci.Text); bool isAs3 = cFile.Context.Settings.LanguageId == "AS3"; FoundDeclaration found = GetDeclarationAtLine(Sci, lineStart); if (found == null || found.member == null) { return; } int position = Sci.PositionFromLine(found.member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); StringBuilder sb = new StringBuilder(); sb.Append("$(Boundary)\n\n"); if ((found.member.Flags & FlagType.Static) > 0) { sb.Append("static "); } sb.Append(ASGenerator.GetPrivateKeyword()); sb.Append(" function "); sb.Append(NewName); sb.Append("():"); sb.Append(isAs3 ? "void " : "Void "); sb.Append("$(CSLB){\n\t"); sb.Append(selText); sb.Append("$(EntryPoint)"); sb.Append("\n}\n$(Boundary)"); ASGenerator.InsertCode(position, sb.ToString()); } finally { Sci.EndUndoAction(); } }
/// <summary> /// AS2/AS3 detection /// </summary> /// <param name="doc">Document to check</param> /// <returns>Detected language</returns> private string DetectActionscriptVersion(ITabbedDocument doc) { ASFileParser parser = new ASFileParser(); FileModel model = new FileModel(doc.FileName); parser.ParseSrc(model, doc.SciControl.Text); if (model.Version == 1 && PluginBase.CurrentProject != null) return PluginBase.CurrentProject.Language; else if (model.Version > 2) return "as3"; else if (model.Version > 1) return "as2"; else if (settingObject.LastASVersion != null) return settingObject.LastASVersion; else return "as2"; }
public void Execute() { Sci = PluginBase.MainForm.CurrentDocument.SciControl; Sci.BeginUndoAction(); try { IASContext context = ASContext.Context; Int32 pos = Sci.CurrentPos; string expression = Sci.SelText.Trim(new char[] { '=', ' ', '\t', '\n', '\r', ';', '.' }); expression = expression.TrimEnd(new char[] { '(', '[', '{', '<' }); expression = expression.TrimStart(new char[] { ')', ']', '}', '>' }); cFile = ASContext.Context.CurrentModel; ASFileParser parser = new ASFileParser(); parser.ParseSrc(cFile, Sci.Text); MemberModel current = cFile.Context.CurrentMember; string characterClass = ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters; int funcBodyStart = ASGenerator.GetBodyStart(current.LineFrom, current.LineTo, Sci); Sci.SetSel(funcBodyStart, Sci.LineEndPosition(current.LineTo)); string currentMethodBody = Sci.SelText; bool isExprInSingleQuotes = (expression.StartsWith("'") && expression.EndsWith("'")); bool isExprInDoubleQuotes = (expression.StartsWith("\"") && expression.EndsWith("\"")); int stylemask = (1 << Sci.StyleBits) - 1; int lastPos = -1; char prevOrNextChar; Sci.Colourise(0, -1); while (true) { lastPos = currentMethodBody.IndexOf(expression, lastPos + 1); if (lastPos > -1) { if (lastPos > 0) { prevOrNextChar = currentMethodBody[lastPos - 1]; if (characterClass.IndexOf(prevOrNextChar) > -1) { continue; } } if (lastPos + expression.Length < currentMethodBody.Length) { prevOrNextChar = currentMethodBody[lastPos + expression.Length]; if (characterClass.IndexOf(prevOrNextChar) > -1) { continue; } } int style = Sci.StyleAt(funcBodyStart + lastPos) & stylemask; if (ASComplete.IsCommentStyle(style)) { continue; } else if ((isExprInDoubleQuotes && currentMethodBody[lastPos] == '"' && currentMethodBody[lastPos + expression.Length - 1] == '"') || (isExprInSingleQuotes && currentMethodBody[lastPos] == '\'' && currentMethodBody[lastPos + expression.Length - 1] == '\'')) { } else if (!ASComplete.IsTextStyle(style)) { continue; } Sci.SetSel(funcBodyStart + lastPos, funcBodyStart + lastPos + expression.Length); Sci.ReplaceSel(NewName); currentMethodBody = currentMethodBody.Substring(0, lastPos) + NewName + currentMethodBody.Substring(lastPos + expression.Length); lastPos += NewName.Length; } else { break; } } Sci.CurrentPos = funcBodyStart; Sci.SetSel(Sci.CurrentPos, Sci.CurrentPos); string snippet = "var " + NewName + ":$(EntryPoint) = " + expression + ";\n$(Boundary)"; SnippetHelper.InsertSnippetText(Sci, Sci.CurrentPos, snippet); } finally { Sci.EndUndoAction(); } }