Ejemplo n.º 1
0
        private void GoToLineNumber()
        {
            var document = _documentService.ActiveDocument as TextDocument;

            if (document == null)
            {
                return;
            }

            Logger.Debug(CultureInfo.InvariantCulture, "Showing Go To Line dialog for \"{0}\".", document.GetName());

            var textEditor = document.GetLastActiveTextEditor();

            if (textEditor == null)
            {
                return;
            }

            var viewModel = new GoToLineViewModel
            {
                LineNumber    = textEditor.TextArea.Caret.Line,
                NumberOfLines = Math.Max(1, document.AvalonEditDocument.LineCount),
            };
            var result = _windowService.ShowDialog(viewModel);

            if (result == true)
            {
                int lineNumber = viewModel.LineNumber;

                Logger.Debug("Jumping to line {0} in \"{1}\".", lineNumber, document.GetName());

                if (lineNumber < 1)
                {
                    lineNumber = 1;
                }
                else if (lineNumber > document.AvalonEditDocument.LineCount)
                {
                    lineNumber = document.AvalonEditDocument.LineCount;
                }

                textEditor.TextArea.Caret.Line = lineNumber;
                textEditor.TextArea.Caret.BringCaretToView();
            }
        }
Ejemplo n.º 2
0
        private void GoToLineNumber()
        {
            var document = _documentService.ActiveDocument as TextDocument;
            if (document == null)
                return;

            Logger.Debug(CultureInfo.InvariantCulture, "Showing Go To Line dialog for \"{0}\".", document.GetName());

            var textEditor = document.GetLastActiveTextEditor();
            if (textEditor == null)
                return;

            var viewModel = new GoToLineViewModel
            {
                LineNumber = textEditor.TextArea.Caret.Line,
                NumberOfLines = Math.Max(1, document.AvalonEditDocument.LineCount),
            };
            var result = _windowService.ShowDialog(viewModel);
            if (result == true)
            {
                int lineNumber = viewModel.LineNumber;

                Logger.Debug("Jumping to line {0} in \"{1}\".", lineNumber, document.GetName());

                if (lineNumber < 1)
                    lineNumber = 1;
                else if (lineNumber > document.AvalonEditDocument.LineCount)
                    lineNumber = document.AvalonEditDocument.LineCount;

                textEditor.TextArea.Caret.Line = lineNumber;
                textEditor.TextArea.Caret.BringCaretToView();
            }
        }