public static string GetSelectedString() { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); if (editor == null) { return(null); } string[] lines = editor.SelectedText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); StringBuilder result = new StringBuilder(); foreach (string line in lines) { string processedLine = line.Trim(); //Remove the leading and trailing " - this is VuGen specific code if (processedLine.StartsWith("\"")) { processedLine = processedLine.Remove(0, 1); } if (processedLine.EndsWith("\"")) { processedLine = processedLine.Remove(processedLine.Length - 1, 1); } processedLine = processedLine.Replace("\\", ""); result.Append(processedLine); } return(result.ToString()); }
private void Reformat(CustomDialog dialog) { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); string selectedText = editor.SelectedText; string[] xmlLines = FormatXml(GetSelectedString()).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); IDocumentLine documentLine = editor.Document.GetLineForOffset(editor.SelectionStart); string lineText = documentLine.Text; string indentation = lineText.Substring(0, lineText.Length - lineText.TrimStart().Length); StringBuilder formattedText = new StringBuilder(); foreach (string line in xmlLines) { formattedText.AppendLine(indentation + "\"" + line.Replace("\"", "\\\"") + "\""); } formattedText.Remove(formattedText.Length - Environment.NewLine.Length, Environment.NewLine.Length); if (!selectedText.TrimStart().StartsWith("\"")) { formattedText.Insert(0, "\"" + Environment.NewLine); } if (!selectedText.TrimEnd().EndsWith("\"")) { formattedText.Append(Environment.NewLine + indentation + "\""); } DocumentUtilitites.FindNextWordStart(editor.Document, documentLine.Offset); editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, formattedText.ToString()); dialog.Close(); }
private void Reformat(CustomDialog dialog) { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); string selectedText = editor.SelectedText; string[] xmlLines = FormatXml(GetSelectedString()).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); StringBuilder formattedText = new StringBuilder(); foreach (string line in xmlLines) { formattedText.AppendLine("\"" + line.Replace("\"", "\\\"") + "\""); } formattedText.Remove(formattedText.Length - Environment.NewLine.Length, Environment.NewLine.Length); if (!selectedText.StartsWith("\"")) { formattedText.Insert(0, "\"" + Environment.NewLine); } if (!selectedText.EndsWith("\"")) { formattedText.Append(Environment.NewLine + "\""); } editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, formattedText.ToString()); dialog.Close(); }
public static string GetSelectedString() { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); if (editor == null) { return(null); } return(editor.SelectedText); }
private void InsertOpticTransactionHeader(string code) { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); string[] rgLines = editor.SelectedText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); StringBuilder newLines = null; int newLineCount = VuGenUtilFunctions.ProcessTransText(rgLines, ref newLines); if (newLineCount > 0) { editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, newLines.ToString()); } }
public override void Run() { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); //Get the file name and extract the directory from it string fileName = editor.FileName.ToString(); int pos = fileName.LastIndexOf("\\"); if (pos > 0) { string directory = fileName.Substring(0, pos); VuGenUtilFunctions.ProcessDirectory(directory); } }
internal static void InsertLines(string[] lines) { ITextEditor editor = UttCodeEditor.GetActiveTextEditor(); StringBuilder newLines = new StringBuilder(); string linePrefix = string.IsNullOrEmpty(editor.SelectedText) ? "\t" : VuGenUtilFunctions.GetLinePrefixSpacesTabs(editor.SelectedText); string lineSuffix = string.Empty; newLines.AppendLine(editor.SelectedText); //newLines.AppendLine(""); for (int i = 0; i < lines.Length; i++) { newLines.Append(linePrefix); newLines.Append(lines[i]); lineSuffix = (i == (lines.Length - 1)) ? string.Empty : System.Environment.NewLine; newLines.Append(lineSuffix); } editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, newLines.ToString()); }