Build FilteredPropertyGrid into mRemoteNG

No longer load the dll.
Makes the small amount of source more maintainable then from the code
project.
Gets rebuilt with latest build env.
This commit is contained in:
Sean Kaim
2016-06-03 22:13:12 -04:00
parent 17f986ea26
commit 8cbf56f7a5
7 changed files with 324 additions and 19 deletions

View File

@@ -34,22 +34,22 @@ Copyright
MIT License
http://www.codeproject.com/KB/recipes/command_line.aspx
DotNetVer
Copyright <20> 2010 David Grinberg
Copyright <20> 2010-2011 Brandon Hansen
http://nsis.sourceforge.net/DotNetVer
FilteredPropertyGrid
Copyright <20> 2006 Azuria
http://www.codeproject.com/KB/cs/FilteredPropertyGrid.aspx
Hotkey Selection Control for .NET
Copyright <20> 2006 Thomas Backman
http://www.codeproject.com/Articles/15085/A-simple-hotkey-selection-control-for-NET
InputBox
Copyright <20> 2016 Jan Slama
http://www.csharp-examples.net/inputbox/
IP TextBox
Copyright <20> 2005 mawnkay
http://www.codeproject.com/Articles/11576/IP-TextBox
InputBox
Copyright <20> 2016 Jan Slama
http://www.csharp-examples.net/inputbox/
Included Components
===================
@@ -64,14 +64,10 @@ Copyright
Modified New BSD License
http://www.mentalis.org/
DockPanel Suite 2.3.1
Copyright <20> 2007 Weifen Luo
DockPanel Suite 2.10.0.beta2
Copyright <20> 2015 @roken and @lextm (formerly Weifen Luo)
MIT License
http://sourceforge.net/projects/dockpanelsuite/
FilteredPropertyGrid 1.0.0.0
Copyright <20> 2006 Azuria
http://www.codeproject.com/KB/cs/FilteredPropertyGrid.aspx
https://github.com/dockpanelsuite/dockpanelsuite
GeckoFX 1.8.1.4
Copyright <20> 2008 Skybound Software

View File

