Esempio n. 1
0
 /// <summary>
 /// Creates a new SearchInputHandler and registers the search-related commands.
 /// </summary>
 public SearchInputHandler(TextArea textArea)
     : base(textArea)
 {
     RegisterCommands(this.CommandBindings);
     panel = new SearchPanel();
     panel.Attach(TextArea);
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new SimpleSelection instance.
 /// </summary>
 internal SimpleSelection(TextArea textArea, TextViewPosition start, TextViewPosition end)
     : base(textArea)
 {
     this.start = start;
     this.end = end;
     this.startOffset = textArea.Document.GetOffset(start.Location);
     this.endOffset = textArea.Document.GetOffset(end.Location);
 }
 /// <summary>
 /// Creates a new TextAreaInputHandler.
 /// </summary>
 public TextAreaInputHandler(TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     this.textArea = textArea;
     commandBindings = new ObserveAddRemoveCollection<CommandBinding>(CommandBinding_Added, CommandBinding_Removed);
     inputBindings = new ObserveAddRemoveCollection<InputBinding>(InputBinding_Added, InputBinding_Removed);
     nestedInputHandlers = new ObserveAddRemoveCollection<ITextAreaInputHandler>(NestedInputHandler_Added, NestedInputHandler_Removed);
 }
Esempio n. 4
0
        public SelectionLayer(TextArea textArea)
            : base(textArea.TextView, KnownLayer.Selection)
        {
            this.IsHitTestVisible = false;

            this.textArea = textArea;
            TextViewWeakEventManager.VisualLinesChanged.AddListener(textView, this);
            TextViewWeakEventManager.ScrollOffsetChanged.AddListener(textView, this);
        }
        /// <summary>
        /// Creates a new TextAreaDefaultInputHandler instance.
        /// </summary>
        public TextAreaDefaultInputHandler(TextArea textArea)
            : base(textArea)
        {
            this.NestedInputHandlers.Add(CaretNavigation = CaretNavigationCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(Editing = EditingCommandHandler.Create(textArea));
            this.NestedInputHandlers.Add(MouseSelection = new SelectionMouseHandler(textArea));

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, ExecuteUndo, CanExecuteUndo));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, ExecuteRedo, CanExecuteRedo));
        }
Esempio n. 6
0
        internal Caret(TextArea textArea)
        {
            this.textArea = textArea;
            this.textView = textArea.TextView;
            position = new TextViewPosition(1, 1, 0);

            caretAdorner = new CaretLayer(textView);
            textView.InsertLayer(caretAdorner, KnownLayer.Caret, LayerInsertionPosition.Replace);
            textView.VisualLinesChanged += TextView_VisualLinesChanged;
            textView.ScrollOffsetChanged += TextView_ScrollOffsetChanged;
        }
