/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using dnSpy.Contracts.Menus;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;
namespace dnSpy.Contracts.Text.Editor {
///
/// Handles events
///
public interface IGlyphTextMarkerHandler {
///
/// Gets the mouse processor or null
///
IGlyphTextMarkerHandlerMouseProcessor? MouseProcessor { get; }
///
/// Creates context menu objects
///
/// Context
/// Marker
/// Position of the mouse pointer relative to the glyph margin
///
IEnumerable GetContextMenuObjects(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, Point marginRelativePoint);
///
/// Gets the tool tip content or null if the next handler should be checked
///
/// Context
/// Marker
///
GlyphTextMarkerToolTip? GetToolTipContent(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker);
///
/// Gets the popup content or null if the next handler should be checked. The popup content is
/// shown above the line (eg. breakpoint toolbar settings popup)
///
/// Context
/// Marker
///
FrameworkElement? GetPopupContent(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker);
}
///
/// Contains the tooltip content and style that is shown when hovering over the glyph in the glyph margin
///
public sealed class GlyphTextMarkerToolTip {
///
/// Tooltip content, a or a UI element
///
public object Content { get; }
///
/// Tooltip style or null. Can be the key of a style in the resources (eg. a ) or a instance
///
public object? Style { get; }
///
/// Constructor
///
/// Text content to show in the tooltip
/// Tooltip style or null. Can be the key of a style in the resources (eg. a ) or a instance
public GlyphTextMarkerToolTip(string content, object? style = null) {
Content = content;
Style = style;
}
///
/// Constructor
///
/// Content to show in the tooltip
/// Tooltip style or null. Can be the key of a style in the resources (eg. a ) or a instance
public GlyphTextMarkerToolTip(object content, object? style) {
Content = content;
Style = style;
}
}
///
/// Returns spans of markers
///
public interface IGlyphTextMarkerSpanProvider {
///
/// Gets the snapshot span of a marker
///
/// Marker
///
SnapshotSpan GetSpan(IGlyphTextMarker marker);
}
///
/// context
///
public interface IGlyphTextMarkerHandlerContext {
///
/// Gets the glyph margin
///
IWpfTextViewMargin Margin { get; }
///
/// Gets the text view host
///
IWpfTextViewHost Host { get; }
///
/// Gets the text view
///
IWpfTextView TextView { get; }
///
/// Gets the line
///
IWpfTextViewLine Line { get; }
///
/// Gets the span provider
///
IGlyphTextMarkerSpanProvider SpanProvider { get; }
}
///
/// mouse processor (see also )
///
public interface IGlyphTextMarkerHandlerMouseProcessor {
///
/// Mouse down handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse up handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse left button down handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseLeftButtonDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse left button up handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseLeftButtonUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse right button down handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseRightButtonDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse right button up handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseRightButtonUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e);
///
/// Mouse move handler
///
/// Context
/// Marker
/// Mouse event args
void OnMouseMove(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseEventArgs e);
}
///
/// Abstract class implementing
///
public abstract class GlyphTextMarkerHandlerMouseProcessorBase : IGlyphTextMarkerHandlerMouseProcessor {
///
/// Constructor
///
protected GlyphTextMarkerHandlerMouseProcessorBase() { }
///
/// Default mouse down handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse up handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse left button down handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseLeftButtonDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse left button up handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseLeftButtonUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse right button down handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseRightButtonDown(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse right button up handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseRightButtonUp(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseButtonEventArgs e) { }
///
/// Default mouse move handler
///
/// Context
/// Marker
/// Mouse event args
public virtual void OnMouseMove(IGlyphTextMarkerHandlerContext context, IGlyphTextMarker marker, MouseEventArgs e) { }
}
}