Skip to content

Commit

Permalink
Some improvements to the graph theme.
Browse files Browse the repository at this point in the history
Allow setting a background colour for graph items.
Add some fallback support to references that dont reference anything.
Remove references to the deleted PairItem.
  • Loading branch information
Lyeeedar committed Feb 12, 2017
1 parent 1831aa3 commit 6f21556
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 203 deletions.
4 changes: 4 additions & 0 deletions StructuredXmlEditor/Core.xmldef
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<Boolean Name="AllowCircularLinks" Default="false" ToolTip="Whether circular links are allowed." VisibleIf="AllowReferenceLinks==true" />
<Boolean Name="FlattenData" Default="false" ToolTip="If true each graph node will be placed in a flat list within this element." VisibleIf="AllowReferenceLinks==true" />
<String Name="NodeStoreName" Default="Nodes" ToolTip="The name of the node added to this to store all the graph nodes." VisibleIf="FlattenData==true" />
<Colour Name="Background" Default="0,0,0,0" />
<String Name="Description" ToolTip="The description to be used. Add a child names inside {} to use the contents of it in the description." />
<String Name="VisibleIf" ToolTip="The expression to use to determine whether this element is visible. Leave blank to have always visible." />
<Colour Name="TextColour" ToolTip="The colour on the element name in the ui." Default="Struct" HasAlpha="false" />
Expand All @@ -263,6 +264,7 @@
<String Name="Name" Default="GraphStruct" ToolTip="The name to be written for this element." />
<String Name="Description" ToolTip="The description to be used. Add a child names inside {} to use the contents of it in the description." />
<String Name="ChildAsGUID" ToolTip="The child to use as this elements GUID." />
<Colour Name="Background" Default="0,0,0,0" />
<String Name="VisibleIf" ToolTip="The expression to use to determine whether this element is visible. Leave blank to have always visible." />
<Colour Name="TextColour" ToolTip="The colour on the element name in the ui." Default="Struct" HasAlpha="false" />
<String Name="ToolTip" ToolTip="The tooltip to display when this element is moused over." />
Expand All @@ -284,6 +286,7 @@
<String Name="NodeStoreName" Default="Nodes" ToolTip="The name of the node added to this to store all the graph nodes." VisibleIf="FlattenData==true" />
<Number Name="MinCount" Min="0" ToolTip="The minimum number of child elements this can have." />
<Number Name="MaxCount" Min="1" Default="99999999" ToolTip="The maximum number of child elements this can have." />
<Colour Name="Background" Default="0,0,0,0" />
<Boolean Name="SkipIfDefault" ToolTip="Don't write out this element if it is at the default value." Default="true" />
<String Name="VisibleIf" ToolTip="The expression to use to determine whether this element is visible. Leave blank to have always visible." />
<Colour Name="TextColour" ToolTip="The colour on the element name in the ui." Default="Collection" HasAlpha="false" />
Expand All @@ -301,6 +304,7 @@
<String Name="Name" Default="GraphCollection" ToolTip="The name to be written for this element. This will be used as the key when referencing it." />
<Number Name="MinCount" Min="0" ToolTip="The minimum number of child elements this can have." />
<Number Name="MaxCount" Min="1" Default="99999999" ToolTip="The maximum number of child elements this can have." />
<Colour Name="Background" Default="0,0,0,0" />
<Boolean Name="SkipIfDefault" ToolTip="Don't write out this element if it is at the default value." Default="true" />
<String Name="VisibleIf" ToolTip="The expression to use to determine whether this element is visible. Leave blank to have always visible." />
<Colour Name="TextColour" ToolTip="The colour on the element name in the ui." Default="Collection" HasAlpha="false" />
Expand Down
24 changes: 0 additions & 24 deletions StructuredXmlEditor/Data/PairItem.cs

This file was deleted.

21 changes: 21 additions & 0 deletions StructuredXmlEditor/Definition/GraphCollectionDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Xml.Linq;

namespace StructuredXmlEditor.Definition
Expand Down Expand Up @@ -100,6 +101,26 @@ public override void Parse(XElement definition)
FlattenData = TryParseBool(definition, "FlattenData", false);
NodeStoreName = definition.Attribute("NodeStoreName")?.Value?.ToString() ?? "Nodes";