@@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using mRemoteNG.App;
namespace mRemoteNG.UI.Controls.FilteredPropertyGrid
{
/// <summary>
/// This class overrides the standard PropertyGrid provided by Microsoft.
/// It also allows to hide (or filter) the properties of the SelectedObject displayed by the PropertyGrid.
/// </summary>
public partial class FilteredPropertyGrid : PropertyGrid
{
/// <summary>Contain a reference to the collection of properties to show in the parent PropertyGrid.</summary>
/// <remarks>By default, m_PropertyDescriptors contain all the properties of the object. </remarks>
List<PropertyDescriptor> m_PropertyDescriptors = new List<PropertyDescriptor>();
/// <summary>Contain a reference to the array of properties to display in the PropertyGrid.</summary>
private AttributeCollection m_HiddenAttributes = null, m_BrowsableAttributes = null;
/// <summary>Contain references to the arrays of properties or categories to hide.</summary>
private string[] m_BrowsableProperties = null, m_HiddenProperties = null;
/// <summary>Contain a reference to the wrapper that contains the object to be displayed into the PropertyGrid.</summary>
private ObjectWrapper m_Wrapper = null;
/// <summary>Public constructor.</summary>
public FilteredPropertyGrid() {
InitializeComponent();
base.SelectedObject = m_Wrapper;
}
public new AttributeCollection BrowsableAttributes {
get { return m_BrowsableAttributes; }
set {
if(m_BrowsableAttributes != value) {
m_HiddenAttributes = null;
m_BrowsableAttributes = value;
RefreshProperties();
}
}
}
/// <summary>Get or set the categories to hide.</summary>
public AttributeCollection HiddenAttributes {
get { return m_HiddenAttributes; }
set {
if(value != m_HiddenAttributes) {
m_HiddenAttributes = value;
m_BrowsableAttributes = null;
RefreshProperties();
}
}
}
/// <summary>Get or set the properties to show.</summary>
/// <exception cref="ArgumentException">if one or several properties don't exist.</exception>
public string[] BrowsableProperties {
get { return m_BrowsableProperties; }
set {
if(value != m_BrowsableProperties) {
m_BrowsableProperties = value;
//m_HiddenProperties = null;
RefreshProperties();
}
}
}
/// <summary>Get or set the properties to hide.</summary>
public string[] HiddenProperties {
get { return m_HiddenProperties; }
set {
if(value != m_HiddenProperties) {
//m_BrowsableProperties = null;
m_HiddenProperties = value;
RefreshProperties();
}
}
}
/// <summary>Overwrite the PropertyGrid.SelectedObject property.</summary>
/// <remarks>The object passed to the base PropertyGrid is the wrapper.</remarks>
public new object SelectedObject {
get { return m_Wrapper != null ? ((ObjectWrapper)base.SelectedObject).SelectedObject : null; }
set {
// Set the new object to the wrapper and create one if necessary.
if(m_Wrapper == null) {
m_Wrapper = new ObjectWrapper(value);
RefreshProperties();
}
else if(m_Wrapper.SelectedObject != value) {
bool needrefresh = value.GetType() != m_Wrapper.SelectedObject.GetType();
m_Wrapper.SelectedObject = value;
if(needrefresh) RefreshProperties();
}
// Set the list of properties to the wrapper.
m_Wrapper.PropertyDescriptors = m_PropertyDescriptors;
// Link the wrapper to the parent PropertyGrid.
base.SelectedObject = m_Wrapper;
}
}
/// <summary>Called when the browsable properties have changed.</summary>
private void OnBrowsablePropertiesChanged() {
if(m_Wrapper == null) return;
}
/// <summary>Build the list of the properties to be displayed in the PropertyGrid, following the filters defined the Browsable and Hidden properties.</summary>
private void RefreshProperties() {
if(m_Wrapper == null) return;
// Clear the list of properties to be displayed.
m_PropertyDescriptors.Clear();
// Check whether the list is filtered
if(m_BrowsableAttributes != null && m_BrowsableAttributes.Count > 0) {
// Add to the list the attributes that need to be displayed.
foreach(Attribute attribute in m_BrowsableAttributes) ShowAttribute(attribute);
} else {
// Fill the collection with all the properties.
PropertyDescriptorCollection originalpropertydescriptors = TypeDescriptor.GetProperties(m_Wrapper.SelectedObject);
foreach(PropertyDescriptor propertydescriptor in originalpropertydescriptors) m_PropertyDescriptors.Add(propertydescriptor);
// Remove from the list the attributes that mustn't be displayed.
if(m_HiddenAttributes != null) foreach(Attribute attribute in m_HiddenAttributes) HideAttribute(attribute);
}
// Get all the properties of the SelectedObject
PropertyDescriptorCollection allproperties = TypeDescriptor.GetProperties(m_Wrapper.SelectedObject);
// Hide if necessary, some properties
if(m_HiddenProperties != null && m_HiddenProperties.Length > 0) {
// Remove from the list the properties that mustn't be displayed.
foreach(string propertyname in m_HiddenProperties) {
try {
PropertyDescriptor property = allproperties[propertyname];
// Remove from the list the property
HideProperty(property);
} catch(Exception ex) {
Runtime.MessageCollector.AddExceptionMessage("FilteredPropertyGrid: Could not hide Property.", ex);
}
}
}
// Display if necessary, some properties
if(m_BrowsableProperties != null && m_BrowsableProperties.Length > 0) {
foreach(string propertyname in m_BrowsableProperties) {
try {
ShowProperty(allproperties[propertyname]);
} catch(Exception knfe) {
Runtime.MessageCollector.AddExceptionMessage("FilteredPropertyGrid: Property not found", knfe);
}
}
}
}
/// <summary>Allows to hide a set of properties to the parent PropertyGrid.</summary>
/// <param name="propertyname">A set of attributes that filter the original collection of properties.</param>
/// <remarks>For better performance, include the BrowsableAttribute with true value.</remarks>
private void HideAttribute(Attribute attribute) {
PropertyDescriptorCollection filteredoriginalpropertydescriptors = TypeDescriptor.GetProperties(m_Wrapper.SelectedObject,new Attribute[] { attribute });
if(filteredoriginalpropertydescriptors == null || filteredoriginalpropertydescriptors.Count == 0) throw new ArgumentException("Attribute not found",attribute.ToString());
foreach(PropertyDescriptor propertydescriptor in filteredoriginalpropertydescriptors) HideProperty(propertydescriptor);
}
/// <summary>Add all the properties that match an attribute to the list of properties to be displayed in the PropertyGrid.</summary>
/// <param name="property">The attribute to be added.</param>
private void ShowAttribute(Attribute attribute) {
PropertyDescriptorCollection filteredoriginalpropertydescriptors = TypeDescriptor.GetProperties(m_Wrapper.SelectedObject,new Attribute[] { attribute });
if(filteredoriginalpropertydescriptors == null || filteredoriginalpropertydescriptors.Count == 0) throw new ArgumentException("Attribute not found",attribute.ToString());
foreach(PropertyDescriptor propertydescriptor in filteredoriginalpropertydescriptors) ShowProperty(propertydescriptor);
}
/// <summary>Add a property to the list of properties to be displayed in the PropertyGrid.</summary>
/// <param name="property">The property to be added.</param>
private void ShowProperty(PropertyDescriptor property) {
if(!m_PropertyDescriptors.Contains(property)) m_PropertyDescriptors.Add(property);
}
/// <summary>Allows to hide a property to the parent PropertyGrid.</summary>
/// <param name="propertyname">The name of the property to be hidden.</param>
private void HideProperty(PropertyDescriptor property) {
if(m_PropertyDescriptors.Contains(property)) m_PropertyDescriptors.Remove(property);
}
}
}

View File

