From 1c291c1b91d503014dc4f49604269e097ddca588 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 11 Jul 2024 22:12:56 +0100 Subject: [PATCH] Added duplicate tile Added drag-n-drop files on til Added add tile on middle-click --- MainForm.Designer.cs | 44 ++++++++ MainForm.cs | 144 ++++++++++++++++++++++++- MainForm.resx | 3 + RokettoLaunch.csproj | 2 +- Windows/Forms/TilePanel.Designer.cs | 41 +------ Windows/Forms/TilePanel.cs | 162 ++++++++++++---------------- Windows/Forms/TilePanel.resx | 65 ++++++++++- 7 files changed, 320 insertions(+), 141 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index de900d0..81edeec 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -78,10 +78,16 @@ namespace RokettoLaunch removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); panel1 = new System.Windows.Forms.Panel(); + tileMenu1 = new System.Windows.Forms.ContextMenuStrip(components); + editToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + removeToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + toolStripMenuItem6 = new System.Windows.Forms.ToolStripMenuItem(); + toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); contextMenuStrip2.SuspendLayout(); menuStrip1.SuspendLayout(); tileContainerMenu1.SuspendLayout(); panel1.SuspendLayout(); + tileMenu1.SuspendLayout(); SuspendLayout(); // // saveFileDialog1 @@ -410,6 +416,38 @@ namespace RokettoLaunch panel1.Size = new System.Drawing.Size(404, 417); panel1.TabIndex = 9; // + // tileMenu1 + // + tileMenu1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { editToolStripMenuItem1, toolStripMenuItem6, toolStripSeparator4, removeToolStripMenuItem1 }); + tileMenu1.Name = "tileMenu1"; + tileMenu1.Size = new System.Drawing.Size(181, 98); + // + // editToolStripMenuItem1 + // + editToolStripMenuItem1.Name = "editToolStripMenuItem1"; + editToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + editToolStripMenuItem1.Text = "&Edit"; + editToolStripMenuItem1.Click += editToolStripMenuItem1_Click; + // + // removeToolStripMenuItem1 + // + removeToolStripMenuItem1.Name = "removeToolStripMenuItem1"; + removeToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + removeToolStripMenuItem1.Text = "&Remove"; + removeToolStripMenuItem1.Click += removeToolStripMenuItem1_Click; + // + // toolStripMenuItem6 + // + toolStripMenuItem6.Name = "toolStripMenuItem6"; + toolStripMenuItem6.Size = new System.Drawing.Size(180, 22); + toolStripMenuItem6.Text = "&Duplicate"; + toolStripMenuItem6.Click += toolStripMenuItem6_Click; + // + // toolStripSeparator4 + // + toolStripSeparator4.Name = "toolStripSeparator4"; + toolStripSeparator4.Size = new System.Drawing.Size(177, 6); + // // MainForm // AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -431,6 +469,7 @@ namespace RokettoLaunch menuStrip1.PerformLayout(); tileContainerMenu1.ResumeLayout(false); panel1.ResumeLayout(false); + tileMenu1.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } @@ -482,6 +521,11 @@ namespace RokettoLaunch private System.Windows.Forms.ToolStripMenuItem bottomToolStripMenuItem; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5; + private System.Windows.Forms.ContextMenuStrip tileMenu1; + private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem6; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; } } diff --git a/MainForm.cs b/MainForm.cs index a176c2e..fbce751 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -5,10 +5,12 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Linq; using RokettoLaunch.Models; using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms.ButtonTextBox; using RyzStudio.Windows.TileForms; +using static RyzStudio.Windows.ThemedForms.ButtonTextBox.ThKeyCodeTextBox; namespace RokettoLaunch { @@ -156,6 +158,41 @@ namespace RokettoLaunch alwaysOnTopToolStripMenuItem.Checked = this.CurrentSession?.AlwaysOnTop ?? false; } + private void tileContainer_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button != MouseButtons.Middle) + { + return; + } + + var control = (sender as Control); + if (control == null) + { + return; + } + + var container = UIControl.GetParentsUntil(sender as Control); + if (container == null) + { + return; + } + + var newCoord = container.GetNextCoord(); + + var tileModel = new TileModel() + { + Title = "New Tile", + IsGroup = false + }; + + var newTile = new RokettoLaunch.Windows.Forms.TilePanel(); + newTile.ContextMenuStrip = tileMenu1; + newTile.LoadInfo(tileModel); + + container.Add(newTile, newCoord.X, newCoord.Y); + + _fileSessionManager.HasChanged = true; + } #region Main Menu @@ -544,6 +581,7 @@ namespace RokettoLaunch var newCoord = container.GetNextCoord(); var newTile = new RokettoLaunch.Windows.Forms.TilePanel(); + newTile.ContextMenuStrip = tileMenu1; newTile.LoadInfo(result); container.Add(newTile, newCoord.X, newCoord.Y); @@ -572,6 +610,7 @@ namespace RokettoLaunch var newCoord = container.GetNextCoord(); var newTile = new RokettoLaunch.Windows.Forms.TilePanel(); + newTile.ContextMenuStrip = tileMenu1; newTile.LoadInfo(result); container.Add(newTile, newCoord.X, newCoord.Y); @@ -759,6 +798,99 @@ namespace RokettoLaunch #endregion + #region Tile + + /// + /// Edit + /// + /// + /// + private void editToolStripMenuItem1_Click(object sender, EventArgs e) + { + var tile = UIControl.GetOwner((ToolStripMenuItem)sender); + if (tile == null) + { + return; + } + + if (tile.ModelInfo.IsGroup) + { + var form = new EditTileFolderForm(tile.ModelInfo); + if (form.ShowDialog() == DialogResult.OK) + { + tile.LoadInfo(form.Result); + + _fileSessionManager.HasChanged = true; + }; + } + else + { + var form = new EditTileForm(tile.ModelInfo); + if (form.ShowDialog() == DialogResult.OK) + { + tile.LoadInfo(form.Result); + + _fileSessionManager.HasChanged = true; + }; + } + } + + /// + /// Duplicate + /// + /// + /// + private void toolStripMenuItem6_Click(object sender, EventArgs e) + { + var tile = UIControl.GetOwner((ToolStripMenuItem)sender); + if (tile == null) + { + return; + } + + var container = UIControl.GetParentsUntil(tile); + if (container == null) + { + return; + } + + var newCoord = container.GetNextCoord(); + + var newTile = new RokettoLaunch.Windows.Forms.TilePanel(); + newTile.ContextMenuStrip = tileMenu1; + newTile.LoadInfo(tile.ModelInfo); + + container.Add(newTile, newCoord.X, newCoord.Y); + + _fileSessionManager.HasChanged = true; + } + + /// + /// Remove + /// + /// + /// + private void removeToolStripMenuItem1_Click(object sender, EventArgs e) + { + var tile = UIControl.GetOwner((ToolStripMenuItem)sender); + if (tile == null) + { + return; + } + + var container = UIControl.GetParentsUntil(tile); + if (container == null) + { + return; + } + + container.Controls?.Remove(tile); + + _fileSessionManager.HasChanged = true; + } + + #endregion + private async Task AddNewTileGroup() { @@ -780,20 +912,24 @@ namespace RokettoLaunch panel.Title = model.Title; panel.IsOpen = model.IsExpanded; panel.TitleContextMenuStrip = tileContainerMenu1; + panel.PaddingBottom = 0; panel.AutoSizeHeight = true; panel.Tag = model; - panel.AutoSize(model.GridSize.Width, model.GridSize.Height); + panel.Height += 4; + + panel.MouseClick += tileContainer_MouseClick; UIControl.Add(flowLayoutPanel1, panel); // Load tiles foreach (var item2 in model.Items ?? new List()) { - var tile = new RokettoLaunch.Windows.Forms.TilePanel(); - tile.LoadInfo(item2); + var newTile = new RokettoLaunch.Windows.Forms.TilePanel(); + newTile.ContextMenuStrip = tileMenu1; + newTile.LoadInfo(item2); - panel.Add(tile, item2.Position.X, item2.Position.Y); + panel.Add(newTile, item2.Position.X, item2.Position.Y); } }); } diff --git a/MainForm.resx b/MainForm.resx index cf646d8..4a573f9 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -433,6 +433,9 @@ 831, 17 + + 990, 17 + AAABAAQAMDAAAAEAIACoJQAARgAAACAgAAABACAAqBAAAO4lAAAYGAAAAQAgAIgJAACWNgAAEBAAAAEA diff --git a/RokettoLaunch.csproj b/RokettoLaunch.csproj index 388cd10..f333389 100644 --- a/RokettoLaunch.csproj +++ b/RokettoLaunch.csproj @@ -14,7 +14,7 @@ Ray Lam 1.0.0.0 1.0.0.0 - 0.3.1.042 + 0.3.2.017 False x64 icon-128.png diff --git a/Windows/Forms/TilePanel.Designer.cs b/Windows/Forms/TilePanel.Designer.cs index b61fcff..2bee63d 100644 --- a/Windows/Forms/TilePanel.Designer.cs +++ b/Windows/Forms/TilePanel.Designer.cs @@ -28,48 +28,17 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.contextMenuStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // contextMenuStrip1 - // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.editToolStripMenuItem, - this.removeToolStripMenuItem}); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(118, 48); - // - // editToolStripMenuItem - // - this.editToolStripMenuItem.Name = "editToolStripMenuItem"; - this.editToolStripMenuItem.Size = new System.Drawing.Size(117, 22); - this.editToolStripMenuItem.Text = "&Edit"; - this.editToolStripMenuItem.Click += new System.EventHandler(this.editToolStripMenuItem_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.removeToolStripMenuItem_Click); + components = new System.ComponentModel.Container(); + toolTip1 = new System.Windows.Forms.ToolTip(components); + SuspendLayout(); // // TilePanel // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.Name = "TilePanel"; - this.contextMenuStrip1.ResumeLayout(false); - this.ResumeLayout(false); + Name = "TilePanel"; + ResumeLayout(false); } #endregion - private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; private System.Windows.Forms.ToolTip toolTip1; } } diff --git a/Windows/Forms/TilePanel.cs b/Windows/Forms/TilePanel.cs index a76f573..18cdeb7 100644 --- a/Windows/Forms/TilePanel.cs +++ b/Windows/Forms/TilePanel.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; @@ -19,7 +20,6 @@ namespace RokettoLaunch.Windows.Forms InitializeComponent(); this.AllowDrop = true; - this.ContextMenuStrip = contextMenuStrip1; this.Font = new Font(this.Font.FontFamily, 8.25F); this.Size = new Size(70, 70); this.AutoScaleMode = AutoScaleMode.None; @@ -49,10 +49,30 @@ namespace RokettoLaunch.Windows.Forms if (this.ModelInfo.IsGroup) { - this.DropFileList(fileList); + foreach (var item in fileList ?? new string[0]) + { + var model = GetTileModel(item); + if (model == null) + { + continue; + } + + this.ModelInfo.Items.Add(model); + } InvalidateGroupMenu(this.ModelInfo); } + else + { + if ((fileList?.Length ?? 0) > 0) + { + var model = GetTileModel(fileList[0]); + if (model != null) + { + LoadInfo(model); + } + } + } } protected override void OnMouseClick(MouseEventArgs e) @@ -96,97 +116,6 @@ namespace RokettoLaunch.Windows.Forms } -#region Context Menu - - /// - /// Edit - /// - /// - /// - private void editToolStripMenuItem_Click(object sender, EventArgs e) - { - if (this.ModelInfo.IsGroup) - { - var form = new EditTileFolderForm(this.ModelInfo); - if (form.ShowDialog() == DialogResult.OK) - { - this.LoadInfo(form.Result); - }; - } - else - { - var form = new EditTileForm(this.ModelInfo); - if (form.ShowDialog() == DialogResult.OK) - { - this.LoadInfo(form.Result); - }; - } - } - - /// - /// Remove - /// - /// - /// - private void removeToolStripMenuItem_Click(object sender, EventArgs e) - { - this.TileContainer?.Controls?.Remove(this); - } - -#endregion - - - public void DropFileList(string[] fileList) - { - if (fileList == null) - { - return; - } - - if (fileList.Length <= 0) - { - return; - } - - if (string.IsNullOrWhiteSpace(fileList[0])) - { - return; - } - - TileModel model = new TileModel() - { - ProcessFilename = fileList[0], - Title = Path.GetFileName(fileList[0]) - }; - - // exe - if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase)) - { - if (File.Exists(fileList[0])) - { - try - { - FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]); - if (fvi != null) - { - model.Title = fvi.ProductName; - } - } - catch - { - // do nothing - } - } - - if (string.IsNullOrWhiteSpace(model.Title)) - { - model.Title = Path.GetFileNameWithoutExtension(fileList[0]); - } - } - - this.ModelInfo.Items.Add(model); - } - public void LoadInfo(TileModel model) { this.modelInfo = model; @@ -208,7 +137,7 @@ namespace RokettoLaunch.Windows.Forms toolTip1.SetToolTip(this, this.Title); } - protected void Execute(TileModel model) + private void Execute(TileModel model) { if (model == null) { @@ -231,7 +160,7 @@ namespace RokettoLaunch.Windows.Forms RyzStudio.Diagnostics.Process.Execute(model.CleanProcessFilename, model.CleanProcessWorkingDirectory, model.CleanProcessArgument, model.ProcessWindowStyle, model.ProcessAsAdmin); } - protected void InvalidateGroupMenu(TileModel model) + private void InvalidateGroupMenu(TileModel model) { var iconSize = ((this.MainForm?.CurrentSession?.ShowBigIcons ?? true) ? 24 : 16); @@ -267,5 +196,46 @@ namespace RokettoLaunch.Windows.Forms } } + private TileModel GetTileModel(string filename) + { + if (string.IsNullOrWhiteSpace(filename)) + { + return null; + } + + TileModel model = new TileModel() + { + ProcessFilename = filename, + Title = Path.GetFileName(filename) + }; + + // exe + if (Path.GetExtension(filename).Equals(".exe", StringComparison.CurrentCultureIgnoreCase)) + { + if (File.Exists(filename)) + { + try + { + FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(filename); + if (fvi != null) + { + model.Title = fvi.ProductName; + } + } + catch + { + // do nothing + } + } + + if (string.IsNullOrWhiteSpace(model.Title)) + { + model.Title = Path.GetFileNameWithoutExtension(filename); + } + } + + return model; + } + } } \ No newline at end of file diff --git a/Windows/Forms/TilePanel.resx b/Windows/Forms/TilePanel.resx index 60ff723..a829b1a 100644 --- a/Windows/Forms/TilePanel.resx +++ b/Windows/Forms/TilePanel.resx @@ -1,4 +1,64 @@ - + + + @@ -57,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - 172, 17