var backgroundCol = definition.Attribute("Background")?.Value?.ToString();
if (backgroundCol != null)
{
var split = backgroundCol.Split(new char[] { ',' });

byte r = 0;
byte g = 0;
byte b = 0;
byte a = 0;

byte.TryParse(split[0], out r);
byte.TryParse(split[1], out g);
byte.TryParse(split[2], out b);
byte.TryParse(split[3], out a);

var col = Color.FromArgb(a, r, g, b);
Background = new SolidColorBrush(col);
Background.Freeze();
}

var childDefs = definition.Elements().Where(e => e.Name != "Attributes");
foreach (var childDef in childDefs)
{
Expand Down
3 changes: 3 additions & 0 deletions StructuredXmlEditor/Definition/GraphNodeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace StructuredXmlEditor.Definition
{
Expand All @@ -13,6 +14,8 @@ public abstract class GraphNodeDefinition : ComplexDataDefinition
public bool FlattenData { get; set; }
public string NodeStoreName { get; set; }

public Brush Background { get; set; }

public GraphNodeDefinition()
{
TextColour = Colours["Struct"];
Expand Down
13 changes: 12 additions & 1 deletion StructuredXmlEditor/Definition/GraphReferenceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public override void RecursivelyResolve(Dictionary<string, DataDefinition> local
{
Definitions[key.Item1] = def as GraphNodeDefinition;
}
else
else if (key.Item1 != "---")
{
Message.Show("Tried to add definition of type " + def.GetType() + " (key = " + key.Item1 + ") to graph reference!", "Reference Resolve Failed", "Ok");
}
Expand All @@ -161,6 +161,17 @@ public override void RecursivelyResolve(Dictionary<string, DataDefinition> local
Message.Show("Failed to find key " + key.Item1 + "!", "Reference Resolve Failed", "Ok");
}
}

if (Keys.Count == 0)
{
Keys.Add(new Tuple<string, string>("---", "---"));

ListCollectionView lcv = new ListCollectionView(Keys);
lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2"));
ItemsSource = lcv;

Definitions["---"] = new GraphStructDefinition();
}
}

public override bool IsDefault(DataItem item)
Expand Down
21 changes: 21 additions & 0 deletions StructuredXmlEditor/Definition/GraphStructDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Xml.Linq;

namespace StructuredXmlEditor.Definition
Expand Down Expand Up @@ -153,6 +154,26 @@ public override void Parse(XElement definition)
FlattenData = TryParseBool(definition, "FlattenData", false);
NodeStoreName = definition.Attribute("NodeStoreName")?.Value?.ToString() ?? "Nodes";

var backgroundCol = definition.Attribute("Background")?.Value?.ToString();
if (backgroundCol != null)
{
var split = backgroundCol.Split(new char[] { ',' });

byte r = 0;
byte g = 0;
byte b = 0;
byte a = 0;

byte.TryParse(split[0], out r);
byte.TryParse(split[1], out g);
byte.TryParse(split[2], out b);
byte.TryParse(split[3], out a);

var col = Color.FromArgb(a, r, g, b);
Background = new SolidColorBrush(col);
Background.Freeze();
}

bool foundChildAsGUID = string.IsNullOrWhiteSpace(ChildAsGUID);

foreach (var child in definition.Elements())
Expand Down
13 changes: 12 additions & 1 deletion StructuredXmlEditor/Definition/ReferenceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,22 @@ public override void RecursivelyResolve(Dictionary<string, DataDefinition> local
{
Definitions[key.Item1] = defs[key.Item1.ToLower()];
}
else
else if (key.Item1 != "---")
{
Message.Show("Failed to find key " + key.Item1 + "!", "Reference Resolve Failed", "Ok");
}
}

if (Keys.Count == 0)
{
Keys.Add(new Tuple<string, string>("---", "---"));

ListCollectionView lcv = new ListCollectionView(Keys);
lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2"));
ItemsSource = lcv;

Definitions["---"] = new DummyDefinition();
}
}

public override bool IsDefault(DataItem item)
Expand Down
1 change: 0 additions & 1 deletion StructuredXmlEditor/StructuredXmlEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
<Compile Include="Data\ICollectionItem.cs" />
<Compile Include="Data\KeyframeItem.cs" />
<Compile Include="Data\NumberItem.cs" />
<Compile Include="Data\PairItem.cs" />
<Compile Include="Data\PrimitiveDataItem.cs" />
<Compile Include="Data\MultilineStringItem.cs" />
<Compile Include="Data\ReferenceItem.cs" />
Expand Down
7 changes: 7 additions & 0 deletions StructuredXmlEditor/View/CustomControls/Graph/GraphNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StructuredXmlEditor.Data;
using StructuredXmlEditor.Definition;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -43,6 +44,12 @@ static GraphNode()
//--------------------------------------------------------------------------
public List<GraphNode> ParentNodes { get; } = new List<GraphNode>();

//--------------------------------------------------------------------------
public Brush BackgroundBrush
{
get { return (GraphNodeItem.Definition as GraphNodeDefinition).Background; }
}

//--------------------------------------------------------------------------
public double X
{
Expand Down
45 changes: 20 additions & 25 deletions StructuredXmlEditor/View/Styles/DataGridTemplates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,6 @@
</Grid>
</DataTemplate>

<DataTemplate
DataType="{x:Type d:PairItem}">
<ContentControl
VerticalAlignment="Center"
Content="{Binding Description, Converter={v:ColourMarkupConverter}}" />
</DataTemplate>

<DataTemplate
DataType="{x:Type d:NumberItem}">
<v:NumericTextBox
Expand Down Expand Up @@ -499,7 +492,7 @@
<ColumnDefinition
Width="20" />
<ColumnDefinition
Width="Auto" />
Width="*" />
</Grid.ColumnDefinitions>

<Button
Expand All @@ -519,6 +512,7 @@

<ComboBox
Grid.Column="2"
Margin="20,0,20,0"
Visibility="{Binding HasContent, Converter={v:ValueTypeConverter}, ConverterParameter=Not}"
VerticalAlignment="Center"
ItemsSource="{Binding Definition.ItemsSource}"
Expand Down Expand Up @@ -666,7 +660,7 @@
<ColumnDefinition
Width="20" />
<ColumnDefinition
Width="Auto" />
Width="*" />
</Grid.ColumnDefinitions>

<Button
Expand All @@ -686,6 +680,7 @@

<ComboBox
Grid.Column="2"
Margin="20,0,20,0"
Visibility="{Binding HasContent, Converter={v:ValueTypeConverter}, ConverterParameter=Not}"
VerticalAlignment="Center"
ItemsSource="{Binding Definition.ItemsSource}"
Expand Down Expand Up @@ -728,8 +723,6 @@
Width="20" />
<ColumnDefinition
Width="20" />
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
Expand Down Expand Up @@ -803,8 +796,16 @@
Width="16" />
</Button>

<ContentControl
Grid.Column="2"
VerticalAlignment="Center"
Margin="5,0,5,0"
Visibility="{Binding ShowComboBox, Converter={v:ValueTypeConverter}, ConverterParameter=Not}"
Content="{Binding Description, Converter={v:ColourMarkupConverter}}" />

<ComboBox
Grid.Column="2"
Margin="20,0,20,0"
Visibility="{Binding ShowComboBox, Converter={v:ValueTypeConverter}}"
ItemsSource="{Binding Definition.ChildDefinitions}"
SelectedItem="{Binding SelectedDefinition}">
Expand All @@ -816,12 +817,6 @@
</ComboBox.ItemTemplate>
</ComboBox>

<ContentControl
Grid.Column="3"
VerticalAlignment="Center"
Margin="5,0,5,0"
Content="{Binding Description, Converter={v:ColourMarkupConverter}}" />

</Grid>
</DataTemplate>

Expand All @@ -834,8 +829,6 @@
Width="20" />
<ColumnDefinition
Width="20" />
<ColumnDefinition
Width="Auto" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
Expand Down Expand Up @@ -909,8 +902,16 @@
Width="16" />
</Button>

<ContentControl
Grid.Column="2"
VerticalAlignment="Center"
Margin="5,0,5,0"
Visibility="{Binding ShowComboBox, Converter={v:ValueTypeConverter}, ConverterParameter=Not}"
Content="{Binding Description, Converter={v:ColourMarkupConverter}}" />

<ComboBox
Grid.Column="2"
Margin="20,0,20,0"
Visibility="{Binding ShowComboBox, Converter={v:ValueTypeConverter}}"
ItemsSource="{Binding Definition.ChildDefinitions}"
SelectedItem="{Binding SelectedDefinition}">
Expand All @@ -921,12 +922,6 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<ContentControl
Grid.Column="3"
VerticalAlignment="Center"
Margin="5,0,5,0"
Content="{Binding Description, Converter={v:ColourMarkupConverter}}" />

</Grid>
</DataTemplate>
Expand Down
Loading

0 comments on commit 6f21556

Please sign in to comment.