Skip to content

Commit 0450f8b

Browse files
committed
Fixed removing Attributes when INotify listeners are attached
Added Delete Attribute button Added LabelledControl Added icon Attribute props column is now always displayed Props column now displays attribute owner too Made Datamodel.AttributeTypes public Made Datamodel.Attribute.Owner public Now trimming Recent Items Added Windows icon registration
1 parent 442590c commit 0450f8b

15 files changed

+268
-64
lines changed

Attributes.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal Attribute(Element owner, string name, object value, long offset)
1717
Name = name;
1818
Value = value;
1919
Offset = offset;
20-
Owner = owner;
20+
this.owner = owner;
2121
if (Owner.Attributes.Count == Int32.MaxValue)
2222
throw new InvalidOperationException("Maximum Attribute count reached for this Element.");
2323
Owner.Attributes.Add(this);
@@ -34,6 +34,12 @@ public string Name
3434
}
3535
string name;
3636

37+
/// <summary>
38+
/// The <see cref="Element"/> which this Attribute is part of.
39+
/// </summary>
40+
public Element Owner { get { return owner; } }
41+
Element owner;
42+
3743
/// <summary>
3844
/// The value held by this Attribute.
3945
/// </summary>
@@ -97,7 +103,6 @@ public object Value
97103
#endregion
98104

99105
long Offset;
100-
Element Owner;
101106
int LastStubSearch = 0;
102107

103108
public override string ToString()

