Lua Console - add a duplicate script menu and toolbar item, functions similarly to new script except it starts with the text from the highlighted script

This commit is contained in:
adelikat 2014-11-09 16:18:09 +00:00
parent 78b466ff78
commit 252ea85f99
2 changed files with 52 additions and 1 deletions

View File

@ -95,6 +95,7 @@
this.PauseToolbarItem = new System.Windows.Forms.ToolStripButton(); this.PauseToolbarItem = new System.Windows.Forms.ToolStripButton();
this.EditToolbarItem = new System.Windows.Forms.ToolStripButton(); this.EditToolbarItem = new System.Windows.Forms.ToolStripButton();
this.RemoveScriptToolbarItem = new System.Windows.Forms.ToolStripButton(); this.RemoveScriptToolbarItem = new System.Windows.Forms.ToolStripButton();
this.DuplicateToolbarButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.MoveUpToolbarItem = new System.Windows.Forms.ToolStripButton(); this.MoveUpToolbarItem = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonMoveDown = new System.Windows.Forms.ToolStripButton();
@ -104,6 +105,7 @@
this.LuaListView = new BizHawk.Client.EmuHawk.VirtualListView(); this.LuaListView = new BizHawk.Client.EmuHawk.VirtualListView();
this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.PathName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.PathName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.DuplicateScriptMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ScriptListContextMenu.SuspendLayout(); this.ScriptListContextMenu.SuspendLayout();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.ConsoleContextMenu.SuspendLayout(); this.ConsoleContextMenu.SuspendLayout();
@ -304,8 +306,9 @@
this.PauseScriptMenuItem, this.PauseScriptMenuItem,
this.EditScriptMenuItem, this.EditScriptMenuItem,
this.RemoveScriptMenuItem, this.RemoveScriptMenuItem,
this.InsertSeparatorMenuItem, this.DuplicateScriptMenuItem,
this.toolStripSeparator7, this.toolStripSeparator7,
this.InsertSeparatorMenuItem,
this.MoveUpMenuItem, this.MoveUpMenuItem,
this.MoveDownMenuItem, this.MoveDownMenuItem,
this.SelectAllMenuItem, this.SelectAllMenuItem,
@ -619,6 +622,7 @@
this.PauseToolbarItem, this.PauseToolbarItem,
this.EditToolbarItem, this.EditToolbarItem,
this.RemoveScriptToolbarItem, this.RemoveScriptToolbarItem,
this.DuplicateToolbarButton,
this.toolStripSeparator2, this.toolStripSeparator2,
this.MoveUpToolbarItem, this.MoveUpToolbarItem,
this.toolStripButtonMoveDown, this.toolStripButtonMoveDown,
@ -701,6 +705,16 @@
this.RemoveScriptToolbarItem.Text = "Remove Script"; this.RemoveScriptToolbarItem.Text = "Remove Script";
this.RemoveScriptToolbarItem.Click += new System.EventHandler(this.RemoveScriptMenuItem_Click); this.RemoveScriptToolbarItem.Click += new System.EventHandler(this.RemoveScriptMenuItem_Click);
// //
// DuplicateToolbarButton
//
this.DuplicateToolbarButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.DuplicateToolbarButton.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Duplicate;
this.DuplicateToolbarButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.DuplicateToolbarButton.Name = "DuplicateToolbarButton";
this.DuplicateToolbarButton.Size = new System.Drawing.Size(23, 22);
this.DuplicateToolbarButton.Text = "toolStripButton1";
this.DuplicateToolbarButton.Click += new System.EventHandler(this.DuplicateScriptMenuItem_Click);
//
// toolStripSeparator2 // toolStripSeparator2
// //
this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Name = "toolStripSeparator2";
@ -774,6 +788,7 @@
this.LuaListView.Size = new System.Drawing.Size(291, 255); this.LuaListView.Size = new System.Drawing.Size(291, 255);
this.LuaListView.TabIndex = 0; this.LuaListView.TabIndex = 0;
this.LuaListView.UseCompatibleStateImageBehavior = false; this.LuaListView.UseCompatibleStateImageBehavior = false;
this.LuaListView.UseCustomBackground = true;
this.LuaListView.View = System.Windows.Forms.View.Details; this.LuaListView.View = System.Windows.Forms.View.Details;
this.LuaListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.LuaListView_ColumnClick); this.LuaListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.LuaListView_ColumnClick);
this.LuaListView.ItemActivate += new System.EventHandler(this.LuaListView_ItemActivate); this.LuaListView.ItemActivate += new System.EventHandler(this.LuaListView_ItemActivate);
@ -789,6 +804,13 @@
this.PathName.Text = "Path"; this.PathName.Text = "Path";
this.PathName.Width = 195; this.PathName.Width = 195;
// //
// DuplicateScriptMenuItem
//
this.DuplicateScriptMenuItem.Name = "DuplicateScriptMenuItem";
this.DuplicateScriptMenuItem.Size = new System.Drawing.Size(218, 22);
this.DuplicateScriptMenuItem.Text = "&Duplicate Script";
this.DuplicateScriptMenuItem.Click += new System.EventHandler(this.DuplicateScriptMenuItem_Click);
//
// LuaConsole // LuaConsole
// //
this.AllowDrop = true; this.AllowDrop = true;
@ -898,5 +920,7 @@
private System.Windows.Forms.ToolStripMenuItem RefreshScriptMenuItem; private System.Windows.Forms.ToolStripMenuItem RefreshScriptMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator10; private System.Windows.Forms.ToolStripSeparator toolStripSeparator10;
private System.Windows.Forms.ToolStripButton EraseToolbarItem; private System.Windows.Forms.ToolStripButton EraseToolbarItem;
private System.Windows.Forms.ToolStripButton DuplicateToolbarButton;
private System.Windows.Forms.ToolStripMenuItem DuplicateScriptMenuItem;
} }
} }

View File

@ -648,6 +648,7 @@ namespace BizHawk.Client.EmuHawk
SelectedFiles.Any(); SelectedFiles.Any();
RemoveScriptMenuItem.Enabled = RemoveScriptMenuItem.Enabled =
DuplicateScriptMenuItem.Enabled =
MoveUpMenuItem.Enabled = MoveUpMenuItem.Enabled =
MoveDownMenuItem.Enabled = MoveDownMenuItem.Enabled =
LuaListView.SelectedIndices().Any(); LuaListView.SelectedIndices().Any();
@ -777,6 +778,32 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private void DuplicateScriptMenuItem_Click(object sender, EventArgs e)
{
if (LuaListView.SelectedIndices().Any())
{
var script = SelectedFiles.First();
var sfd = new SaveFileDialog
{
InitialDirectory = Path.GetDirectoryName(script.Path),
DefaultExt = ".lua",
FileName = Path.GetFileNameWithoutExtension(script.Path) + " (1)",
OverwritePrompt = true,
Filter = "Lua Scripts (*.lua)|*.lua|All Files (*.*)|*.*"
};
if (sfd.ShowDialog() == DialogResult.OK)
{
string text = File.ReadAllText(script.Path);
File.WriteAllText(sfd.FileName, text);
_luaList.Add(new LuaFile(Path.GetFileNameWithoutExtension(sfd.FileName), sfd.FileName));
UpdateDialog();
System.Diagnostics.Process.Start(sfd.FileName);
}
}
}
private void InsertSeparatorMenuItem_Click(object sender, EventArgs e) private void InsertSeparatorMenuItem_Click(object sender, EventArgs e)
{ {
var indices = LuaListView.SelectedIndices().ToList(); var indices = LuaListView.SelectedIndices().ToList();