diff --git a/CREDITS.TXT b/CREDITS.TXT index aa4c975d..05cef011 100644 --- a/CREDITS.TXT +++ b/CREDITS.TXT @@ -34,22 +34,22 @@ Copyright MIT License http://www.codeproject.com/KB/recipes/command_line.aspx -DotNetVer -Copyright © 2010 David Grinberg -Copyright © 2010-2011 Brandon Hansen -http://nsis.sourceforge.net/DotNetVer +FilteredPropertyGrid +Copyright © 2006 Azuria +http://www.codeproject.com/KB/cs/FilteredPropertyGrid.aspx Hotkey Selection Control for .NET Copyright © 2006 Thomas Backman http://www.codeproject.com/Articles/15085/A-simple-hotkey-selection-control-for-NET +InputBox +Copyright © 2016 Jan Slama +http://www.csharp-examples.net/inputbox/ + IP TextBox Copyright © 2005 mawnkay http://www.codeproject.com/Articles/11576/IP-TextBox -InputBox -Copyright © 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 © 2007 Weifen Luo +DockPanel Suite 2.10.0.beta2 +Copyright © 2015 @roken and @lextm (formerly Weifen Luo) MIT License -http://sourceforge.net/projects/dockpanelsuite/ - -FilteredPropertyGrid 1.0.0.0 -Copyright © 2006 Azuria -http://www.codeproject.com/KB/cs/FilteredPropertyGrid.aspx +https://github.com/dockpanelsuite/dockpanelsuite GeckoFX 1.8.1.4 Copyright © 2008 Skybound Software diff --git a/mRemoteV1/References/FilteredPropertyGrid.dll b/mRemoteV1/References/FilteredPropertyGrid.dll deleted file mode 100644 index 4561e8a9..00000000 Binary files a/mRemoteV1/References/FilteredPropertyGrid.dll and /dev/null differ diff --git a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs new file mode 100644 index 00000000..7531970e --- /dev/null +++ b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.cs @@ -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 +{ + /// + /// 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. + /// + public partial class FilteredPropertyGrid : PropertyGrid + { + /// Contain a reference to the collection of properties to show in the parent PropertyGrid. + /// By default, m_PropertyDescriptors contain all the properties of the object. + List m_PropertyDescriptors = new List(); + /// Contain a reference to the array of properties to display in the PropertyGrid. + private AttributeCollection m_HiddenAttributes = null, m_BrowsableAttributes = null; + /// Contain references to the arrays of properties or categories to hide. + private string[] m_BrowsableProperties = null, m_HiddenProperties = null; + /// Contain a reference to the wrapper that contains the object to be displayed into the PropertyGrid. + private ObjectWrapper m_Wrapper = null; + + /// Public constructor. + 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(); + } + } + } + + /// Get or set the categories to hide. + public AttributeCollection HiddenAttributes { + get { return m_HiddenAttributes; } + set { + if(value != m_HiddenAttributes) { + m_HiddenAttributes = value; + m_BrowsableAttributes = null; + RefreshProperties(); + } + } + } + /// Get or set the properties to show. + /// if one or several properties don't exist. + public string[] BrowsableProperties { + get { return m_BrowsableProperties; } + set { + if(value != m_BrowsableProperties) { + m_BrowsableProperties = value; + //m_HiddenProperties = null; + RefreshProperties(); + } + } + } + + /// Get or set the properties to hide. + public string[] HiddenProperties { + get { return m_HiddenProperties; } + set { + if(value != m_HiddenProperties) { + //m_BrowsableProperties = null; + m_HiddenProperties = value; + RefreshProperties(); + } + } + } + + /// Overwrite the PropertyGrid.SelectedObject property. + /// The object passed to the base PropertyGrid is the wrapper. + 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; + } + } + + /// Called when the browsable properties have changed. + private void OnBrowsablePropertiesChanged() { + if(m_Wrapper == null) return; + } + + /// Build the list of the properties to be displayed in the PropertyGrid, following the filters defined the Browsable and Hidden properties. + 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); + } + } + } + } + /// Allows to hide a set of properties to the parent PropertyGrid. + /// A set of attributes that filter the original collection of properties. + /// For better performance, include the BrowsableAttribute with true value. + 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); + } + /// Add all the properties that match an attribute to the list of properties to be displayed in the PropertyGrid. + /// The attribute to be added. + 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); + } + /// Add a property to the list of properties to be displayed in the PropertyGrid. + /// The property to be added. + private void ShowProperty(PropertyDescriptor property) { + if(!m_PropertyDescriptors.Contains(property)) m_PropertyDescriptors.Add(property); + } + /// Allows to hide a property to the parent PropertyGrid. + /// The name of the property to be hidden. + private void HideProperty(PropertyDescriptor property) { + if(m_PropertyDescriptors.Contains(property)) m_PropertyDescriptors.Remove(property); + } + } +} \ No newline at end of file diff --git a/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.designer.cs b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.designer.cs new file mode 100644 index 00000000..586b8813 --- /dev/null +++ b/mRemoteV1/UI/Controls/FilteredPropertyGrid/FilteredPropertyGrid.designer.cs @@ -0,0 +1,34 @@ +namespace mRemoteNG.UI.Controls.FilteredPropertyGrid +{ + partial class FilteredPropertyGrid + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if(disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/mRemoteV1/UI/Controls/FilteredPropertyGrid/ObjectWrapper.cs b/mRemoteV1/UI/Controls/FilteredPropertyGrid/ObjectWrapper.cs new file mode 100644 index 00000000..3f2f1d62 --- /dev/null +++ b/mRemoteV1/UI/Controls/FilteredPropertyGrid/ObjectWrapper.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace mRemoteNG.UI.Controls.FilteredPropertyGrid +{ + /// This class is a wrapper. It contains the object the propertyGrid has to display. + internal class ObjectWrapper : ICustomTypeDescriptor + { + /// Contain a reference to the selected objet that will linked to the parent PropertyGrid. + private object m_SelectedObject = null; + /// Contain a reference to the collection of properties to show in the parent PropertyGrid. + /// By default, m_PropertyDescriptors contain all the properties of the object. + List m_PropertyDescriptors = new List(); + + /// Simple constructor. + /// A reference to the selected object that will linked to the parent PropertyGrid. + internal ObjectWrapper(object obj) { + m_SelectedObject = obj; + } + + /// Get or set a reference to the selected objet that will linked to the parent PropertyGrid. + public object SelectedObject { + get { return m_SelectedObject; } + set { if(m_SelectedObject != value) m_SelectedObject = value; } + } + + /// Get or set a reference to the collection of properties to show in the parent PropertyGrid. + public List 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); + } + + /// GetAttributes. + /// AttributeCollection + public AttributeCollection GetAttributes() { + return TypeDescriptor.GetAttributes(m_SelectedObject,true); + } + /// Get Class Name. + /// String + public String GetClassName() { + return TypeDescriptor.GetClassName(m_SelectedObject,true); + } + /// GetComponentName. + /// String + public String GetComponentName() { + return TypeDescriptor.GetComponentName(m_SelectedObject,true); + } + + /// GetConverter. + /// TypeConverter + public TypeConverter GetConverter() { + return TypeDescriptor.GetConverter(m_SelectedObject,true); + } + + /// GetDefaultEvent. + /// EventDescriptor + public EventDescriptor GetDefaultEvent() { + return TypeDescriptor.GetDefaultEvent(m_SelectedObject,true); + } + + /// GetDefaultProperty. + /// PropertyDescriptor + public PropertyDescriptor GetDefaultProperty() { + return TypeDescriptor.GetDefaultProperty(m_SelectedObject,true); + } + + /// GetEditor. + /// editorBaseType + /// object + 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 + + } +} diff --git a/mRemoteV1/UI/Window/ConfigWindow.cs b/mRemoteV1/UI/Window/ConfigWindow.cs index 55c04088..790dc7bf 100644 --- a/mRemoteV1/UI/Window/ConfigWindow.cs +++ b/mRemoteV1/UI/Window/ConfigWindow.cs @@ -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; diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index a7e0aac1..10b902e2 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -105,10 +105,6 @@ False References\DiffieHellman.dll - - False - References\FilteredPropertyGrid.dll - False References\log4net.dll @@ -226,6 +222,13 @@ + + Component + + + FilteredPropertyGrid.cs + + UserControl