Merge branch 'pre-commit'

This commit is contained in:
Michael Becker 2021-05-27 23:39:49 -04:00
commit fa562503a3
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C
7 changed files with 225 additions and 15 deletions

View File

@ -4,7 +4,7 @@
<!-- Associate the PropertyList ObjectModel with its DataFormats -->
<Association>
<Filters>
<Filter Title="Windows configuration document">
<Filter Title="Windows configuration document" HintComparison="FilterOnly">
<FileNameFilters>
<FileNameFilter>*.ini</FileNameFilter>
<FileNameFilter>*.inf</FileNameFilter>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<UniversalEditor Version="5.0">
<Editors>
<Editor ID="{452b75d6-6818-4cb8-a18d-f94485cb0b29}" TypeName="UniversalEditor.Editors.PropertyList.PropertyListEditor" Title="Property List Editor">
<Contexts>
<Context ID="{694c583d-d96a-438e-a138-db1d636d9e93}" Name="Tree View - Property List Editor" />
</Contexts>
<CommandBindings>
<!-- set up the default command bindings for this editor context -->
</CommandBindings>
<Commands>
<Command ID="PropertyListContextMenu_New_Property" Title="_Property" />
<Command ID="PropertyListContextMenu_New_Group" Title="_Group" />
<Command ID="PropertyListContextMenu_New" Title="_New">
<Items>
<CommandReference CommandID="PropertyListContextMenu_New_Property" />
<CommandReference CommandID="PropertyListContextMenu_New_Group" />
</Items>
</Command>
<Command ID="PropertyListContextMenu">
<Items>
<CommandReference CommandID="PropertyListContextMenu_New" />
<Separator />
<CommandReference CommandID="EditCut" />
<CommandReference CommandID="EditCopy" />
<CommandReference CommandID="EditPaste" />
<CommandReference CommandID="EditDelete" />
<Separator />
<CommandReference CommandID="FileProperties" />
</Items>
</Command>
</Commands>
</Editor>
</Editors>
</UniversalEditor>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkTreeStore" id="tm">
@ -8,17 +8,16 @@
<column type="gchararray"/>
<!-- column-name colValue -->
<column type="gchararray"/>
<!-- column-name colIcon -->
<column type="GdkPixbuf"/>
</columns>
</object>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<property name="can-focus">False</property>
<child>
<object class="GtkTreeView" id="tv">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can-focus">True</property>
<property name="model">tm</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
@ -29,9 +28,17 @@
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">0</property>
<property name="sort-column-id">0</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererPixbuf"/>
<attributes>
<attribute name="pixbuf">2</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText">
<property name="editable">True</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
@ -44,9 +51,11 @@
<property name="title" translatable="yes">Value</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">1</property>
<property name="sort-column-id">1</property>
<child>
<object class="GtkCellRendererText"/>
<object class="GtkCellRendererText">
<property name="editable">True</property>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>

View File

@ -318,6 +318,7 @@
<Content Include="Editors\Blockchain\BlockchainEditor.glade" />
<Content Include="Panels\PropertyList\PropertyListPanel.glade" />
<Content Include="Editors\Database\ContextMenu_Columns.uexml" />
<Content Include="Editors\PropertyList\Commands.uexml" />
</ItemGroup>
<ItemGroup>
<Content Include="Configuration\Application.upl" />

View File

