Renamed rows to sections Prompt before removing tiles and sections Added bottom padding Added duplicate tile on middle-click (prompt for folders) Fixed add/remove/duplicate row/section Changed section title font colour Changed default new tile/folder/section name
293 lines
8.8 KiB
C#
293 lines
8.8 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using RokettoLaunch.Models;
|
|
using RyzStudio.Windows.Forms;
|
|
|
|
namespace RokettoLaunch.Windows.Forms
|
|
{
|
|
public partial class TilePanel : RyzStudio.Windows.TileForms.Tile
|
|
{
|
|
public TilePanel()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.AllowDrop = true;
|
|
this.Font = new Font(this.Font.FontFamily, 8.25F);
|
|
this.Size = new Size(70, 70);
|
|
this.AutoScaleMode = AutoScaleMode.None;
|
|
|
|
this.EnableMovable = true;
|
|
}
|
|
|
|
|
|
[Browsable(false)]
|
|
public TileModel ModelInfo { get; protected set; } = new TileModel();
|
|
|
|
public RyzStudio.Windows.TileForms.TileContainer TileContainer { get => UIControl.GetParentsUntil<RyzStudio.Windows.TileForms.TileContainer>(this); }
|
|
|
|
protected MainForm MainForm { get => UIControl.GetParentsUntil<MainForm>(this); }
|
|
|
|
|
|
protected override void OnDragOver(DragEventArgs e)
|
|
{
|
|
base.OnDragDrop(e);
|
|
|
|
e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None;
|
|
}
|
|
|
|
protected override void OnDragDrop(DragEventArgs e)
|
|
{
|
|
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
fileList = fileList ?? new string[0];
|
|
|
|
if (fileList.Length <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
{
|
|
foreach (var item in fileList)
|
|
{
|
|
var model = GetTileModel(item);
|
|
if (model == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
this.ModelInfo.Items.Add(model);
|
|
}
|
|
|
|
InvalidateGroupMenu();
|
|
}
|
|
else
|
|
{
|
|
if (fileList.Length > 1)
|
|
{
|
|
var result = MessageBox.Show("Do you want to add this as a folder ?", "Convert to Folder", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
this.ModelInfo.Title = "New Folder";
|
|
this.ModelInfo.IsGroup = true;
|
|
|
|
foreach (var item in fileList)
|
|
{
|
|
var model = GetTileModel(item);
|
|
if (model == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
this.ModelInfo.Items.Add(model);
|
|
}
|
|
|
|
InvalidateGroupMenu();
|
|
}
|
|
else if (result == DialogResult.No)
|
|
{
|
|
LoadInfo(fileList[0]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LoadInfo(fileList[0]);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
|
{
|
|
if (Control.ModifierKeys == Keys.Control)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.ModelInfo == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
if (this.ModelInfo.IsGroup)
|
|
{
|
|
var iconSize = ((this.MainForm?.CurrentSession?.ShowBigIcons ?? true) ? 24 : 16);
|
|
|
|
this.LeftContextMenuStrip.ImageScalingSize = new Size(iconSize, iconSize);
|
|
|
|
this.LeftContextMenuStrip?.Show(this, e.Location);
|
|
}
|
|
else
|
|
{
|
|
OnMouseDoubleClick(e);
|
|
}
|
|
}
|
|
else if (e.Button == MouseButtons.Middle)
|
|
{
|
|
var mainForm = UIControl.GetParentsUntil<MainForm>(this);
|
|
if (mainForm == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
{
|
|
var result = MessageBox.Show("Are you sure you want to duplicate tile?", "Duplicate Tile", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
if (result != DialogResult.Yes)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
mainForm.DuplicateTile(this);
|
|
}
|
|
}
|
|
|
|
protected override void OnMouseDoubleClick(MouseEventArgs e)
|
|
{
|
|
base.OnMouseDoubleClick(e);
|
|
|
|
if (Control.ModifierKeys == Keys.Control)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
Execute(this.ModelInfo);
|
|
}
|
|
}
|
|
|
|
|
|
public void LoadInfo(TileModel model)
|
|
{
|
|
this.ModelInfo = model;
|
|
|
|
InvalidateGroupMenu();
|
|
}
|
|
|
|
public void LoadInfo(string filename)
|
|
{
|
|
var model = GetTileModel(filename);
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
LoadInfo(model);
|
|
}
|
|
|
|
private void Execute(TileModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (model.IsGroup)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.MainForm != null)
|
|
{
|
|
if (this.MainForm.CurrentSession?.HideOnExecute ?? true)
|
|
{
|
|
this.MainForm.Visible = false;
|
|
}
|
|
}
|
|
|
|
RyzStudio.Diagnostics.Process.Execute(model.CleanProcessFilename, model.CleanProcessWorkingDirectory, model.CleanProcessArgument, model.ProcessWindowStyle, model.ProcessAsAdmin);
|
|
}
|
|
|
|
private void InvalidateGroupMenu()
|
|
{
|
|
this.Title = this.ModelInfo.Title;
|
|
this.LargeIcon = (this.ModelInfo.IsGroup ? AppResource.folder_32 : RyzStudio.IO.File.GetIcon(this.ModelInfo.CleanProcessFilename));
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
{
|
|
this.ModelInfo.ProcessFilename = "";
|
|
this.ModelInfo.ProcessArgument = "";
|
|
this.ModelInfo.ProcessAsAdmin = false;
|
|
this.ModelInfo.ProcessWindowStyle = ProcessWindowStyle.Normal;
|
|
this.ModelInfo.ProcessWorkingDirectory = "";
|
|
this.ModelInfo.Version = "";
|
|
|
|
if (this.LeftContextMenuStrip == null) this.LeftContextMenuStrip = new ContextMenuStrip();
|
|
this.LeftContextMenuStrip.Items.Clear();
|
|
|
|
foreach (var item in this.ModelInfo?.Items ?? new System.Collections.Generic.List<TileModel>())
|
|
{
|
|
ToolStripItem toolItem = this.LeftContextMenuStrip.Items.Add(item.Title);
|
|
toolItem.Image = RyzStudio.IO.File.GetIcon(item.CleanProcessFilename);
|
|
toolItem.Tag = item;
|
|
toolItem.Click += (object sender, EventArgs e) =>
|
|
{
|
|
var menuItem = (System.Windows.Forms.ToolStripMenuItem)sender;
|
|
if (menuItem == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var model = (menuItem.Tag as TileModel);
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Execute(model);
|
|
};
|
|
}
|
|
}
|
|
|
|
toolTip1.SetToolTip(this, this.Title);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
} |