Esempio n. 7
0
        EventHandler requerySuggestedHandler; // we need to keep the event handler instance alive because CommandManager.RequerySuggested uses weak references

        #endregion Fields

        #region Constructors

        public ImeSupport(TextArea textArea)
        {
            if (textArea == null)
                throw new ArgumentNullException("textArea");
            this.textArea = textArea;
            InputMethod.SetIsInputMethodSuspended(this.textArea, textArea.Options.EnableImeSupport);
            // We listen to CommandManager.RequerySuggested for both caret offset changes and changes to the set of read-only sections.
            // This is because there's no dedicated event for read-only section changes; but RequerySuggested needs to be raised anyways
            // to invalidate the Paste command.
            requerySuggestedHandler = OnRequerySuggested;
            CommandManager.RequerySuggested += requerySuggestedHandler;
            textArea.OptionChanged += TextAreaOptionChanged;
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new InsertionContext instance.
        /// </summary>
        public InsertionContext(TextArea textArea, int insertionPosition)
        {
            if (textArea == null)
                throw new ArgumentNullException("textArea");
            this.TextArea = textArea;
            this.Document = textArea.Document;
            this.SelectedText = textArea.Selection.GetText();
            this.InsertionPosition = insertionPosition;
            this.startPosition = insertionPosition;

            DocumentLine startLine = this.Document.GetLineByOffset(insertionPosition);
            ISegment indentation = TextUtilities.GetWhitespaceAfter(this.Document, startLine.Offset);
            this.Indentation = Document.GetText(indentation.Offset, Math.Min(indentation.EndOffset, insertionPosition) - indentation.Offset);
            this.Tab = textArea.Options.IndentationString;

            this.LineTerminator = TextUtilities.GetNewLineFromDocument(this.Document, startLine.LineNumber);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new code completion window.
        /// </summary>
        public CompletionWindow(TextArea textArea)
            : base(textArea)
        {
            // keep height automatic
            this.CloseAutomatically = true;
            this.SizeToContent = SizeToContent.Height;
            this.MaxHeight = 300;
            this.Width = 175;
            this.Content = completionList;
            // prevent user from resizing window to 0x0
            this.MinHeight = 15;
            this.MinWidth = 30;

            toolTip.PlacementTarget = this;
            toolTip.Placement = PlacementMode.Right;
            toolTip.Closed += toolTip_Closed;

            AttachEvents();
        }
        static void CopyWholeLine(TextArea textArea, DocumentLine line)
        {
            ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
            string text = textArea.Document.GetText(wholeLine);
            // Ensure we use the appropriate newline sequence for the OS
            text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
            DataObject data = new DataObject(text);

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
            HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));

            MemoryStream lineSelected = new MemoryStream(1);
            lineSelected.WriteByte(1);
            data.SetData(LineSelectedType, lineSelected, false);

            try {
                Clipboard.SetDataObject(data, true);
            } catch (ExternalException) {
                // Apparently this exception sometimes happens randomly.
                // The MS controls just ignore it, so we'll do the same.
                return;
            }
            textArea.OnTextCopied(new TextEventArgs(text));
        }
 /// <summary>
 /// Creates a new <see cref="TextAreaInputHandler"/> for the text area.
 /// </summary>
 public static TextAreaInputHandler Create(TextArea textArea)
 {
     TextAreaInputHandler handler = new TextAreaInputHandler(textArea);
     handler.CommandBindings.AddRange(CommandBindings);
     handler.InputBindings.AddRange(InputBindings);
     return handler;
 }
 static void ConvertTabsToSpaces(TextArea textArea, ISegment segment)
 {
     TextDocument document = textArea.Document;
     int endOffset = segment.EndOffset;
     string indentationString = new string(' ', textArea.Options.IndentationSize);
     for (int offset = segment.Offset; offset < endOffset; offset++) {
         if (document.GetCharAt(offset) == '\t') {
             document.Replace(offset, 1, indentationString, OffsetChangeMappingType.CharacterReplace);
             endOffset += indentationString.Length - 1;
         }
     }
 }
        static void CopySelectedText(TextArea textArea)
        {
            var data = textArea.Selection.CreateDataObject(textArea);

            try {
                Clipboard.SetDataObject(data, true);
            } catch (ExternalException) {
                // Apparently this exception sometimes happens randomly.
                // The MS controls just ignore it, so we'll do the same.
                return;
            }

            string text = textArea.Selection.GetText();
            text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
            textArea.OnTextCopied(new TextEventArgs(text));
        }
