From 1eed5e83c2e60e377523d5dc1a4a9280c204079b Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 18 Jun 2020 10:17:52 -0400 Subject: [PATCH] implement rudimentary editor for Markup ObjectModel --- .../Editors/Markup/MarkupEditor.glade | 308 ++++++++++++++++++ ...lEditor.Content.PlatformIndependent.csproj | 1 + .../Editors/Markup/MarkupEditor.cs | 211 ++++++++++++ .../UniversalEditor.UserInterface.csproj | 2 + 4 files changed, 522 insertions(+) create mode 100644 Content/UniversalEditor.Content.PlatformIndependent/Editors/Markup/MarkupEditor.glade create mode 100644 Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Markup/MarkupEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Markup/MarkupEditor.glade new file mode 100644 index 00000000..85ce9d8d --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Markup/MarkupEditor.glade @@ -0,0 +1,308 @@ + + + + + + + + + + + + + + False + + + + + + True + False + vertical + + + True + True + vertical + True + True + + + True + False + vertical + + + True + False + + + True + True + True + + + 1 + 0 + + + + + True + False + 8 + 8 + 8 + 8 + _Name + True + + + 0 + 0 + + + + + False + True + 0 + + + + + True + False + 8 + 8 + 8 + 8 + 0 + none + + + True + False + 12 + + + True + False + vertical + + + True + False + + + True + False + Add Attribute + __glade_unnamed_20 + True + gtk-add + + + False + True + + + + + True + False + Edit Attribute + __glade_unnamed_20 + True + gtk-edit + + + False + True + + + + + True + False + Remove Attribute + __glade_unnamed_20 + True + gtk-remove + + + False + True + + + + + False + True + 0 + + + + + True + True + in + + + True + True + tm + 0 + + + + + + True + Name + True + True + 0 + + + + 0 + + + + + + + True + Value + True + True + 1 + + + + 1 + + + + + + + + + True + True + 1 + + + + + + + + + True + False + 8 + 8 + 8 + 8 + Attributes + + + + + True + True + 1 + + + + + False + True + + + + + True + False + vertical + + + True + False + 8 + 8 + 8 + 8 + 0 + none + + + True + False + 12 + + + True + False + vertical + + + True + True + in + + + True + True + + + + + True + True + 0 + + + + + + + + + True + False + 8 + 8 + 8 + 8 + Value + + + + + True + True + 0 + + + + + True + True + + + + + True + True + 0 + + + + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 4bc2260c..8315fae1 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -743,6 +743,7 @@ + diff --git a/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs b/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs new file mode 100644 index 00000000..aaa3343b --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/Editors/Markup/MarkupEditor.cs @@ -0,0 +1,211 @@ +// +// MarkupEditor.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Text; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; + +using UniversalEditor.ObjectModels.Markup; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Editors.Markup +{ + [ContainerLayout("~/Editors/Markup/MarkupEditor.glade")] + public class MarkupEditor : Editor + { + private ListView tv; + private DefaultTreeModel tm; + private TextBox txtValue; + private SplitContainer scAttributesValue; + + private static EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = base.MakeReference(); + _er.SupportedObjectModels.Add(typeof(MarkupObjectModel)); + } + return _er; + } + + public override void UpdateSelections() + { + } + + protected override EditorSelection CreateSelectionInternal(object content) + { + return null; + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + OnObjectModelChanged(e); + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + if (!IsCreated) return; + + tm.Rows.Clear(); + + MarkupObjectModel mom = (ObjectModel as MarkupObjectModel); + if (mom == null) return; + + for (int i = 0; i < mom.Elements.Count; i++) + { + RecursiveLoadDocumentExplorer(mom.Elements[i], null); + } + } + + private const int MAX_PREVIEW_LENGTH = 24; + + private void RecursiveLoadDocumentExplorer(MarkupElement el, EditorDocumentExplorerNode parent) + { + string title = el.Name; + if (el is MarkupPreprocessorElement) + { + title = String.Format("", el.Name, el.Value); + } + else if (el is MarkupCommentElement) + { + title = String.Format("", el.Value.Substring(0, Math.Min(el.Value.Length, MAX_PREVIEW_LENGTH)), (el.Value.Length > MAX_PREVIEW_LENGTH ? "..." : String.Empty)); + } + else if (el is MarkupTagElement) + { + MarkupTagElement tag = (el as MarkupTagElement); + StringBuilder sb = new StringBuilder(); + sb.Append('<'); + sb.Append(el.Name); + if (tag.Attributes.Count > 0) + { + sb.Append(' '); + for (int i = 0; i < tag.Attributes.Count; i++) + { + sb.Append(tag.Attributes[i].Name); + sb.Append('='); + sb.Append('"'); + sb.Append(tag.Attributes[i].Value); + sb.Append('"'); + if (i < tag.Attributes.Count - 1) + { + sb.Append(' '); + } + } + } + + if (String.IsNullOrEmpty(el.Value)) + { + sb.Append(" />"); + } + else + { + sb.Append(">...'); + } + title = sb.ToString(); + } + + EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(title); + node.SetExtraData("el", el); + + if (el is MarkupContainerElement) + { + MarkupContainerElement ct = (el as MarkupContainerElement); + for (int i = 0; i < ct.Elements.Count; i++) + { + RecursiveLoadDocumentExplorer(ct.Elements[i], node); + } + } + + if (parent == null) + { + DocumentExplorer.Nodes.Add(node); + } + else + { + parent.Nodes.Add(node); + } + } + + protected internal override void OnDocumentExplorerSelectionChanged(EditorDocumentExplorerSelectionChangedEventArgs e) + { + base.OnDocumentExplorerSelectionChanged(e); + + tm.Rows.Clear(); + if (e.Node != null) + { + MarkupElement el = e.Node.GetExtraData("el"); + if (el is MarkupTagElement) + { + MarkupTagElement tag = (el as MarkupTagElement); + for (int i = 0; i < tag.Attributes.Count; i++) + { + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(tm.Columns[0], tag.Attributes[i].Name), + new TreeModelRowColumn(tm.Columns[1], tag.Attributes[i].Value) + }); + row.SetExtraData("att", tag.Attributes[i]); + tm.Rows.Add(row); + } + scAttributesValue.Panel1.Expanded = true; + } + else + { + scAttributesValue.Panel1.Expanded = false; + } + txtValue.Text = el.Value; + } + } + + private void RecursiveLoadElement(MarkupElement el, TreeModelRow parent) + { + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(tm.Columns[0], el.Name), + new TreeModelRowColumn(tm.Columns[1], el.Value) + }); + + if (el is MarkupContainerElement) + { + MarkupContainerElement ct = (el as MarkupContainerElement); + for (int i = 0; i < ct.Elements.Count; i++) + { + RecursiveLoadElement(ct.Elements[i], row); + } + } + + if (parent == null) + { + tm.Rows.Add(row); + } + else + { + parent.Rows.Add(row); + } + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index b45553ae..ebd7c8ea 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -131,6 +131,7 @@ + @@ -185,6 +186,7 @@ +