Skip to content

Commit

Permalink
Add the Copy context menu to the text editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Jul 5, 2017
1 parent 4d5c590 commit 1ac4818
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/StructuredLogViewer/Controls/TextViewerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
ShowLineNumbers="True"
LineNumbersForeground="Teal"
FontSize="14">
<a:TextEditor.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" Click="copyMenu_Click" />
</ContextMenu>
</a:TextEditor.ContextMenu>
</a:TextEditor>

<!--<ScrollViewer VerticalScrollBarVisibility="Auto">
Expand Down
32 changes: 24 additions & 8 deletions src/StructuredLogViewer/Controls/TextViewerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Folding;
Expand All @@ -23,6 +24,15 @@ public TextViewerControl()
{
InitializeComponent();
SearchPanel.Install(textEditor.TextArea);
textEditor.TextArea.MouseRightButtonDown += TextAreaMouseRightButtonDown;

var textView = textEditor.TextArea.TextView;
textView.CurrentLineBackground = new SolidColorBrush(Color.FromRgb(224, 224, 224));
textView.CurrentLineBorder = new Pen(Brushes.Transparent, 0);
textView.Options.HighlightCurrentLine = true;
textView.Options.EnableEmailHyperlinks = false;
textView.Options.EnableHyperlinks = false;
textEditor.IsReadOnly = true;
}

public void DisplaySource(
Expand All @@ -39,18 +49,19 @@ public void DisplaySource(

filePathText.Text = sourceFilePath;

var textView = textEditor.TextArea.TextView;
textView.CurrentLineBackground = Brushes.LightCyan;
textView.CurrentLineBorder = new Pen(Brushes.Transparent, 0);
textView.Options.HighlightCurrentLine = true;
textView.Options.EnableEmailHyperlinks = false;
textView.Options.EnableHyperlinks = false;
textEditor.IsReadOnly = true;

SetText(text);
DisplaySource(lineNumber, column);
}

private void TextAreaMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
var position = textEditor.GetPositionFromPoint(e.GetPosition(textEditor));
if (position.HasValue)
{
textEditor.TextArea.Caret.Position = position.Value;
}
}

public void SetText(string text)
{
Text = text;
Expand Down Expand Up @@ -139,5 +150,10 @@ private void wordWrap_Unchecked(object sender, RoutedEventArgs e)
{
textEditor.WordWrap = false;
}

private void copyMenu_Click(object sender, RoutedEventArgs e)
{
textEditor.Copy();
}
}
}

0 comments on commit 1ac4818

Please sign in to comment.