28 changed files with 733 additions and 11 deletions
@ -0,0 +1,61 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.Core.Presentation; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.Commands; |
||||||
|
using ICSharpCode.SharpDevelop.Editor.ContextActions; |
||||||
|
using ICSharpCode.SharpDevelop.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions |
||||||
|
{ |
||||||
|
public class ClipboardRing : ResolveResultMenuCommand |
||||||
|
{ |
||||||
|
public override void Run(ResolveResult symbol) |
||||||
|
{ |
||||||
|
ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>(); |
||||||
|
if(editor == null) |
||||||
|
return; |
||||||
|
|
||||||
|
EditorRefactoringContext context = new EditorRefactoringContext(editor); |
||||||
|
MakePopupWithClipboardOptions(context).OpenAtCaretAndFocus(); |
||||||
|
} |
||||||
|
|
||||||
|
static ContextActionsPopup MakePopupWithClipboardOptions(EditorRefactoringContext context) |
||||||
|
{ |
||||||
|
var popupViewModel = new ContextActionsPopupViewModel(); |
||||||
|
var actions = BuildClipboardRingData(context); |
||||||
|
|
||||||
|
string labelSource = "${res:SharpDevelop.Refactoring.ClipboardRing}"; |
||||||
|
if (actions == null || actions.Count == 0) |
||||||
|
labelSource = "${res:SharpDevelop.Refactoring.ClipboardRingEmpty}"; |
||||||
|
|
||||||
|
popupViewModel.Title = MenuService.ConvertLabel(StringParser.Parse(labelSource)); |
||||||
|
popupViewModel.Actions = actions; |
||||||
|
return new ClipboardRingPopup { Actions = popupViewModel }; |
||||||
|
} |
||||||
|
|
||||||
|
static ObservableCollection<ContextActionViewModel> BuildClipboardRingData(EditorRefactoringContext context) |
||||||
|
{ |
||||||
|
var clipboardRing = ICSharpCode.SharpDevelop.Gui.TextEditorSideBar.Instance; |
||||||
|
var clipboardRingItems = clipboardRing.GetClipboardRingItems(); |
||||||
|
|
||||||
|
var list = new ObservableCollection<ContextActionViewModel>(); |
||||||
|
foreach (var item in clipboardRingItems) { |
||||||
|
list.Add(new ContextActionViewModel(new ClipboardRingAction(item), context)); |
||||||
|
} |
||||||
|
|
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions |
||||||
|
{ |
||||||
|
public class ClipboardRingAction : IContextAction |
||||||
|
{ |
||||||
|
readonly int maxLength = 50; |
||||||
|
|
||||||
|
readonly string endString = "..."; |
||||||
|
|
||||||
|
public string Text { get; private set; } |
||||||
|
|
||||||
|
public string DisplayName { get; private set; } |
||||||
|
|
||||||
|
public IEntity Entity { get; private set; } |
||||||
|
|
||||||
|
public IContextActionProvider Provider { get { return null; } } |
||||||
|
|
||||||
|
public ClipboardRingAction(string text) |
||||||
|
{ |
||||||
|
string entry = text.Trim(); |
||||||
|
if(entry.Length > maxLength) |
||||||
|
entry = entry.Substring(0, maxLength-endString.Length) + endString; |
||||||
|
|
||||||
|
this.DisplayName = entry; |
||||||
|
this.Text = text; |
||||||
|
} |
||||||
|
|
||||||
|
public string GetDisplayName(EditorRefactoringContext context) |
||||||
|
{ |
||||||
|
return DisplayName; |
||||||
|
} |
||||||
|
|
||||||
|
public void Execute(EditorRefactoringContext context) |
||||||
|
{ |
||||||
|
/* insert to editor */ |
||||||
|
ITextEditor editor = context.Editor; |
||||||
|
editor.Document.Insert(context.CaretOffset, this.Text); |
||||||
|
|
||||||
|
/* update clipboard ring */ |
||||||
|
var clipboardRing = ICSharpCode.SharpDevelop.Gui.TextEditorSideBar.Instance; |
||||||
|
if (clipboardRing != null) { |
||||||
|
clipboardRing.PutInClipboardRing(this.Text); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,73 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Controls.Primitives; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Editor.ContextActions; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions |
||||||
|
{ |
||||||
|
public class ClipboardRingPopup : ContextActionsPopup |
||||||
|
{ |
||||||
|
ToolTip toolTip; |
||||||
|
|
||||||
|
public ClipboardRingPopup() : base() |
||||||
|
{ |
||||||
|
this.toolTip = new ToolTip(); |
||||||
|
this.toolTip.PlacementTarget = this.ActionsControl; |
||||||
|
this.toolTip.Placement = PlacementMode.Right; |
||||||
|
this.toolTip.Closed += new RoutedEventHandler(ClipboardRingPopup_Closed); |
||||||
|
|
||||||
|
this.ActionsControl.ActionExecuted += delegate |
||||||
|
{ |
||||||
|
if(this.toolTip != null) |
||||||
|
this.toolTip.IsOpen = false; |
||||||
|
}; |
||||||
|
this.ActionsControl.ActionSelected += new RoutedEventHandler(ClipboardRingPopup_ActionSelected); |
||||||
|
this.ActionsControl.ActionUnselected += new RoutedEventHandler(ClipboardRingPopup_ActionUnselected); |
||||||
|
} |
||||||
|
|
||||||
|
#region ToolTip handling
|
||||||
|
|
||||||
|
string ExtractTextFromEvent(RoutedEventArgs args) |
||||||
|
{ |
||||||
|
var button = args.Source as Button; |
||||||
|
if (button == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
var command = button.Command as ContextActionCommand; |
||||||
|
if (command == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
var clipboardRingAction = command.ContextAction as ClipboardRingAction; |
||||||
|
if (clipboardRingAction == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
return clipboardRingAction.Text; |
||||||
|
} |
||||||
|
|
||||||
|
void ClipboardRingPopup_ActionSelected(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
if (this.toolTip != null) { |
||||||
|
var text = ExtractTextFromEvent(e); |
||||||
|
this.toolTip.Content = text; |
||||||
|
this.toolTip.IsOpen = (text != null); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ClipboardRingPopup_ActionUnselected(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void ClipboardRingPopup_Closed(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
if(toolTip != null) |
||||||
|
toolTip.Content = null; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,103 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
using ICSharpCode.AvalonEdit.Document; |
||||||
|
using ICSharpCode.AvalonEdit.Rendering; |
||||||
|
|
||||||
|
namespace ICSharpCode.AvalonEdit.Rendering |
||||||
|
{ |
||||||
|
sealed class CurrentLineHighlightRenderer : IBackgroundRenderer |
||||||
|
{ |
||||||
|
#region Fields
|
||||||
|
|
||||||
|
int line; |
||||||
|
TextView textView; |
||||||
|
|
||||||
|
public static readonly Color DefaultBackground = Color.FromArgb(22, 20, 220, 224); |
||||||
|
public static readonly Color DefaultBorder = Color.FromArgb(52, 0, 255, 110); |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public int Line { |
||||||
|
get { return this.Line; } |
||||||
|
set { |
||||||
|
if (this.line != value) { |
||||||
|
this.line = value; |
||||||
|
this.textView.InvalidateLayer(this.Layer); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public KnownLayer Layer |
||||||
|
{ |
||||||
|
get { return KnownLayer.Selection; } |
||||||
|
} |
||||||
|
|
||||||
|
public Brush BackgroundBrush { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
|
||||||
|
public Pen BorderPen { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public CurrentLineHighlightRenderer(TextView textView) |
||||||
|
{ |
||||||
|
if (textView == null) |
||||||
|
throw new ArgumentNullException("textView"); |
||||||
|
|
||||||
|
this.BorderPen = new Pen(new SolidColorBrush(DefaultBorder), 1); |
||||||
|
this.BorderPen.Freeze(); |
||||||
|
|
||||||
|
this.BackgroundBrush = new SolidColorBrush(DefaultBackground); |
||||||
|
this.BackgroundBrush.Freeze(); |
||||||
|
|
||||||
|
this.textView = textView; |
||||||
|
this.textView.BackgroundRenderers.Add(this); |
||||||
|
|
||||||
|
this.line = 0; |
||||||
|
} |
||||||
|
|
||||||
|
public void Draw(TextView textView, DrawingContext drawingContext) |
||||||
|
{ |
||||||
|
if(!this.textView.Options.HighlightCurrentLine) |
||||||
|
return; |
||||||
|
|
||||||
|
BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder(); |
||||||
|
|
||||||
|
builder.CornerRadius = 1; |
||||||
|
builder.AlignToMiddleOfPixels = true; |
||||||
|
|
||||||
|
var visualLine = this.textView.GetVisualLine(line); |
||||||
|
if(visualLine == null) return; |
||||||
|
|
||||||
|
var textViewPos = visualLine.GetTextViewPosition(0); |
||||||
|
if(textViewPos == null) return; |
||||||
|
|
||||||
|
var position = this.textView.GetVisualPosition(textViewPos, VisualYPosition.LineTop); |
||||||
|
if(position == null) return; |
||||||
|
|
||||||
|
var lineWidth = this.textView.ActualWidth; |
||||||
|
var lineHeigth = visualLine.Height; |
||||||
|
var linePosX = position.X; |
||||||
|
var linePosY = position.Y - this.textView.ScrollOffset.Y; |
||||||
|
|
||||||
|
builder.AddRectangle(textView, new Rect(linePosX, linePosY, lineWidth, lineHeigth)); |
||||||
|
|
||||||
|
Geometry geometry = builder.CreateGeometry(); |
||||||
|
if (geometry != null) { |
||||||
|
drawingContext.DrawGeometry(this.BackgroundBrush, this.BorderPen, geometry); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue