Improve display and fix display indices

This commit is contained in:
Michael Bucari-Tovo 2022-05-09 20:29:08 -06:00
parent 6474ef98f5
commit b1968caa0f
4 changed files with 53 additions and 31 deletions

View File

@ -33,22 +33,27 @@
// //
// textBox1 // 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.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; this.textBox1.Location = new System.Drawing.Point(3, 3);
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Multiline = true; this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1"; this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true; 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; this.textBox1.TabIndex = 0;
// //
// DescriptionDisplay // DescriptionDisplay
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.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.Name = "DescriptionDisplay";
this.Text = "DescriptionDisplay"; this.Text = "DescriptionDisplay";
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -1,18 +1,26 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace LibationWinForms namespace LibationWinForms
{ {
public partial class DescriptionDisplay : Form 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 string DescriptionText { get => textBox1.Text; set => textBox1.Text = value; }
public Point SpawnLocation { get; set; } public Point SpawnLocation { get; set; }
public DescriptionDisplay() public DescriptionDisplay()
@ -34,13 +42,7 @@ namespace LibationWinForms
int lineCount = textBox1.GetLineFromCharIndex(int.MaxValue) + 2; int lineCount = textBox1.GetLineFromCharIndex(int.MaxValue) + 2;
Height = Height - textBox1.Height + lineCount * TextRenderer.MeasureText("X", textBox1.Font).Height; Height = Height - textBox1.Height + lineCount * TextRenderer.MeasureText("X", textBox1.Font).Height;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height; Location = new Point(SpawnLocation.X, Math.Min(SpawnLocation.Y, Screen.PrimaryScreen.WorkingArea.Height - 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));
} }
[DllImport("user32.dll")] [DllImport("user32.dll")]

View File

@ -266,7 +266,7 @@ namespace LibationWinForms
{ {
var doc = new HtmlAgilityPack.HtmlDocument(); var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(book?.Description?.Replace("</p> ", "\r\n\r\n</p>") ?? ""); doc.LoadHtml(book?.Description?.Replace("</p> ", "\r\n\r\n</p>") ?? "");
return doc.DocumentNode.InnerText; return doc.DocumentNode.InnerText.Trim();
} }
private static string TrimTextToWord(string text, int maxLength) private static string TrimTextToWord(string text, int maxLength)

View File

@ -62,27 +62,33 @@ namespace LibationWinForms
if (e.RowIndex < 0) if (e.RowIndex < 0)
return; 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)); await Liberate_Click(getGridEntry(e.RowIndex));
else if (propertyName == tagAndDetailsGVColumn.DataPropertyName) else if (clickedColumn == tagAndDetailsGVColumn)
Details_Click(getGridEntry(e.RowIndex)); 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)); 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 var displayWindow = new DescriptionDisplay
{ {
Text = $"{liveGridEntry.Title} description", SpawnLocation = PointToScreen(cellDisplay.Location + new Size(cellDisplay.Width, 0)),
SpawnLocation = PointToScreen(cell.Location + new Size(cell.Width, 0)), DescriptionText = liveGridEntry.LongDescription,
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.Show(this);
displayWindow.FormClosing += (_, _) => displayWindow.SaveSizeAndLocation(Configuration.Instance);
} }
private static async Task Liberate_Click(GridEntry liveGridEntry) private static async Task Liberate_Click(GridEntry liveGridEntry)
@ -249,8 +255,8 @@ namespace LibationWinForms
//Restore Grid Display Settings //Restore Grid Display Settings
var config = Configuration.Instance; var config = Configuration.Instance;
var gridColumnsVisibilities = config.GridColumnsVisibilities; var gridColumnsVisibilities = config.GridColumnsVisibilities;
var displayIndices = config.GridColumnsDisplayIndices;
var gridColumnsWidths = config.GridColumnsWidths; var gridColumnsWidths = config.GridColumnsWidths;
var displayIndices = config.GridColumnsDisplayIndices;
var cmsKiller = new ContextMenuStrip(); var cmsKiller = new ContextMenuStrip();
@ -261,18 +267,17 @@ namespace LibationWinForms
var menuItem = new ToolStripMenuItem() var menuItem = new ToolStripMenuItem()
{ {
Text = itemName, Text = column.HeaderText,
Checked = visible, Checked = visible,
Tag = itemName Tag = itemName
}; };
menuItem.Click += HideMenuItem_Click; menuItem.Click += HideMenuItem_Click;
contextMenuStrip1.Items.Add(menuItem); contextMenuStrip1.Items.Add(menuItem);
column.Visible = visible;
column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index);
column.Width = gridColumnsWidths.GetValueOrDefault(itemName, column.Width); column.Width = gridColumnsWidths.GetValueOrDefault(itemName, column.Width);
column.MinimumWidth = 10; column.MinimumWidth = 10;
column.HeaderCell.ContextMenuStrip = contextMenuStrip1; column.HeaderCell.ContextMenuStrip = contextMenuStrip1;
column.Visible = visible;
//Setting a default ContextMenuStrip will allow the columns to handle the //Setting a default ContextMenuStrip will allow the columns to handle the
//Show() event so it is not passed up to the _dataGridView.ContextMenuStrip. //Show() event so it is not passed up to the _dataGridView.ContextMenuStrip.
@ -281,6 +286,16 @@ namespace LibationWinForms
column.ContextMenuStrip = cmsKiller; 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<DataGridViewColumn>()
.Single(c => c.DataPropertyName == itemName);
column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index);
}
base.OnVisibleChanged(e); base.OnVisibleChanged(e);
} }