Datamodel.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace Datamodel
1616
public class Datamodel : INotifyPropertyChanged, IDisposable
1717
{
1818
#region Attribute types
19-
internal static readonly Type[] AttributeTypes = { typeof(Element), typeof(int), typeof(float), typeof(bool), typeof(string), typeof(byte[]),
19+
public static Type[] AttributeTypes { get { return _AttributeTypes; } }
20+
static Type[] _AttributeTypes = { typeof(Element), typeof(int), typeof(float), typeof(bool), typeof(string), typeof(byte[]),
2021
typeof(TimeSpan), typeof(System.Drawing.Color), typeof(Vector2), typeof(Vector3),typeof(Vector4), typeof(Angle), typeof(Quaternion), typeof(Matrix) };
2122

2223
/// <summary>

DmxPad/App.xaml

+10-32
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<l:ChildPathConverter x:Key="ChildPathConverter"/>
1414
<l:ValueColumnWidthConverter x:Key="ValueColumnWidthConverter"/>
1515
<l:ValuePanelVisibilityConverter x:Key="ValuePanelVisibilityConverter"/>
16+
<l:EnsureElementConverter x:Key="EnsureElementConverter"/>
1617

1718
<l:InspectPaneTemplateSelector x:Key="InspectPaneTemplateSelector"/>
1819
<l:ValueColumnTemplateSelector x:Key="ValueColumnTemplateSelector"/>
@@ -25,40 +26,17 @@
2526
</DataTemplate>
2627

2728
<DataTemplate x:Key="ObjectList">
28-
<ListBox ItemsSource="{Binding}" />
29+
<Grid>
30+
<Grid.RowDefinitions>
31+
<RowDefinition Height="Auto"/>
32+
<RowDefinition Height="*"/>
33+
</Grid.RowDefinitions>
34+
35+
<TextBlock Text="{Binding Path=Value.Count,StringFormat={}{0} items}"/>
36+
<ListBox Grid.Row="1" ItemsSource="{Binding Path=Value}"/>
37+
</Grid>
2938
<!--<DataGrid ItemsSource="{Binding}" DisplayMemberPath="Value" HeadersVisibility="Column" MinColumnWidth="80" HorizontalAlignment="Left" VerticalAlignment="Top" />-->
3039
</DataTemplate>
31-
<DataTemplate x:Key="ElementAttrs">
32-
<StackPanel Grid.Row="0">
33-
<StackPanel.Resources>
34-
<Style TargetType="TextBlock">
35-
<Setter Property="Width" Value="50" />
36-
<Setter Property="TextAlignment" Value="Right"/>
37-
<Setter Property="VerticalAlignment" Value="Center" />
38-
<Setter Property="Margin" Value="0,0,5,0"/>
39-
</Style>
40-
<Style TargetType="TextBox">
41-
<Setter Property="Width" Value="250" />
42-
<Setter Property="VerticalAlignment" Value="Center" />
43-
</Style>
44-
<Style TargetType="StackPanel">
45-
<Setter Property="Margin" Value="0,2" />
46-
</Style>
47-
</StackPanel.Resources>
48-
<StackPanel Orientation="Horizontal">
49-
<TextBlock Text="Name:" />
50-
<TextBox Text="{Binding Path=Name}" />
51-
</StackPanel>
52-
<StackPanel Orientation="Horizontal">
53-
<TextBlock Text="Class:" />
54-
<TextBox Text="{Binding Path=ClassName}" />
55-
</StackPanel>
56-
<StackPanel Orientation="Horizontal">
57-
<TextBlock Text="GUID:" />
58-
<TextBox Text="{Binding Path=ID,Mode=OneWay}" IsReadOnly="True" BorderThickness="0" Background="Transparent" FontFamily="Consolas" />
59-
</StackPanel>
60-
</StackPanel>
61-
</DataTemplate>
6240

6341
</Application.Resources>
6442
</Application>

DmxPad/Controls/LabelledControl.xaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<UserControl x:Class="DmxPad.Controls.LabelledControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d" d:DesignHeight="50" d:DesignWidth="300">
7+
</UserControl>
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
using System.Windows.Documents;
9+
using System.Windows.Input;
10+
using System.Windows.Media;
11+
using System.Windows.Media.Imaging;
12+
using System.Windows.Navigation;
13+
using System.Windows.Shapes;
14+
15+
namespace DmxPad.Controls
16+
{
17+
/// <summary>
18+
/// Interaction logic for LabelledControl.xaml
19+
/// </summary>
20+
public partial class LabelledControl : UserControl
21+
{
22+
public LabelledControl()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
static LabelledControl()
28+
{
29+
DefaultStyleKeyProperty.OverrideMetadata(
30+
typeof(LabelledControl),
31+
new FrameworkPropertyMetadata(typeof(LabelledControl)));
32+
}
33+
34+
public string LabelText
35+
{
36+
get { return (string)GetValue(LabelTextProperty); }
37+
set { SetValue(LabelTextProperty, value); }
38+
}
39+
public static readonly DependencyProperty LabelTextProperty =
40+
DependencyProperty.Register("LabelText", typeof(string), typeof(LabelledControl), new PropertyMetadata("FOO"));
41+
42+
public GridLength LabelWidth
43+
{
44+
get { return (GridLength)GetValue(LabelWidthProperty); }
45+
set { SetValue(LabelWidthProperty, value); }
46+
}
47+
48+
// Using a DependencyProperty as the backing store for LabelWidth. This enables animation, styling, binding, etc...
49+
public static readonly DependencyProperty LabelWidthProperty =
50+
DependencyProperty.Register("LabelWidth", typeof(GridLength), typeof(LabelledControl), new PropertyMetadata(GridLength.Auto));
51+
52+
53+
}
54+
}

DmxPad/Converters.cs

+26-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public class VisibleIfNotNull : IValueConverter
154154
{
155155
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
156156
{
157-
return value != null ? Visibility.Visible : Visibility.Collapsed;
157+
return value != null || System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()) ? Visibility.Visible : Visibility.Collapsed;
158158
}
159159

160160
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
@@ -295,4 +295,29 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
295295
throw new NotImplementedException();
296296
}
297297
}
298+
299+
public class EnsureElementConverter : IValueConverter
300+
{
301+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
302+
{
303+
if (value is Element)
304+
return value;
305+
306+
var dm = value as Datamodel.Datamodel;
307+
if (dm != null)
308+
return new object[] { dm.Root };
309+
310+
var attr = value as Datamodel.Attribute;
311+
if (attr != null)
312+
return attr.Owner;
313+
314+
return DependencyProperty.UnsetValue;
315+
}
316+
317+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
318+
{
319+
throw new NotImplementedException();
320+
}
321+
}
322+
298323
}

