add more stuff for stability

This commit is contained in:
Bitl 2021-08-30 18:04:32 -07:00
parent 59c7480e4c
commit 85d47a76b4
3 changed files with 183 additions and 170 deletions

View File

@ -26,7 +26,6 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(XMLContentEditor));
this.XMLStrip = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -34,26 +33,28 @@
this.contentProvidersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.partColorsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.insetRowAtSelectedRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteSelectedRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.XMLView = new System.Windows.Forms.DataGridView();
this.XMLContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.insertRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteRowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.XMLStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.XMLView)).BeginInit();
this.XMLContextMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// XMLStrip
//
this.XMLStrip.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.XMLStrip.AutoSize = false;
this.XMLStrip.BackColor = System.Drawing.Color.Transparent;
this.XMLStrip.Dock = System.Windows.Forms.DockStyle.None;
this.XMLStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.XMLStrip.Location = new System.Drawing.Point(0, 0);
this.fileToolStripMenuItem,
this.editToolStripMenuItem});
this.XMLStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.XMLStrip.Location = new System.Drawing.Point(0, -1);
this.XMLStrip.Name = "XMLStrip";
this.XMLStrip.Size = new System.Drawing.Size(45, 24);
this.XMLStrip.Size = new System.Drawing.Size(800, 22);
this.XMLStrip.TabIndex = 29;
this.XMLStrip.Text = "menuStrip1";
//
@ -63,7 +64,7 @@
this.loadToolStripMenuItem,
this.saveToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 18);
this.fileToolStripMenuItem.Text = "File";
//
// loadToolStripMenuItem
@ -96,6 +97,29 @@
this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.insetRowAtSelectedRowToolStripMenuItem,
this.deleteSelectedRowToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 18);
this.editToolStripMenuItem.Text = "Edit";
//
// insetRowAtSelectedRowToolStripMenuItem
//
this.insetRowAtSelectedRowToolStripMenuItem.Name = "insetRowAtSelectedRowToolStripMenuItem";
this.insetRowAtSelectedRowToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.insetRowAtSelectedRowToolStripMenuItem.Text = "Insert Row at Selected Row";
this.insetRowAtSelectedRowToolStripMenuItem.Click += new System.EventHandler(this.insertRowToolStripMenuItem_Click);
//
// deleteSelectedRowToolStripMenuItem
//
this.deleteSelectedRowToolStripMenuItem.Name = "deleteSelectedRowToolStripMenuItem";
this.deleteSelectedRowToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
this.deleteSelectedRowToolStripMenuItem.Text = "Delete Selected Row";
this.deleteSelectedRowToolStripMenuItem.Click += new System.EventHandler(this.deleteRowToolStripMenuItem_Click);
//
// XMLView
//
this.XMLView.AllowUserToOrderColumns = true;
@ -111,31 +135,8 @@
this.XMLView.Name = "XMLView";
this.XMLView.Size = new System.Drawing.Size(800, 426);
this.XMLView.TabIndex = 30;
this.XMLView.CellMouseUp += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.XMLView_CellMouseUp);
this.XMLView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.XMLView_MouseClick);
//
// XMLContextMenuStrip
//
this.XMLContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.insertRowToolStripMenuItem,
this.deleteRowToolStripMenuItem});
this.XMLContextMenuStrip.Name = "contextMenuStrip1";
this.XMLContextMenuStrip.Size = new System.Drawing.Size(134, 48);
//
// insertRowToolStripMenuItem
//
this.insertRowToolStripMenuItem.Name = "insertRowToolStripMenuItem";
this.insertRowToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.insertRowToolStripMenuItem.Text = "Insert Row";
this.insertRowToolStripMenuItem.Click += new System.EventHandler(this.insertRowToolStripMenuItem_Click);
//
// deleteRowToolStripMenuItem
//
this.deleteRowToolStripMenuItem.Name = "deleteRowToolStripMenuItem";
this.deleteRowToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.deleteRowToolStripMenuItem.Text = "Delete Row";
this.deleteRowToolStripMenuItem.Click += new System.EventHandler(this.deleteRowToolStripMenuItem_Click);
//
// XMLContentEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -148,12 +149,11 @@
this.MinimumSize = new System.Drawing.Size(340, 210);
this.Name = "XMLContentEditor";
this.Text = "XML Content Editor";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.XMLContentEditor_OnClosing);
this.XMLStrip.ResumeLayout(false);
this.XMLStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.XMLView)).EndInit();
this.XMLContextMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
@ -165,7 +165,7 @@
private System.Windows.Forms.ToolStripMenuItem partColorsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
private System.Windows.Forms.DataGridView XMLView;
private System.Windows.Forms.ContextMenuStrip XMLContextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem insertRowToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteRowToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem insetRowAtSelectedRowToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteSelectedRowToolStripMenuItem;
}