@ -52,6 +52,13 @@ namespace UniversalEditor.IO
string charBuffer = null;
int charBufferIndex = 0;
public char[] ReadChars(int count)
{
char[] value = new char[count];
for (int i = 0; i < count; i++)
value[i] = ReadChar();
return value;
}
public char ReadChar(Encoding encoding = null)
{
if (encoding == null)
@ -1747,7 +1754,7 @@ namespace UniversalEditor.IO
public string ReadLine()
{
string line = ReadUntil(GetNewLineSequence());
ReadBytes(GetNewLineSequence().Length);
ReadChars(GetNewLineSequence().Length);
if (line.EndsWith("\r"))
line = line.Substring(0, line.Length - 1);
return line;

View File

@ -69,6 +69,33 @@ namespace UniversalEditor.DataFormats.PropertyList
Reader tr = base.Accessor.Reader;
Group CurrentGroup = null;
if (!tr.EndOfStream)
{
long pos = tr.Accessor.Position;
// determine BOM
string line = tr.ReadLine();
if (line.StartsWith("\xff\xfe"))
{
tr.Endianness = Endianness.LittleEndian;
tr.Accessor.DefaultEncoding = Encoding.UTF16LittleEndian;
pos += 2;
}
else if (line.StartsWith("\xfe\xff"))
{
tr.Endianness = Endianness.BigEndian;
tr.Accessor.DefaultEncoding = Encoding.UTF16BigEndian;
pos += 2;
}
else if (line.StartsWith("\xef\xbb\xbf"))
{
tr.Accessor.DefaultEncoding = Encoding.UTF8;
pos += 3;
}
tr.Accessor.Position = pos;
}
while (!tr.EndOfStream)
{
string line = tr.ReadLine();

View File

@ -22,9 +22,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MBS.Framework;
using MBS.Framework.UserInterface;
using MBS.Framework.UserInterface.Controls.ListView;
using MBS.Framework.UserInterface.Drawing;
using UniversalEditor.ObjectModels.PropertyList;
using UniversalEditor.UserInterface;
@ -42,6 +43,7 @@ namespace UniversalEditor.Editors.PropertyList
if (_er == null)
{
_er = base.MakeReference();
_er.ID = new Guid("{452b75d6-6818-4cb8-a18d-f94485cb0b29}");
_er.SupportedObjectModels.Add(typeof(PropertyListObjectModel));
}
return _er;
@ -59,9 +61,134 @@ namespace UniversalEditor.Editors.PropertyList
protected override void OnCreated(EventArgs e)
{
base.OnCreated(e);
Context.AttachCommandEventHandler("PropertyListContextMenu_New_Property", PropertyListContextMenu_New_Property);
Context.AttachCommandEventHandler("PropertyListContextMenu_New_Group", PropertyListContextMenu_New_Group);
OnObjectModelChanged(EventArgs.Empty);
}
[EventHandler(nameof(tv), nameof(Control.BeforeContextMenu))]
private void tv_BeforeContextMenu(object sender, EventArgs e)
{
tv.ContextMenuCommandID = "PropertyListContextMenu";
}
[EventHandler(nameof(tv), nameof(ListViewControl.CellEdited))]
private void tv_CellEdited(object sender, CellEditedEventArgs e)
{
Group group = e.Row.GetExtraData<Group>("group");
Property property = e.Row.GetExtraData<Property>("property");
if (e.Column == tv.Model.Columns[0])
{
// changing the Name
if (group != null)
{
group.Name = e.NewValue?.ToString();
}
else if (property != null)
{
property.Name = e.NewValue?.ToString();
}
}
else if (e.Column == tv.Model.Columns[1])
{
// changing the Value
if (group != null)
{
}
else if (property != null)
{
property.Value = e.NewValue;
}
}
}
private int GetNextIndex<T>(IPropertyListContainer parent = null) where T : PropertyListItem
{
if (parent == null)
parent = (ObjectModel as PropertyListObjectModel);
int lastIndex = 0;
for (int i = 0; i < parent.Items.Count; i++)
{
if (parent.Items[i] is T)
{
string newName = String.Format("New {0} ", typeof(T).Name);
if (parent.Items[i].Name.StartsWith(newName, StringComparison.CurrentCulture))
{
if (Int32.TryParse(parent.Items[i].Name.Substring(newName.Length), out int thisIndex))
{
if (thisIndex > lastIndex)
lastIndex = thisIndex;
}
}
}
}
return lastIndex + 1;
}
private void PropertyListContextMenu_New_Property(object sender, EventArgs e)
{
Property p = new Property();
TreeModelRow rowParent = null;
IPropertyListContainer parent = ObjectModel as PropertyListObjectModel;
if (tv.SelectedRows.Count == 1)
{
rowParent = tv.SelectedRows[0];
parent = rowParent.GetExtraData<Group>("group");
}
p.Name = String.Format("New Property {0}", GetNextIndex<Property>());
parent.Items.Add(p);
RecursiveAddProperty(p, rowParent);
}
private void PropertyListContextMenu_New_Group(object sender, EventArgs e)
{
Group p = new Group();
TreeModelRow rowParent = null;
IPropertyListContainer parent = ObjectModel as PropertyListObjectModel;
if (tv.SelectedRows.Count == 1)
{
rowParent = tv.SelectedRows[0];
parent = rowParent.GetExtraData<Group>("group");
}
p.Name = String.Format("New Group {0}", GetNextIndex<Group>());
parent.Items.Add(p);
RecursiveAddGroup(p, rowParent);
}
[EventHandler(nameof(tv), nameof(ListViewControl.SelectionChanged))]
private void tv_SelectionChanged(object sender, EventArgs e)
{
if (tv.SelectedRows.Count > 0)
{
Application.Instance.Commands["EditCut"].Enabled = true;
Application.Instance.Commands["EditCopy"].Enabled = true;
Application.Instance.Commands["EditDelete"].Enabled = true;
if (tv.SelectedRows[0].GetExtraData<Group>("group") != null)
{
tv.Columns[1].Renderers[0].Editable = false;
}
else
{
tv.Columns[1].Renderers[0].Editable = true;
}
}
else
{
Application.Instance.Commands["EditCut"].Enabled = false;
Application.Instance.Commands["EditCopy"].Enabled = false;
Application.Instance.Commands["EditDelete"].Enabled = false;
}
}
protected override void OnObjectModelChanged(EventArgs e)
{
base.OnObjectModelChanged(e);
@ -87,7 +214,8 @@ namespace UniversalEditor.Editors.PropertyList
TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tm.Columns[0], p.Name),
new TreeModelRowColumn(tm.Columns[1], p.Value)
new TreeModelRowColumn(tm.Columns[1], p.Value),
new TreeModelRowColumn(tm.Columns[2], Image.FromStock(StockType.File, 16))
});
if (parent == null)
@ -104,7 +232,8 @@ namespace UniversalEditor.Editors.PropertyList
{
TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tm.Columns[0], g.Name)
new TreeModelRowColumn(tm.Columns[0], g.Name),
new TreeModelRowColumn(tm.Columns[2], Image.FromStock(StockType.Folder, 16))
});
if (parent == null)