From c49c9308c0fe08d18bb5a30e969b8a9adca9d1d4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 17 May 2020 19:52:37 +0100 Subject: [PATCH] Changed: session settings + layout panel init-size --- LinearAppLauncher.csproj | 1 + MainForm.Designer.cs | 3 +- MainForm.cs | 28 ++++++++++----- Models/LauncherSession.cs | 10 ++++++ Windows/Forms/AForm.cs | 48 ++++++++++++++++++++++++- Windows/Forms/Tile/TTilePanelLayout.cs | 49 ++++++++------------------ 6 files changed, 93 insertions(+), 46 deletions(-) create mode 100644 Models/LauncherSession.cs diff --git a/LinearAppLauncher.csproj b/LinearAppLauncher.csproj index f4342b1..479e7b1 100644 --- a/LinearAppLauncher.csproj +++ b/LinearAppLauncher.csproj @@ -55,6 +55,7 @@ + Form diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index ca2e933..27971b9 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -178,7 +178,7 @@ this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 58); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(0, 0, 10, 0); - this.flowLayoutPanel1.Size = new System.Drawing.Size(620, 341); + this.flowLayoutPanel1.Size = new System.Drawing.Size(620, 340); this.flowLayoutPanel1.TabIndex = 27; this.flowLayoutPanel1.WrapContents = false; // @@ -202,6 +202,7 @@ this.ClientSize = new System.Drawing.Size(633, 400); this.Controls.Add(this.flowLayoutPanel1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MinimumSize = new System.Drawing.Size(633, 280); this.Name = "MainForm"; this.Text = "Launcher"; this.TitleContextMenuStrip = this.contextMenuStrip1; diff --git a/MainForm.cs b/MainForm.cs index 55745c2..85fe7a2 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -277,8 +277,8 @@ namespace AppLauncher return; } - List rs = JsonConvert.DeserializeObject>(sourceCode); - if (rs == null) + LauncherSession launcherSession = JsonConvert.DeserializeObject(sourceCode); + if (launcherSession == null) { return; } @@ -286,15 +286,19 @@ namespace AppLauncher int maxWidth = 0; flowLayoutPanel1.Controls.Clear(); - foreach (TileGroupModel item in rs) + if (launcherSession.Groups != null) { - TTilePanelLayout panel = new TTilePanelLayout(item); - maxWidth = Math.Max(maxWidth, panel.Width); + foreach (TileGroupModel item in launcherSession.Groups) + { + TTilePanelLayout panel = new TTilePanelLayout(item); + maxWidth = Math.Max(maxWidth, panel.Width); - flowLayoutPanel1.Controls.Add(panel); + flowLayoutPanel1.Controls.Add(panel); + } } this.Width = maxWidth + SystemInformation.VerticalScrollBarWidth + 20 + flowLayoutPanel1.Left; + this.Height = launcherSession.DefaultHeight; } protected void newSession() @@ -335,7 +339,13 @@ namespace AppLauncher isBusy = true; - List rs = new List(); + LauncherSession launcherSession = new LauncherSession() + { + DefaultHeight = this.Height, + Groups = new List() + }; + + launcherSession.Groups = new List(); for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++) { if (flowLayoutPanel1.Controls[i].GetType() != typeof(TTilePanelLayout)) @@ -344,12 +354,12 @@ namespace AppLauncher } TTilePanelLayout container = flowLayoutPanel1.Controls[i] as TTilePanelLayout; - rs.Add(container.Model); + launcherSession.Groups.Add(container.Model); } try { - File.WriteAllText(filename, JsonConvert.SerializeObject(rs)); + File.WriteAllText(filename, JsonConvert.SerializeObject(launcherSession)); if (showNotices) { diff --git a/Models/LauncherSession.cs b/Models/LauncherSession.cs new file mode 100644 index 0000000..bd333bc --- /dev/null +++ b/Models/LauncherSession.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace AppLauncher.Models +{ + public class LauncherSession + { + public int DefaultHeight { get; set; } = 280; + public List Groups { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Windows/Forms/AForm.cs b/Windows/Forms/AForm.cs index 3cbd64e..eaaed42 100644 --- a/Windows/Forms/AForm.cs +++ b/Windows/Forms/AForm.cs @@ -21,6 +21,7 @@ namespace AppLauncher.Windows.Forms protected internal RyzStudio.Windows.Forms.TImageBox imageBox2; protected internal RyzStudio.Windows.Forms.TImageBox imageBox1; private NotifyIcon notifyIcon1; + private Panel panel1; private IContainer components; public AForm() : base() @@ -38,17 +39,25 @@ namespace AppLauncher.Windows.Forms { base.OnLoad(e); - this.SuspendLayout(); + imageBox3.Left = this.DisplayRectangle.Width - imageBox3.Width - 17; imageBox3.Top = 18; imageBox3.Anchor = (AnchorStyles.Top | AnchorStyles.Right); + imageBox2.Left = imageBox3.Left - imageBox2.Width - 8; imageBox2.Top = 18; imageBox2.Anchor = (AnchorStyles.Top | AnchorStyles.Right); + imageBox1.Left = imageBox2.Left - imageBox1.Width - 8; imageBox1.Top = 18; imageBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right); + + panel1.Left = this.DisplayRectangle.Left; + panel1.Top = this.DisplayRectangle.Height - panel1.Height; + panel1.Width = this.DisplayRectangle.Width; + panel1.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom); + this.ResumeLayout(); } @@ -182,6 +191,7 @@ namespace AppLauncher.Windows.Forms this.imageBox2 = new RyzStudio.Windows.Forms.TImageBox(); this.imageBox1 = new RyzStudio.Windows.Forms.TImageBox(); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); + this.panel1 = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.imageBox3)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.imageBox2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.imageBox1)).BeginInit(); @@ -249,9 +259,23 @@ namespace AppLauncher.Windows.Forms this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon"))); this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click); // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.Transparent; + this.panel1.Cursor = System.Windows.Forms.Cursors.SizeNS; + this.panel1.Location = new System.Drawing.Point(109, 114); + this.panel1.Margin = new System.Windows.Forms.Padding(0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(200, 2); + this.panel1.TabIndex = 149; + this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown); + this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove); + this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp); + // // AForm // this.ClientSize = new System.Drawing.Size(421, 321); + this.Controls.Add(this.panel1); this.Controls.Add(this.imageBox1); this.Controls.Add(this.imageBox2); this.Controls.Add(this.imageBox3); @@ -302,5 +326,27 @@ namespace AppLauncher.Windows.Forms notifyIcon1.Visible = !this.Visible; } + private void panel1_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + isDragging = true; + startPosition = e.Location; + } + } + + private void panel1_MouseUp(object sender, MouseEventArgs e) + { + isDragging = false; + } + + private void panel1_MouseMove(object sender, MouseEventArgs e) + { + if (isDragging) + { + this.Size = new Size(this.Width, e.Y - startPosition.Y + this.Height); + } + } + } } \ No newline at end of file diff --git a/Windows/Forms/Tile/TTilePanelLayout.cs b/Windows/Forms/Tile/TTilePanelLayout.cs index a161391..cce0945 100644 --- a/Windows/Forms/Tile/TTilePanelLayout.cs +++ b/Windows/Forms/Tile/TTilePanelLayout.cs @@ -36,6 +36,7 @@ namespace AppLauncher.Windows.Forms protected bool isAnimating = false; protected bool isChecked = true; protected Point lastMousePosition = new Point(); + protected Point gridSize = new Point(); public TTilePanelLayout(TileGroupModel model) : base() { @@ -182,10 +183,11 @@ namespace AppLauncher.Windows.Forms { get { - int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize)); - int h = (int)Math.Floor(decimal.Divide(this.Height - labelHeight, this.TileSize)); + //int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize)); + //int h = (int)Math.Floor(decimal.Divide(this.Height - labelHeight, this.TileSize)); - return new Point(w, h); + //return new Point(w, h); + return gridSize; } } @@ -308,20 +310,6 @@ namespace AppLauncher.Windows.Forms }); } - public async Task CollapseNow() - { - await Task.Run(() => - { - if (isAnimating) return; - - isAnimating = true; - - ThreadControl.SetHeight(this, this.CollapseHeight); - - isAnimating = false; - }); - } - public async Task Expand() { await Task.Run(() => @@ -355,7 +343,7 @@ namespace AppLauncher.Windows.Forms return new Point((x * this.TileSize), ((y * this.TileSize) + labelHeight)); } - public async Task InvalidateContainer(bool animate = true) + public async Task InvalidateContainer() { if (isAnimating) { @@ -368,14 +356,7 @@ namespace AppLauncher.Windows.Forms } else { - if (animate) - { - await this.Collapse(); - } - else - { - await this.CollapseNow(); - } + await this.Collapse(); } } @@ -393,10 +374,7 @@ namespace AppLauncher.Windows.Forms })); } - public void AddRow() - { - this.SetGridSize(groupInfo.GridSize.Width, (groupInfo.GridSize.Height + 1)); - } + public void AddRow() =>this.SetGridSize(groupInfo.GridSize.Width, (groupInfo.GridSize.Height + 1)); public void EditGroup() => EditGroupForm.ShowDialog(this); @@ -404,10 +382,9 @@ namespace AppLauncher.Windows.Forms { groupInfo = model; - this.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height); - isChecked = groupInfo.IsExpanded; + this.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height); this.LoadTiles(model.Items); this.Invalidate(); @@ -416,7 +393,7 @@ namespace AppLauncher.Windows.Forms public void UpdateModel(TileGroupModel model) { groupInfo = model; - isChecked = groupInfo.IsExpanded; + //isChecked = groupInfo.IsExpanded; this.Invalidate(); } @@ -566,9 +543,12 @@ namespace AppLauncher.Windows.Forms public void SetGridSize(int width, int height) { + gridSize = new Point(width, height); + expandedHeight = (this.TileSize * height) + labelHeight; - this.Size = new Size((this.TileSize * width), expandedHeight); + //this.Size = new Size((this.TileSize * width), expandedHeight); + this.Size = new Size((this.TileSize * width), (isChecked ? this.ExpandedHeight : this.CollapseHeight)); } protected Point convertCoordToLocation(Point position) => new Point((position.X * this.TileSize), ((position.Y * this.TileSize) + labelHeight)); @@ -768,6 +748,5 @@ namespace AppLauncher.Windows.Forms private void removeGroupMenuItem3_Click(object sender, EventArgs e) => this.Remove(); - } }