Move Inspector into utilities

This commit is contained in:
John Lewin 2017-09-19 08:56:48 -07:00
parent 0aebbbe841
commit 80dd7a379b
4 changed files with 3 additions and 3 deletions

105
Utilities/InspectForm.Designer.cs generated Normal file
View file

@ -0,0 +1,105 @@
namespace MatterHackers.MatterControl
{
partial class InspectForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.treeView1 = new System.Windows.Forms.TreeView();
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.treeView1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.propertyGrid1);
this.splitContainer1.Size = new System.Drawing.Size(951, 632);
this.splitContainer1.SplitterDistance = 590;
this.splitContainer1.SplitterWidth = 3;
this.splitContainer1.TabIndex = 0;
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.FullRowSelect = true;
this.treeView1.HideSelection = false;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(590, 632);
this.treeView1.TabIndex = 0;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// propertyGrid1
//
this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid1.LineColor = System.Drawing.SystemColors.ControlDark;
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(358, 632);
this.propertyGrid1.TabIndex = 0;
this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged);
//
// InspectForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(951, 632);
this.Controls.Add(this.splitContainer1);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "InspectForm";
this.Text = "InspectForm";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.PropertyGrid propertyGrid1;
}
}

203
Utilities/InspectForm.cs Normal file
View file

@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl
{
public partial class InspectForm : Form
{
private TreeNode activeTreeNode;
private GuiWidget inspectedSystemWindow;
private Vector2 mousePosition;
private Dictionary<GuiWidget, TreeNode> treeNodes = new Dictionary<GuiWidget, TreeNode>();
public InspectForm(GuiWidget inspectionSource)
{
InitializeComponent();
// Store position on move, invalidate in needed
inspectionSource.MouseMove += (s, e) =>
{
mousePosition = e.Position;
if (this.InspectedWidget?.FirstWidgetUnderMouse == false)
{
this.inspectedSystemWindow.Invalidate();
}
};
inspectionSource.AfterDraw += (s, e) =>
{
if (this.Inspecting && !inspectionSource.HasBeenClosed)
{
var namedChildren = new List<GuiWidget.WidgetAndPosition>();
inspectedSystemWindow.FindNamedChildrenRecursive(
"",
namedChildren,
new RectangleDouble(mousePosition.x, mousePosition.y, mousePosition.x + 1, mousePosition.y + 1),
GuiWidget.SearchType.Partial,
allowDisabledOrHidden: false);
// If the context changed, update the UI
if (namedChildren.LastOrDefault()?.widget is GuiWidget firstUnderMouse
&& firstUnderMouse != this.InspectedWidget)
{
RebuildUI(namedChildren);
this.InspectedWidget = firstUnderMouse;
}
}
};
this.inspectedSystemWindow = inspectionSource;
inspectionSource.Invalidate();
}
public bool Inspecting { get; set; }
private GuiWidget _inspectedWidget;
private GuiWidget InspectedWidget
{
get => _inspectedWidget;
set
{
if (_inspectedWidget != null)
{
_inspectedWidget.DebugShowBounds = false;
_inspectedWidget.MouseUp -= InspectedWidget_MouseUp;
_inspectedWidget.MouseDown -= InspectedWidget_MouseUp;
}
_inspectedWidget = value;
if (_inspectedWidget != null)
{
propertyGrid1.SelectedObject = _inspectedWidget;
_inspectedWidget.DebugShowBounds = true;
// Hook to stop listing on click
_inspectedWidget.MouseUp += InspectedWidget_MouseUp;
_inspectedWidget.MouseDown += InspectedWidget_MouseUp;
}
if (activeTreeNode != null)
{
activeTreeNode.Checked = false;
}
if (treeNodes.TryGetValue(_inspectedWidget, out TreeNode treeNode))
{
treeView1.SelectedNode = treeNode;
activeTreeNode = treeNode;
activeTreeNode.Checked = true;
}
_inspectedWidget.Invalidate();
}
}
private void InspectedWidget_MouseUp(object sender, Agg.UI.MouseEventArgs e)
{
// Stop listing on click
this.Inspecting = false;
}
private void AddItem(GuiWidget widget, string text, TreeNode childNode = null)
{
if (treeNodes.TryGetValue(widget, out TreeNode existingNode))
{
existingNode.Nodes.Add(childNode);
existingNode.Expand();
}
else
{
var node = new TreeNode(text)
{
Tag = widget
};
if (childNode != null)
{
node.Nodes.Add(childNode);
node.Expand();
}
treeNodes.Add(widget, node);
var parent = widget.Parent;
if (parent == null)
{
treeView1.Nodes.Add(node);
}
else
{
AddItem(parent, parent.Text, node);
}
}
}
public void RebuildUI(List<GuiWidget.WidgetAndPosition> namedChildren)
{
treeView1.Nodes.Clear();
treeNodes.Clear();
treeView1.SuspendLayout();
for (int i = 0; i < namedChildren.Count; i++)
{
var child = namedChildren[i];
AddItem(child.widget, BuildName(child.widget));
}
treeView1.ResumeLayout();
}
private string BuildName(GuiWidget widget)
{
string nameToWrite = _inspectedWidget == widget ? "* " : "";
if (!string.IsNullOrEmpty(widget.Name))
{
nameToWrite += $"{widget.GetType().Name} --- {widget.Name}";
}
else
{
nameToWrite += $"{widget.GetType().Name}";
}
return nameToWrite;
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
this.InspectedWidget = e.Node.Tag as GuiWidget;
}
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
this.InspectedWidget.Invalidate();
}
public void MoveUpTree()
{
if (activeTreeNode?.Parent is TreeNode parent)
{
this.InspectedWidget = parent.Tag as GuiWidget;
}
}
public void MoveDownTree()
{
if (activeTreeNode?.Nodes.Cast<TreeNode>().FirstOrDefault() is TreeNode firstChild)
{
this.InspectedWidget = firstChild.Tag as GuiWidget;
}
}
}
}

120
Utilities/InspectForm.resx Normal file
View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>