Skip to content
This repository has been archived by the owner on Jan 11, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Some local updates to MSAGL and better text for graph nodes - #6
  • Loading branch information
daveaglick committed Apr 8, 2015
1 parent 3bb7a5b commit de97dd7
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 12 deletions.
10 changes: 10 additions & 0 deletions LINQPad.CodeAnalysis/SyntaxTokenWrapper.cs
Expand Up @@ -60,6 +60,16 @@ public override string GetKind()
return "None";
}

public override string GetGraphText()
{
return string.IsNullOrEmpty(_token.Text) ? GetKind() : _token.Text;
}

public override FontStyle GetGraphFontStyle()
{
return string.IsNullOrEmpty(_token.Text) ? base.GetGraphFontStyle() : FontStyle.Italic;
}

public override string GetSpan()
{
return _token.FullSpan.ToString();
Expand Down
19 changes: 12 additions & 7 deletions LINQPad.CodeAnalysis/SyntaxTreePanel.cs
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -79,7 +80,13 @@ private static GViewer CreateGraphViewer()
{
GViewer graphViewer = new GViewer
{
Dock = DockStyle.Fill
Dock = DockStyle.Fill,
OutsideAreaBrush = Brushes.White,
LayoutEditingEnabled = false,
LayoutAlgorithmSettingsButtonVisible = false,
EdgeInsertButtonVisible = false,
SaveAsMsaglEnabled = false,
UndoRedoButtonsVisible = false
};
return graphViewer;
}
Expand Down Expand Up @@ -123,7 +130,7 @@ private static TreeListView CreateTreeList(TextBox textBox, GViewer graphViewer,
treeList.Columns.Add(new OLVColumn("Kind", null)
{
AspectGetter = x => x,
AspectToStringConverter = x => ((SyntaxWrapper)x).GetKind()
AspectToStringConverter = x => ((SyntaxWrapper)x).GetTreeText()
});
treeList.Columns.Add(new OLVColumn("Span", null)
{
Expand Down Expand Up @@ -332,10 +339,6 @@ private static void AutoSizeColumns(TreeListView treeList, int depth, bool recal
}

// TODO: Filter for node types
// TODO: Filter for declaration filter (this might already work due to set root)
// TODO: Hide toolbar?
// TODO: clicking a node highlights in the tree
// TODO: better text values
// TODO: white background
private static void PopulateGraph(GViewer graphViewer, SyntaxWrapper wrapper)
{
Expand All @@ -358,8 +361,10 @@ private static int PopulateGraph(Graph graph, SyntaxWrapper wrapper, int id, str
Node node = new Node(nodeId);
Color color = wrapper.GetColor();
node.Attr.FillColor = new Microsoft.Msagl.Drawing.Color(color.R, color.G, color.B);
node.LabelText = wrapper.GetKind();
node.Attr.LabelMargin = 10;
node.LabelText = wrapper.GetGraphText();
node.Label.FontColor = Microsoft.Msagl.Drawing.Color.White;
node.Label.FontStyle = (Microsoft.Msagl.Drawing.FontStyle)(int) wrapper.GetGraphFontStyle();
graph.AddNode(node);

// Add the edge
Expand Down
13 changes: 8 additions & 5 deletions LINQPad.CodeAnalysis/SyntaxTriviaWrapper.cs
Expand Up @@ -41,23 +41,26 @@ public override Color GetColor()

public override string GetKind()
{
string kind = "None";

// C#
Microsoft.CodeAnalysis.CSharp.SyntaxKind cSharpKind = Microsoft.CodeAnalysis.CSharp.CSharpExtensions.Kind(_trivia);
if (cSharpKind != Microsoft.CodeAnalysis.CSharp.SyntaxKind.None)
{
kind = cSharpKind.ToString();
return cSharpKind.ToString();
}

// Visual Basic
Microsoft.CodeAnalysis.VisualBasic.SyntaxKind visualBasicKind = Microsoft.CodeAnalysis.VisualBasic.VisualBasicExtensions.Kind(_trivia);
if (visualBasicKind != Microsoft.CodeAnalysis.VisualBasic.SyntaxKind.None)
{
kind = visualBasicKind.ToString();
return visualBasicKind.ToString();
}

return (_trivia.Token.LeadingTrivia.Contains(_trivia) ? "Lead: " : "Trail: ") + kind;
return "None";
}

public override string GetTreeText()
{
return (_trivia.Token.LeadingTrivia.Contains(_trivia) ? "Lead: " : "Trail: ") + GetKind();
}

public override string GetSpan()
Expand Down
18 changes: 18 additions & 0 deletions LINQPad.CodeAnalysis/SyntaxWrapper.cs
Expand Up @@ -51,8 +51,26 @@ public virtual void FormatCell(FormatCellEventArgs format)
}

public abstract Color GetColor();

public abstract string GetKind();

public virtual string GetTreeText()
{
return GetKind();
}

public virtual string GetGraphText()
{
return GetKind();
}

public virtual FontStyle GetGraphFontStyle()
{
return FontStyle.Regular;
}

public abstract string GetSpan();

public abstract string GetText();
}
}
Binary file modified lib/Microsoft.Msagl.Drawing.dll
Binary file not shown.
35 changes: 35 additions & 0 deletions lib/Microsoft.Msagl.Drawing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions lib/Microsoft.Msagl.GraphViewerGdi.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified lib/Microsoft.Msagl.GraphViewerGdi.dll
Binary file not shown.
Binary file modified lib/Microsoft.Msagl.dll
Binary file not shown.

0 comments on commit de97dd7

Please sign in to comment.