Beispiel #1
0
        private void Trim()
        {
            TextDocumentHandler handler = new TextDocumentHandler(this.dte);

            if (handler.HasNonEmptySelection)
            {
                Options options = this.package.Options;

                bool execute = true;
                if (!options.OnlyShowTrimDialogWhenShiftIsPressed || Utilities.IsShiftPressed)
                {
                    TrimDialog dialog = new TrimDialog();
                    execute = dialog.Execute(options);
                }

                if (execute && (options.TrimStart || options.TrimEnd))
                {
                    string    text  = handler.SelectedText;
                    TextLines lines = new TextLines(text);
                    lines.Trim(options.TrimStart, options.TrimEnd);
                    string trimmedText = lines.ToString();
                    handler.SetSelectedTextIfUnchanged(trimmedText, "Trim");
                }
            }
        }
Beispiel #2
0
        private void SortLines()
        {
            TextDocumentHandler handler = new TextDocumentHandler(this.dte);

            if (handler.HasNonEmptySelection)
            {
                Options options = this.package.Options;

                SortDialog dialog = new SortDialog();
                if (dialog.Execute(options))
                {
                    StringComparison comparison;
                    if (options.SortCompareByOrdinal)
                    {
                        comparison = options.SortCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
                    }
                    else
                    {
                        comparison = options.SortCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
                    }

                    // Now sort the lines and put them back as the selection
                    string    text  = handler.SelectedText;
                    TextLines lines = new TextLines(text);
                    lines.Sort(comparison, options.SortAscending, options.SortIgnoreWhitespace, options.SortIgnorePunctuation, options.SortEliminateDuplicates);
                    string sortedText = lines.ToString();
                    handler.SetSelectedTextIfUnchanged(sortedText, "Sort Lines");
                }
            }
        }
        private static void UpdateSelectedText(TextDocumentHandler handler, string commandName, Action <TextLines> updateSelection)
        {
            string    text  = handler.SelectedText;
            TextLines lines = new TextLines(text);

            updateSelection(lines);
            handler.SetSelectedTextIfUnchanged(lines.ToString(), commandName);
        }
Beispiel #4
0
        private void StreamText()
        {
            TextDocumentHandler handler = new TextDocumentHandler(this.dte);

            if (handler.HasNonEmptySelection)
            {
                string    text         = handler.SelectedText;
                TextLines lines        = new TextLines(text);
                string    streamedText = lines.Stream();
                handler.SetSelectedTextIfUnchanged(streamedText, "Stream Text");
            }
        }