/// <summary> /// The actual process implementation /// </summary> protected override void ExecutionImplementation() { IASContext context = ASContext.Context; ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; Int32 pos = sci.CurrentPos; List <MemberModel> imports = new List <MemberModel>(context.CurrentModel.Imports.Count); imports.AddRange(context.CurrentModel.Imports.Items); ImportsComparerLine comparerLine = new ImportsComparerLine(); imports.Sort(comparerLine); sci.SetSel(sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineFrom), sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineTo)); String publicClassText = sci.SelText; String privateClassText = ""; if (context.CurrentModel.Classes.Count > 1) { sci.SetSel(pos, pos); sci.SetSel(sci.PositionFromLine(context.CurrentModel.Classes[1].LineFrom), sci.PositionFromLine(sci.LineCount)); privateClassText = sci.SelText; } if (imports.Count > 1 || (imports.Count > 0 && this.TruncateImports)) { sci.BeginUndoAction(); foreach (MemberModel import in imports) { sci.GotoLine(import.LineFrom); this.ImportIndents.Add(new KeyValuePair <MemberModel, Int32>(import, sci.GetLineIndentation(import.LineFrom))); sci.LineDelete(); } if (this.TruncateImports) { for (Int32 j = 0; j < imports.Count; j++) { MemberModel import = imports[j]; String[] parts = import.Type.Split('.'); if (parts.Length > 0 && parts[parts.Length - 1] != "*") { parts[parts.Length - 1] = "*"; } import.Type = String.Join(".", parts); } } imports.Reverse(); Imports separatedImports = this.SeparateImports(imports, context.CurrentModel.PrivateSectionIndex); this.InsertImports(separatedImports.PackageImports, publicClassText, sci, separatedImports.PackageImportsIndent); if (context.CurrentModel.Classes.Count > 1) { this.InsertImports(separatedImports.PrivateImports, privateClassText, sci, separatedImports.PrivateImportsIndent); } sci.SetSel(pos, pos); sci.EndUndoAction(); } this.FireOnRefactorComplete(); }
/// <summary> /// The actual process implementation /// </summary> protected override void ExecutionImplementation() { IASContext context = ASContext.Context; ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; Int32 pos = sci.CurrentPos; List <MemberModel> imports = new List <MemberModel>(context.CurrentModel.Imports.Count); imports.AddRange(context.CurrentModel.Imports.Items); int cppPpStyle = (int)ScintillaNet.Lexers.CPP.PREPROCESSOR; for (Int32 i = imports.Count - 1; i >= 0; i--) { bool isPP = sci.LineIsInPreprocessor(sci, cppPpStyle, imports[i].LineTo); if ((imports[i].Flags & (FlagType.Using | FlagType.Constant)) != 0 || isPP) { imports.RemoveAt(i); } } ImportsComparerLine comparerLine = new ImportsComparerLine(); imports.Sort(comparerLine); if (sci.ConfigurationLanguage == "haxe") { if (context.CurrentModel.Classes.Count > 0) { Int32 start = sci.PositionFromLine(context.CurrentModel.Classes[0].LineFrom); sci.SetSel(start, sci.Length); } } else { Int32 start = sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineFrom); Int32 end = sci.PositionFromLine(context.CurrentModel.GetPublicClass().LineTo); sci.SetSel(start, end); } String publicClassText = sci.SelText; String privateClassText = ""; if (context.CurrentModel.Classes.Count > 1) { sci.SetSel(pos, pos); sci.SetSel(sci.PositionFromLine(context.CurrentModel.Classes[1].LineFrom), sci.PositionFromLine(sci.LineCount)); privateClassText = sci.SelText; } if (imports.Count > 1 || (imports.Count > 0 && this.TruncateImports)) { sci.BeginUndoAction(); foreach (MemberModel import in imports) { sci.GotoLine(import.LineFrom); this.ImportIndents.Add(new KeyValuePair <MemberModel, Int32>(import, sci.GetLineIndentation(import.LineFrom))); sci.LineDelete(); } if (this.TruncateImports) { for (Int32 j = 0; j < imports.Count; j++) { MemberModel import = imports[j]; String[] parts = import.Type.Split('.'); if (parts.Length > 0 && parts[parts.Length - 1] != "*") { parts[parts.Length - 1] = "*"; } import.Type = String.Join(".", parts); } } imports.Reverse(); Imports separatedImports = this.SeparateImports(imports, context.CurrentModel.PrivateSectionIndex); this.InsertImports(separatedImports.PackageImports, publicClassText, sci, separatedImports.PackageImportsIndent); if (context.CurrentModel.Classes.Count > 1) { this.InsertImports(separatedImports.PrivateImports, privateClassText, sci, separatedImports.PrivateImportsIndent); } sci.SetSel(pos, pos); sci.EndUndoAction(); } context.UpdateCurrentFile(true); this.FireOnRefactorComplete(); }