From c0f0297c71486d2a53eb8b74375df50ac65948bb Mon Sep 17 00:00:00 2001 From: alcexhim Date: Thu, 4 Feb 2016 13:00:27 -0500 Subject: [PATCH] Provide context menu on tree view and list view for EXE sections to improve usability --- .../Executable/ExecutableEditor.Designer.cs | 164 +++++++++--------- .../Editors/Executable/ExecutableEditor.cs | 53 +++++- .../Editors/Executable/ExecutableEditor.resx | 6 +- 3 files changed, 131 insertions(+), 92 deletions(-) diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs index dcc3df3d..26cd3db8 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.Designer.cs @@ -31,27 +31,28 @@ this.components = new System.ComponentModel.Container(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.tv = new System.Windows.Forms.TreeView(); + this.mnuContextSections = new AwesomeControls.CommandBars.CBContextMenu(this.components); + this.mnuContextSectionsDelete = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuContextSectionsSep1 = new System.Windows.Forms.ToolStripSeparator(); + this.mnuContextSectionsImport = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuContextSectionsExport = new System.Windows.Forms.ToolStripMenuItem(); this.pnlSections = new System.Windows.Forms.Panel(); this.lvSections = new System.Windows.Forms.ListView(); this.chSectionName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chSectionOffset = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chSectionLength = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.mnuContextListViewSections = new AwesomeControls.CommandBars.CBContextMenu(this.components); - this.mnuContextListViewSectionsDelete = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuContextListViewSectionsSep1 = new System.Windows.Forms.ToolStripSeparator(); - this.mnuContextListViewSectionsImport = new System.Windows.Forms.ToolStripMenuItem(); - this.mnuContextListViewSectionsExport = new System.Windows.Forms.ToolStripMenuItem(); this.pnlSection = new System.Windows.Forms.Panel(); - this.lblSectionName = new System.Windows.Forms.Label(); - this.txtSectionName = new System.Windows.Forms.TextBox(); this.fraSectionCharacteristics = new System.Windows.Forms.GroupBox(); this.lvSectionCharacteristics = new System.Windows.Forms.ListView(); this.chTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.txtSectionName = new System.Windows.Forms.TextBox(); + this.lblSectionName = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + this.mnuContextSections.SuspendLayout(); this.pnlSections.SuspendLayout(); - this.mnuContextListViewSections.SuspendLayout(); this.pnlSection.SuspendLayout(); this.fraSectionCharacteristics.SuspendLayout(); this.SuspendLayout(); @@ -69,21 +70,61 @@ // // splitContainer1.Panel2 // - this.splitContainer1.Panel2.Controls.Add(this.pnlSection); this.splitContainer1.Panel2.Controls.Add(this.pnlSections); - this.splitContainer1.Size = new System.Drawing.Size(502, 247); + this.splitContainer1.Panel2.Controls.Add(this.pnlSection); + this.splitContainer1.Size = new System.Drawing.Size(590, 332); this.splitContainer1.SplitterDistance = 167; this.splitContainer1.TabIndex = 0; // // tv // + this.tv.ContextMenuStrip = this.mnuContextSections; this.tv.Dock = System.Windows.Forms.DockStyle.Fill; this.tv.HideSelection = false; this.tv.Location = new System.Drawing.Point(0, 0); this.tv.Name = "tv"; - this.tv.Size = new System.Drawing.Size(167, 247); + this.tv.Size = new System.Drawing.Size(167, 332); this.tv.TabIndex = 0; this.tv.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterSelect); + this.tv.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tv_MouseDown); + // + // mnuContextSections + // + this.mnuContextSections.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuContextSectionsDelete, + this.mnuContextSectionsSep1, + this.mnuContextSectionsImport, + this.mnuContextSectionsExport}); + this.mnuContextSections.Name = "mnuContextListViewSections"; + this.mnuContextSections.Size = new System.Drawing.Size(119, 76); + this.mnuContextSections.Opening += new System.ComponentModel.CancelEventHandler(this.mnuContextListViewSections_Opening); + // + // mnuContextSectionsDelete + // + this.mnuContextSectionsDelete.Name = "mnuContextSectionsDelete"; + this.mnuContextSectionsDelete.Size = new System.Drawing.Size(118, 22); + this.mnuContextSectionsDelete.Text = "&Delete"; + this.mnuContextSectionsDelete.Click += new System.EventHandler(this.mnuContextListViewSectionsDelete_Click); + // + // mnuContextSectionsSep1 + // + this.mnuContextSectionsSep1.Name = "mnuContextSectionsSep1"; + this.mnuContextSectionsSep1.Size = new System.Drawing.Size(115, 6); + // + // mnuContextSectionsImport + // + this.mnuContextSectionsImport.Name = "mnuContextSectionsImport"; + this.mnuContextSectionsImport.Size = new System.Drawing.Size(118, 22); + this.mnuContextSectionsImport.Text = "&Import..."; + this.mnuContextSectionsImport.Click += new System.EventHandler(this.mnuContextListViewSectionsImport_Click); + // + // mnuContextSectionsExport + // + this.mnuContextSectionsExport.Enabled = false; + this.mnuContextSectionsExport.Name = "mnuContextSectionsExport"; + this.mnuContextSectionsExport.Size = new System.Drawing.Size(118, 22); + this.mnuContextSectionsExport.Text = "&Export..."; + this.mnuContextSectionsExport.Click += new System.EventHandler(this.mnuContextListViewSectionsExport_Click); // // pnlSections // @@ -91,7 +132,7 @@ this.pnlSections.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlSections.Location = new System.Drawing.Point(0, 0); this.pnlSections.Name = "pnlSections"; - this.pnlSections.Size = new System.Drawing.Size(331, 247); + this.pnlSections.Size = new System.Drawing.Size(419, 332); this.pnlSections.TabIndex = 0; // // lvSections @@ -100,14 +141,14 @@ this.chSectionName, this.chSectionOffset, this.chSectionLength}); - this.lvSections.ContextMenuStrip = this.mnuContextListViewSections; + this.lvSections.ContextMenuStrip = this.mnuContextSections; this.lvSections.Dock = System.Windows.Forms.DockStyle.Fill; this.lvSections.FullRowSelect = true; this.lvSections.GridLines = true; this.lvSections.HideSelection = false; this.lvSections.Location = new System.Drawing.Point(0, 0); this.lvSections.Name = "lvSections"; - this.lvSections.Size = new System.Drawing.Size(331, 247); + this.lvSections.Size = new System.Drawing.Size(419, 332); this.lvSections.TabIndex = 0; this.lvSections.UseCompatibleStateImageBehavior = false; this.lvSections.View = System.Windows.Forms.View.Details; @@ -125,44 +166,6 @@ // this.chSectionLength.Text = "Length"; // - // mnuContextListViewSections - // - this.mnuContextListViewSections.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.mnuContextListViewSectionsDelete, - this.mnuContextListViewSectionsSep1, - this.mnuContextListViewSectionsImport, - this.mnuContextListViewSectionsExport}); - this.mnuContextListViewSections.Name = "mnuContextListViewSections"; - this.mnuContextListViewSections.Size = new System.Drawing.Size(119, 76); - this.mnuContextListViewSections.Opening += new System.ComponentModel.CancelEventHandler(this.mnuContextListViewSections_Opening); - // - // mnuContextListViewSectionsDelete - // - this.mnuContextListViewSectionsDelete.Name = "mnuContextListViewSectionsDelete"; - this.mnuContextListViewSectionsDelete.Size = new System.Drawing.Size(118, 22); - this.mnuContextListViewSectionsDelete.Text = "&Delete"; - this.mnuContextListViewSectionsDelete.Click += new System.EventHandler(this.mnuContextListViewSectionsDelete_Click); - // - // mnuContextListViewSectionsSep1 - // - this.mnuContextListViewSectionsSep1.Name = "mnuContextListViewSectionsSep1"; - this.mnuContextListViewSectionsSep1.Size = new System.Drawing.Size(115, 6); - // - // mnuContextListViewSectionsImport - // - this.mnuContextListViewSectionsImport.Name = "mnuContextListViewSectionsImport"; - this.mnuContextListViewSectionsImport.Size = new System.Drawing.Size(118, 22); - this.mnuContextListViewSectionsImport.Text = "&Import..."; - this.mnuContextListViewSectionsImport.Click += new System.EventHandler(this.mnuContextListViewSectionsImport_Click); - // - // mnuContextListViewSectionsExport - // - this.mnuContextListViewSectionsExport.Enabled = false; - this.mnuContextListViewSectionsExport.Name = "mnuContextListViewSectionsExport"; - this.mnuContextListViewSectionsExport.Size = new System.Drawing.Size(118, 22); - this.mnuContextListViewSectionsExport.Text = "&Export..."; - this.mnuContextListViewSectionsExport.Click += new System.EventHandler(this.mnuContextListViewSectionsExport_Click); - // // pnlSection // this.pnlSection.Controls.Add(this.fraSectionCharacteristics); @@ -171,27 +174,9 @@ this.pnlSection.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlSection.Location = new System.Drawing.Point(0, 0); this.pnlSection.Name = "pnlSection"; - this.pnlSection.Size = new System.Drawing.Size(331, 247); + this.pnlSection.Size = new System.Drawing.Size(419, 332); this.pnlSection.TabIndex = 1; // - // lblSectionName - // - this.lblSectionName.AutoSize = true; - this.lblSectionName.Location = new System.Drawing.Point(3, 6); - this.lblSectionName.Name = "lblSectionName"; - this.lblSectionName.Size = new System.Drawing.Size(75, 13); - this.lblSectionName.TabIndex = 0; - this.lblSectionName.Text = "Section &name:"; - // - // txtSectionName - // - this.txtSectionName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtSectionName.Location = new System.Drawing.Point(84, 3); - this.txtSectionName.Name = "txtSectionName"; - this.txtSectionName.Size = new System.Drawing.Size(244, 20); - this.txtSectionName.TabIndex = 1; - // // fraSectionCharacteristics // this.fraSectionCharacteristics.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -200,7 +185,7 @@ this.fraSectionCharacteristics.FlatStyle = System.Windows.Forms.FlatStyle.System; this.fraSectionCharacteristics.Location = new System.Drawing.Point(3, 29); this.fraSectionCharacteristics.Name = "fraSectionCharacteristics"; - this.fraSectionCharacteristics.Size = new System.Drawing.Size(325, 161); + this.fraSectionCharacteristics.Size = new System.Drawing.Size(413, 161); this.fraSectionCharacteristics.TabIndex = 2; this.fraSectionCharacteristics.TabStop = false; this.fraSectionCharacteristics.Text = "Characteristics"; @@ -218,7 +203,7 @@ this.lvSectionCharacteristics.HideSelection = false; this.lvSectionCharacteristics.Location = new System.Drawing.Point(6, 19); this.lvSectionCharacteristics.Name = "lvSectionCharacteristics"; - this.lvSectionCharacteristics.Size = new System.Drawing.Size(313, 136); + this.lvSectionCharacteristics.Size = new System.Drawing.Size(401, 136); this.lvSectionCharacteristics.TabIndex = 0; this.lvSectionCharacteristics.UseCompatibleStateImageBehavior = false; this.lvSectionCharacteristics.View = System.Windows.Forms.View.Details; @@ -228,18 +213,37 @@ this.chTitle.Text = "Characteristic"; this.chTitle.Width = 300; // + // txtSectionName + // + this.txtSectionName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtSectionName.Location = new System.Drawing.Point(84, 3); + this.txtSectionName.Name = "txtSectionName"; + this.txtSectionName.Size = new System.Drawing.Size(332, 20); + this.txtSectionName.TabIndex = 1; + // + // lblSectionName + // + this.lblSectionName.AutoSize = true; + this.lblSectionName.Location = new System.Drawing.Point(3, 6); + this.lblSectionName.Name = "lblSectionName"; + this.lblSectionName.Size = new System.Drawing.Size(75, 13); + this.lblSectionName.TabIndex = 0; + this.lblSectionName.Text = "Section &name:"; + // // ExecutableEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.splitContainer1); this.Name = "ExecutableEditor"; - this.Size = new System.Drawing.Size(502, 247); + this.Size = new System.Drawing.Size(590, 332); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.mnuContextSections.ResumeLayout(false); this.pnlSections.ResumeLayout(false); - this.mnuContextListViewSections.ResumeLayout(false); this.pnlSection.ResumeLayout(false); this.pnlSection.PerformLayout(); this.fraSectionCharacteristics.ResumeLayout(false); @@ -256,11 +260,11 @@ private System.Windows.Forms.ColumnHeader chSectionName; private System.Windows.Forms.ColumnHeader chSectionOffset; private System.Windows.Forms.ColumnHeader chSectionLength; - private AwesomeControls.CommandBars.CBContextMenu mnuContextListViewSections; - private System.Windows.Forms.ToolStripMenuItem mnuContextListViewSectionsExport; - private System.Windows.Forms.ToolStripMenuItem mnuContextListViewSectionsImport; - private System.Windows.Forms.ToolStripMenuItem mnuContextListViewSectionsDelete; - private System.Windows.Forms.ToolStripSeparator mnuContextListViewSectionsSep1; + private AwesomeControls.CommandBars.CBContextMenu mnuContextSections; + private System.Windows.Forms.ToolStripMenuItem mnuContextSectionsExport; + private System.Windows.Forms.ToolStripMenuItem mnuContextSectionsImport; + private System.Windows.Forms.ToolStripMenuItem mnuContextSectionsDelete; + private System.Windows.Forms.ToolStripSeparator mnuContextSectionsSep1; private System.Windows.Forms.Panel pnlSection; private System.Windows.Forms.TextBox txtSectionName; private System.Windows.Forms.Label lblSectionName; diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs index 825c8ce1..eddcc647 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.cs @@ -120,23 +120,50 @@ namespace UniversalEditor.Editors.Executable private void mnuContextListViewSections_Opening(object sender, CancelEventArgs e) { - mnuContextListViewSectionsDelete.Enabled = (lvSections.SelectedItems.Count > 0); - mnuContextListViewSectionsExport.Enabled = (lvSections.SelectedItems.Count > 0); + if (lvSections.Focused) + { + mnuContextSectionsDelete.Enabled = (lvSections.SelectedItems.Count > 0); + mnuContextSectionsExport.Enabled = (lvSections.SelectedItems.Count > 0); + } + else if (tv.Focused) + { + mnuContextSectionsDelete.Enabled = (tv.SelectedNode != null && tv.SelectedNode.Tag is ExecutableSection); + mnuContextSectionsExport.Enabled = (tv.SelectedNode != null && tv.SelectedNode.Tag is ExecutableSection); + } } private void mnuContextListViewSectionsExport_Click(object sender, EventArgs e) { - foreach (ListViewItem lvi in lvSections.SelectedItems) + if (lvSections.Focused) { - ExecutableSection section = (lvi.Tag as ExecutableSection); - - SaveFileDialog sfd = new SaveFileDialog(); - sfd.FileName = section.Name; - if (sfd.ShowDialog() == DialogResult.OK) + foreach (ListViewItem lvi in lvSections.SelectedItems) { - section.Save(sfd.FileName); + ExecutableSection section = (lvi.Tag as ExecutableSection); + UISaveSection(section); } } + else if (tv.Focused) + { + ExecutableSection section = (tv.SelectedNode.Tag as ExecutableSection); + UISaveSection(section); + } + } + + /// + /// Displays the Save file dialog and saves the specified section if the user clicks the Save button. + /// + /// The section to save. + /// True if the user clicks the Save button and saves the section; false otherwise. + private bool UISaveSection(ExecutableSection section) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.FileName = section.Name; + if (sfd.ShowDialog() == DialogResult.OK) + { + section.Save(sfd.FileName); + return true; + } + return false; } private void mnuContextListViewSectionsImport_Click(object sender, EventArgs e) @@ -199,5 +226,13 @@ namespace UniversalEditor.Editors.Executable SwitchTo(null); } } + + private void tv_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Right) + { + tv.SelectedNode = tv.HitTest(e.Location).Node; + } + } } } diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx index 6435bc7f..d4943cd3 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Executable.UserInterface.WindowsForms/Editors/Executable/ExecutableEditor.resx @@ -112,12 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 \ No newline at end of file