2022-12-26 23:37:53 +00:00
|
|
|
|
using System;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2022-12-26 23:37:53 +00:00
|
|
|
|
using FizzyLauncher.Models;
|
|
|
|
|
using RyzStudio.Windows.Forms;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
namespace FizzyLauncher.Windows.Forms
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public partial class TilePanelLayout : TileGridPanelLayout<TilePanel>
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
protected TileGroupModel groupModel = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TilePanelLayout(TileGroupModel model) : base()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.TitleContextMenuStrip = contextMenuStrip2;
|
|
|
|
|
this.ContainerContextMenuStrip = contextMenuStrip1;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
this.LoadModel(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragDrop(DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LoadShortcuts(fileList);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public new bool EnableAnimation
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
MainForm mainForm = this.MainForm;
|
|
|
|
|
if (mainForm == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mainForm.CurrentSession == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
base.EnableAnimation = mainForm.CurrentSession.EnableAnimation;
|
|
|
|
|
|
|
|
|
|
return base.EnableAnimation;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
2024-07-01 00:55:19 +00:00
|
|
|
|
set => base.EnableAnimation = value;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public void LoadShortcuts(string[] fileList)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
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.AddTile(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TileGroupModel Model
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
TileGroupModel rs = new TileGroupModel()
|
|
|
|
|
{
|
|
|
|
|
Title = groupModel.Title,
|
|
|
|
|
GridSize = new Size(this.GridSize.X, this.GridSize.Y),
|
2024-07-01 00:55:19 +00:00
|
|
|
|
IsExpanded = this.IsExpanded,
|
2021-07-22 23:45:30 +00:00
|
|
|
|
IsExclusive = groupModel.IsExclusive,
|
|
|
|
|
Items = this.Tiles
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public MainForm MainForm { get => UIControl.GetParentsUntil<MainForm>(this.Parent); }
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
public List<TileModel> Tiles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
List<TileModel> result = new List<TileModel>();
|
|
|
|
|
foreach (GridTileItem item in this.GridTileItems.Where(x => x.Tile.GetType() == typeof(TilePanel)))
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
TileModel model = (item.Tile as TilePanel).ModelInfo;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
model.Position = item.Coord;
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
result.Add(model);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
return result;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddTile(TileModel tile)
|
|
|
|
|
{
|
|
|
|
|
Point gridSize = this.GridSize;
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (GridTileItems.Count >= (gridSize.X * gridSize.Y))
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
this.SetGridSize(gridSize.X, (gridSize.Y + 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Point? newCoord = tile.Position;
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if ((newCoord == null) || HasTile(tile.Position))
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
newCoord = FindLastFreeCoord();
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newCoord == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tile.Position = newCoord.Value;
|
|
|
|
|
|
|
|
|
|
TilePanel panel = new TilePanel();
|
|
|
|
|
panel.LoadInfo(tile);
|
2024-07-01 00:55:19 +00:00
|
|
|
|
panel.Location = ConvertCoordToLocation(tile.Position);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
GridTileItems.Add(new GridTileItem()
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
Tile = panel,
|
|
|
|
|
Coord = tile.Position
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(panel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddGroup()
|
|
|
|
|
{
|
|
|
|
|
if (this.FlowLayoutPanel == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.FlowLayoutPanel.Controls.Add(new TilePanelLayout(new TileGroupModel()
|
|
|
|
|
{
|
|
|
|
|
Title = "New Group",
|
|
|
|
|
GridSize = new Size(8, 1)
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public void AddRow() => this.SetGridSize(this.GridSize.X, (this.GridSize.Y + 1));
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public void EditGroup()
|
|
|
|
|
{
|
|
|
|
|
//EditGroupForm.ShowDialog(this);
|
|
|
|
|
}
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public async void LoadModel(TileGroupModel model)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
groupModel = model;
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.Title = groupModel?.Title ?? string.Empty;
|
|
|
|
|
this.IsExpanded = groupModel.IsExpanded;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
//label1.Image = (isExpanded ? AppResource.toggle_right_ea_16 : AppResource.toggle_left_ea_16);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
this.SetGridSize(groupModel.GridSize.Width, groupModel.GridSize.Height);
|
|
|
|
|
this.LoadTiles(model.Items);
|
|
|
|
|
this.SetGridSize(groupModel.GridSize.Width, groupModel.GridSize.Height);
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
await this.Invalidate();
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public async void UpdateModel(TileGroupModel model)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
groupModel = model;
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.Title = groupModel?.Title ?? string.Empty;
|
|
|
|
|
this.IsExpanded = groupModel.IsExpanded;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
await this.Invalidate();
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadTiles(List<TileModel> tiles)
|
|
|
|
|
{
|
|
|
|
|
if (tiles == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tiles.Count() <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TileModel item in tiles)
|
|
|
|
|
{
|
|
|
|
|
// resolve final grid position
|
2024-07-01 00:55:19 +00:00
|
|
|
|
Point? confirmedPosition = ResolveCoord(item.Position);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
if (confirmedPosition == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// place control
|
|
|
|
|
TilePanel panel = new TilePanel();
|
|
|
|
|
panel.LoadInfo(item);
|
2024-07-01 00:55:19 +00:00
|
|
|
|
panel.Location = ConvertCoordToLocation(confirmedPosition.Value);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
GridTileItems.Add(new GridTileItem()
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
Tile = panel,
|
|
|
|
|
Coord = confirmedPosition.Value
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(panel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
private void SetGridSize(int width, int height)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.GridSize = new Point(width, height);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
groupModel.GridSize = new Size(groupModel.GridSize.Width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected override async void label1_MouseClick(object sender, MouseEventArgs e)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
base.label1_MouseClick(sender, e);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (isAnimating)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
return;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
// exclusivity
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.IsExpanded)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (this.Model.IsExclusive)
|
|
|
|
|
{
|
|
|
|
|
if (this.FlowLayoutPanel != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (TilePanelLayout item in this.FlowLayoutPanel.Controls.OfType<TilePanelLayout>())
|
|
|
|
|
{
|
|
|
|
|
if (item.Equals(this))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await item.Collapse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 17:29:21 +00:00
|
|
|
|
#region tile context menu
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add tile
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void addTileMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
Point coord = ConvertLocationToCoord(lastMousePosition.X, lastMousePosition.Y);
|
2021-07-31 17:29:21 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
//EditTileForm.ShowAddDialog(this, coord);
|
2021-07-31 17:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add folder
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void addListTileMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
Point coord = ConvertLocationToCoord(lastMousePosition.X, lastMousePosition.Y);
|
2021-07-31 17:29:21 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
//EditTileFolderForm.ShowAddDialog(this, coord);
|
2021-07-31 17:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region group context menu
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add group
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void addGroupMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.AddGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit group
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void editGroupMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.EditGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add row
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void toolStripMenuItem5_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.AddRow();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 16:09:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove row
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2021-07-31 17:29:21 +00:00
|
|
|
|
private void removeRowToolStripMenuItem_Click_1(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.GridSize.Y <= 1)
|
2021-07-31 17:29:21 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
bool rs = GridTileItems.Exists(x => x.Coord.Y.Equals(this.GridSize.Y - 1));
|
2021-07-31 17:29:21 +00:00
|
|
|
|
if (rs)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.SetGridSize(this.GridSize.X, (this.GridSize.Y - 1));
|
2021-07-31 17:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move to top
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void moveTopMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.MoveTop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move up
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void moveUpMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.MoveUp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move down
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void moveDownMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.MoveDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Move to bottom
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void moveBottomMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.MoveBottom();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove group
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void removeGroupMenuItem3_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2021-07-31 16:09:43 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|