Skip to content

Commit 7258ed6

Browse files
committed
Add support for const data items. These are non-editable fields that are added to the data.
1 parent a8a8006 commit 7258ed6

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using StructuredXmlEditor.Definition;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace StructuredXmlEditor.Data
9+
{
10+
public class ConstDataItem : DataItem
11+
{
12+
public ConstDataItem(DataDefinition definition, UndoRedoManager undoRedo) : base(definition, undoRedo)
13+
{
14+
}
15+
16+
public override bool IsVisible
17+
{
18+
get
19+
{
20+
return false;
21+
}
22+
set { }
23+
}
24+
25+
public override string Description => null;
26+
27+
public override void Copy()
28+
{
29+
30+
}
31+
32+
public override void Paste()
33+
{
34+
35+
}
36+
37+
public override void ResetToDefault()
38+
{
39+
40+
}
41+
}
42+
}

StructuredXmlEditor/Data/Item/DataItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public bool IsFilterMatched
142142
}
143143

144144
//-----------------------------------------------------------------------
145-
public bool IsVisible
145+
public virtual bool IsVisible
146146
{
147147
get { return m_isVisible && !m_isSearchFiltered && !IsMultieditFiltered && IsVisibleFromBindings; }
148148
set
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Xml.Linq;
7+
using StructuredXmlEditor.Data;
8+
9+
namespace StructuredXmlEditor.Definition
10+
{
11+
public class ConstDefinition : DataDefinition
12+
{
13+
private String Value { get; set; }
14+
15+
public override DataItem CreateData(UndoRedoManager undoRedo)
16+
{
17+
return new ConstDataItem(this, undoRedo);
18+
}
19+
20+
public override void DoSaveData(XElement parent, DataItem item)
21+
{
22+
var el = new XElement(Name, Value);
23+
parent.Add(el);
24+
}
25+
26+
public override bool IsDefault(DataItem item)
27+
{
28+
return true;
29+
}
30+
31+
public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
32+
{
33+
return new ConstDataItem(this, undoRedo);
34+
}
35+
36+
public override void Parse(XElement definition)
37+
{
38+
Name = definition.Attribute("Name").Value;
39+
Value = definition.Value;
40+
}
41+
}
42+
}

StructuredXmlEditor/Definition/DataDefinition.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public void SaveData(XElement parent, DataItem item, bool isRoot = false)
6767

6868
public static DataDefinition LoadDefinition(XElement element, string forceLoadAs = null)
6969
{
70+
if (element.Name.ToString() == "Const")
71+
{
72+
var constDef = new ConstDefinition();
73+
constDef.Parse(element);
74+
return constDef;
75+
}
76+
7077
var name = element.Attribute(MetaNS + "RefKey")?.Value.ToString().ToUpper();
7178
if (name == null) name = element.Attribute("RefKey")?.Value.ToString().ToUpper();
7279
if (name == null) name = element.Name.ToString().ToUpper();

StructuredXmlEditor/StructuredXmlEditor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Compile Include="Data\Item\ColourItem.cs" />
101101
<Compile Include="Data\Item\CommentItem.cs" />
102102
<Compile Include="Data\Item\ComplexDataItem.cs" />
103+
<Compile Include="Data\Item\ConstDataItem.cs" />
103104
<Compile Include="Data\Item\DataItem.cs" />
104105
<Compile Include="Data\Item\DummyItem.cs" />
105106
<Compile Include="Data\Item\EnumItem.cs" />
@@ -122,6 +123,7 @@
122123
<Compile Include="Data\Item\TreeItem.cs" />
123124
<Compile Include="Data\Item\VectorItem.cs" />
124125
<Compile Include="Definition\CommentDefinition.cs" />
126+
<Compile Include="Definition\ConstDefinition.cs" />
125127
<Compile Include="Definition\FlagsDefinition.cs" />
126128
<Compile Include="Definition\GraphCollectionDefinition.cs" />
127129
<Compile Include="Definition\GraphNodeDefinition.cs" />

0 commit comments

Comments
 (0)