public static void Execute() { if (Globals.SciControl == null) { return; } ScintillaControl sci = Globals.SciControl; //Project project = (Project) PluginBase.CurrentProject; //if (project == null) return; MainForm mainForm = (MainForm)Globals.MainForm; ITabbedDocument document = mainForm.CurrentDocument; String dir = Path.GetDirectoryName(document.FileName); Hashtable details = ASComplete.ResolveElement(sci, null); IASContext context = ASContext.Context; ClassModel cClass = context.CurrentClass; string package = context.CurrentModel.Package; sci.BeginUndoAction(); if (sci.SelText == "") { sci.SelectionStart = sci.PositionFromLine(cClass.LineFrom); sci.SelectionEnd = sci.PositionFromLine(cClass.LineTo + 1); } String content = Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline); String contents = "package " + package + " {\n" + content + "\n}"; TraceManager.Add(contents); //TraceManager.Add(cClass.LineTo.ToString()); Encoding encoding = sci.Encoding; String file = dir + "\\" + cClass.Name + ".as"; FileHelper.WriteFile(file, contents, encoding); sci.Clear(); sci.EndUndoAction(); }
public static void Execute() { if ( Globals.SciControl == null ) return; ScintillaControl sci = Globals.SciControl; MainForm mainForm = (MainForm) Globals.MainForm; ITabbedDocument document = mainForm.CurrentDocument; String documentDirectory = Path.GetDirectoryName(document.FileName); ASContext context = (ASContext) ASContext.Context; string currentPackage = context.CurrentModel.Package; List<ClassModel> classes = context.CurrentModel.Classes; MemberList imports = context.CurrentModel.Imports; sci.BeginUndoAction(); String pattern = "}"; FRSearch search = new FRSearch(pattern); search.Filter = SearchFilter.None; List<SearchMatch> matches = search.Matches(sci.Text); if (matches == null || matches.Count == 0) return; if (classes.Count < 2) return; SearchMatch match = GetNextDocumentMatch(sci, matches, sci.PositionFromLine(classes[0].LineTo + 1)); Int32 packageEnd = sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value); // wchar to byte text length String strImport = ""; if (imports.Count > 0) { for (int i=imports.Count-1; i>0; --i ) { MemberModel import = imports[i]; if(packageEnd < sci.PositionFromLine(import.LineFrom)) { sci.SelectionStart = sci.PositionFromLine(import.LineFrom); sci.SelectionEnd = sci.PositionFromLine(import.LineTo + 1); strImport = sci.SelText + strImport; sci.Clear(); } } } context.UpdateCurrentFile(true); Int32 prevClassEnd = packageEnd; foreach (ClassModel currentClass in classes) { // 最初のクラスは無視 if (currentClass == classes[0]) continue; sci.SelectionStart = prevClassEnd; sci.SelectionEnd = sci.PositionFromLine(currentClass.LineTo + 1); String content = "package " + currentPackage + "\n{\n" + Regex.Replace( strImport, @"^", "\t", RegexOptions.Multiline) + Regex.Replace( sci.SelText, @"^", "\t", RegexOptions.Multiline) + "\n}\n"; prevClassEnd = sci.PositionFromLine(currentClass.LineTo + 1); Encoding encoding = sci.Encoding; String file = documentDirectory + "\\" + currentClass.Name + ".as"; FileHelper.WriteFile(file, content, encoding); } sci.SelectionStart = packageEnd; sci.Clear(); sci.EndUndoAction(); }
public static void Execute() { if (Globals.SciControl == null) { return; } ScintillaControl sci = Globals.SciControl; string selectStr = sci.SelText; if (selectStr.Length < 1) { MessageBox.Show("クラスにするコマンドを選択してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Project project = (Project)PluginBase.CurrentProject; if (project == null) { return; } MainForm mainForm = (MainForm)Globals.MainForm; FlashDevelopActions flashDevelopActions = new FlashDevelopActions(mainForm); FileActions fileActions = new FileActions(mainForm, flashDevelopActions); if (!File.Exists(TEMP_PATH)) { StreamWriter tmpWriter = new StreamWriter(TEMP_PATH, false, System.Text.Encoding.UTF8, 512); tmpWriter.Write(TMP_FILE); tmpWriter.Close(); } ITabbedDocument currentDocument = (ITabbedDocument)mainForm.CurrentDocument; String parentPath = System.IO.Path.GetDirectoryName(currentDocument.FileName); fileActions.AddFileFromTemplate(project, parentPath, TEMP_PATH); String fileName = fileActions.ProcessArgs(project, "$(FileName)"); String newFilePath = parentPath + "\\" + fileName + ".as"; if (!File.Exists(newFilePath)) { TraceManager.Add("キャンセルされました"); return; } StreamReader reader = new StreamReader(newFilePath); String value = reader.ReadToEnd(); reader.Close(); StreamWriter writer = new StreamWriter(newFilePath, false, System.Text.Encoding.UTF8, 512); writer.Write(fileActions.ProcessArgs(project, value)); writer.Close(); string insText = "new " + fileName + "()"; sci.BeginUndoAction(); sci.Clear(); sci.InsertText(sci.CurrentPos, insText); sci.SelectionStart = sci.CurrentPos; sci.SelectionEnd = sci.CurrentPos + insText.Length; sci.EndUndoAction(); TraceManager.Add(fileName + " が作成されました"); }