Esempio n. 14
0
            /*
            void DemoMode()
            {
                foldingGenerator = new FoldingElementGenerator() { FoldingManager = fm };
                foldingMargin = new FoldingMargin { FoldingManager = fm };
                foldingMarginBorder = new Border {
                    Child = foldingMargin,
                    Background = new LinearGradientBrush(Colors.White, Colors.Transparent, 0)
                };
                foldingMarginBorder.SizeChanged += UpdateTextViewClip;
                textEditor.TextArea.TextView.ElementGenerators.Add(foldingGenerator);
                textEditor.TextArea.LeftMargins.Add(foldingMarginBorder);
            }

            void UpdateTextViewClip(object sender, SizeChangedEventArgs e)
            {
                textEditor.TextArea.TextView.Clip = new RectangleGeometry(
                    new Rect(-foldingMarginBorder.ActualWidth,
                             0,
                             textEditor.TextArea.TextView.ActualWidth + foldingMarginBorder.ActualWidth,
                             textEditor.TextArea.TextView.ActualHeight));
            }
             */
            public void Uninstall()
            {
                Clear();
                if (textArea != null) {
                    textArea.Caret.PositionChanged -= textArea_Caret_PositionChanged;
                    textArea.LeftMargins.Remove(margin);
                    textArea.TextView.ElementGenerators.Remove(generator);
                    textArea.TextView.Services.RemoveService(typeof(FoldingManager));
                    margin = null;
                    generator = null;
                    textArea = null;
                }
            }
 static void ConvertSpacesToTabs(TextArea textArea, ISegment segment)
 {
     TextDocument document = textArea.Document;
     int endOffset = segment.EndOffset;
     int indentationSize = textArea.Options.IndentationSize;
     int spacesCount = 0;
     for (int offset = segment.Offset; offset < endOffset; offset++) {
         if (document.GetCharAt(offset) == ' ') {
             spacesCount++;
             if (spacesCount == indentationSize) {
                 document.Replace(offset - (indentationSize - 1), indentationSize, "\t", OffsetChangeMappingType.CharacterReplace);
                 spacesCount = 0;
                 offset -= indentationSize - 1;
                 endOffset -= indentationSize - 1;
             }
         } else {
             spacesCount = 0;
         }
     }
 }
Esempio n. 16
0
 public SelectionColorizer(TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     this.textArea = textArea;
 }
Esempio n. 17
0
        /// <summary>
        /// Attaches this SearchPanel to a TextArea instance.
        /// </summary>
        public void Attach(TextArea textArea)
        {
            if (textArea == null)
                throw new ArgumentNullException("textArea");
            this.textArea = textArea;
            adorner = new SearchPanelAdorner(textArea, this);
            DataContext = this;

            renderer = new SearchResultBackgroundRenderer();
            currentDocument = textArea.Document;
            if (currentDocument != null)
                currentDocument.TextChanged += textArea_Document_TextChanged;
            textArea.DocumentChanged += textArea_DocumentChanged;
            KeyDown += SearchLayerKeyDown;

            this.CommandBindings.Add(new CommandBinding(SearchCommands.FindNext, (sender, e) => FindNext()));
            this.CommandBindings.Add(new CommandBinding(SearchCommands.FindPrevious, (sender, e) => FindPrevious()));
            this.CommandBindings.Add(new CommandBinding(SearchCommands.CloseSearchPanel, (sender, e) => Close()));
            IsClosed = true;
        }
Esempio n. 18
0
 /// <summary>
 /// Creates a new simple selection that selects the text in the specified segment.
 /// </summary>
 public static Selection Create(TextArea textArea, ISegment segment)
 {
     if (segment == null)
         throw new ArgumentNullException("segment");
     return Create(textArea, segment.Offset, segment.EndOffset);
 }
Esempio n. 19
0
 internal static Selection Create(TextArea textArea, TextViewPosition start, TextViewPosition end)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     if (textArea.Document.GetOffset(start.Location) == textArea.Document.GetOffset(end.Location) && start.VisualColumn == end.VisualColumn)
         return textArea.emptySelection;
     else
         return new SimpleSelection(textArea, start, end);
 }
 public SelectionMouseHandler(TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     this.textArea = textArea;
 }
Esempio n. 21
0
 public RestoreCaretAndSelectionUndoAction(TextArea textArea)
 {
     this.textAreaReference = new WeakReference(textArea);
     // Just save the old caret position, no need to validate here.
     // If we restore it, we'll validate it anyways.
     this.caretPosition = textArea.Caret.NonValidatedPosition;
     this.selection = textArea.Selection;
 }
Esempio n. 22
0
 /// <summary>
 /// Adds Folding support to the specified text area.
 /// Warning: The folding manager is only valid for the text area's current document. The folding manager
 /// must be uninstalled before the text area is bound to a different document.
 /// </summary>
 /// <returns>The <see cref="FoldingManager"/> that manages the list of foldings inside the text area.</returns>
 public static FoldingManager Install(TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     return new FoldingManagerInstallation(textArea);
 }