DmxPad/DmxPad.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
3737
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
3838
</PropertyGroup>
39+
<PropertyGroup>
40+
<ApplicationIcon>Resources\dmx.ico</ApplicationIcon>
41+
</PropertyGroup>
3942
<ItemGroup>
4043
<Reference Include="System" />
4144
<Reference Include="System.Data" />
@@ -57,7 +60,14 @@
5760
<Generator>MSBuild:Compile</Generator>
5861
<SubType>Designer</SubType>
5962
</ApplicationDefinition>
63+
<Compile Include="Controls\LabelledControl.xaml.cs">
64+
<DependentUpon>LabelledControl.xaml</DependentUpon>
65+
</Compile>
6066
<Compile Include="Controls\TreeGrid.cs" />
67+
<Page Include="Controls\LabelledControl.xaml">
68+
<SubType>Designer</SubType>
69+
<Generator>MSBuild:Compile</Generator>
70+
</Page>
6171
<Page Include="DmxView.xaml">
6272
<SubType>Designer</SubType>
6373
<Generator>MSBuild:Compile</Generator>
@@ -130,6 +140,9 @@
130140
<Name>Datamodel.NET</Name>
131141
</ProjectReference>
132142
</ItemGroup>
143+
<ItemGroup>
144+
<Resource Include="Resources\dmx.ico" />
145+
</ItemGroup>
133146
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
134147
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
135148
Other similar extension points exist, see Microsoft.Common.targets.

DmxPad/DmxView.xaml

+63-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Grid>
66
<Grid.ColumnDefinitions>
77
<ColumnDefinition Width="*"/>
8-
<ColumnDefinition Name="ValueColumn" Width="{Binding SelectedItem, Converter={StaticResource ValueColumnWidthConverter}, ElementName=DmxTree, Mode=OneWay}"/>
8+
<ColumnDefinition Width="*"/>
99
</Grid.ColumnDefinitions>
1010
<Grid.RowDefinitions>
1111
<RowDefinition Height="Auto" />
@@ -18,13 +18,14 @@
1818
MouseDown="ResetRoot_Click" ToolTip="Return to the root element"/>
1919
</Grid>
2020

21-
<c:TreeGridView x:Name="DmxTree" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding}" ChildItemsSelector="{Binding Converter={StaticResource ChildPathConverter}}"
22-
UseLayoutRounding="True" d:DataContext="{Binding Path=AllElements}" TitleColumnHeader="Name">
21+
<c:TreeGridView x:Name="DmxTree" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Converter={StaticResource EnsureElementConverter}}" ChildItemsSelector="{Binding Converter={StaticResource ChildPathConverter}}"
22+
UseLayoutRounding="True" d:DataContext="{Binding Path=AllElements}" TitleColumnHeader="Name" Loaded="DmxTree_Loaded">
2323
<c:TreeGridView.ColumnDefinitions>
2424
<c:TreeGridContentColumnDefinition Header="Type" Binding="{Binding Converter={StaticResource GetFriendlyTypeName}}">
2525
<c:TreeGridContentColumnDefinition.CellStyle>
26-
<Style TargetType="c:TreeGridViewCell">
27-
<Setter Property="Foreground" Value="Gray"/>
26+
<Style TargetType="Control">
27+
<Setter Property="Control.Opacity" Value="0.5"/>
28+
<Setter Property="IsTabStop" Value="False"/>
2829
</Style>
2930
</c:TreeGridContentColumnDefinition.CellStyle>
3031
</c:TreeGridContentColumnDefinition>
@@ -35,7 +36,7 @@
3536
<ContentControl Content="{Binding}"/>
3637
</DataTemplate>
3738
</c:TreeGridView.TitleTemplate>
38-
39+
3940
<c:TreeGridView.Resources>
4041
<DataTemplate DataType="{x:Type dm:Attribute}">
4142
<StackPanel Orientation="Horizontal" Margin="0,0,5,0" VerticalAlignment="Center">
@@ -58,10 +59,63 @@
5859
</c:TreeGridView>
5960

