예제 #1
0
        public override void Run()
        {
            IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;

            if (window == null || !(window.ViewContent is ITextEditorControlProvider))
            {
                return;
            }

            using (SortOptionsDialog sortOptionsDialog = new SortOptionsDialog()) {
                sortOptionsDialog.Owner = (Form)WorkbenchSingleton.Workbench;
                if (sortOptionsDialog.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK)
                {
                    TextArea textarea = ((ITextEditorControlProvider)window.ViewContent).TextEditorControl.ActiveTextAreaControl.TextArea;
                    textarea.BeginUpdate();
                    if (textarea.SelectionManager.HasSomethingSelected)
                    {
                        foreach (ISelection selection in textarea.SelectionManager.SelectionCollection)
                        {
                            SortLines(textarea.Document, selection.StartPosition.Y, selection.EndPosition.Y);
                        }
                    }
                    else
                    {
                        SortLines(textarea.Document, 0, textarea.Document.TotalNumberOfLines - 1);
                    }
                    textarea.Caret.ValidateCaretPos();
                    textarea.EndUpdate();
                    textarea.Refresh();
                }
            }
        }
예제 #2
0
		public override void Run()
		{
			SortOptionsDialog dlg = new SortOptionsDialog();
			dlg.Owner = SD.Workbench.MainWindow;
			if (dlg.ShowDialog() == true) {
				StringComparer comparer = SortOptions.CaseSensitive ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase;
				if (SortOptions.IgnoreTrailingWhitespaces)
					comparer = new IgnoreTrailingWhitespaceComparer(comparer);
				if (SortOptions.SortDirection == SortDirection.Descending)
					comparer = new DescendingStringComparer(comparer);
				
				ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>();
				if (editor != null) {
					if (editor.SelectionLength > 0) {
						int start = editor.Document.GetLineByOffset(editor.SelectionStart).LineNumber;
						int end = editor.Document.GetLineByOffset(editor.SelectionStart + editor.SelectionLength).LineNumber;
						SortLines(editor.Document, start, end, comparer, SortOptions.RemoveDuplicates);
					} else {
						SortLines(editor.Document, 1, editor.Document.LineCount, comparer, SortOptions.RemoveDuplicates);
					}
				}
			}
		}