@@ -0,0 +1,34 @@
namespace mRemoteNG.UI.Controls.FilteredPropertyGrid
{
partial class FilteredPropertyGrid
{
/// <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 Component 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() {
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace mRemoteNG.UI.Controls.FilteredPropertyGrid
{
/// <summary>This class is a wrapper. It contains the object the propertyGrid has to display.</summary>
internal class ObjectWrapper : ICustomTypeDescriptor
{
/// <summary>Contain a reference to the selected objet that will linked to the parent PropertyGrid.</summary>
private object m_SelectedObject = null;
/// <summary>Contain a reference to the collection of properties to show in the parent PropertyGrid.</summary>
/// <remarks>By default, m_PropertyDescriptors contain all the properties of the object. </remarks>
List<PropertyDescriptor> m_PropertyDescriptors = new List<PropertyDescriptor>();
/// <summary>Simple constructor.</summary>
/// <param name="obj">A reference to the selected object that will linked to the parent PropertyGrid.</param>
internal ObjectWrapper(object obj) {
m_SelectedObject = obj;
}
/// <summary>Get or set a reference to the selected objet that will linked to the parent PropertyGrid.</summary>
public object SelectedObject {
get { return m_SelectedObject; }
set { if(m_SelectedObject != value) m_SelectedObject = value; }
}
/// <summary>Get or set a reference to the collection of properties to show in the parent PropertyGrid.</summary>
public List<PropertyDescriptor> PropertyDescriptors {
get { return m_PropertyDescriptors; }
set { m_PropertyDescriptors = value; }
}
#region ICustomTypeDescriptor Members
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
return GetProperties();
}
public PropertyDescriptorCollection GetProperties() {
return new PropertyDescriptorCollection(m_PropertyDescriptors.ToArray(),true);
}
/// <summary>GetAttributes.</summary>
/// <returns>AttributeCollection</returns>
public AttributeCollection GetAttributes() {
return TypeDescriptor.GetAttributes(m_SelectedObject,true);
}
/// <summary>Get Class Name.</summary>
/// <returns>String</returns>
public String GetClassName() {
return TypeDescriptor.GetClassName(m_SelectedObject,true);
}
/// <summary>GetComponentName.</summary>
/// <returns>String</returns>
public String GetComponentName() {
return TypeDescriptor.GetComponentName(m_SelectedObject,true);
}
/// <summary>GetConverter.</summary>
/// <returns>TypeConverter</returns>
public TypeConverter GetConverter() {
return TypeDescriptor.GetConverter(m_SelectedObject,true);
}
/// <summary>GetDefaultEvent.</summary>
/// <returns>EventDescriptor</returns>
public EventDescriptor GetDefaultEvent() {
return TypeDescriptor.GetDefaultEvent(m_SelectedObject,true);
}
/// <summary>GetDefaultProperty.</summary>
/// <returns>PropertyDescriptor</returns>
public PropertyDescriptor GetDefaultProperty() {
return TypeDescriptor.GetDefaultProperty(m_SelectedObject,true);
}
/// <summary>GetEditor.</summary>
/// <param name="editorBaseType">editorBaseType</param>
/// <returns>object</returns>
public object GetEditor(Type editorBaseType) {
return TypeDescriptor.GetEditor(this,editorBaseType,true);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes) {
return TypeDescriptor.GetEvents(m_SelectedObject,attributes,true);
}
public EventDescriptorCollection GetEvents() {
return TypeDescriptor.GetEvents(m_SelectedObject,true);
}
public object GetPropertyOwner(PropertyDescriptor pd) {
return m_SelectedObject;
}
#endregion
}
}

View File

@@ -1,4 +1,3 @@
using Azuria.Common.Controls;
using mRemoteNG.App;
using mRemoteNG.Connection;
using mRemoteNG.Connection.Protocol.RDP;
@@ -13,6 +12,7 @@ using System.Drawing;
using System.IO;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using mRemoteNG.UI.Controls.FilteredPropertyGrid;
using WeifenLuo.WinFormsUI.Docking;

View File

@@ -105,10 +105,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>References\DiffieHellman.dll</HintPath>
</Reference>
<Reference Include="FilteredPropertyGrid, Version=1.0.2258.31541, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>References\FilteredPropertyGrid.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>References\log4net.dll</HintPath>
@@ -226,6 +222,13 @@
<Compile Include="Tree\NodeType.cs" />
<Compile Include="Tree\Root\RootNodeTypeEnum.cs" />
<Compile Include="Tree\TreeNodeMover.cs" />
<Compile Include="UI\Controls\FilteredPropertyGrid\FilteredPropertyGrid.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UI\Controls\FilteredPropertyGrid\FilteredPropertyGrid.designer.cs">
<DependentUpon>FilteredPropertyGrid.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\FilteredPropertyGrid\ObjectWrapper.cs" />
<Compile Include="UI\Controls\IPTextBox.cs">
<SubType>UserControl</SubType>
</Compile>