2020-04-11 17:43:20 +00:00
|
|
|
|
using AppLauncher.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace AppLauncher.Windows.Forms
|
|
|
|
|
{
|
2020-05-16 12:25:59 +00:00
|
|
|
|
public partial class TTilePanel : AUserControl
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
protected bool isDragging = false;
|
|
|
|
|
protected Point startPosition = new Point();
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
protected TileModel modelInfo = new TileModel();
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
public TTilePanel() : base()
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
this.BackColor = Color.FromArgb(250, 250, 250);
|
2020-04-27 12:17:13 +00:00
|
|
|
|
this.ContextMenuStrip = contextMenuStrip1;
|
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
label1.ForeColor = Color.FromArgb(99, 105, 119);
|
|
|
|
|
label1.Font = new Font(this.Font.FontFamily, 8.25F);
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
this.MouseDown += panel_MouseDown;
|
|
|
|
|
this.MouseUp += panel_MouseUp;
|
|
|
|
|
this.MouseMove += panel_MouseMove;
|
|
|
|
|
pictureBox1.MouseDown += panel_MouseDown;
|
|
|
|
|
pictureBox1.MouseUp += panel_MouseUp;
|
|
|
|
|
pictureBox1.MouseMove += panel_MouseMove;
|
|
|
|
|
label1.MouseDown += panel_MouseDown;
|
|
|
|
|
label1.MouseUp += panel_MouseUp;
|
|
|
|
|
label1.MouseMove += panel_MouseMove;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(e);
|
|
|
|
|
|
|
|
|
|
Graphics g = e.Graphics;
|
|
|
|
|
|
|
|
|
|
g.DrawRectangle(new Pen(Color.FromArgb(204, 206, 218), 1), new Rectangle(this.DisplayRectangle.X, this.DisplayRectangle.Y, (this.DisplayRectangle.Width - 1), (this.DisplayRectangle.Height - 1)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
[Category("Appearance"), Browsable(true)]
|
|
|
|
|
public string Title { get => label1.Text; protected set => label1.Text = value; }
|
|
|
|
|
|
|
|
|
|
[Category("Appearance"), Browsable(true)]
|
|
|
|
|
public Image Image { get => pictureBox1.BackgroundImage; protected set => pictureBox1.BackgroundImage = value; }
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
2020-05-02 16:17:10 +00:00
|
|
|
|
public TileModel ModelInfo => modelInfo;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
public TTilePanelLayout PanelContainer
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (this.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
if (this.Parent.GetType() != typeof(TTilePanelLayout))
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 12:25:59 +00:00
|
|
|
|
return (TTilePanelLayout)this.Parent;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInfo(TileModel model)
|
|
|
|
|
{
|
2020-05-02 16:17:10 +00:00
|
|
|
|
this.modelInfo = model;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
this.Title = model.Title;
|
2020-05-02 16:17:10 +00:00
|
|
|
|
|
2020-05-10 10:03:55 +00:00
|
|
|
|
if (this.modelInfo.IsGroup)
|
2020-05-02 16:17:10 +00:00
|
|
|
|
{
|
2020-05-16 12:25:59 +00:00
|
|
|
|
this.Image = Properties.Resources.folder_32;
|
2020-05-10 10:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Image = model.Icon;
|
|
|
|
|
|
|
|
|
|
if (this.Image == null)
|
2020-05-02 16:17:10 +00:00
|
|
|
|
{
|
2020-05-10 10:03:55 +00:00
|
|
|
|
if (File.Exists(model.ProcessFilename))
|
2020-05-02 16:17:10 +00:00
|
|
|
|
{
|
2020-05-10 10:03:55 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.Image = Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2020-05-02 16:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
2020-05-03 14:53:15 +00:00
|
|
|
|
toolTip1.SetToolTip(this, this.Title);
|
|
|
|
|
toolTip1.SetToolTip(pictureBox1, this.Title);
|
|
|
|
|
toolTip1.SetToolTip(label1, this.Title);
|
2020-04-11 17:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void panel_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2020-05-16 12:25:59 +00:00
|
|
|
|
TTilePanelLayout container = this.PanelContainer;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
if (container == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 14:53:15 +00:00
|
|
|
|
if (e.Button != MouseButtons.Right)
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.BringToFront();
|
|
|
|
|
|
|
|
|
|
isDragging = true;
|
|
|
|
|
startPosition = e.Location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void panel_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
isDragging = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void panel_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (isDragging)
|
|
|
|
|
{
|
2020-05-16 12:25:59 +00:00
|
|
|
|
TTilePanelLayout layoutPanel = this.PanelContainer;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
if (layoutPanel == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int x = (this.Location.X + (e.Location.X - startPosition.X));
|
|
|
|
|
int y = (this.Location.Y + (e.Location.Y - startPosition.Y));
|
|
|
|
|
|
|
|
|
|
layoutPanel.MoveTile(this, x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 10:03:55 +00:00
|
|
|
|
private void panel_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.ModelInfo == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
panel_MouseDoubleClick(sender, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 14:53:15 +00:00
|
|
|
|
private void panel_MouseDoubleClick(object sender, MouseEventArgs e)
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
2020-05-10 10:03:55 +00:00
|
|
|
|
if (e.Button != MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (this.ModelInfo == null)
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 10:03:55 +00:00
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(this.ModelInfo.ProcessFilename))
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (!File.Exists(this.ModelInfo.ProcessFilename))
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessStartInfo p = new ProcessStartInfo();
|
2020-05-02 16:17:10 +00:00
|
|
|
|
p.FileName = this.ModelInfo.ProcessFilename;
|
|
|
|
|
p.WindowStyle = this.ModelInfo.ProcessWindowStyle;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.ModelInfo.ProcessArgument)) p.Arguments = this.ModelInfo.ProcessArgument;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(this.ModelInfo.ProcessWorkingDirectory)) p.WorkingDirectory = this.ModelInfo.ProcessWorkingDirectory;
|
|
|
|
|
if (this.ModelInfo.ProcessAsAdmin) p.Verb = "runas";
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(p);
|
|
|
|
|
}
|
2020-05-03 14:53:15 +00:00
|
|
|
|
catch (Exception exc)
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
2020-05-03 14:53:15 +00:00
|
|
|
|
MessageBox.Show(exc.Message);
|
2020-04-11 17:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 12:17:13 +00:00
|
|
|
|
private void editToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-05-10 10:03:55 +00:00
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
EditListTileForm.ShowDialog(this);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EditTileForm.ShowDialog(this);
|
|
|
|
|
}
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (this.PanelContainer == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-27 12:17:13 +00:00
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
this.PanelContainer.Remove(this);
|
2020-04-27 12:17:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|