diff --git a/.gitignore b/.gitignore index 28bcb4a..6b26d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.vs /bin /obj +/packages diff --git a/LinearAppLauncher.csproj b/LinearAppLauncher.csproj index f1e2ffa..a53b0f6 100644 --- a/LinearAppLauncher.csproj +++ b/LinearAppLauncher.csproj @@ -36,6 +36,9 @@ true + + packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + @@ -49,12 +52,14 @@ + Form MainForm.cs + @@ -68,19 +73,25 @@ UserControl - + UserControl - - HeadingPanel.cs + + TileGroupLabel.cs - + UserControl - + + TileContainer.cs + + UserControl - + + UserControl + + TilePanel.cs @@ -96,15 +107,22 @@ ResXFileCodeGenerator Resources.Designer.cs - - HeadingPanel.cs + + TileGroupLabel.cs - + + TileContainer.cs + + + TileLayoutPanel.cs + + TilePanel.cs TitlePanel.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -136,5 +154,8 @@ + + + \ No newline at end of file diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index a32b3c4..b218141 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -28,22 +28,17 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.titlePanel1 = new AppLauncher.Windows.Forms.TitlePanel(); - this.headingPanel1 = new AppLauncher.Windows.Forms.HeadingPanel(); - this.panel6 = new System.Windows.Forms.Panel(); - this.panel7 = new System.Windows.Forms.Panel(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.button2 = new System.Windows.Forms.Button(); - this.tilePanel2 = new AppLauncher.Windows.Forms.TilePanel(); - this.tilePanel1 = new AppLauncher.Windows.Forms.TilePanel(); - this.panel4 = new System.Windows.Forms.Panel(); - this.panel1 = new System.Windows.Forms.Panel(); - this.tilePanelContainer1 = new AppLauncher.Windows.Forms.TilePanelContainer(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.headingPanel2 = new AppLauncher.Windows.Forms.HeadingPanel(); - this.headingPanel3 = new AppLauncher.Windows.Forms.HeadingPanel(); - this.flowLayoutPanel1.SuspendLayout(); + this.button3 = new System.Windows.Forms.Button(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.contextMenuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // button1 @@ -56,57 +51,31 @@ this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // - // richTextBox1 - // - this.richTextBox1.Location = new System.Drawing.Point(412, 69); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.Size = new System.Drawing.Size(215, 88); - this.richTextBox1.TabIndex = 2; - this.richTextBox1.Text = ""; - // // titlePanel1 // this.titlePanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.titlePanel1.Location = new System.Drawing.Point(0, 0); + this.titlePanel1.MainMenu = this.contextMenuStrip1; this.titlePanel1.MinimumSize = new System.Drawing.Size(40, 40); this.titlePanel1.Name = "titlePanel1"; this.titlePanel1.Size = new System.Drawing.Size(800, 40); this.titlePanel1.TabIndex = 8; this.titlePanel1.TitleText = "Launcher"; // - // headingPanel1 + // contextMenuStrip1 // - this.headingPanel1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.headingPanel1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.headingPanel1.Checked = false; - this.headingPanel1.Location = new System.Drawing.Point(12, 64); - this.headingPanel1.MinimumSize = new System.Drawing.Size(100, 20); - this.headingPanel1.Name = "headingPanel1"; - this.headingPanel1.Size = new System.Drawing.Size(291, 20); - this.headingPanel1.TabIndex = 9; - this.headingPanel1.TilePanelContainer = null; - this.headingPanel1.TitleText = "Featured"; + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.exitToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(94, 26); // - // panel6 + // exitToolStripMenuItem // - this.panel6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.panel6.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.panel6.Location = new System.Drawing.Point(233, 90); - this.panel6.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.panel6.Name = "panel6"; - this.panel6.Size = new System.Drawing.Size(70, 70); - this.panel6.TabIndex = 12; - // - // panel7 - // - this.panel7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.panel7.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.panel7.Location = new System.Drawing.Point(160, 90); - this.panel7.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.panel7.Name = "panel7"; - this.panel7.Size = new System.Drawing.Size(70, 70); - this.panel7.TabIndex = 11; + this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + this.exitToolStripMenuItem.Size = new System.Drawing.Size(93, 22); + this.exitToolStripMenuItem.Text = "E&xit"; + this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // // button2 // @@ -118,117 +87,32 @@ this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // - // tilePanel2 - // - this.tilePanel2.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tilePanel2.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tilePanel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.tilePanel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234))))); - this.tilePanel2.IconImage = global::AppLauncher.Properties.Resources.folder_ea_32; - this.tilePanel2.Location = new System.Drawing.Point(726, 46); - this.tilePanel2.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.tilePanel2.MaximumSize = new System.Drawing.Size(70, 70); - this.tilePanel2.MinimumSize = new System.Drawing.Size(70, 70); - this.tilePanel2.Name = "tilePanel2"; - this.tilePanel2.ProcessArgument = null; - this.tilePanel2.ProcessFilename = null; - this.tilePanel2.ProcessWindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; - this.tilePanel2.ProcessWorkingDirectory = null; - this.tilePanel2.Size = new System.Drawing.Size(70, 70); - this.tilePanel2.TabIndex = 25; - this.tilePanel2.TitleText = "Accessories"; - // - // tilePanel1 - // - this.tilePanel1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tilePanel1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tilePanel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.tilePanel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234))))); - this.tilePanel1.IconImage = global::AppLauncher.Properties.Resources.mail_ea_32; - this.tilePanel1.Location = new System.Drawing.Point(653, 46); - this.tilePanel1.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.tilePanel1.MaximumSize = new System.Drawing.Size(70, 70); - this.tilePanel1.MinimumSize = new System.Drawing.Size(70, 70); - this.tilePanel1.Name = "tilePanel1"; - this.tilePanel1.ProcessArgument = null; - this.tilePanel1.ProcessFilename = null; - this.tilePanel1.ProcessWindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; - this.tilePanel1.ProcessWorkingDirectory = null; - this.tilePanel1.Size = new System.Drawing.Size(70, 70); - this.tilePanel1.TabIndex = 24; - this.tilePanel1.TitleText = "Mail"; - // - // panel4 - // - this.panel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.panel4.BackgroundImage = global::AppLauncher.Properties.Resources.mail_ea_32; - this.panel4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.panel4.Location = new System.Drawing.Point(87, 90); - this.panel4.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.panel4.Name = "panel4"; - this.panel4.Size = new System.Drawing.Size(70, 70); - this.panel4.TabIndex = 10; - // - // panel1 - // - this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68))))); - this.panel1.BackgroundImage = global::AppLauncher.Properties.Resources.chrome_ea_32; - this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.panel1.Location = new System.Drawing.Point(14, 90); - this.panel1.Margin = new System.Windows.Forms.Padding(3, 3, 0, 0); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(70, 70); - this.panel1.TabIndex = 3; - // - // tilePanelContainer1 - // - this.tilePanelContainer1.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.tilePanelContainer1.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.tilePanelContainer1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255))))); - this.tilePanelContainer1.Location = new System.Drawing.Point(2, 23); - this.tilePanelContainer1.Margin = new System.Windows.Forms.Padding(2, 0, 0, 0); - this.tilePanelContainer1.Name = "tilePanelContainer1"; - this.tilePanelContainer1.Size = new System.Drawing.Size(584, 146); - this.tilePanelContainer1.TabIndex = 26; - // // flowLayoutPanel1 // - this.flowLayoutPanel1.Controls.Add(this.headingPanel2); - this.flowLayoutPanel1.Controls.Add(this.tilePanelContainer1); - this.flowLayoutPanel1.Controls.Add(this.headingPanel3); this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 163); + this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 59); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(615, 265); + this.flowLayoutPanel1.Size = new System.Drawing.Size(672, 369); this.flowLayoutPanel1.TabIndex = 27; // - // headingPanel2 + // button3 // - this.headingPanel2.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.headingPanel2.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.headingPanel2.Checked = false; - this.headingPanel2.Location = new System.Drawing.Point(0, 0); - this.headingPanel2.Margin = new System.Windows.Forms.Padding(0, 0, 0, 3); - this.headingPanel2.MinimumSize = new System.Drawing.Size(100, 20); - this.headingPanel2.Name = "headingPanel2"; - this.headingPanel2.Size = new System.Drawing.Size(223, 20); - this.headingPanel2.TabIndex = 10; - this.headingPanel2.TilePanelContainer = this.tilePanelContainer1; - this.headingPanel2.TitleText = "Featured"; + this.button3.Location = new System.Drawing.Point(722, 355); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(78, 40); + this.button3.TabIndex = 28; + this.button3.Text = "button3"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); // - // headingPanel3 + // pictureBox1 // - this.headingPanel3.AutoScrollMargin = new System.Drawing.Size(0, 0); - this.headingPanel3.AutoScrollMinSize = new System.Drawing.Size(0, 0); - this.headingPanel3.Checked = false; - this.headingPanel3.Location = new System.Drawing.Point(0, 169); - this.headingPanel3.Margin = new System.Windows.Forms.Padding(0, 0, 0, 3); - this.headingPanel3.MinimumSize = new System.Drawing.Size(100, 20); - this.headingPanel3.Name = "headingPanel3"; - this.headingPanel3.Size = new System.Drawing.Size(223, 20); - this.headingPanel3.TabIndex = 27; - this.headingPanel3.TilePanelContainer = null; - this.headingPanel3.TitleText = "Featured"; + this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + this.pictureBox1.Location = new System.Drawing.Point(695, 96); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(100, 109); + this.pictureBox1.TabIndex = 29; + this.pictureBox1.TabStop = false; // // MainForm // @@ -237,21 +121,16 @@ this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(83)))), ((int)(((byte)(93))))); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.ClientSize = new System.Drawing.Size(800, 440); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.button3); this.Controls.Add(this.flowLayoutPanel1); - this.Controls.Add(this.tilePanel2); - this.Controls.Add(this.tilePanel1); this.Controls.Add(this.button2); - this.Controls.Add(this.panel6); - this.Controls.Add(this.panel7); - this.Controls.Add(this.panel4); - this.Controls.Add(this.headingPanel1); this.Controls.Add(this.titlePanel1); - this.Controls.Add(this.panel1); - this.Controls.Add(this.richTextBox1); this.Controls.Add(this.button1); this.Name = "MainForm"; this.Text = "Form1"; - this.flowLayoutPanel1.ResumeLayout(false); + this.contextMenuStrip1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } @@ -259,20 +138,13 @@ #endregion private System.Windows.Forms.Button button1; - private System.Windows.Forms.RichTextBox richTextBox1; - private System.Windows.Forms.Panel panel1; private Windows.Forms.TitlePanel titlePanel1; - private Windows.Forms.HeadingPanel headingPanel1; - private System.Windows.Forms.Panel panel4; - private System.Windows.Forms.Panel panel6; - private System.Windows.Forms.Panel panel7; private System.Windows.Forms.Button button2; - private Windows.Forms.TilePanel tilePanel1; - private Windows.Forms.TilePanel tilePanel2; - private Windows.Forms.TilePanelContainer tilePanelContainer1; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private Windows.Forms.HeadingPanel headingPanel2; - private Windows.Forms.HeadingPanel headingPanel3; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.PictureBox pictureBox1; } } diff --git a/MainForm.cs b/MainForm.cs index 2d18725..d8598b4 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,4 +1,6 @@ -using AppLauncher.Windows.Forms; +using AppLauncher.Models; +using AppLauncher.Windows.Forms; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,6 +9,7 @@ using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -21,7 +24,7 @@ namespace AppLauncher { InitializeComponent(); - + //headingPanel2.Checked = true; } private async void button1_Click(object sender, EventArgs e) @@ -39,6 +42,41 @@ namespace AppLauncher private void button2_Click(object sender, EventArgs e) { + + + + //List groupList = new List(); + + //TileGroupModel group1 = new TileGroupModel() + //{ + // Title = "Featured", + // IsExpanded = true, + // Items = new List(), + // GridSize = new Size(8, 2) + //}; + //group1.Items.Add(new TileModel() + //{ + // Title = "CubicExplorer", + // Icon = null, + // Position = new Point(0, 0), + // ProcessFilename = @"C:\B\Portable Files\CubicExplorer\v0.95.1\CubicExplorer.exe", + // ProcessWorkingDirectory = @"N:\D" + //}); + //group1.Items.Add(new TileModel() + //{ + // Title = "VeraCrypt", + // Icon = null, + // Position = new Point(1, 0), + // ProcessFilename = @"C:\B\Portable Files\VeraCrypt\VeraCrypt-x64.exe", + // ProcessWorkingDirectory = @"L:\" + //}); + + //groupList.Add(group1); + + //File.WriteAllText(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig", JsonConvert.SerializeObject(groupList)); + + + //ProcessStartInfo process = new ProcessStartInfo(); //process.FileName = @"C:\B\Portable Files (pure)\Build and Deploy Utility\v0.2.0.046 alpha\badutil.exe"; //process.Arguments = ""; @@ -48,11 +86,11 @@ namespace AppLauncher //richTextBox1.Text += tilePanelContainer1.GridSize.ToString() + Environment.NewLine; - tilePanelContainer1.Controls.Add(tilePanel1); - tilePanel1.Location = new Point(0, 0); + //tilePanelContainer1.Controls.Add(tilePanel1); + //tilePanel1.Location = new Point(0, 0); - tilePanelContainer1.Controls.Add(tilePanel2); - tilePanel2.Location = new Point(0, 0); + //tilePanelContainer1.Controls.Add(tilePanel2); + //tilePanel2.Location = new Point(0, 0); @@ -106,17 +144,39 @@ namespace AppLauncher }); } - //private void Form1_MouseDown(object sender, MouseEventArgs e) - //{ - // const int WM_NCLBUTTONDOWN = 0xA1; - // const int HT_CAPTION = 0x2; + private void exitToolStripMenuItem_Click(object sender, EventArgs e) + { + this.Close(); + } - // this.Capture = false; + protected void loadSession(string filename) + { + string sourceCode = File.ReadAllText(filename); + if (string.IsNullOrWhiteSpace(sourceCode)) + { + return; + } - // Message msg = Message.Create(this.Handle, WM_NCLBUTTONDOWN, (IntPtr)HT_CAPTION, IntPtr.Zero); + List rs = JsonConvert.DeserializeObject>(sourceCode); + if (rs == null) + { + return; + } - // WndProc(ref msg); - //} + flowLayoutPanel1.Controls.Clear(); + foreach (TileGroupModel item in rs) + { + TileContainer panel = new TileContainer(item); + flowLayoutPanel1.Controls.Add(panel); + } + + } + + private void button3_Click(object sender, EventArgs e) + { + loadSession(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig"); + + } } } diff --git a/MainForm.resx b/MainForm.resx index 1af7de1..ad53752 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Models/TileGroupModel.cs b/Models/TileGroupModel.cs new file mode 100644 index 0000000..ab8974a --- /dev/null +++ b/Models/TileGroupModel.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Drawing; + +namespace AppLauncher.Models +{ + public class TileGroupModel + { + public string Title { get; set; } + public bool IsExpanded { get; set; } = false; + public bool IsExclusive { get; set; } = false; + public List Items { get; set; } = new List(); + public Size GridSize = new Size(0, 0); + } +} \ No newline at end of file diff --git a/Models/TileModel.cs b/Models/TileModel.cs new file mode 100644 index 0000000..cf71072 --- /dev/null +++ b/Models/TileModel.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; + +namespace AppLauncher.Models +{ + public class TileModel + { + public string Title { get; set; } + public Image Icon { get; set; } + public string ProcessFilename { get; set; } + public string ProcessArgument { get; set; } + public string ProcessWorkingDirectory { get; set; } + public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal; + public bool ProcessAsAdmin { get; set; } = false; + public Point Position { get; set; } + + public bool IsGroup { get; set; } = false; + protected List Items { get; set; } = new List(); + + } +} diff --git a/Windows/Forms/Tile/TileContainer.Designer.cs b/Windows/Forms/Tile/TileContainer.Designer.cs new file mode 100644 index 0000000..4dcd41d --- /dev/null +++ b/Windows/Forms/Tile/TileContainer.Designer.cs @@ -0,0 +1,78 @@ +namespace AppLauncher.Windows.Forms +{ + partial class TileContainer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new AppLauncher.Windows.Forms.TileGroupLabel(); + this.panel1 = new AppLauncher.Windows.Forms.TileLayoutPanel(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.label1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.label1.Checked = false; + this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Margin = new System.Windows.Forms.Padding(0, 0, 0, 3); + this.label1.MinimumSize = new System.Drawing.Size(100, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(223, 20); + this.label1.TabIndex = 11; + this.label1.TileGroupPanel = null; + this.label1.TitleText = "Featured"; + // + // panel1 + // + this.panel1.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.panel1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.panel1.BackColor = System.Drawing.Color.Transparent; + this.panel1.Location = new System.Drawing.Point(0, 23); + this.panel1.Margin = new System.Windows.Forms.Padding(2, 0, 0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(223, 127); + this.panel1.TabIndex = 27; + // + // TileContainer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.panel1); + this.Controls.Add(this.label1); + this.Name = "TileContainer"; + this.Size = new System.Drawing.Size(370, 150); + this.ResumeLayout(false); + + } + + #endregion + + private TileGroupLabel label1; + private TileLayoutPanel panel1; + } +} diff --git a/Windows/Forms/Tile/TileContainer.cs b/Windows/Forms/Tile/TileContainer.cs new file mode 100644 index 0000000..bdc8c47 --- /dev/null +++ b/Windows/Forms/Tile/TileContainer.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Threading; +using AppLauncher.Models; + +namespace AppLauncher.Windows.Forms +{ + public partial class TileContainer : AUserControl + { + protected int collapseIncrement = 6; + protected int expandIncrement = 8; + protected TileGroupModel groupInfo = null; + + public TileContainer(TileGroupModel model) : base() + { + InitializeComponent(); + + label1.TileGroupPanel = this; + + groupInfo = model; + + label1.TitleText = groupInfo.Title; + panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height); + label1.Checked = groupInfo.IsExpanded; + + //label1.Width = panel1.Width; + //label1.PanelHeight = panel1.Height; + + //this.Margin = new Padding(0); + //this.Size = new Size(panel1.Width, (label1.Height + panel1.Height)); + //this.MaximumSize = this.Size; + //this.MinimumSize = this.Size; + + panel1.LoadTiles(model.Items); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + label1.Width = panel1.Width; + + this.Margin = new Padding(0); + this.MaximumSize = new Size(panel1.Width, (label1.Height + panel1.ExpandedHeight)); + this.MinimumSize = new Size(panel1.Width, label1.Height); + this.Size = this.MaximumSize; + } + + protected int collapseHeight => label1.Height + panel1.CollapseHeight; + + protected int expandedHeight => label1.Height + panel1.ExpandedHeight; + + public async Task Collapse() + { + await Task.Run(() => + { + while (this.Height > collapseHeight) + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.Height -= collapseIncrement; + })); + } + else + { + this.Height -= collapseIncrement; + } + + Thread.Sleep(10); + } + }); + } + + public async Task CollapseNow() + { + await Task.Run(() => + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.Height = collapseHeight; + })); + } + else + { + this.Height = collapseHeight; + } + }); + } + + public async Task Expand() + { + await Task.Run(() => + { + while (this.Height < expandedHeight) + { + if (this.InvokeRequired) + { + this.Invoke(new MethodInvoker(() => { + this.Height += expandIncrement; + this.Invalidate(); + })); + } + else + { + this.Height += expandIncrement; + this.Invalidate(); + } + + Thread.Sleep(10); + } + }); + } + + } +} diff --git a/Windows/Forms/HeadingPanel.resx b/Windows/Forms/Tile/TileContainer.resx similarity index 100% rename from Windows/Forms/HeadingPanel.resx rename to Windows/Forms/Tile/TileContainer.resx diff --git a/Windows/Forms/HeadingPanel.Designer.cs b/Windows/Forms/Tile/TileGroupLabel.Designer.cs similarity index 93% rename from Windows/Forms/HeadingPanel.Designer.cs rename to Windows/Forms/Tile/TileGroupLabel.Designer.cs index 324a61b..461bd35 100644 --- a/Windows/Forms/HeadingPanel.Designer.cs +++ b/Windows/Forms/Tile/TileGroupLabel.Designer.cs @@ -1,6 +1,6 @@ namespace AppLauncher.Windows.Forms { - partial class HeadingPanel + partial class TileGroupLabel { /// /// Required designer variable. @@ -48,8 +48,8 @@ this.label1.Size = new System.Drawing.Size(575, 20); this.label1.TabIndex = 8; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick); - this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick); + this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); + this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); // // pictureBox1 // @@ -67,8 +67,8 @@ this.pictureBox1.Size = new System.Drawing.Size(20, 20); this.pictureBox1.TabIndex = 7; this.pictureBox1.TabStop = false; - this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick); - this.pictureBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick); + this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); + this.pictureBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); // // HeadingPanel // @@ -79,7 +79,7 @@ this.MinimumSize = new System.Drawing.Size(100, 20); this.Name = "HeadingPanel"; this.Size = new System.Drawing.Size(600, 20); - this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick); + this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panel_MouseClick); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); diff --git a/Windows/Forms/HeadingPanel.cs b/Windows/Forms/Tile/TileGroupLabel.cs similarity index 59% rename from Windows/Forms/HeadingPanel.cs rename to Windows/Forms/Tile/TileGroupLabel.cs index c2d1021..d43696d 100644 --- a/Windows/Forms/HeadingPanel.cs +++ b/Windows/Forms/Tile/TileGroupLabel.cs @@ -5,11 +5,11 @@ using System.Windows.Forms; namespace AppLauncher.Windows.Forms { - public partial class HeadingPanel : AUserControl + public partial class TileGroupLabel : AUserControl { protected bool isChecked = false; - public HeadingPanel() : base() + public TileGroupLabel() : base() { InitializeComponent(); @@ -32,26 +32,17 @@ namespace AppLauncher.Windows.Forms } } - public TilePanelContainer TilePanelContainer { get; set; } = null; + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public TileContainer TileGroupPanel { get; set; } = null; protected async override void OnLoad(EventArgs e) { base.OnLoad(e); - if (this.TilePanelContainer != null) - { - if (this.Checked) - { - await this.TilePanelContainer.Expand(120); - } - else - { - await this.TilePanelContainer.Collapse(0); - } - } + await invalidateToggle(false); } - private async void HeadingPanel_MouseClick(object sender, MouseEventArgs e) + protected async void panel_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { @@ -60,18 +51,32 @@ namespace AppLauncher.Windows.Forms this.Checked = !this.Checked; - if (this.TilePanelContainer != null) + await invalidateToggle(); + } + + protected async Task invalidateToggle(bool animate = true) + { + if (this.TileGroupPanel == null) { - if (this.Checked) + return; + } + + if (this.Checked) + { + await this.TileGroupPanel.Expand(); + } + else + { + if (animate) { - await this.TilePanelContainer.Expand(120); + await this.TileGroupPanel.Collapse(); } else { - await this.TilePanelContainer.Collapse(0); + await this.TileGroupPanel.CollapseNow(); } } } } -} +} \ No newline at end of file diff --git a/Windows/Forms/TilePanel.resx b/Windows/Forms/Tile/TileGroupLabel.resx similarity index 100% rename from Windows/Forms/TilePanel.resx rename to Windows/Forms/Tile/TileGroupLabel.resx diff --git a/Windows/Forms/Tile/TileLayoutPanel.cs b/Windows/Forms/Tile/TileLayoutPanel.cs new file mode 100644 index 0000000..f6eb73e --- /dev/null +++ b/Windows/Forms/Tile/TileLayoutPanel.cs @@ -0,0 +1,220 @@ +using AppLauncher.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AppLauncher.Windows.Forms +{ + public class TileLayoutPanel : AUserControl + { + public class Item + { + public TilePanel Tile { get; set; } + public Point Coord { get; set; } = new Point(0, 0); + } + + protected readonly int tileSize = 70; + protected readonly int margin = 3; + + protected int collapseHeight = 0; + protected int expandedHeight = 0; + + protected List items = new List(); + + public TileLayoutPanel() : base() + { + this.BackColor = System.Drawing.Color.Transparent; + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + OnResize(e); + } + + public Point GridSize + { + get + { + int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize)); + int h = (int)Math.Floor(decimal.Divide(this.Height, this.TileSize)); + + return new Point(w, h); + } + } + + public int TileSize => (tileSize + margin); + + public int CollapseHeight => collapseHeight; + + public int ExpandedHeight => expandedHeight; + + public void Clear() + { + this.Controls.Clear(); + } + + //public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y); + + //public Point GetTileCoord(int posX, int posY) + //{ + // int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); + // int y = (int)Math.Round(decimal.Divide(posY, this.TileSize)); + + // if (x < 0) x = 0; + // if (y < 0) y = 0; + + // return new Point(x, y); + //} + + //public Point GetTilePosition(Point location) => this.GetTilePosition(location.X, location.Y); + + public Point GetTilePosition(int posX, int posY) + { + int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); + int y = (int)Math.Round(decimal.Divide(posY, this.TileSize)); + + if (x < 0) x = 0; + if (y < 0) y = 0; + + return new Point((x * this.TileSize), (y * this.TileSize)); + } + + public void SetGridSize(int width, int height) + { + expandedHeight = (this.TileSize * height); + + this.Size = new Size((this.TileSize * width), expandedHeight); + } + + public void LoadTiles(List tiles) + { + if (tiles == null) + { + return; + } + + if (tiles.Count() <= 0) + { + return; + } + + foreach (TileModel item in tiles) + { + // resolve final grid position + Point? confirmedPosition = resolvePosition(item.Position); + if (confirmedPosition == null) + { + continue; + + } + + // place control + TilePanel panel = new TilePanel(); + panel.LoadInfo(item); + panel.Location = convertPositionToLocation(confirmedPosition.Value); + + items.Add(new Item() + { + Tile = panel, + Coord = confirmedPosition.Value + }); + + this.Controls.Add(panel); + } + } + + public void MoveTile(TilePanel panel, int posX, int posY) + { + + + + } + + protected Point convertPositionToLocation(Point position) => new Point((position.X * this.TileSize), (position.Y * this.TileSize)); + + protected Point? resolvePosition(Point position) + { + if (!isTileInBounds(position)) + { + return null; + } + + if (!hasTile(position)) + { + return position; + } + + return resolveNextPosition(position); + } + + protected Point? resolveNextPosition(Point position) + { + Point gridSize = this.GridSize; + Point newPosition = position; + + while (true) + { + newPosition.X++; + + if (newPosition.X >= gridSize.X) + { + newPosition.Y++; + newPosition.X = 0; + } + + if (!isTileInBounds(newPosition)) + { + return null; + } + + if (hasTile(newPosition)) + { + continue; + } + + return newPosition; + } + } + + protected bool hasTile(Point position) + { + if (items == null) + { + return false; + } + + if (items.Count <= 0) + { + return false; + } + + return (items.Count(x => x.Coord.Equals(position)) > 0); + } + + protected bool isTileInBounds(Point position) + { + Point gridSize = this.GridSize; + + if (position.X > gridSize.X) + { + return false; + } + + if (position.Y > gridSize.Y) + { + return false; + } + + return true; + } + + } +} \ No newline at end of file diff --git a/Windows/Forms/Tile/TileLayoutPanel.resx b/Windows/Forms/Tile/TileLayoutPanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Windows/Forms/Tile/TileLayoutPanel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Windows/Forms/TilePanel.Designer.cs b/Windows/Forms/Tile/TilePanel.Designer.cs similarity index 85% rename from Windows/Forms/TilePanel.Designer.cs rename to Windows/Forms/Tile/TilePanel.Designer.cs index 12eb908..8dc31d6 100644 --- a/Windows/Forms/TilePanel.Designer.cs +++ b/Windows/Forms/Tile/TilePanel.Designer.cs @@ -44,6 +44,8 @@ this.label1.Size = new System.Drawing.Size(70, 13); this.label1.TabIndex = 24; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label1.Click += new System.EventHandler(this.TilePanel_Click); + this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TilePanel_MouseDoubleClick); // // pictureBox1 // @@ -57,6 +59,8 @@ this.pictureBox1.Size = new System.Drawing.Size(70, 38); this.pictureBox1.TabIndex = 25; this.pictureBox1.TabStop = false; + this.pictureBox1.Click += new System.EventHandler(this.TilePanel_Click); + this.pictureBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TilePanel_MouseDoubleClick); // // TilePanel // @@ -71,6 +75,8 @@ this.MinimumSize = new System.Drawing.Size(70, 70); this.Name = "TilePanel"; this.Size = new System.Drawing.Size(70, 70); + this.Click += new System.EventHandler(this.TilePanel_Click); + this.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TilePanel_MouseDoubleClick); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); diff --git a/Windows/Forms/Tile/TilePanel.cs b/Windows/Forms/Tile/TilePanel.cs new file mode 100644 index 0000000..cace978 --- /dev/null +++ b/Windows/Forms/Tile/TilePanel.cs @@ -0,0 +1,174 @@ +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 +{ + public partial class TilePanel : AUserControl + { + protected bool isDragging = false; + protected Point startPosition = new Point(); + + protected TileModel model = new TileModel(); + + public TilePanel() : base() + { + InitializeComponent(); + + 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; + } + + [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)] + public TileModel Info => model; + + //[Browsable(false)] + //public string ProcessArgument { get; set; } + + //[Browsable(false)] + //public string ProcessWorkingDirectory { get; set; } + + //[Browsable(false)] + //public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal; + + public TileLayoutPanel PanelContainer + { + get + { + if (this.Parent == null) + { + return null; + } + + if (this.Parent.GetType() != typeof(TileLayoutPanel)) + { + return null; + } + + return (TileLayoutPanel)this.Parent; + } + } + + public void LoadInfo(TileModel model) + { + this.model = model; + + this.Title = model.Title; + this.Image = model.Icon; + + if (this.Image == null) + { + if (File.Exists(model.ProcessFilename)) + { + try + { + this.Image = Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap(); + } + catch + { + + } + } + } + } + + private void panel_MouseDown(object sender, MouseEventArgs e) + { + TileLayoutPanel container = this.PanelContainer; + if (container == null) + { + return; + } + + if (e.Button != MouseButtons.Left) + { + 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) + { + TileLayoutPanel layoutPanel = this.PanelContainer; + if (layoutPanel == null) + { + return; + } + + int x = (this.Location.X + (e.Location.X - startPosition.X)); + int y = (this.Location.Y + (e.Location.Y - startPosition.Y)); + + //this.Location = layoutPanel.GetTilePosition(x, y); + layoutPanel.MoveTile(this, x, y); + } + } + + private void TilePanel_MouseDoubleClick(object sender, MouseEventArgs e) + { + if (this.Info == null) + { + return; + } + + if (string.IsNullOrWhiteSpace(this.Info.ProcessFilename)) + { + return; + } + + if (!File.Exists(this.Info.ProcessFilename)) + { + return; + } + + ProcessStartInfo p = new ProcessStartInfo(); + p.FileName = this.Info.ProcessFilename; + p.WindowStyle = this.Info.ProcessWindowStyle; + if (!string.IsNullOrWhiteSpace(this.Info.ProcessArgument)) p.Arguments = this.Info.ProcessArgument; + if (!string.IsNullOrWhiteSpace(this.Info.ProcessWorkingDirectory)) p.WorkingDirectory = this.Info.ProcessWorkingDirectory; + if (this.Info.ProcessAsAdmin) p.Verb = "runas"; + + try + { + Process.Start(p); + } + catch + { + // do nothing + } + } + + private void TilePanel_Click(object sender, EventArgs e) + { + // do nothing yet + } + + } +} \ No newline at end of file diff --git a/Windows/Forms/Tile/TilePanel.resx b/Windows/Forms/Tile/TilePanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Windows/Forms/Tile/TilePanel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Windows/Forms/TilePanel.cs b/Windows/Forms/TilePanel.cs deleted file mode 100644 index e11ceed..0000000 --- a/Windows/Forms/TilePanel.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Diagnostics; - -namespace AppLauncher.Windows.Forms -{ - public partial class TilePanel : AUserControl - { - protected bool isDragging = false; - protected Point startPosition = new Point(); - - public TilePanel() : base() - { - InitializeComponent(); - - 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; - } - - protected override void OnLocationChanged(EventArgs e) - { - base.OnLocationChanged(e); - - if (this.Parent != null) - { - if (this.Parent.GetType() == typeof(TilePanelContainer)) - { - TilePanelContainer container = (TilePanelContainer)this.Parent; - Point p = container.GetTilePosition(this.Location); - - //label1.Text = p.X.ToString() + ", " + p.Y.ToString(); - } - } - } - - [Category("Appearance"), Browsable(true)] - public string TitleText { get => label1.Text; set => label1.Text = value; } - - [Category("Appearance"), Browsable(true)] - public Image IconImage { get => pictureBox1.BackgroundImage; set => pictureBox1.BackgroundImage = value; } - - [Browsable(false)] - public string ProcessFilename { get; set; } - - [Browsable(false)] - public string ProcessArgument { get; set; } - - [Browsable(false)] - public string ProcessWorkingDirectory { get; set; } - - [Browsable(false)] - public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal; - - public TilePanelContainer PanelContainer - { - get - { - if (this.Parent == null) - { - return null; - } - - if (this.Parent.GetType() != typeof(TilePanelContainer)) - { - return null; - } - - return (TilePanelContainer)this.Parent; - } - } - - private void panel_MouseDown(object sender, MouseEventArgs e) - { - TilePanelContainer container = this.PanelContainer; - if (container == null) - { - return; - } - - if (e.Button != MouseButtons.Left) - { - return; - } - - 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) - { - TilePanelContainer container = this.PanelContainer; - if (container == null) - { - return; - } - - //label1.Text = e.Location.ToString(); - //this.Location = new Point(e.Location.X - windowOffset.X, e.Location.Y - windowOffset.Y); - - //int x = parentPosition.X + (e.Location.X - positionOffset.X); - //int y = parentPosition.Y + (e.Location.Y - positionOffset.Y); - //this.Location = new Point(x, y); - - //int x = (tilePosition.X + e.Location.X); - //int y = (tilePosition.Y + e.Location.Y); - - int x = (this.Location.X + (e.Location.X - startPosition.X)); - int y = (this.Location.Y + (e.Location.Y - startPosition.Y)); - - this.Location = container.GetTilePosition(x, y); - - - //label1.Text = x.ToString() + ", " + y.ToString(); - - //label1.Text = e.X.ToString() + ", " + e.Y.ToString(); - - - //Point pos = this.PointToScreen(e.Location); - - //int y = Math.Max((pos.Y - windowOffset.Y), Screen.PrimaryScreen.WorkingArea.Y); - //y = Math.Min(y, (Screen.PrimaryScreen.WorkingArea.Y + Screen.PrimaryScreen.WorkingArea.Height) - this.Height); - - //this.Parent.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, y); - } - - } - - } -} \ No newline at end of file diff --git a/Windows/Forms/TilePanelContainer.cs b/Windows/Forms/TilePanelContainer.cs deleted file mode 100644 index 1ae9df4..0000000 --- a/Windows/Forms/TilePanelContainer.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace AppLauncher.Windows.Forms -{ - public class TilePanelContainer : AUserControl - { - protected readonly int tileSize = 70; - protected readonly int margin = 3; - - public TilePanelContainer() : base() - { - - } - - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - - OnResize(e); - } - - public Point GridSize - { - get - { - int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize)); - int h = (int)Math.Floor(decimal.Divide(this.Height, this.TileSize)); - - return new Point(w, h); - } - } - - public int TileSize => (tileSize + margin); - - - public async Task Collapse(int height, int increment = 6) - { - await Task.Run(() => - { - while (this.Height > height) - { - if (this.InvokeRequired) - { - this.Invoke(new MethodInvoker(() => { - this.Height -= increment; - })); - } - else - { - this.Height -= increment; - } - - Thread.Sleep(10); - } - }); - } - - public async Task Expand(int height, int increment = 8) - { - await Task.Run(() => - { - while (this.Height < height) - { - if (this.InvokeRequired) - { - this.Invoke(new MethodInvoker(() => { - this.Height += increment; - this.Invalidate(); - })); - } - else - { - this.Height += increment; - this.Invalidate(); - } - - Thread.Sleep(10); - } - }); - } - - public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y); - - public Point GetTileCoord(int posX, int posY) - { - int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); - int y = (int)Math.Round(decimal.Divide(posY, this.TileSize)); - - if (x < 0) x = 0; - if (y < 0) y = 0; - - return new Point(x, y); - } - - public Point GetTilePosition(Point location) => this.GetTilePosition(location.X, location.Y); - - public Point GetTilePosition(int posX, int posY) - { - int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); - int y = (int)Math.Round(decimal.Divide(posY, this.TileSize)); - - if (x < 0) x = 0; - if (y < 0) y = 0; - - return new Point((x * this.TileSize), (y * this.TileSize)); - } - - public void SetGridSize(int width, int height) - { - this.Size = new Size((this.TileSize * width), (this.TileSize * height)); - } - } -} \ No newline at end of file diff --git a/Windows/Forms/TitlePanel.Designer.cs b/Windows/Forms/TitlePanel.Designer.cs index 123fa3e..1c09f91 100644 --- a/Windows/Forms/TitlePanel.Designer.cs +++ b/Windows/Forms/TitlePanel.Designer.cs @@ -48,6 +48,7 @@ this.pictureBox1.Size = new System.Drawing.Size(40, 40); this.pictureBox1.TabIndex = 5; this.pictureBox1.TabStop = false; + this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); // // label1 // diff --git a/Windows/Forms/TitlePanel.cs b/Windows/Forms/TitlePanel.cs index 04d801f..6207f52 100644 --- a/Windows/Forms/TitlePanel.cs +++ b/Windows/Forms/TitlePanel.cs @@ -42,6 +42,8 @@ namespace AppLauncher.Windows.Forms set => label1.Text = value; } + public ContextMenuStrip MainMenu { get; set; } = null; + protected void parentForm_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) @@ -71,5 +73,16 @@ namespace AppLauncher.Windows.Forms } } + private void pictureBox1_MouseUp(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + if (this.MainMenu != null) + { + this.MainMenu.Show(this.PointToScreen(e.Location)); + } + } + } + } } diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file