View File

@ -24,7 +24,6 @@ public partial class XMLContentEditor : Form
public Provider[] contentProviders;
List<object> loaderList = new List<object>();
XMLContentType ListType;
private int rowIndex = 0;
#endregion
#region Constructor
@ -47,10 +46,155 @@ public partial class XMLContentEditor : Form
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (XMLView.CurrentCell.IsInEditMode)
SaveXML();
}
private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (XMLView.Rows.Count == 0)
{
return;
}
if (!XMLView.Rows[XMLView.CurrentCell.RowIndex].IsNewRow)
{
XMLView.Rows.RemoveAt(XMLView.CurrentCell.RowIndex);
}
}
private void insertRowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (XMLView.Rows.Count == 0)
{
return;
}
if (!XMLView.Rows[XMLView.CurrentCell.RowIndex].IsNewRow)
{
XMLView.Rows.Insert(XMLView.CurrentCell.RowIndex, 1);
}
}
//https://stackoverflow.com/questions/14431936/how-to-force-datagridviewcell-to-end-edit-when-row-header-is-clicked/14498870
private void XMLView_MouseClick(object sender, MouseEventArgs e)
{
if (XMLView.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.RowHeader)
{
XMLView.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
XMLView.EndEdit();
}
else
{
XMLView.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
private void XMLContentEditor_OnClosing(object sender, FormClosingEventArgs e)
{
DialogResult res = MessageBox.Show("This file may have unsaved changes. Would you like to save?", "XML Content Editor - Save Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
switch (res)
{
case DialogResult.Yes:
SaveXML();
break;
case DialogResult.Cancel:
e.Cancel = true;
break;
case DialogResult.No:
default:
break;
}
}
#endregion
#region Functions
private void LoadXML(XMLContentType type)
{
loaderList.Clear();
switch (type)
{
case XMLContentType.ContentProviders:
if (File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ContentProviderXMLName))
{
contentProviders = OnlineClothing.GetContentProviders();
}
else
{
MessageBox.Show("Cannot load the Content Provider list because the Content Provider XML file does not exist", "XML Content Editor - Content Provider Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
loaderList.AddRange(contentProviders);
break;
case XMLContentType.PartColors:
if (File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.PartColorXMLName))
{
PartColorList = PartColorLoader.GetPartColors();
}
else
{
MessageBox.Show("Cannot load the Part Color list because the Part Color XML file does not exist", "XML Content Editor - Part Color Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
loaderList.AddRange(PartColorList);
break;
default:
break;
}
XMLView.Rows.Clear();
XMLView.Columns.Clear();
if (loaderList.Count > 0)
{
if (loaderList.OfType<Provider>().Any())
{
XMLView.ColumnCount = 3;
XMLView.Columns[0].Name = "Name";
XMLView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[1].Name = "URL";
XMLView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[2].Name = "Icon File";
XMLView.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
ListType = XMLContentType.ContentProviders;
}
else if (loaderList.OfType<PartColor>().Any())
{
XMLView.ColumnCount = 3;
XMLView.Columns[0].Name = "Name";
XMLView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[1].Name = "ID";
XMLView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[2].Name = "RGB Value";
XMLView.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
ListType = XMLContentType.PartColors;
}
foreach (var obj in loaderList)
{
if (obj is Provider)
{
Provider pro = obj as Provider;
string[] providerRow = new string[] { pro.Name, pro.URL, pro.Icon };
XMLView.Rows.Add(providerRow);
}
else if (obj is PartColor)
{
PartColor pc = obj as PartColor;
string[] partColorRow = new string[] { pc.ColorName, pc.ColorID.ToString(), pc.ColorRGB };
XMLView.Rows.Add(partColorRow);
}
}
}
else
{
MessageBox.Show("Unable to load XML file information because no information exists in the XML file.", "XML Content Editor - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SaveXML()
{
XMLView.EndEdit();
//https://stackoverflow.com/questions/37145086/datagridview-remove-empty-rows-button
for (int i = XMLView.Rows.Count - 1; i > -1; i--)
@ -149,134 +293,6 @@ public partial class XMLContentEditor : Form
LoadXML(ListType);
}
//http://csharp.net-informations.com/datagridview/deletegridview.htm
private void XMLView_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right && !XMLView.CurrentCell.IsInEditMode)
{
XMLView.Rows[e.RowIndex].Selected = true;
rowIndex = e.RowIndex;
XMLView.CurrentCell = XMLView.Rows[e.RowIndex].Cells[1];
XMLContextMenuStrip.Show(Cursor.Position);
}
}
private void deleteRowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!XMLView.Rows[rowIndex].IsNewRow)
{
XMLView.Rows.RemoveAt(rowIndex);
}
}
private void insertRowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!XMLView.Rows[rowIndex].IsNewRow)
{
XMLView.Rows.Insert(rowIndex, 1);
}
}
//https://stackoverflow.com/questions/14431936/how-to-force-datagridviewcell-to-end-edit-when-row-header-is-clicked/14498870
private void XMLView_MouseClick(object sender, MouseEventArgs e)
{
if (XMLView.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.RowHeader)
{
XMLView.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
XMLView.EndEdit();
}
else
{
XMLView.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
#endregion
#region Functions
private void LoadXML(XMLContentType type)
{
loaderList.Clear();
switch (type)
{
case XMLContentType.ContentProviders:
if (File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ContentProviderXMLName))
{
contentProviders = OnlineClothing.GetContentProviders();
}
else
{
MessageBox.Show("Cannot load the Content Provider list because the Content Provider XML file does not exist", "XML Content Editor - Content Provider Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
loaderList.AddRange(contentProviders);
break;
case XMLContentType.PartColors:
if (File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.PartColorXMLName))
{
PartColorList = PartColorLoader.GetPartColors();
}
else
{
MessageBox.Show("Cannot load the Part Color list because the Part Color XML file does not exist", "XML Content Editor - Part Color Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
loaderList.AddRange(PartColorList);
break;
default:
break;
}
XMLView.Rows.Clear();
XMLView.Columns.Clear();
if (loaderList.Count > 0)
{
if (loaderList.OfType<Provider>().Any())
{
XMLView.ColumnCount = 3;
XMLView.Columns[0].Name = "Name";
XMLView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[1].Name = "URL";
XMLView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[2].Name = "Icon File";
XMLView.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
ListType = XMLContentType.ContentProviders;
}
else if (loaderList.OfType<PartColor>().Any())
{
XMLView.ColumnCount = 3;
XMLView.Columns[0].Name = "Name";
XMLView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[1].Name = "ID";
XMLView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
XMLView.Columns[2].Name = "RGB Value";
XMLView.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
ListType = XMLContentType.PartColors;
}
foreach (var obj in loaderList)
{
if (obj is Provider)
{
Provider pro = obj as Provider;
string[] providerRow = new string[] { pro.Name, pro.URL, pro.Icon };
XMLView.Rows.Add(providerRow);
}
else if (obj is PartColor)
{
PartColor pc = obj as PartColor;
string[] partColorRow = new string[] { pc.ColorName, pc.ColorID.ToString(), pc.ColorRGB };
XMLView.Rows.Add(partColorRow);
}
}
}
else
{
MessageBox.Show("Unable to load XML file information because no information exists in the XML file.", "XML Content Editor - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//this is completely fucking dumb.
private string GenerateComment(string add)
{

View File

@ -120,9 +120,6 @@
<metadata name="XMLStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="XMLContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>118, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>