implement rudimentary editor for Markup ObjectModel

This commit is contained in:
Michael Becker 2020-06-18 10:17:52 -04:00
parent 6da14c1c67
commit 1eed5e83c2
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
4 changed files with 522 additions and 0 deletions

View File

@ -0,0 +1,308 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkTreeStore" id="tm">
<columns>
<!-- column-name colName -->
<column type="gchararray"/>
<!-- column-name colValue -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow">
<property name="can_focus">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkPaned" id="scAttributesValue">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="orientation">vertical</property>
<property name="position_set">True</property>
<property name="wide_handle">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="txtName">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lblName">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="label" translatable="yes">_Name</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="fraAttributes">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkToolButton" id="tsbAttributeAdd">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Add Attribute</property>
<property name="label" translatable="yes">__glade_unnamed_20</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-add</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="tsbAttributeEdit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Edit Attribute</property>
<property name="label" translatable="yes">__glade_unnamed_20</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-edit</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="tsbAttributeRemove">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Remove Attribute</property>
<property name="label" translatable="yes">__glade_unnamed_20</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-remove</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="tv">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">tm</property>
<property name="search_column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcName">
<property name="resizable">True</property>
<property name="title" translatable="yes">Name</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">0</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tvcValue">
<property name="resizable">True</property>
<property name="title" translatable="yes">Value</property>
<property name="clickable">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">1</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="label" translatable="yes">Attributes</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="txtValue">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="margin_right">8</property>
<property name="margin_top">8</property>
<property name="margin_bottom">8</property>
<property name="label" translatable="yes">Value</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -743,6 +743,7 @@
<Content Include="Editors\NewWorldComputing\Map\MapEditor.glade" />
<Content Include="Editors\Multimedia\PictureCollection\PictureCollectionEditor.glade" />
<Content Include="Editors\Multimedia\PictureCollection\Dialogs\AnimationPropertiesDialog.glade" />
<Content Include="Editors\Markup\MarkupEditor.glade" />
<Content Include="Extensions\GraphicDesigner\Associations\Picture\TIFF.uexml" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,211 @@
//
// MarkupEditor.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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("<?{0} {1}?>", el.Name, el.Value);
}
else if (el is MarkupCommentElement)
{
title = String.Format("<!-- {0}{1} -->", 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(">...</");
sb.Append(el.Name);
sb.Append('>');
}
title = sb.ToString();
}
EditorDocumentExplorerNode node = new EditorDocumentExplorerNode(title);
node.SetExtraData<MarkupElement>("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<MarkupElement>("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<MarkupAttribute>("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);
}
}
}
}

View File

@ -131,6 +131,7 @@
<Compile Include="EditorDocumentExplorer.cs" />
<Compile Include="EditorDocumentExplorerNode.cs" />
<Compile Include="EditorDocumentExplorerSelectionChangedEvent.cs" />
<Compile Include="Editors\Markup\MarkupEditor.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@ -185,6 +186,7 @@
<Folder Include="Editors\Database\" />
<Folder Include="Editors\RIFF\" />
<Folder Include="Editors\RIFF\Dialogs\" />
<Folder Include="Editors\Markup\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.