From ee7bffe7a98abb729487acffc60e1a37d249182b Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 27 May 2021 23:02:39 -0400 Subject: [PATCH 1/4] you dum dum, a char isn't always one byte in length --- Libraries/UniversalEditor.Core/IO/Reader.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/UniversalEditor.Core/IO/Reader.cs b/Libraries/UniversalEditor.Core/IO/Reader.cs index b1bd3aab..0cfb6ac1 100644 --- a/Libraries/UniversalEditor.Core/IO/Reader.cs +++ b/Libraries/UniversalEditor.Core/IO/Reader.cs @@ -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; From e19f1a84b2f57913e0ffd19cc90df27fe6ea05a3 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 27 May 2021 23:03:11 -0400 Subject: [PATCH 2/4] add HintComparison so we accurately detect INI/INF files --- .../Associations/PropertyList.uexml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Associations/PropertyList.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Associations/PropertyList.uexml index d4636ed3..85435c3b 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Associations/PropertyList.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Associations/PropertyList.uexml @@ -4,7 +4,7 @@ - + *.ini *.inf From 9825a5ad7a0244cce5e3b8473826943bba9253e3 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 27 May 2021 23:04:06 -0400 Subject: [PATCH 3/4] properly detect Unicode(UTF-16BE/LE) and UTF-8 BOM (this should be done in PlainTextDataFormat...) --- .../WindowsConfigurationDataFormat.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Libraries/UniversalEditor.Essential/DataFormats/PropertyList/WindowsConfigurationDataFormat.cs b/Libraries/UniversalEditor.Essential/DataFormats/PropertyList/WindowsConfigurationDataFormat.cs index be435c0d..b348d6fb 100644 --- a/Libraries/UniversalEditor.Essential/DataFormats/PropertyList/WindowsConfigurationDataFormat.cs +++ b/Libraries/UniversalEditor.Essential/DataFormats/PropertyList/WindowsConfigurationDataFormat.cs @@ -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(); From 5cfa5dc96890d9e90f8060c7e913989bd701df87 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 27 May 2021 23:37:32 -0400 Subject: [PATCH 4/4] implement adding new Groups and Properties, as well as feature enhancements to PropertyListEditor --- .../Editors/PropertyList/Commands.uexml | 37 +++++ .../PropertyList/PropertyListEditor.glade | 29 ++-- ...lEditor.Content.PlatformIndependent.csproj | 1 + .../PropertyList/PropertyListEditor.cs | 135 +++++++++++++++++- 4 files changed, 189 insertions(+), 13 deletions(-) create mode 100644 Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/Commands.uexml diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/Commands.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/Commands.uexml new file mode 100644 index 00000000..a29b791f --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/Commands.uexml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/PropertyListEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/PropertyListEditor.glade index ee10ea38..f3ef9c8e 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/PropertyListEditor.glade +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/PropertyList/PropertyListEditor.glade @@ -1,5 +1,5 @@ - + @@ -8,17 +8,16 @@ + + - False - - - + False True - True + True tm @@ -29,9 +28,17 @@ Name True True - 0 + 0 - + + + 2 + + + + + True + 0 @@ -44,9 +51,11 @@ Value True True - 1 + 1 - + + True + 1 diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 57cdae3a..987fd972 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -318,6 +318,7 @@ + diff --git a/Libraries/UniversalEditor.UserInterface/Editors/PropertyList/PropertyListEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/PropertyList/PropertyListEditor.cs index 838ffdee..50d5dd39 100644 --- a/Libraries/UniversalEditor.UserInterface/Editors/PropertyList/PropertyListEditor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editors/PropertyList/PropertyListEditor.cs @@ -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"); + Property property = e.Row.GetExtraData("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(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"); + } + + p.Name = String.Format("New Property {0}", GetNextIndex()); + 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"); + } + + p.Name = String.Format("New Group {0}", GetNextIndex()); + 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") != 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)