6061
<GridSplitter Grid.Column="1" Grid.Row="1" Width="2" VerticalAlignment="Stretch" HorizontalAlignment="Left" ResizeDirection="Columns"/>
61-
62+
6263
<Grid Name="AttributeProperties" Grid.Column="1" Grid.Row="1" Margin="5,0" Background="{DynamicResource {x:Static SystemColors.WindowColor}}"
63-
d:DataContext="{Binding Path=Root[model]}" DataContext="{Binding ElementName=DmxTree, Path=SelectedItem}" Visibility="{Binding ElementName=ValueColumn,Path=Width,Converter={StaticResource ValuePanelVisibilityConverter}}">
64-
<ContentControl Content="{Binding Converter={StaticResource GetAttributeValue}}" ContentTemplateSelector="{StaticResource InspectPaneTemplateSelector}" />
64+
Visibility="{Binding ElementName=DmxTree, Path=SelectedItem, Converter={StaticResource VisibleIfNotNull},FallbackValue=Visible}"
65+
d:DataContext="{Binding Path=Root}" DataContext="{Binding ElementName=DmxTree, Path=SelectedItem}">
66+
<Grid.RowDefinitions>
67+
<RowDefinition Height="Auto" />
68+
<RowDefinition Height="*" />
69+
</Grid.RowDefinitions>
70+
<Grid.Resources>
71+
<Style TargetType="c:LabelledControl">
72+
<Setter Property="LabelWidth" Value="45"/>
73+
<Setter Property="Margin" Value="3,0"/>
74+
</Style>
75+
<Style TargetType="GroupBox">
76+
<Setter Property="Margin" Value="0,3"/>
77+
<Setter Property="Padding" Value="5"/>
78+
</Style>
79+
</Grid.Resources>
80+
<GroupBox Header="Element" DataContext="{Binding Converter={StaticResource EnsureElementConverter}}">
81+
<StackPanel>
82+
<c:LabelledControl LabelText="Name:">
83+
<TextBox Text="{Binding Path=Name}" />
84+
</c:LabelledControl>
85+
86+
<c:LabelledControl LabelText="Class:">
87+
<TextBox Text="{Binding Path=ClassName}" />
88+
</c:LabelledControl>
89+
90+
<c:LabelledControl LabelText="GUID:">
91+
<TextBox Text="{Binding Path=ID,Mode=OneWay}" IsReadOnly="True" BorderThickness="0" Background="Transparent" FontFamily="Consolas" />
92+
</c:LabelledControl>
93+
</StackPanel>
94+
</GroupBox>
95+
96+
<GroupBox Grid.Row="1" Header="Attribute">
97+
<Grid>
98+
<Grid.RowDefinitions>
99+
<RowDefinition Height="Auto"/>
100+
<RowDefinition Height="Auto"/>
101+
<RowDefinition Height="*"/>
102+
<RowDefinition Height="Auto"/>
103+
</Grid.RowDefinitions>
104+
<c:LabelledControl LabelText="Name:" Grid.Row="0">
105+
<TextBox Text="{Binding Path=Name}" />
106+
</c:LabelledControl>
107+
<c:LabelledControl LabelText="Type:" Grid.Row="1">
108+
<TextBlock Text="{Binding Converter={StaticResource GetFriendlyTypeName}}"/>
109+
<!--<ComboBox ItemsSource="{x:Static dm:Datamodel.AttributeTypes}" SelectedItem="{Binding Converter={StaticResource DebugConverter}}" ItemTemplate="{Binding Converter={StaticResource GetFriendlyTypeName}}"/>-->
110+
</c:LabelledControl>
111+
<c:LabelledControl LabelText="Value:" Grid.Row="2">
112+
<ContentPresenter Content="{Binding}" ContentTemplateSelector="{StaticResource InspectPaneTemplateSelector}"/>
113+
</c:LabelledControl>
114+
<StackPanel Orientation="Horizontal" Grid.Row="3">
115+
<Button Content="Delete" Click="DeleteButton_Click"/>
116+
</StackPanel>
117+
</Grid>
118+
</GroupBox>
65119
</Grid>
66120
</Grid>
67121
</UserControl>

0 commit comments

Comments
 (0)