2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using System.Globalization;
|
2012-07-10 10:20:45 +00:00
|
|
|
using CodeImp.DoomBuilder.Types;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
2009-05-21 08:18:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Control to view and/or change custom UDMF fields.
|
|
|
|
/// </summary>
|
2009-04-19 18:07:22 +00:00
|
|
|
public partial class FieldsEditorControl : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
private const string ADD_FIELD_TEXT = " (click to add custom field)";
|
|
|
|
private const string FIELD_PREFIX_SUGGESTION = "user_";
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2011-07-26 18:16:52 +00:00
|
|
|
public delegate void SingleFieldNameEvent(string fieldname);
|
|
|
|
public delegate void DualFieldNameEvent(string oldname, string newname);
|
|
|
|
|
|
|
|
// Events
|
|
|
|
public event SingleFieldNameEvent OnFieldInserted;
|
|
|
|
public event DualFieldNameEvent OnFieldNameChanged;
|
|
|
|
public event SingleFieldNameEvent OnFieldValueChanged;
|
|
|
|
public event SingleFieldNameEvent OnFieldTypeChanged;
|
|
|
|
public event SingleFieldNameEvent OnFieldDeleted;
|
|
|
|
public event SingleFieldNameEvent OnFieldUndefined;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Variables
|
|
|
|
private string elementname;
|
|
|
|
private string lasteditfieldname;
|
2010-09-01 14:36:31 +00:00
|
|
|
private bool autoinsertuserprefix;
|
2013-08-10 11:28:51 +00:00
|
|
|
private Dictionary<string, UniversalType> uifields;//mxd
|
2016-02-07 23:04:20 +00:00
|
|
|
private bool showfixedfields = true; //mxd
|
2010-09-01 14:36:31 +00:00
|
|
|
|
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2010-09-01 14:36:31 +00:00
|
|
|
#region ================== Properties
|
2011-07-26 18:16:52 +00:00
|
|
|
|
|
|
|
public bool AllowInsert { get { return fieldslist.AllowUserToAddRows; } set { fieldslist.AllowUserToAddRows = value; SetupNewRowStyle(); } }
|
2010-09-01 14:36:31 +00:00
|
|
|
public bool AutoInsertUserPrefix { get { return autoinsertuserprefix; } set { autoinsertuserprefix = value; } }
|
2011-07-26 18:16:52 +00:00
|
|
|
public int PropertyColumnWidth { get { return fieldname.Width; } set { fieldname.Width = value; UpdateValueColumn(); UpdateBrowseButton(); } }
|
|
|
|
public int TypeColumnWidth { get { return fieldtype.Width; } set { fieldtype.Width = value; UpdateValueColumn(); UpdateBrowseButton(); } }
|
|
|
|
public bool PropertyColumnVisible { get { return fieldname.Visible; } set { fieldname.Visible = value; UpdateValueColumn(); UpdateBrowseButton(); } }
|
|
|
|
public bool TypeColumnVisible { get { return fieldtype.Visible; } set { fieldtype.Visible = value; UpdateValueColumn(); UpdateBrowseButton(); } }
|
|
|
|
public bool ValueColumnVisible { get { return fieldvalue.Visible; } set { fieldvalue.Visible = value; UpdateValueColumn(); UpdateBrowseButton(); } }
|
2016-02-07 23:04:20 +00:00
|
|
|
public bool ShowFixedFields {get { return showfixedfields; } set { showfixedfields = value; UpdateFixedFieldsVisibility(); } } //mxd
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public FieldsEditorControl()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2010-09-01 14:36:31 +00:00
|
|
|
autoinsertuserprefix = true;
|
2009-04-19 18:07:22 +00:00
|
|
|
enumscombo.Location = new Point(-1000, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Setup / Apply
|
|
|
|
|
|
|
|
// This sets up the control
|
|
|
|
public void Setup(string elementname)
|
|
|
|
{
|
|
|
|
// Keep element name
|
|
|
|
this.elementname = elementname;
|
2013-08-08 11:04:13 +00:00
|
|
|
|
2016-02-07 23:04:20 +00:00
|
|
|
//mxd. Get proper UIFields
|
Removed "Paste Properties Options" action.
Added "Paste Properties Special" actions in "Classic" and "Visual" categories. They work the same way as "Paste Special" action.
Added: "Copy Properties", "Paste Properties" and "Paste Properties Special" options are now shown in the Edit menu if current classic mode supports them.
Changed, Paste Properties Special window: only options relevant to current map format are now displayed.
Changed, Paste Properties Special window, UDMF: all UI-managed options are now available.
Fixed: MAPINFO parser was unable to process "include" directives.
Fixed, General interface: selection info was reset to "Nothing selected" after few seconds regardless of current selection.
Fixed, Visual mode: thing bounding boxes were not updated when changing things positions using Randomize mode.
Fixed, Visual mode: event lines were displayed at incorrect height when entering Visual mode for the first time.
Fixed, Texture Browser window: when MixTexturesFlats Game Configuration option is disabled, textures/flats are no longer shown in the Used group when flats/textures with the same names are used in the map.
Fixed(?): probably fixed an exception some users reported when trying to initialize a Classic mode after switching from Visual mode with "Sync cameras" option enabled.
Changed, Game configurations, Thing Categories: a block must have at least one thing category property to be recognized as a thing category.
Changed, Visplane Explorer: the plugin now outputs more info when it fails to initialize vpo.dll.
Cosmetic, Thing Edit window, Doom/Hexen map format: adjusted UI layout so thing flags control no longer displays scrollbars in Hexen map format.
Internal: merged methods from UDMFTools into UniFields, removed UDMFTools.
Updated Inno Setup script (added VC++ 2008 SP1 distributive).
Updated ZDoom_DECORATE.cfg (A_CheckBlock).
Updated documentation (added "System Requirements" page).
2015-10-09 12:38:12 +00:00
|
|
|
uifields = General.Map.FormatInterface.UIFields[General.Map.FormatInterface.GetElementType(elementname)];
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Make types list
|
|
|
|
fieldtype.Items.Clear();
|
|
|
|
fieldtype.Items.AddRange(General.Types.GetCustomUseAttributes());
|
|
|
|
}
|
|
|
|
|
|
|
|
// This applies last sort order
|
|
|
|
private void Sort()
|
|
|
|
{
|
|
|
|
// Sort
|
|
|
|
int sortcolumn = General.Settings.ReadSetting("customfieldssortcolumn", 0);
|
|
|
|
int sortorder = General.Settings.ReadSetting("customfieldssortorder", (int)ListSortDirection.Ascending);
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
switch(sortorder)
|
2015-07-15 09:09:47 +00:00
|
|
|
{
|
|
|
|
case (int)SortOrder.Ascending:
|
|
|
|
fieldslist.Sort(fieldslist.Columns[sortcolumn], ListSortDirection.Ascending);
|
|
|
|
break;
|
|
|
|
case (int)SortOrder.Descending:
|
|
|
|
fieldslist.Sort(fieldslist.Columns[sortcolumn], ListSortDirection.Descending);
|
|
|
|
break;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This adds a list of fixed fields (in undefined state)
|
|
|
|
public void ListFixedFields(List<UniversalFieldInfo> list)
|
|
|
|
{
|
|
|
|
// Add all fields
|
2014-12-03 23:15:26 +00:00
|
|
|
foreach(UniversalFieldInfo uf in list)
|
|
|
|
{
|
2013-08-10 11:28:51 +00:00
|
|
|
if(uifields.ContainsKey(uf.Name)) continue; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
fieldslist.Rows.Add(new FieldsEditorRow(fieldslist, uf));
|
2013-08-08 11:04:13 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Sort fields
|
|
|
|
Sort();
|
|
|
|
|
|
|
|
// Update new row
|
|
|
|
SetupNewRowStyle();
|
|
|
|
}
|
|
|
|
|
2010-09-01 14:36:31 +00:00
|
|
|
// Use this in case you don't want the fixed fields
|
|
|
|
public void ListNoFixedFields()
|
|
|
|
{
|
|
|
|
// Update new row
|
|
|
|
SetupNewRowStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all fields
|
|
|
|
public void ClearFields()
|
|
|
|
{
|
|
|
|
// Trash rows
|
|
|
|
fieldslist.Rows.Clear();
|
|
|
|
|
|
|
|
// Update new row
|
|
|
|
SetupNewRowStyle();
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This sets up the fields and values from a UniFields object
|
|
|
|
// When first is true, the values are applied unconditionally
|
|
|
|
// When first is false, the values in the grid are erased when
|
|
|
|
// they differ from the given values (for multiselection)
|
|
|
|
public void SetValues(UniFields fromfields, bool first)
|
|
|
|
{
|
|
|
|
// Go for all the fields
|
|
|
|
foreach(KeyValuePair<string, UniValue> f in fromfields)
|
|
|
|
{
|
2013-08-10 11:28:51 +00:00
|
|
|
if(uifields.ContainsKey(f.Key)) continue; //mxd
|
2013-08-08 11:04:13 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Go for all rows
|
|
|
|
bool foundrow = false;
|
2016-02-08 21:51:03 +00:00
|
|
|
bool skiprow = false; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Row name matches with field
|
|
|
|
if(frow.Name == f.Key)
|
|
|
|
{
|
2016-02-08 21:51:03 +00:00
|
|
|
//mxd. User vars are set separately
|
|
|
|
if(frow.RowType == FieldsEditorRowType.USERVAR)
|
|
|
|
{
|
|
|
|
skiprow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// First time?
|
|
|
|
if(first)
|
|
|
|
{
|
|
|
|
// Set type when row is not fixed
|
2016-02-08 21:51:03 +00:00
|
|
|
if(frow.RowType == FieldsEditorRowType.DYNAMIC) frow.ChangeType(f.Value.Type);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Apply value of field to row
|
|
|
|
frow.Define(f.Value.Value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check if the value is different
|
|
|
|
if(!frow.TypeHandler.GetValue().Equals(f.Value.Value))
|
|
|
|
{
|
|
|
|
// Clear the value in the row
|
|
|
|
frow.Define(f.Value.Value);
|
|
|
|
frow.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
foundrow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-08 21:51:03 +00:00
|
|
|
|
|
|
|
//mxd. User vars are set separately
|
|
|
|
if(skiprow) continue;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Row not found?
|
|
|
|
if(!foundrow)
|
|
|
|
{
|
|
|
|
// Make new row
|
2016-02-08 21:51:03 +00:00
|
|
|
FieldsEditorRow frow = new FieldsEditorRow(fieldslist, f.Key, f.Value.Type, f.Value.Value, false);
|
2009-04-19 18:07:22 +00:00
|
|
|
fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
// When not the first, clear the field because the others did not define this one
|
2009-04-19 18:07:22 +00:00
|
|
|
if(!first) frow.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check for rows that the givens fields do NOT have
|
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Is this row defined previously?
|
|
|
|
if(frow.IsDefined)
|
|
|
|
{
|
|
|
|
// Check if this row can not be found in the fields at all
|
|
|
|
if(!fromfields.ContainsKey(frow.Name))
|
|
|
|
{
|
|
|
|
// It is not defined in these fields, clear the value
|
|
|
|
frow.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort fields
|
|
|
|
Sort();
|
|
|
|
}
|
2016-02-08 21:51:03 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
public void SetUserVars(Dictionary<string, UniversalType> vars, UniFields fromfields, bool first)
|
|
|
|
{
|
|
|
|
foreach(KeyValuePair<string, UniversalType> group in vars)
|
|
|
|
{
|
|
|
|
// Go for all rows
|
|
|
|
bool foundrow = false;
|
|
|
|
TypeHandler vartype = General.Types.GetFieldHandler((int)group.Value, 0);
|
|
|
|
object value = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue();
|
|
|
|
|
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Row name matches with user var?
|
|
|
|
if(frow.RowType == FieldsEditorRowType.USERVAR && frow.Name == group.Key)
|
|
|
|
{
|
|
|
|
// First time?
|
|
|
|
if(first)
|
|
|
|
{
|
|
|
|
frow.Define(value);
|
|
|
|
}
|
|
|
|
// Check if the value is different
|
|
|
|
else if(!frow.TypeHandler.GetValue().Equals(value))
|
|
|
|
{
|
|
|
|
// Clear the value in the row
|
|
|
|
frow.Define(value);
|
|
|
|
frow.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
foundrow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Row not found?
|
|
|
|
if(!foundrow)
|
|
|
|
{
|
|
|
|
// Make new row
|
|
|
|
object defaultvalue = vartype.GetDefaultValue();
|
|
|
|
FieldsEditorRow frow = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true);
|
|
|
|
if(!value.Equals(defaultvalue)) frow.Define(value);
|
|
|
|
fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check for rows that the givens fields do NOT have
|
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Don't undefine user var rows defined by other actor types
|
|
|
|
if(frow.RowType != FieldsEditorRowType.USERVAR || !vars.ContainsKey(frow.Name)) continue;
|
|
|
|
|
|
|
|
// Is this row defined previously?
|
|
|
|
if(frow.IsDefined)
|
|
|
|
{
|
|
|
|
// Check if this row can not be found in the fields at all
|
|
|
|
if(!fromfields.ContainsKey(frow.Name))
|
|
|
|
{
|
|
|
|
// It is not defined in these fields, undefine the value
|
|
|
|
frow.Undefine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This applies the current fields to a UniFields object
|
|
|
|
public void Apply(UniFields tofields)
|
|
|
|
{
|
2009-06-11 21:21:20 +00:00
|
|
|
tofields.BeforeFieldsChange();
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Go for all the fields
|
|
|
|
UniFields tempfields = new UniFields(tofields);
|
2014-12-03 23:15:26 +00:00
|
|
|
foreach(KeyValuePair<string, UniValue> f in tempfields)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(uifields.ContainsKey(f.Key)) continue; //mxd
|
2013-08-08 11:04:13 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Go for all rows
|
|
|
|
bool foundrow = false;
|
2016-02-08 21:51:03 +00:00
|
|
|
bool skiprow = false; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field and matches field name?
|
|
|
|
if((row is FieldsEditorRow) && (row.Cells[0].Value.ToString() == f.Key))
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
//mxd. User vars are stored separately
|
|
|
|
if(frow.RowType == FieldsEditorRowType.USERVAR)
|
|
|
|
{
|
|
|
|
skiprow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Field is defined?
|
|
|
|
if(frow.IsDefined)
|
|
|
|
{
|
|
|
|
foundrow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
//mxd. User vars are stored separately
|
|
|
|
if(skiprow) continue;
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// No such row?
|
|
|
|
if(!foundrow)
|
|
|
|
{
|
|
|
|
// Remove the definition from the fields
|
|
|
|
tofields.Remove(f.Key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all rows
|
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Field is defined and not empty?
|
2016-02-08 21:51:03 +00:00
|
|
|
if(frow.RowType != FieldsEditorRowType.USERVAR && frow.IsDefined && !frow.IsEmpty)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Apply field
|
|
|
|
object oldvalue = null;
|
|
|
|
if(tofields.ContainsKey(frow.Name)) oldvalue = tofields[frow.Name].Value;
|
|
|
|
tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, frow.GetResult(oldvalue));
|
|
|
|
|
|
|
|
// Custom row?
|
2016-02-08 21:51:03 +00:00
|
|
|
if(frow.RowType == FieldsEditorRowType.DYNAMIC)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Write type to map configuration
|
|
|
|
General.Map.Options.SetUniversalFieldType(elementname, frow.Name, frow.TypeHandler.Index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
//mxd
|
|
|
|
public void ApplyUserVars(Dictionary<string, UniversalType> vars, UniFields tofields)
|
|
|
|
{
|
|
|
|
// Apply user variables when target map element contains user var definition and the value is not default
|
|
|
|
foreach(DataGridViewRow row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Row is a field?
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
|
|
|
if(frow.RowType != FieldsEditorRowType.USERVAR || !vars.ContainsKey(frow.Name)) continue;
|
|
|
|
|
|
|
|
object oldvalue = (tofields.ContainsKey(frow.Name) ? tofields[frow.Name].Value : null);
|
|
|
|
object newvalue = frow.GetResult(oldvalue);
|
|
|
|
|
|
|
|
// Skip field when mixed values
|
|
|
|
if(newvalue == null) continue;
|
|
|
|
|
|
|
|
// Remove field
|
|
|
|
if(newvalue.Equals(frow.TypeHandler.GetDefaultValue()))
|
|
|
|
{
|
|
|
|
if(tofields.ContainsKey(frow.Name)) tofields.Remove(frow.Name);
|
|
|
|
}
|
|
|
|
// Add field
|
|
|
|
else if(!newvalue.Equals(oldvalue))
|
|
|
|
{
|
|
|
|
tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, newvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Column header clicked
|
|
|
|
private void fieldslist_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
{
|
|
|
|
// Save sort order
|
|
|
|
if(fieldslist.SortedColumn != null)
|
|
|
|
{
|
|
|
|
int sortcolumn = fieldslist.SortedColumn.Index;
|
|
|
|
int sortorder = (int)fieldslist.SortOrder;
|
|
|
|
General.Settings.WriteSetting("customfieldssortcolumn", sortcolumn);
|
|
|
|
General.Settings.WriteSetting("customfieldssortorder", sortorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop any cell editing
|
|
|
|
ApplyEnums(true);
|
|
|
|
fieldslist.EndEdit();
|
|
|
|
HideBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resized
|
|
|
|
private void FieldsEditorControl_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Rearrange controls
|
|
|
|
fieldslist.Size = this.ClientSize;
|
2011-07-26 18:16:52 +00:00
|
|
|
UpdateValueColumn();
|
2009-04-19 18:07:22 +00:00
|
|
|
UpdateBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layout change
|
|
|
|
private void FieldsEditorControl_Layout(object sender, LayoutEventArgs e)
|
|
|
|
{
|
|
|
|
FieldsEditorControl_Resize(sender, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cell clicked
|
|
|
|
private void fieldslist_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
{
|
|
|
|
ApplyEnums(true);
|
|
|
|
|
|
|
|
// Anything selected
|
|
|
|
if(fieldslist.SelectedCells.Count > 0)
|
|
|
|
{
|
|
|
|
if(e.RowIndex == fieldslist.NewRowIndex)
|
|
|
|
fieldslist.BeginEdit(false);
|
|
|
|
else if(e.ColumnIndex > 0)
|
|
|
|
fieldslist.BeginEdit(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cell doubleclicked
|
|
|
|
private void fieldslist_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = null;
|
|
|
|
|
|
|
|
// Anything selected
|
2012-04-14 14:02:32 +00:00
|
|
|
if(fieldslist.SelectedRows.Count > 0 && e.RowIndex > -1)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Get the row
|
|
|
|
DataGridViewRow row = fieldslist.Rows[e.RowIndex];
|
|
|
|
if(row is FieldsEditorRow) frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// First column?
|
|
|
|
if(e.ColumnIndex == 0)
|
|
|
|
{
|
2016-02-08 21:51:03 +00:00
|
|
|
// Dynamic field?
|
|
|
|
if((frow != null) && frow.RowType == FieldsEditorRowType.DYNAMIC)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
lasteditfieldname = frow.Name;
|
|
|
|
fieldslist.CurrentCell = fieldslist.SelectedRows[0].Cells[0];
|
|
|
|
fieldslist.CurrentCell.ReadOnly = false;
|
|
|
|
|
|
|
|
if((e.RowIndex == fieldslist.NewRowIndex) ||
|
2016-02-01 22:04:00 +00:00
|
|
|
frow.Name.StartsWith(FIELD_PREFIX_SUGGESTION, StringComparison.OrdinalIgnoreCase))
|
2009-04-19 18:07:22 +00:00
|
|
|
fieldslist.BeginEdit(false);
|
|
|
|
else
|
|
|
|
fieldslist.BeginEdit(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User deletes a row
|
|
|
|
private void fieldslist_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
|
|
|
|
{
|
|
|
|
// Get the row
|
|
|
|
FieldsEditorRow row = e.Row as FieldsEditorRow;
|
2016-02-08 21:51:03 +00:00
|
|
|
if(row == null) return;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
// Fixed/uservar field?
|
|
|
|
if(row.RowType == FieldsEditorRowType.FIXED || row.RowType == FieldsEditorRowType.USERVAR)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Just undefine the field
|
|
|
|
row.Undefine();
|
|
|
|
e.Cancel = true;
|
2011-07-26 18:16:52 +00:00
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldUndefined != null) OnFieldUndefined(row.Name);
|
2011-07-26 18:16:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldDeleted != null) OnFieldDeleted(row.Name);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User selects a cell for editing
|
|
|
|
private void fieldslist_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
|
|
|
|
{
|
|
|
|
// Field name cell?
|
|
|
|
if(e.ColumnIndex == 0)
|
|
|
|
{
|
|
|
|
// New row index?
|
|
|
|
if(e.RowIndex == fieldslist.NewRowIndex)
|
|
|
|
{
|
|
|
|
// Remove all text
|
|
|
|
fieldslist.Rows[e.RowIndex].Cells[0].Style.ForeColor = SystemColors.WindowText;
|
2016-02-08 21:51:03 +00:00
|
|
|
fieldslist.Rows[e.RowIndex].Cells[0].Value = (autoinsertuserprefix ? FIELD_PREFIX_SUGGESTION : string.Empty);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Value cell?
|
|
|
|
else if(e.ColumnIndex == 2)
|
|
|
|
{
|
|
|
|
// Get the row
|
|
|
|
DataGridViewRow row = fieldslist.Rows[e.RowIndex];
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
// Get specializedrow
|
2015-12-28 15:01:53 +00:00
|
|
|
FieldsEditorRow frow = row as FieldsEditorRow;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Enumerable?
|
|
|
|
if(frow.TypeHandler.IsEnumerable)
|
|
|
|
{
|
|
|
|
// Fill combo with enums
|
|
|
|
enumscombo.SelectedItem = null;
|
|
|
|
enumscombo.Text = "";
|
|
|
|
enumscombo.Items.Clear();
|
|
|
|
enumscombo.Items.AddRange(frow.TypeHandler.GetEnumList().ToArray());
|
|
|
|
enumscombo.Tag = frow;
|
|
|
|
|
|
|
|
// Lock combo to enums?
|
|
|
|
if(frow.TypeHandler.IsLimitedToEnums)
|
|
|
|
enumscombo.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
|
|
else
|
|
|
|
enumscombo.DropDownStyle = ComboBoxStyle.DropDown;
|
|
|
|
|
|
|
|
// Position combobox
|
|
|
|
Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false);
|
|
|
|
enumscombo.Location = new Point(cellrect.Left, cellrect.Top);
|
|
|
|
enumscombo.Width = cellrect.Width;
|
|
|
|
int internalheight = cellrect.Height - (enumscombo.Height - enumscombo.ClientRectangle.Height) - 6;
|
|
|
|
General.SendMessage(enumscombo.Handle, General.CB_SETITEMHEIGHT, -1, internalheight);
|
|
|
|
|
|
|
|
// Select the value of this field (for DropDownList style combo)
|
|
|
|
foreach(EnumItem i in enumscombo.Items)
|
|
|
|
{
|
|
|
|
// Matches?
|
2016-02-01 22:04:00 +00:00
|
|
|
if(string.Compare(i.Title, frow.TypeHandler.GetStringValue(), StringComparison.OrdinalIgnoreCase) == 0)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Select this item
|
|
|
|
enumscombo.SelectedItem = i;
|
2016-02-01 22:04:00 +00:00
|
|
|
break; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the display text in the text (for DropDown style combo)
|
|
|
|
enumscombo.Text = frow.TypeHandler.GetStringValue();
|
|
|
|
|
|
|
|
// Show combo
|
|
|
|
enumscombo.Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done editing cell contents
|
|
|
|
private void fieldslist_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = null;
|
2014-02-21 14:42:12 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Get the row
|
2014-02-21 14:42:12 +00:00
|
|
|
DataGridViewRow row = fieldslist.Rows[e.RowIndex];
|
2009-04-19 18:07:22 +00:00
|
|
|
if(row is FieldsEditorRow) frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Renaming a field?
|
|
|
|
if(e.ColumnIndex == 0)
|
|
|
|
{
|
|
|
|
// Row is a new row?
|
|
|
|
if(frow == null)
|
|
|
|
{
|
|
|
|
// Name given?
|
|
|
|
if((row.Cells[0].Value != null) && (row.Cells[0].Value.ToString() != FIELD_PREFIX_SUGGESTION))
|
|
|
|
{
|
|
|
|
// Make a valid UDMF field name
|
|
|
|
string validname = UniValue.ValidateName(row.Cells[0].Value.ToString());
|
2013-09-16 13:41:00 +00:00
|
|
|
if(validname.Length > 0)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 23:15:26 +00:00
|
|
|
if(uifields.ContainsKey(validname)) //mxd
|
|
|
|
{
|
2013-09-16 13:41:00 +00:00
|
|
|
MessageBox.Show("Please set this field's value via user interface.");
|
2014-12-03 23:15:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-16 13:41:00 +00:00
|
|
|
// Check if no other row already has this name
|
2015-12-28 15:01:53 +00:00
|
|
|
foreach(DataGridViewRow r in fieldslist.Rows)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2013-09-16 13:41:00 +00:00
|
|
|
// Name matches and not the same row?
|
2015-12-28 15:01:53 +00:00
|
|
|
if((r.Index != row.Index) && (r.Cells.Count > 0) && (r.Cells[0].Value != null) &&
|
2014-12-03 23:15:26 +00:00
|
|
|
(r.Cells[0].Value.ToString().ToLowerInvariant() == validname))
|
|
|
|
{
|
2013-09-16 13:41:00 +00:00
|
|
|
// Cannot have two rows with same name
|
|
|
|
validname = "";
|
|
|
|
General.ShowWarningMessage("Fields must have unique names!", MessageBoxButtons.OK);
|
|
|
|
break;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 13:41:00 +00:00
|
|
|
// Still valid?
|
2015-12-28 15:01:53 +00:00
|
|
|
if(validname.Length > 0)
|
2013-09-16 13:41:00 +00:00
|
|
|
{
|
|
|
|
// Try to find the type in the map options
|
|
|
|
int type = General.Map.Options.GetUniversalFieldType(elementname, validname, 0);
|
|
|
|
|
|
|
|
// Make new row
|
2016-02-08 21:51:03 +00:00
|
|
|
frow = new FieldsEditorRow(fieldslist, validname, type, null, false);
|
2013-09-16 13:41:00 +00:00
|
|
|
frow.Visible = false;
|
|
|
|
fieldslist.Rows.Insert(e.RowIndex + 1, frow);
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldInserted != null) OnFieldInserted(validname);
|
2013-09-16 13:41:00 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the row for delete
|
|
|
|
row.ReadOnly = true;
|
|
|
|
deleterowstimer.Start();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Name given?
|
|
|
|
if(row.Cells[0].Value != null)
|
|
|
|
{
|
|
|
|
// Make a valid UDMF field name
|
|
|
|
string validname = UniValue.ValidateName(row.Cells[0].Value.ToString());
|
2013-08-10 11:28:51 +00:00
|
|
|
if(validname.Length > 0 && !uifields.ContainsKey(validname)) //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Check if no other row already has this name
|
|
|
|
foreach(DataGridViewRow r in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
// Name matches and not the same row?
|
|
|
|
if((r.Index != row.Index) && (r.Cells.Count > 0) && (r.Cells[0].Value != null) &&
|
|
|
|
(r.Cells[0].Value.ToString().ToLowerInvariant() == validname))
|
|
|
|
{
|
|
|
|
// Cannot have two rows with same name
|
|
|
|
validname = "";
|
|
|
|
row.Cells[0].Value = lasteditfieldname;
|
|
|
|
General.ShowWarningMessage("Fields must have unique names!", MessageBoxButtons.OK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still valid?
|
|
|
|
if(validname.Length > 0)
|
|
|
|
{
|
|
|
|
// Try to find the type in the map options
|
|
|
|
int type = General.Map.Options.GetUniversalFieldType(elementname, validname, -1);
|
|
|
|
|
|
|
|
// Rename row and change type
|
|
|
|
row.Cells[0].Value = validname;
|
|
|
|
if(type != -1) frow.ChangeType(type);
|
2011-07-26 18:16:52 +00:00
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldNameChanged != null) OnFieldNameChanged(lasteditfieldname, validname);
|
|
|
|
if(OnFieldTypeChanged != null) OnFieldTypeChanged(validname);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Keep old name
|
|
|
|
row.Cells[0].Value = lasteditfieldname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Keep old name
|
|
|
|
row.Cells[0].Value = lasteditfieldname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Keep old name
|
|
|
|
row.Cells[0].Value = lasteditfieldname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-26 18:16:52 +00:00
|
|
|
// Changing field type?
|
|
|
|
if((e.ColumnIndex == 1) && (frow != null))
|
|
|
|
{
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldTypeChanged != null) OnFieldTypeChanged(frow.Name);
|
2011-07-26 18:16:52 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
// Changing field value?
|
|
|
|
if((e.ColumnIndex == 2) && (frow != null))
|
|
|
|
{
|
|
|
|
// Apply changes
|
|
|
|
ApplyValue(frow, row.Cells[2].Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updated
|
|
|
|
if(frow != null) frow.CellChanged();
|
|
|
|
|
|
|
|
// Update button
|
|
|
|
UpdateBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time to delete rows
|
|
|
|
private void deleterowstimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Stop timer
|
|
|
|
deleterowstimer.Stop();
|
|
|
|
|
|
|
|
// Delete all rows that must be deleted
|
|
|
|
for(int i = fieldslist.Rows.Count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if(fieldslist.Rows[i].ReadOnly)
|
2016-02-07 23:04:20 +00:00
|
|
|
{
|
|
|
|
try { fieldslist.Rows.RemoveAt(i); } catch { }
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
else
|
2016-02-07 23:04:20 +00:00
|
|
|
{
|
|
|
|
//mxd. Preserve fixed fields visibility setting
|
|
|
|
FieldsEditorRow frow = (fieldslist.Rows[i] as FieldsEditorRow);
|
2016-02-08 21:51:03 +00:00
|
|
|
if(frow != null && frow.RowType == FieldsEditorRowType.FIXED) frow.Visible = showfixedfields;
|
2016-02-07 23:04:20 +00:00
|
|
|
else fieldslist.Rows[i].Visible = true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update new row
|
|
|
|
SetupNewRowStyle();
|
|
|
|
|
|
|
|
// Update button
|
|
|
|
UpdateBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selection changes
|
|
|
|
private void fieldslist_SelectionChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
browsebutton.Visible = false;
|
|
|
|
ApplyEnums(true);
|
|
|
|
|
|
|
|
// Update button
|
|
|
|
UpdateBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Browse clicked
|
|
|
|
private void browsebutton_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Any row selected?
|
|
|
|
if(fieldslist.SelectedRows.Count > 0)
|
|
|
|
{
|
|
|
|
// Get selected row
|
|
|
|
DataGridViewRow row = fieldslist.SelectedRows[0];
|
|
|
|
if(row is FieldsEditorRow)
|
|
|
|
{
|
|
|
|
// Browse
|
|
|
|
(row as FieldsEditorRow).Browse(this.ParentForm);
|
2010-08-22 11:36:09 +00:00
|
|
|
fieldslist.Focus();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This handles field data errors
|
|
|
|
private void fieldslist_DataError(object sender, DataGridViewDataErrorEventArgs e)
|
|
|
|
{
|
|
|
|
// Ignore this, because we want to display values
|
|
|
|
// in the type column that are not in their combobox
|
|
|
|
e.ThrowException = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate value in enums combobox
|
|
|
|
private void enumscombo_Validating(object sender, CancelEventArgs e)
|
|
|
|
{
|
|
|
|
ApplyEnums(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scrolling
|
|
|
|
private void fieldslist_Scroll(object sender, ScrollEventArgs e)
|
|
|
|
{
|
|
|
|
// Stop any cell editing
|
|
|
|
ApplyEnums(true);
|
|
|
|
fieldslist.EndEdit();
|
|
|
|
HideBrowseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse up event
|
|
|
|
private void fieldslist_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
{
|
|
|
|
// Focus to enums combobox when visible
|
|
|
|
if(enumscombo.Visible)
|
|
|
|
{
|
|
|
|
enumscombo.Focus();
|
|
|
|
enumscombo.SelectAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Private Methods
|
|
|
|
|
|
|
|
// This applies a value to a row
|
|
|
|
private void ApplyValue(FieldsEditorRow frow, object value)
|
|
|
|
{
|
|
|
|
// Defined?
|
2016-02-08 21:51:03 +00:00
|
|
|
if((value != null) && (frow.RowType == FieldsEditorRowType.DYNAMIC || frow.RowType == FieldsEditorRowType.USERVAR
|
|
|
|
|| !frow.Info.Default.Equals(value)))
|
2011-07-26 18:16:52 +00:00
|
|
|
{
|
2009-04-19 18:07:22 +00:00
|
|
|
frow.Define(value);
|
2011-07-26 18:16:52 +00:00
|
|
|
}
|
2016-02-08 21:51:03 +00:00
|
|
|
else if(frow.RowType == FieldsEditorRowType.FIXED)
|
2011-07-26 18:16:52 +00:00
|
|
|
{
|
2009-04-19 18:07:22 +00:00
|
|
|
frow.Undefine();
|
2011-07-26 18:16:52 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 21:51:03 +00:00
|
|
|
if(OnFieldValueChanged != null) OnFieldValueChanged(frow.Name);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the contents of the enums combobox and hides (if opened)
|
|
|
|
private void ApplyEnums(bool hide)
|
|
|
|
{
|
|
|
|
// Enums combobox shown?
|
|
|
|
if((enumscombo.Visible) && (enumscombo.Tag is FieldsEditorRow))
|
|
|
|
{
|
|
|
|
// Get the row
|
|
|
|
FieldsEditorRow frow = (enumscombo.Tag as FieldsEditorRow);
|
|
|
|
|
|
|
|
// Take the selected value and apply it
|
|
|
|
ApplyValue(frow, enumscombo.Text);
|
|
|
|
|
|
|
|
// Updated
|
|
|
|
frow.CellChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hide)
|
|
|
|
{
|
|
|
|
// Hide combobox
|
|
|
|
enumscombo.Tag = null;
|
|
|
|
enumscombo.Visible = false;
|
|
|
|
enumscombo.Items.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets up the new row
|
|
|
|
private void SetupNewRowStyle()
|
|
|
|
{
|
2011-07-26 18:16:52 +00:00
|
|
|
if(fieldslist.AllowUserToAddRows)
|
|
|
|
{
|
|
|
|
// Show text for new row
|
|
|
|
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Value = ADD_FIELD_TEXT;
|
|
|
|
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].Style.ForeColor = SystemColors.GrayText;
|
|
|
|
fieldslist.Rows[fieldslist.NewRowIndex].Cells[0].ReadOnly = false;
|
|
|
|
|
|
|
|
// Make sure user can only enter property name in a new row
|
|
|
|
fieldslist.Rows[fieldslist.NewRowIndex].Cells[1].ReadOnly = true;
|
|
|
|
fieldslist.Rows[fieldslist.NewRowIndex].Cells[2].ReadOnly = true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This hides the browse button
|
|
|
|
private void HideBrowseButton()
|
|
|
|
{
|
|
|
|
browsebutton.Visible = false;
|
|
|
|
}
|
|
|
|
|
2011-07-26 18:16:52 +00:00
|
|
|
// This updates the Value column width
|
|
|
|
private void UpdateValueColumn()
|
|
|
|
{
|
|
|
|
int fieldnamewidth = fieldname.Visible ? fieldname.Width : 0;
|
|
|
|
int fieldtypewidth = fieldtype.Visible ? fieldtype.Width : 0;
|
|
|
|
fieldvalue.Width = fieldslist.ClientRectangle.Width - fieldnamewidth - fieldtypewidth - SystemInformation.VerticalScrollBarWidth - 10;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This updates the button
|
|
|
|
private void UpdateBrowseButton()
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = null;
|
|
|
|
|
|
|
|
// Any row selected?
|
|
|
|
if(fieldslist.SelectedRows.Count > 0)
|
|
|
|
{
|
|
|
|
// Get selected row
|
2014-02-21 14:42:12 +00:00
|
|
|
DataGridViewRow row = fieldslist.SelectedRows[0];
|
2009-04-19 18:07:22 +00:00
|
|
|
if(row is FieldsEditorRow) frow = row as FieldsEditorRow;
|
|
|
|
|
|
|
|
// Not the new row and FieldsEditorRow available?
|
|
|
|
if((row.Index < fieldslist.NewRowIndex) && (frow != null))
|
|
|
|
{
|
|
|
|
// Browse button available for this type?
|
|
|
|
if(frow.TypeHandler.IsBrowseable && !frow.TypeHandler.IsEnumerable)
|
|
|
|
{
|
|
|
|
Rectangle cellrect = fieldslist.GetCellDisplayRectangle(2, row.Index, false);
|
|
|
|
|
|
|
|
// Show button
|
|
|
|
enumscombo.Visible = false;
|
2010-08-22 11:36:09 +00:00
|
|
|
browsebutton.Image = frow.TypeHandler.BrowseImage;
|
2009-04-19 18:07:22 +00:00
|
|
|
browsebutton.Location = new Point(cellrect.Right - browsebutton.Width, cellrect.Top);
|
|
|
|
browsebutton.Height = cellrect.Height;
|
|
|
|
browsebutton.Visible = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HideBrowseButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HideBrowseButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HideBrowseButton();
|
|
|
|
}
|
|
|
|
}
|
2016-02-07 23:04:20 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private void UpdateFixedFieldsVisibility()
|
|
|
|
{
|
|
|
|
foreach(var row in fieldslist.Rows)
|
|
|
|
{
|
|
|
|
FieldsEditorRow frow = (row as FieldsEditorRow);
|
2016-02-08 21:51:03 +00:00
|
|
|
if(frow != null && frow.RowType == FieldsEditorRowType.FIXED) frow.Visible = showfixedfields;
|
2016-02-07 23:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|