Skip to content

Commit

Permalink
Implement the Copy All context menu on other treeviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Jun 18, 2017
1 parent 3b0c872 commit cc3c0c4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/StructuredLogViewer/Controls/BuildControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand Down Expand Up @@ -32,6 +33,8 @@ public partial class BuildControl : UserControl
private MenuItem viewItem;
private MenuItem preprocessItem;
private MenuItem hideItem;
private MenuItem copyAllItem;
private ContextMenu sharedTreeContextMenu;

public TreeView ActiveTreeView;

Expand Down Expand Up @@ -73,6 +76,11 @@ public BuildControl(Build build, string logFilePath)
sourceFileResolver = new SourceFileResolver(logFilePath);
}

sharedTreeContextMenu = new ContextMenu();
copyAllItem = new MenuItem() { Header = "Copy All" };
copyAllItem.Click += (s, a) => CopyAll();
sharedTreeContextMenu.Items.Add(copyAllItem);

var contextMenu = new ContextMenu();
contextMenu.Opened += ContextMenu_Opened;
copyItem = new MenuItem() { Header = "Copy" };
Expand Down Expand Up @@ -116,9 +124,12 @@ public BuildControl(Build build, string logFilePath)
searchLogControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
searchLogControl.ResultsList.SelectedItemChanged += ResultsList_SelectionChanged;
searchLogControl.ResultsList.GotFocus += (s, a) => ActiveTreeView = searchLogControl.ResultsList;
searchLogControl.ResultsList.ContextMenu = sharedTreeContextMenu;

findInFilesControl.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
findInFilesControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
findInFilesControl.ResultsList.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
findInFilesControl.ResultsList.ContextMenu = sharedTreeContextMenu;

if (archiveFile != null)
{
Expand Down Expand Up @@ -229,6 +240,7 @@ private void PopulateFilesTab()

filesTree.ItemsSource = root.Children;
filesTree.GotFocus += (s, a) => ActiveTreeView = filesTree;
filesTree.ContextMenu = sharedTreeContextMenu;
}

private void CompressTree(Folder parent)
Expand Down Expand Up @@ -434,6 +446,24 @@ public void CopySubtree()
}
}

private void CopyAll()
{
var tree = ActiveTreeView;
if (tree == null)
{
return;
}

var sb = new StringBuilder();
foreach (var item in tree.Items)
{
var text = Microsoft.Build.Logging.StructuredLogger.StringWriter.GetString(item);
sb.AppendLine(text);
}

CopyToClipboard(sb.ToString());
}

private static void CopyToClipboard(string text)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/StructuredLogViewer/ProxyNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ private string GetProjectFileExtension()

return result;
}

public override string ToString() => Original.ToString();
}
}
5 changes: 5 additions & 0 deletions src/StructuredLogger/ObjectModel/SourceFileLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ public class SourceFileLine : TreeNode
{
public int LineNumber { get; set; }
public string LineText { get; set; }

public override string ToString()
{
return LineNumber.ToString().PadRight(5, ' ') + LineText;
}
}
}
5 changes: 5 additions & 0 deletions src/StructuredLogger/Serialization/StringWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static string GetString(object rootNode)

private static void WriteNode(object rootNode, StringBuilder sb, int indent = 0)
{
if (rootNode == null)
{
return;
}

Indent(sb, indent);
var text = rootNode.ToString() ?? "";

Expand Down

0 comments on commit cc3c0c4

Please sign in to comment.