Volian.Base.Library & Baseline
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Windows.Forms;
|
||||
using System.Reflection;
|
||||
@@ -17,10 +13,10 @@ namespace Volian.Base.Library
|
||||
// PropertyValueChanged event args...
|
||||
public delegate void MyPropertyValueChangedEventHandler(object sender, PropertyValueChangedEventArgs e);
|
||||
public static event MyPropertyValueChangedEventHandler MyPropertyValueChanged;
|
||||
private bool AllowAddDel = false; // flags whether the Add/Delete buttons should be displayed:
|
||||
private readonly bool AllowAddDel = false; // flags whether the Add/Delete buttons should be displayed:
|
||||
// Inherit the default constructor from the standard
|
||||
// Collection Editor...
|
||||
private Type _origType;
|
||||
private readonly Type _origType;
|
||||
public PropGridCollEditor(Type type)
|
||||
: base(type)
|
||||
{
|
||||
@@ -29,11 +25,8 @@ namespace Volian.Base.Library
|
||||
if (type.Name == "ReplaceStrData") AllowAddDel = true; // Defaults to not having the 'Add' & 'Remove' buttons.
|
||||
}
|
||||
|
||||
protected override Type CreateCollectionItemType()
|
||||
{
|
||||
return base.CreateCollectionItemType();
|
||||
}
|
||||
private Button resetbtn = null;
|
||||
protected override Type CreateCollectionItemType() => base.CreateCollectionItemType();
|
||||
private Button resetbtn = null;
|
||||
// Override this method in order to access the containing user controls
|
||||
// from the default Collection Editor form or to add new ones...
|
||||
protected override CollectionForm CreateCollectionForm()
|
||||
@@ -49,30 +42,31 @@ namespace Volian.Base.Library
|
||||
|
||||
if (!AllowAddDel)
|
||||
{
|
||||
// add a reset button and put next to ok button:
|
||||
resetbtn = new Button();
|
||||
resetbtn.Text = "Reset";
|
||||
resetbtn.Location = new System.Drawing.Point(okbtn.Location.X - 20, okbtn.Location.Y);
|
||||
resetbtn.Width = 250;
|
||||
resetbtn.Visible = true;
|
||||
resetbtn.Enabled = false; // only enabled on data change
|
||||
resetbtn.Click += resetbtn_Click;
|
||||
// add a reset button and put next to ok button:
|
||||
resetbtn = new Button
|
||||
{
|
||||
Text = "Reset",
|
||||
Location = new System.Drawing.Point(okbtn.Location.X - 20, okbtn.Location.Y),
|
||||
Width = 250,
|
||||
Visible = true,
|
||||
Enabled = false // only enabled on data change
|
||||
};
|
||||
resetbtn.Click += resetbtn_Click;
|
||||
okbtn.Parent.Controls.Add(resetbtn);
|
||||
}
|
||||
SetMembersLabel(collectionForm);
|
||||
TableLayoutPanel tlpLayout = frmCollectionEditorForm.Controls[0] as TableLayoutPanel;
|
||||
if (tlpLayout != null)
|
||||
{
|
||||
// Get a reference to the inner PropertyGrid and hook an event handler to it.
|
||||
if (tlpLayout.Controls[5] is PropertyGrid)
|
||||
{
|
||||
propertyGrid = tlpLayout.Controls[5] as PropertyGrid;
|
||||
propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);
|
||||
propertyGrid.SelectedGridItemChanged += PG_SelectedGridItemChanged;
|
||||
}
|
||||
}
|
||||
if (frmCollectionEditorForm.Controls[0] is TableLayoutPanel tlpLayout)
|
||||
{
|
||||
// Get a reference to the inner PropertyGrid and hook an event handler to it.
|
||||
if (tlpLayout.Controls[5] is PropertyGrid)
|
||||
{
|
||||
propertyGrid = tlpLayout.Controls[5] as PropertyGrid;
|
||||
propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);
|
||||
propertyGrid.SelectedGridItemChanged += PG_SelectedGridItemChanged;
|
||||
}
|
||||
}
|
||||
|
||||
return collectionForm;
|
||||
return collectionForm;
|
||||
}
|
||||
|
||||
// when the reset button is clicked the data will be reset to the data from the original format file. Note that if
|
||||
@@ -93,28 +87,15 @@ namespace Volian.Base.Library
|
||||
else if (SelectedGridField.Contains("Active CheckOff"))
|
||||
ResetValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active");
|
||||
}
|
||||
private void ShowReflection(Object data)
|
||||
{
|
||||
if (data == null) return;
|
||||
//Object data = new A();
|
||||
FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public |
|
||||
BindingFlags.NonPublic |
|
||||
BindingFlags.Instance);
|
||||
String str = "";
|
||||
foreach (FieldInfo f in fields)
|
||||
{
|
||||
str += f.Name + " = " + f.GetValue(data) + "\r\n";
|
||||
}
|
||||
Console.WriteLine("reflection = {0}", str);
|
||||
}
|
||||
PropertyGrid propertyGrid = null;
|
||||
|
||||
PropertyGrid propertyGrid = null;
|
||||
private string SelectedGridField = "";
|
||||
// The following method is used to enable and set text on the 'Reset' button. When a grid item is selected, if it has
|
||||
// UCF data, then put the original value as part of the button text & enable it:
|
||||
void PG_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e)
|
||||
{
|
||||
if (resetbtn == null) return;
|
||||
if (propertyGrid != null) Console.WriteLine(LabelPath(propertyGrid.SelectedGridItem)); // PG.SelectedGridItem.Label + " : " + PG.SelectedGridItem.Value;
|
||||
if (propertyGrid != null) Console.WriteLine(LabelPath(propertyGrid.SelectedGridItem));
|
||||
// see if data has changed, and if so, enable the Reset button.
|
||||
bool enabled = false;
|
||||
resetbtn.Text = "Reset";
|
||||
@@ -124,7 +105,7 @@ namespace Volian.Base.Library
|
||||
string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "WindowsFont");
|
||||
if (origForButton != null)
|
||||
{
|
||||
resetbtn.Text = "Reset to " + origForButton;
|
||||
resetbtn.Text = $"Reset to {origForButton}";
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +114,7 @@ namespace Volian.Base.Library
|
||||
string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "LeftMargin");
|
||||
if (origForButton != null)
|
||||
{
|
||||
resetbtn.Text = "Reset to " + origForButton;
|
||||
resetbtn.Text = $"Reset to {origForButton}";
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -142,7 +123,7 @@ namespace Volian.Base.Library
|
||||
string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "PageLength");
|
||||
if (origForButton != null)
|
||||
{
|
||||
resetbtn.Text = "Reset to " + origForButton;
|
||||
resetbtn.Text = $"Reset to {origForButton}";
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +132,7 @@ namespace Volian.Base.Library
|
||||
string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active");
|
||||
if (origForButton != null)
|
||||
{
|
||||
resetbtn.Text = "Reset to " + origForButton;
|
||||
resetbtn.Text = $"Reset to {origForButton}";
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +141,7 @@ namespace Volian.Base.Library
|
||||
string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active");
|
||||
if (origForButton != null)
|
||||
{
|
||||
resetbtn.Text = "Reset to " + origForButton;
|
||||
resetbtn.Text = $"Reset to {origForButton}";
|
||||
enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -182,8 +163,8 @@ namespace Volian.Base.Library
|
||||
// field to compare the 2 to see if a change was made, i.e. UCF data exists.
|
||||
foreach (FieldInfo f in fields)
|
||||
{
|
||||
if (f.Name == "_" + fieldName) fldVal = f;
|
||||
if (f.Name == "_Orig" + fieldName) fldOrig = f;
|
||||
if (f.Name == $"_{fieldName}") fldVal = f;
|
||||
if (f.Name == $"_Orig{fieldName}") fldOrig = f;
|
||||
}
|
||||
if (fldVal != null && fldOrig != null)
|
||||
{
|
||||
@@ -200,8 +181,8 @@ namespace Volian.Base.Library
|
||||
if (orig != newv) return retval;
|
||||
else return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -218,8 +199,8 @@ namespace Volian.Base.Library
|
||||
BindingFlags.Instance);
|
||||
foreach (FieldInfo f in fields)
|
||||
{
|
||||
if (f.Name == "_" + fieldName) fldVal = f;
|
||||
if (f.Name == "_Orig" + fieldName) fldOrig = f;
|
||||
if (f.Name == $"_{fieldName}") fldVal = f;
|
||||
if (f.Name == $"_Orig{fieldName}") fldOrig = f;
|
||||
}
|
||||
if (fldVal != null && fldOrig != null)
|
||||
{
|
||||
@@ -227,14 +208,11 @@ namespace Volian.Base.Library
|
||||
propertyGrid.Refresh();
|
||||
}
|
||||
}
|
||||
// Remove this on release, and any uses of it.
|
||||
private string LabelPath(GridItem gi)
|
||||
{
|
||||
return (gi.Parent == null ? "" : LabelPath(gi.Parent) + ":" + gi.Label);
|
||||
}
|
||||
// Remove this on release, and any uses of it.
|
||||
private string LabelPath(GridItem gi) => gi.Parent == null ? "" : $"{LabelPath(gi.Parent)}:{gi.Label}";
|
||||
|
||||
// set the 'members' label to better reflect what is displayed:
|
||||
private bool SetMembersLabel(Control myControl)
|
||||
// set the 'members' label to better reflect what is displayed:
|
||||
private bool SetMembersLabel(Control myControl)
|
||||
{
|
||||
if (myControl is Label && myControl.Text.ToUpper().Contains("MEMBER"))
|
||||
{
|
||||
@@ -291,11 +269,8 @@ namespace Volian.Base.Library
|
||||
|
||||
void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
|
||||
{
|
||||
// Fire our customized collection event...
|
||||
if (PropGridCollEditor.MyPropertyValueChanged != null)
|
||||
{
|
||||
PropGridCollEditor.MyPropertyValueChanged(this, e);
|
||||
}
|
||||
}
|
||||
// Fire our customized collection event...
|
||||
PropGridCollEditor.MyPropertyValueChanged?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user