diff --git a/BizHawk.Client.Common/lua/LuaFunctionList.cs b/BizHawk.Client.Common/lua/LuaFunctionList.cs index cbaf9b1386..1bc0849b09 100644 --- a/BizHawk.Client.Common/lua/LuaFunctionList.cs +++ b/BizHawk.Client.Common/lua/LuaFunctionList.cs @@ -16,7 +16,15 @@ namespace BizHawk.Client.Common public void RemoveFunction(NamedLuaFunction function) { Global.Emulator.CoreComm.InputCallback.Remove(function.Callback); + Global.Emulator.CoreComm.MemoryCallbackSystem.Remove(function.Callback); Remove(function); } + + public void ClearAll() + { + Global.Emulator.CoreComm.InputCallback.RemoveAll(this.Select(x => x.Callback)); + Global.Emulator.CoreComm.MemoryCallbackSystem.RemoveAll(this.Select(x => x.Callback)); + Clear(); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.Designer.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.Designer.cs index 95bfbb77a3..936832d7de 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.Designer.cs @@ -28,133 +28,146 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LuaRegisteredFunctionsList)); - this.FunctionView = new System.Windows.Forms.ListView(); - this.FunctionsEvent = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.FunctionsName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.FunctionsGUID = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.OK = new System.Windows.Forms.Button(); - this.CallButton = new System.Windows.Forms.Button(); - this.RemoveButton = new System.Windows.Forms.Button(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.callToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.contextMenuStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // FunctionView - // - this.FunctionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LuaRegisteredFunctionsList)); + this.FunctionView = new System.Windows.Forms.ListView(); + this.FunctionsEvent = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.FunctionsName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.FunctionsGUID = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.OK = new System.Windows.Forms.Button(); + this.CallButton = new System.Windows.Forms.Button(); + this.RemoveButton = new System.Windows.Forms.Button(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.callToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.RemoveAllBtn = new System.Windows.Forms.Button(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // FunctionView + // + this.FunctionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.FunctionView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.FunctionView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.FunctionsEvent, this.FunctionsName, this.FunctionsGUID}); - this.FunctionView.FullRowSelect = true; - this.FunctionView.GridLines = true; - this.FunctionView.Location = new System.Drawing.Point(12, 12); - this.FunctionView.Name = "FunctionView"; - this.FunctionView.Size = new System.Drawing.Size(498, 266); - this.FunctionView.TabIndex = 3; - this.FunctionView.UseCompatibleStateImageBehavior = false; - this.FunctionView.View = System.Windows.Forms.View.Details; - this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged); - this.FunctionView.DoubleClick += new System.EventHandler(this.FunctionView_DoubleClick); - // - // FunctionsEvent - // - this.FunctionsEvent.Text = "Event"; - this.FunctionsEvent.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - this.FunctionsEvent.Width = 111; - // - // FunctionsName - // - this.FunctionsName.Text = "Name"; - this.FunctionsName.Width = 99; - // - // FunctionsGUID - // - this.FunctionsGUID.Text = "Guid"; - this.FunctionsGUID.Width = 284; - // - // OK - // - this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.OK.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.OK.Location = new System.Drawing.Point(435, 284); - this.OK.Name = "OK"; - this.OK.Size = new System.Drawing.Size(75, 23); - this.OK.TabIndex = 2; - this.OK.Text = "&Ok"; - this.OK.UseVisualStyleBackColor = true; - this.OK.Click += new System.EventHandler(this.OK_Click); - // - // CallButton - // - this.CallButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.CallButton.Enabled = false; - this.CallButton.Location = new System.Drawing.Point(12, 284); - this.CallButton.Name = "CallButton"; - this.CallButton.Size = new System.Drawing.Size(75, 23); - this.CallButton.TabIndex = 4; - this.CallButton.Text = "&Call"; - this.CallButton.UseVisualStyleBackColor = true; - this.CallButton.Click += new System.EventHandler(this.CallButton_Click); - // - // RemoveButton - // - this.RemoveButton.Enabled = false; - this.RemoveButton.Location = new System.Drawing.Point(93, 284); - this.RemoveButton.Name = "RemoveButton"; - this.RemoveButton.Size = new System.Drawing.Size(75, 23); - this.RemoveButton.TabIndex = 5; - this.RemoveButton.Text = "&Remove"; - this.RemoveButton.UseVisualStyleBackColor = true; - this.RemoveButton.Click += new System.EventHandler(this.RemoveButton_Click); - // - // contextMenuStrip1 - // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.FunctionView.FullRowSelect = true; + this.FunctionView.GridLines = true; + this.FunctionView.Location = new System.Drawing.Point(12, 12); + this.FunctionView.Name = "FunctionView"; + this.FunctionView.Size = new System.Drawing.Size(498, 266); + this.FunctionView.TabIndex = 3; + this.FunctionView.UseCompatibleStateImageBehavior = false; + this.FunctionView.View = System.Windows.Forms.View.Details; + this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged); + this.FunctionView.DoubleClick += new System.EventHandler(this.FunctionView_DoubleClick); + // + // FunctionsEvent + // + this.FunctionsEvent.Text = "Event"; + this.FunctionsEvent.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.FunctionsEvent.Width = 111; + // + // FunctionsName + // + this.FunctionsName.Text = "Name"; + this.FunctionsName.Width = 99; + // + // FunctionsGUID + // + this.FunctionsGUID.Text = "Guid"; + this.FunctionsGUID.Width = 284; + // + // OK + // + this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.OK.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.OK.Location = new System.Drawing.Point(435, 284); + this.OK.Name = "OK"; + this.OK.Size = new System.Drawing.Size(75, 23); + this.OK.TabIndex = 2; + this.OK.Text = "&Ok"; + this.OK.UseVisualStyleBackColor = true; + this.OK.Click += new System.EventHandler(this.OK_Click); + // + // CallButton + // + this.CallButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.CallButton.Enabled = false; + this.CallButton.Location = new System.Drawing.Point(12, 284); + this.CallButton.Name = "CallButton"; + this.CallButton.Size = new System.Drawing.Size(75, 23); + this.CallButton.TabIndex = 4; + this.CallButton.Text = "&Call"; + this.CallButton.UseVisualStyleBackColor = true; + this.CallButton.Click += new System.EventHandler(this.CallButton_Click); + // + // RemoveButton + // + this.RemoveButton.Enabled = false; + this.RemoveButton.Location = new System.Drawing.Point(93, 284); + this.RemoveButton.Name = "RemoveButton"; + this.RemoveButton.Size = new System.Drawing.Size(75, 23); + this.RemoveButton.TabIndex = 5; + this.RemoveButton.Text = "&Remove"; + this.RemoveButton.UseVisualStyleBackColor = true; + this.RemoveButton.Click += new System.EventHandler(this.RemoveButton_Click); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.callToolStripMenuItem, this.removeToolStripMenuItem}); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(118, 48); - // - // callToolStripMenuItem - // - this.callToolStripMenuItem.Name = "callToolStripMenuItem"; - this.callToolStripMenuItem.Size = new System.Drawing.Size(152, 22); - this.callToolStripMenuItem.Text = "&Call"; - this.callToolStripMenuItem.Click += new System.EventHandler(this.CallButton_Click); - // - // removeToolStripMenuItem - // - this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; - this.removeToolStripMenuItem.Size = new System.Drawing.Size(117, 22); - this.removeToolStripMenuItem.Text = "&Remove"; - this.removeToolStripMenuItem.Click += new System.EventHandler(this.RemoveButton_Click); - // - // LuaRegisteredFunctionsList - // - this.AcceptButton = this.OK; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this.OK; - this.ClientSize = new System.Drawing.Size(521, 319); - this.Controls.Add(this.RemoveButton); - this.Controls.Add(this.CallButton); - this.Controls.Add(this.FunctionView); - this.Controls.Add(this.OK); - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MinimumSize = new System.Drawing.Size(200, 50); - this.Name = "LuaRegisteredFunctionsList"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Active Registered Functions"; - this.Load += new System.EventHandler(this.LuaRegisteredFunctionsList_Load); - this.contextMenuStrip1.ResumeLayout(false); - this.ResumeLayout(false); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(118, 48); + // + // callToolStripMenuItem + // + this.callToolStripMenuItem.Name = "callToolStripMenuItem"; + this.callToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.callToolStripMenuItem.Text = "&Call"; + this.callToolStripMenuItem.Click += new System.EventHandler(this.CallButton_Click); + // + // removeToolStripMenuItem + // + this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; + this.removeToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.removeToolStripMenuItem.Text = "&Remove"; + this.removeToolStripMenuItem.Click += new System.EventHandler(this.RemoveButton_Click); + // + // RemoveAllBtn + // + this.RemoveAllBtn.Enabled = false; + this.RemoveAllBtn.Location = new System.Drawing.Point(174, 284); + this.RemoveAllBtn.Name = "RemoveAllBtn"; + this.RemoveAllBtn.Size = new System.Drawing.Size(75, 23); + this.RemoveAllBtn.TabIndex = 6; + this.RemoveAllBtn.Text = "Remove &All"; + this.RemoveAllBtn.UseVisualStyleBackColor = true; + this.RemoveAllBtn.Click += new System.EventHandler(this.RemoveAllBtn_Click); + // + // LuaRegisteredFunctionsList + // + this.AcceptButton = this.OK; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.OK; + this.ClientSize = new System.Drawing.Size(521, 319); + this.Controls.Add(this.RemoveAllBtn); + this.Controls.Add(this.RemoveButton); + this.Controls.Add(this.CallButton); + this.Controls.Add(this.FunctionView); + this.Controls.Add(this.OK); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MinimumSize = new System.Drawing.Size(200, 50); + this.Name = "LuaRegisteredFunctionsList"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Active Registered Functions"; + this.Load += new System.EventHandler(this.LuaRegisteredFunctionsList_Load); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); } @@ -170,5 +183,6 @@ private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem callToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; + private System.Windows.Forms.Button RemoveAllBtn; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs index 12dfd08d99..e92d6abf42 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaRegisteredFunctionsList.cs @@ -40,6 +40,8 @@ namespace BizHawk.Client.EmuHawk item.SubItems.Add(nlf.GUID.ToString()); FunctionView.Items.Add(item); } + + DoButtonsStatus(); } private void CallButton_Click(object sender, EventArgs e) @@ -74,14 +76,26 @@ namespace BizHawk.Client.EmuHawk private void FunctionView_SelectedIndexChanged(object sender, EventArgs e) { - ListView.SelectedIndexCollection indexes = FunctionView.SelectedIndices; - CallButton.Enabled = indexes.Count > 0; - RemoveButton.Enabled = indexes.Count > 0; + DoButtonsStatus(); } private void FunctionView_DoubleClick(object sender, EventArgs e) { CallFunction(); } + + private void RemoveAllBtn_Click(object sender, EventArgs e) + { + GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.ClearAll(); + PopulateListView(); + } + + private void DoButtonsStatus() + { + ListView.SelectedIndexCollection indexes = FunctionView.SelectedIndices; + CallButton.Enabled = indexes.Count > 0; + RemoveButton.Enabled = indexes.Count > 0; + RemoveAllBtn.Enabled = GlobalWin.Tools.LuaConsole.LuaImp.RegisteredFunctions.Any(); + } } } diff --git a/BizHawk.Emulation.Common/Interfaces/CoreComms.cs b/BizHawk.Emulation.Common/Interfaces/CoreComms.cs index dcc34e6c3e..70c5de1b00 100644 --- a/BizHawk.Emulation.Common/Interfaces/CoreComms.cs +++ b/BizHawk.Emulation.Common/Interfaces/CoreComms.cs @@ -143,6 +143,14 @@ namespace BizHawk.Emulation.Common _list.Remove(action); } + public void RemoveAll(IEnumerable actions) + { + foreach (var action in actions) + { + _list.Remove(action); + } + } + public void Clear() { _list.Clear(); @@ -215,6 +223,14 @@ namespace BizHawk.Emulation.Common } } + public void RemoveAll(IEnumerable actions) + { + foreach (var action in actions) + { + Remove(action); + } + } + public void Clear() { _reads.Clear();