diff --git a/Source/LibationWinForms/grid/DescriptionDisplay.Designer.cs b/Source/LibationWinForms/grid/DescriptionDisplay.Designer.cs index 89b553bf..8a1f7cd2 100644 --- a/Source/LibationWinForms/grid/DescriptionDisplay.Designer.cs +++ b/Source/LibationWinForms/grid/DescriptionDisplay.Designer.cs @@ -33,22 +33,27 @@ // // textBox1 // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Location = new System.Drawing.Point(3, 3); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; - this.textBox1.Size = new System.Drawing.Size(413, 162); + this.textBox1.Size = new System.Drawing.Size(544, 144); this.textBox1.TabIndex = 0; // // DescriptionDisplay // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(413, 162); + this.BackColor = System.Drawing.SystemColors.Highlight; + this.ClientSize = new System.Drawing.Size(550, 150); this.Controls.Add(this.textBox1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; this.Name = "DescriptionDisplay"; this.Text = "DescriptionDisplay"; this.ResumeLayout(false); diff --git a/Source/LibationWinForms/grid/DescriptionDisplay.cs b/Source/LibationWinForms/grid/DescriptionDisplay.cs index 7905e0a5..43c22a9d 100644 --- a/Source/LibationWinForms/grid/DescriptionDisplay.cs +++ b/Source/LibationWinForms/grid/DescriptionDisplay.cs @@ -1,18 +1,26 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace LibationWinForms { public partial class DescriptionDisplay : Form { + private int borderThickness = 0; + + public int BorderThickness + { + get => borderThickness; + set + { + borderThickness = value; + textBox1.Location = new Point(borderThickness, borderThickness); + textBox1.Size = new Size(Width - 2 * borderThickness, Height - 2 * borderThickness); + } + } public string DescriptionText { get => textBox1.Text; set => textBox1.Text = value; } public Point SpawnLocation { get; set; } public DescriptionDisplay() @@ -34,13 +42,7 @@ namespace LibationWinForms int lineCount = textBox1.GetLineFromCharIndex(int.MaxValue) + 2; Height = Height - textBox1.Height + lineCount * TextRenderer.MeasureText("X", textBox1.Font).Height; - int screenHeight = Screen.PrimaryScreen.WorkingArea.Height; - - - var tboxLocation = PointToScreen(textBox1.Location); - var tboxOffset = new Size(tboxLocation.X - Location.X, tboxLocation.Y - Location.Y); - - Location = new Point(SpawnLocation.X - tboxOffset.Width, Math.Min(SpawnLocation.Y - tboxOffset.Height, screenHeight - Height)); + Location = new Point(SpawnLocation.X, Math.Min(SpawnLocation.Y, Screen.PrimaryScreen.WorkingArea.Height - Height)); } [DllImport("user32.dll")] diff --git a/Source/LibationWinForms/grid/GridEntry.cs b/Source/LibationWinForms/grid/GridEntry.cs index 8b93dd12..0a6ab244 100644 --- a/Source/LibationWinForms/grid/GridEntry.cs +++ b/Source/LibationWinForms/grid/GridEntry.cs @@ -266,7 +266,7 @@ namespace LibationWinForms { var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(book?.Description?.Replace("

", "\r\n\r\n

") ?? ""); - return doc.DocumentNode.InnerText; + return doc.DocumentNode.InnerText.Trim(); } private static string TrimTextToWord(string text, int maxLength) diff --git a/Source/LibationWinForms/grid/ProductsGrid.cs b/Source/LibationWinForms/grid/ProductsGrid.cs index 2df9be7f..48bd2e49 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.cs @@ -62,27 +62,33 @@ namespace LibationWinForms if (e.RowIndex < 0) return; - var propertyName = _dataGridView.Columns[e.ColumnIndex].DataPropertyName; + var clickedColumn = _dataGridView.Columns[e.ColumnIndex]; - if (propertyName == liberateGVColumn.DataPropertyName) + if (clickedColumn == liberateGVColumn) await Liberate_Click(getGridEntry(e.RowIndex)); - else if (propertyName == tagAndDetailsGVColumn.DataPropertyName) + else if (clickedColumn == tagAndDetailsGVColumn) Details_Click(getGridEntry(e.RowIndex)); - else if (propertyName == descriptionGVColumn.DataPropertyName) + else if (clickedColumn == descriptionGVColumn) DescriptionClick(getGridEntry(e.RowIndex), _dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false)); } - private void DescriptionClick(GridEntry liveGridEntry, Rectangle cell) + private void DescriptionClick(GridEntry liveGridEntry, Rectangle cellDisplay) { var displayWindow = new DescriptionDisplay { - Text = $"{liveGridEntry.Title} description", - SpawnLocation = PointToScreen(cell.Location + new Size(cell.Width, 0)), - DescriptionText = liveGridEntry.LongDescription + SpawnLocation = PointToScreen(cellDisplay.Location + new Size(cellDisplay.Width, 0)), + DescriptionText = liveGridEntry.LongDescription, + BorderThickness = 2, }; - displayWindow.RestoreSizeAndLocation(Configuration.Instance); + + void CloseWindow (object o, EventArgs e) + { + displayWindow.Close(); + } + + _dataGridView.Scroll += CloseWindow; + displayWindow.FormClosed += (_,_) => _dataGridView.Scroll -= CloseWindow; displayWindow.Show(this); - displayWindow.FormClosing += (_, _) => displayWindow.SaveSizeAndLocation(Configuration.Instance); } private static async Task Liberate_Click(GridEntry liveGridEntry) @@ -249,8 +255,8 @@ namespace LibationWinForms //Restore Grid Display Settings var config = Configuration.Instance; var gridColumnsVisibilities = config.GridColumnsVisibilities; - var displayIndices = config.GridColumnsDisplayIndices; var gridColumnsWidths = config.GridColumnsWidths; + var displayIndices = config.GridColumnsDisplayIndices; var cmsKiller = new ContextMenuStrip(); @@ -261,18 +267,17 @@ namespace LibationWinForms var menuItem = new ToolStripMenuItem() { - Text = itemName, + Text = column.HeaderText, Checked = visible, Tag = itemName }; menuItem.Click += HideMenuItem_Click; contextMenuStrip1.Items.Add(menuItem); - column.Visible = visible; - column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index); column.Width = gridColumnsWidths.GetValueOrDefault(itemName, column.Width); column.MinimumWidth = 10; column.HeaderCell.ContextMenuStrip = contextMenuStrip1; + column.Visible = visible; //Setting a default ContextMenuStrip will allow the columns to handle the //Show() event so it is not passed up to the _dataGridView.ContextMenuStrip. @@ -281,6 +286,16 @@ namespace LibationWinForms column.ContextMenuStrip = cmsKiller; } + //We must set DisplayIndex properties in ascending order + foreach (var itemName in displayIndices.OrderBy(i => i.Value).Select(i => i.Key)) + { + var column = _dataGridView.Columns + .Cast() + .Single(c => c.DataPropertyName == itemName); + + column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index); + } + base.OnVisibleChanged(e); }