예제 #1
0
        public void ShowFor(MonoTextEditor editor, bool replaceMode)
        {
            Editor = editor;
            this.selectionOnly = false;
            window1.TransientFor = Editor.Toplevel as Window;
            Mono.TextEditor.Selection selected = Editor.MainSelection;
            if (Editor.SelectedText != null)
            {
                if (selected.MaxLine == selected.MinLine)
                    txtLookFor.Text = Editor.SelectedText;
                else
                {
                    Editor.SearchEngine.SearchRequest.SearchRegion = Editor.SelectionRange;
                    this.selectionOnly = true;
                }
            }
            else
            {
                // Get the current word that the caret is on
                Caret caret = Editor.Caret;
                int start = Editor.GetTextEditorData().FindCurrentWordStart(caret.Offset);
                int end = Editor.GetTextEditorData().FindCurrentWordEnd(caret.Offset);
                txtLookFor.Text = Editor.GetTextBetween(start, end);
            }
            ReplaceMode = replaceMode;
            editor.HighlightSearchPattern = true;

            window1.Parent = editor.Toplevel;
            UpdateTitleBar();
            window1.Show();
            txtLookFor.GrabFocus();
        }
예제 #2
0
		public static Selection Clone (Selection selection)
		{
			if (selection == null)
				return null;
			return new Selection (selection.Anchor, selection.Lead, selection.SelectionMode);
		}
예제 #3
0
            void CopyData(TextEditorData data, Selection selection)
            {
                copiedDocument = null;
                monoDocument   = null;
                if (selection != null && data != null && data.Document != null)
                {
                    copiedDocument = new TextDocument();
                    monoDocument   = new TextDocument();
                    this.docStyle  = data.ColorStyle;
                    this.options   = data.Options;
                    this.mode      = SyntaxModeService.GetSyntaxMode(monoDocument, data.MimeType);
                    switch (selection.SelectionMode)
                    {
                    case SelectionMode.Normal:
                        isBlockMode = false;
                        var segment = selection.GetSelectionRange(data);
                        var text    = data.GetTextAt(segment);
                        copiedDocument.Text = text;
                        monoDocument.Text   = text;
                        var line      = data.Document.GetLineByOffset(segment.Offset);
                        var spanStack = line.StartSpan.Clone();
                        SyntaxModeService.ScanSpans(data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, segment.Offset);
                        this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack;
                        break;

                    case SelectionMode.Block:
                        isBlockMode = true;
                        DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor);
                        DocumentLocation visEnd   = data.LogicalToVisualLocation(selection.Lead);
                        int startCol = System.Math.Min(visStart.Column, visEnd.Column);
                        int endCol   = System.Math.Max(visStart.Column, visEnd.Column);
                        for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++)
                        {
                            DocumentLine curLine = data.Document.GetLine(lineNr);
                            int          col1    = curLine.GetLogicalColumn(data, startCol) - 1;
                            int          col2    = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length);
                            if (col1 < col2)
                            {
                                copiedDocument.Insert(copiedDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1));
                                monoDocument.Insert(monoDocument.TextLength, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1));
                            }
                            if (lineNr < selection.MaxLine)
                            {
                                // Clipboard line end needs to be system dependend and not the document one.
                                copiedDocument.Insert(copiedDocument.TextLength, Environment.NewLine);
                                // \r in mono document stands for block selection line end.
                                monoDocument.Insert(monoDocument.TextLength, "\r");
                            }
                        }
                        line      = data.Document.GetLine(selection.MinLine);
                        spanStack = line.StartSpan.Clone();
                        SyntaxModeService.ScanSpans(data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, line.Offset + startCol);
                        this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack;
                        break;
                    }
                }
                else
                {
                    copiedDocument = null;
                }
            }