Allow text edits / saving

This commit is contained in:
Kurt 2018-11-17 12:08:31 -08:00
parent d780a03694
commit 6d5cfca1c4
4 changed files with 47 additions and 10 deletions

View File

@ -22,6 +22,8 @@ public void EditCommon()
var tc = new TextContainer(text, config);
var editor = new TextEditor(tc, TextEditor.TextEditorMode.Common);
editor.ShowDialog();
if (!editor.Modified)
text.CancelEdits();
}
public void EditScript()
@ -32,6 +34,8 @@ public void EditScript()
var tc = new TextContainer(text, config);
var editor = new TextEditor(tc, TextEditor.TextEditorMode.Script);
editor.ShowDialog();
if (!editor.Modified)
text.CancelEdits();
}
}
}

View File

@ -36,5 +36,15 @@ public string GetFileName(int i)
return Path.GetFileNameWithoutExtension(f.GetFileName(i));
return i.ToString();
}
public void Save()
{
for (int i = 0; i < Length; i++)
{
if (Cache[i] == null)
continue;
Container[i] = TextFile.GetBytes(Cache[i], Config, Remap);
}
}
}
}

View File

@ -251,7 +251,7 @@ private void B_RemoveLine_Click(object sender, EventArgs e)
dgv.Rows[i].Cells[0].Value = i.ToString();
}
private void TextEditor_FormClosing(object sender, FormClosingEventArgs e)
private void SaveCurrentFile()
{
// Save any pending edits
dgv.EndEdit();
@ -325,5 +325,15 @@ private void B_Randomize_Click(object sender, EventArgs e)
WinFormsUtil.Alert("Strings randomized!");
}
private void B_Save_Click(object sender, EventArgs e)
{
Modified = true;
SaveCurrentFile();
TextData.Save();
Close();
}
public bool Modified { get; set; }
}
}

View File

@ -36,6 +36,7 @@ private void InitializeComponent()
this.label1 = new System.Windows.Forms.Label();
this.B_Import = new System.Windows.Forms.Button();
this.B_Randomize = new System.Windows.Forms.Button();
this.B_Save = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit();
this.SuspendLayout();
//
@ -44,7 +45,7 @@ private void InitializeComponent()
this.CB_Entry.FormattingEnabled = true;
this.CB_Entry.Location = new System.Drawing.Point(68, 7);
this.CB_Entry.Name = "CB_Entry";
this.CB_Entry.Size = new System.Drawing.Size(175, 21);
this.CB_Entry.Size = new System.Drawing.Size(152, 21);
this.CB_Entry.TabIndex = 5;
this.CB_Entry.SelectedIndexChanged += new System.EventHandler(this.ChangeEntry);
//
@ -64,13 +65,13 @@ private void InitializeComponent()
this.dgv.RowHeadersVisible = false;
this.dgv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
this.dgv.ShowEditingIcon = false;
this.dgv.Size = new System.Drawing.Size(744, 331);
this.dgv.Size = new System.Drawing.Size(854, 367);
this.dgv.TabIndex = 0;
//
// B_AddLine
//
this.B_AddLine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.B_AddLine.Location = new System.Drawing.Point(570, 7);
this.B_AddLine.Location = new System.Drawing.Point(598, 5);
this.B_AddLine.Name = "B_AddLine";
this.B_AddLine.Size = new System.Drawing.Size(90, 23);
this.B_AddLine.TabIndex = 6;
@ -81,7 +82,7 @@ private void InitializeComponent()
// B_RemoveLine
//
this.B_RemoveLine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.B_RemoveLine.Location = new System.Drawing.Point(666, 7);
this.B_RemoveLine.Location = new System.Drawing.Point(694, 5);
this.B_RemoveLine.Name = "B_RemoveLine";
this.B_RemoveLine.Size = new System.Drawing.Size(90, 23);
this.B_RemoveLine.TabIndex = 7;
@ -91,7 +92,7 @@ private void InitializeComponent()
//
// B_Export
//
this.B_Export.Location = new System.Drawing.Point(249, 6);
this.B_Export.Location = new System.Drawing.Point(226, 7);
this.B_Export.Name = "B_Export";
this.B_Export.Size = new System.Drawing.Size(90, 23);
this.B_Export.TabIndex = 8;
@ -110,7 +111,7 @@ private void InitializeComponent()
//
// B_Import
//
this.B_Import.Location = new System.Drawing.Point(345, 6);
this.B_Import.Location = new System.Drawing.Point(317, 7);
this.B_Import.Name = "B_Import";
this.B_Import.Size = new System.Drawing.Size(90, 23);
this.B_Import.TabIndex = 10;
@ -120,7 +121,7 @@ private void InitializeComponent()
//
// B_Randomize
//
this.B_Randomize.Location = new System.Drawing.Point(441, 6);
this.B_Randomize.Location = new System.Drawing.Point(413, 7);
this.B_Randomize.Name = "B_Randomize";
this.B_Randomize.Size = new System.Drawing.Size(70, 23);
this.B_Randomize.TabIndex = 11;
@ -128,11 +129,23 @@ private void InitializeComponent()
this.B_Randomize.UseVisualStyleBackColor = true;
this.B_Randomize.Click += new System.EventHandler(this.B_Randomize_Click);
//
// B_Save
//
this.B_Save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.B_Save.Location = new System.Drawing.Point(790, 5);
this.B_Save.Name = "B_Save";
this.B_Save.Size = new System.Drawing.Size(76, 23);
this.B_Save.TabIndex = 12;
this.B_Save.Text = "Save";
this.B_Save.UseVisualStyleBackColor = true;
this.B_Save.Click += new System.EventHandler(this.B_Save_Click);
//
// TextEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(768, 376);
this.ClientSize = new System.Drawing.Size(878, 412);
this.Controls.Add(this.B_Save);
this.Controls.Add(this.B_Randomize);
this.Controls.Add(this.B_Import);
this.Controls.Add(this.label1);
@ -145,7 +158,6 @@ private void InitializeComponent()
this.Name = "TextEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Text Editor";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TextEditor_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -162,5 +174,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button B_Import;
private System.Windows.Forms.Button B_Randomize;
private System.Windows.Forms.Button B_Save;
}
}