Esempio n. 23
0
 /// <summary>
 /// Creates a new InsightWindow.
 /// </summary>
 public InsightWindow(TextArea textArea)
     : base(textArea)
 {
     this.CloseAutomatically = true;
     AttachEvents();
 }
Esempio n. 24
0
 public SearchPanelAdorner(TextArea textArea, SearchPanel panel)
     : base(textArea)
 {
     this.panel = panel;
     AddVisualChild(panel);
 }
Esempio n. 25
0
 /// <summary>
 /// Creates a new simple selection that selects the text from startOffset to endOffset.
 /// </summary>
 public static Selection Create(TextArea textArea, int startOffset, int endOffset)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     if (startOffset == endOffset)
         return textArea.emptySelection;
     else
         return new SimpleSelection(textArea,
                                    new TextViewPosition(textArea.Document.GetLocation(startOffset)),
                                    new TextViewPosition(textArea.Document.GetLocation(endOffset)));
 }
Esempio n. 26
0
 public FoldingManagerInstallation(TextArea textArea)
     : base(textArea.Document)
 {
     this.textArea = textArea;
     margin = new FoldingMargin() { FoldingManager = this };
     generator = new FoldingElementGenerator() { FoldingManager = this };
     textArea.LeftMargins.Add(margin);
     textArea.TextView.Services.AddService(typeof(FoldingManager), this);
     // HACK: folding only works correctly when it has highest priority
     textArea.TextView.ElementGenerators.Insert(0, generator);
     textArea.Caret.PositionChanged += textArea_Caret_PositionChanged;
 }
Esempio n. 27
0
        /// <summary>
        /// Creates a data object containing the selection's text.
        /// </summary>
        public virtual DataObject CreateDataObject(TextArea textArea)
        {
            string text = GetText();
            // Ensure we use the appropriate newline sequence for the OS
            DataObject data = new DataObject(TextUtilities.NormalizeNewLines(text, Environment.NewLine));
            // we cannot use DataObject.SetText - then we cannot drag to SciTe
            // (but dragging to Word works in both cases)

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            HtmlClipboard.SetHtml(data, CreateHtmlFragment(new HtmlOptions(textArea.Options)));
            return data;
        }
Esempio n. 28
0
 public static bool SetCompositionFont(HwndSource source, IntPtr hIMC, TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     LOGFONT lf = new LOGFONT();
     Rect characterBounds = textArea.TextView.GetCharacterBounds(textArea.Caret.Position, source);
     lf.lfFaceName = textArea.FontFamily.Source;
     lf.lfHeight = (int)characterBounds.Height;
     return ImmSetCompositionFont(hIMC, ref lf);
 }
Esempio n. 29
0
 /// <summary>
 /// Constructor for Selection.
 /// </summary>
 protected Selection(TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     this.textArea = textArea;
 }
Esempio n. 30
0
 public static bool SetCompositionWindow(HwndSource source, IntPtr hIMC, TextArea textArea)
 {
     if (textArea == null)
         throw new ArgumentNullException("textArea");
     Rect textViewBounds = textArea.TextView.GetBounds(source);
     Rect characterBounds = textArea.TextView.GetCharacterBounds(textArea.Caret.Position, source);
     CompositionForm form = new CompositionForm();
     form.dwStyle = 0x0020;
     form.ptCurrentPos.x = (int)Math.Max(characterBounds.Left, textViewBounds.Left);
     form.ptCurrentPos.y = (int)Math.Max(characterBounds.Top, textViewBounds.Top);
     form.rcArea.left = (int)textViewBounds.Left;
     form.rcArea.top = (int)textViewBounds.Top;
     form.rcArea.right = (int)textViewBounds.Right;
     form.rcArea.bottom = (int)textViewBounds.Bottom;
     return ImmSetCompositionWindow(hIMC, ref form);
 }