Add option for user to hide columns in ProductsGrid

This commit is contained in:
Michael Bucari-Tovo 2022-05-09 12:58:09 -06:00
parent 15b6b673d7
commit aecc54401d
6 changed files with 441 additions and 369 deletions

View File

@ -125,6 +125,9 @@ namespace AppScaffolding
if (!config.Exists(nameof(config.AutoScan))) if (!config.Exists(nameof(config.AutoScan)))
config.AutoScan = true; config.AutoScan = true;
if (!config.Exists(nameof(config.HiddenGridColumns)))
config.HiddenGridColumns = Array.Empty<string>();
} }
/// <summary>Initialize logging. Run after migration</summary> /// <summary>Initialize logging. Run after migration</summary>

View File

@ -7,236 +7,237 @@ using Newtonsoft.Json.Linq;
namespace FileManager namespace FileManager
{ {
public class PersistentDictionary public class PersistentDictionary
{ {
public string Filepath { get; } public string Filepath { get; }
public bool IsReadOnly { get; } public bool IsReadOnly { get; }
// optimize for strings. expectation is most settings will be strings and a rare exception will be something else // optimize for strings. expectation is most settings will be strings and a rare exception will be something else
private Dictionary<string, string> stringCache { get; } = new Dictionary<string, string>(); private Dictionary<string, string> stringCache { get; } = new Dictionary<string, string>();
private Dictionary<string, object> objectCache { get; } = new Dictionary<string, object>(); private Dictionary<string, object> objectCache { get; } = new Dictionary<string, object>();
public PersistentDictionary(string filepath, bool isReadOnly = false) public PersistentDictionary(string filepath, bool isReadOnly = false)
{ {
Filepath = filepath; Filepath = filepath;
IsReadOnly = isReadOnly; IsReadOnly = isReadOnly;
if (File.Exists(Filepath)) if (File.Exists(Filepath))
return; return;
// will create any missing directories, incl subdirectories. if all already exist: no action // will create any missing directories, incl subdirectories. if all already exist: no action
Directory.CreateDirectory(Path.GetDirectoryName(filepath)); Directory.CreateDirectory(Path.GetDirectoryName(filepath));
if (IsReadOnly) if (IsReadOnly)
return; return;
createNewFile(); createNewFile();
} }
public string GetString(string propertyName) public string GetString(string propertyName)
{ {
if (!stringCache.ContainsKey(propertyName)) if (!stringCache.ContainsKey(propertyName))
{ {
var jObject = readFile(); var jObject = readFile();
if (!jObject.ContainsKey(propertyName)) if (!jObject.ContainsKey(propertyName))
return null; return null;
stringCache[propertyName] = jObject[propertyName].Value<string>(); stringCache[propertyName] = jObject[propertyName].Value<string>();
} }
return stringCache[propertyName]; return stringCache[propertyName];
} }
public T GetNonString<T>(string propertyName) public T GetNonString<T>(string propertyName)
{ {
var obj = GetObject(propertyName); var obj = GetObject(propertyName);
if (obj is null) return default; if (obj is null) return default;
if (obj is JValue jValue) return jValue.Value<T>(); if (obj is JValue jValue) return jValue.Value<T>();
if (obj is JObject jObject) return jObject.ToObject<T>(); if (obj is JObject jObject) return jObject.ToObject<T>();
return (T)obj; if (obj is JArray jArray && typeof(T).IsArray) return jArray.ToObject<T>();
} return (T)obj;
}
public object GetObject(string propertyName) public object GetObject(string propertyName)
{ {
if (!objectCache.ContainsKey(propertyName)) if (!objectCache.ContainsKey(propertyName))
{ {
var jObject = readFile(); var jObject = readFile();
if (!jObject.ContainsKey(propertyName)) if (!jObject.ContainsKey(propertyName))
return null; return null;
objectCache[propertyName] = jObject[propertyName].Value<object>(); objectCache[propertyName] = jObject[propertyName].Value<object>();
} }
return objectCache[propertyName]; return objectCache[propertyName];
} }
public string GetStringFromJsonPath(string jsonPath, string propertyName) => GetStringFromJsonPath($"{jsonPath}.{propertyName}"); public string GetStringFromJsonPath(string jsonPath, string propertyName) => GetStringFromJsonPath($"{jsonPath}.{propertyName}");
public string GetStringFromJsonPath(string jsonPath) public string GetStringFromJsonPath(string jsonPath)
{ {
if (!stringCache.ContainsKey(jsonPath)) if (!stringCache.ContainsKey(jsonPath))
{ {
try try
{ {
var jObject = readFile(); var jObject = readFile();
var token = jObject.SelectToken(jsonPath); var token = jObject.SelectToken(jsonPath);
if (token is null) if (token is null)
return null; return null;
stringCache[jsonPath] = (string)token; stringCache[jsonPath] = (string)token;
} }
catch catch
{ {
return null; return null;
} }
} }
return stringCache[jsonPath]; return stringCache[jsonPath];
} }
public bool Exists(string propertyName) => readFile().ContainsKey(propertyName); public bool Exists(string propertyName) => readFile().ContainsKey(propertyName);
private object locker { get; } = new object(); private object locker { get; } = new object();
public void SetString(string propertyName, string newValue) public void SetString(string propertyName, string newValue)
{ {
// only do this check in string cache, NOT object cache // only do this check in string cache, NOT object cache
if (stringCache.ContainsKey(propertyName) && stringCache[propertyName] == newValue) if (stringCache.ContainsKey(propertyName) && stringCache[propertyName] == newValue)
return; return;
// set cache // set cache
stringCache[propertyName] = newValue; stringCache[propertyName] = newValue;
writeFile(propertyName, newValue); writeFile(propertyName, newValue);
} }
public void SetNonString(string propertyName, object newValue) public void SetNonString(string propertyName, object newValue)
{ {
// set cache // set cache
objectCache[propertyName] = newValue; objectCache[propertyName] = newValue;
var parsedNewValue = JToken.Parse(JsonConvert.SerializeObject(newValue)); var parsedNewValue = JToken.Parse(JsonConvert.SerializeObject(newValue));
writeFile(propertyName, parsedNewValue); writeFile(propertyName, parsedNewValue);
} }
private void writeFile(string propertyName, JToken newValue) private void writeFile(string propertyName, JToken newValue)
{ {
if (IsReadOnly) if (IsReadOnly)
return; return;
// write new setting to file // write new setting to file
lock (locker) lock (locker)
{ {
var jObject = readFile(); var jObject = readFile();
var startContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); var startContents = JsonConvert.SerializeObject(jObject, Formatting.Indented);
jObject[propertyName] = newValue; jObject[propertyName] = newValue;
var endContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); var endContents = JsonConvert.SerializeObject(jObject, Formatting.Indented);
if (startContents == endContents) if (startContents == endContents)
return; return;
File.WriteAllText(Filepath, endContents);
}
try File.WriteAllText(Filepath, endContents);
{ }
var str = formatValueForLog(newValue?.ToString());
Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { propertyName, newValue = str });
}
catch { }
}
/// <summary>WILL ONLY set if already present. WILL NOT create new</summary> try
/// <returns>Value was changed</returns> {
public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false) var str = formatValueForLog(newValue?.ToString());
{ Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { propertyName, newValue = str });
if (IsReadOnly) }
return false; catch { }
}
var path = $"{jsonPath}.{propertyName}"; /// <summary>WILL ONLY set if already present. WILL NOT create new</summary>
/// <returns>Value was changed</returns>
public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false)
{
if (IsReadOnly)
return false;
{ var path = $"{jsonPath}.{propertyName}";
// only do this check in string cache, NOT object cache
if (stringCache.ContainsKey(path) && stringCache[path] == newValue)
return false;
// set cache {
stringCache[path] = newValue; // only do this check in string cache, NOT object cache
} if (stringCache.ContainsKey(path) && stringCache[path] == newValue)
return false;
try // set cache
{ stringCache[path] = newValue;
lock (locker) }
{
var jObject = readFile();
var token = jObject.SelectToken(jsonPath);
if (token is null || token[propertyName] is null)
return false;
var oldValue = token.Value<string>(propertyName); try
if (oldValue == newValue) {
return false; lock (locker)
{
var jObject = readFile();
var token = jObject.SelectToken(jsonPath);
if (token is null || token[propertyName] is null)
return false;
token[propertyName] = newValue; var oldValue = token.Value<string>(propertyName);
File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); if (oldValue == newValue)
} return false;
}
catch (Exception exDebug)
{
return false;
}
if (!suppressLogging) token[propertyName] = newValue;
{ File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented));
try }
{ }
var str = formatValueForLog(newValue?.ToString()); catch (Exception exDebug)
Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { jsonPath, propertyName, newValue = str }); {
} return false;
catch { } }
}
return true; if (!suppressLogging)
} {
try
{
var str = formatValueForLog(newValue?.ToString());
Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { jsonPath, propertyName, newValue = str });
}
catch { }
}
private static string formatValueForLog(string value) return true;
=> value is null ? "[null]" }
: string.IsNullOrEmpty(value) ? "[empty]"
: string.IsNullOrWhiteSpace(value) ? $"[whitespace. Length={value.Length}]"
: value.Length > 100 ? $"[Length={value.Length}] {value[0..50]}...{value[^50..^0]}"
: value;
private JObject readFile() private static string formatValueForLog(string value)
{ => value is null ? "[null]"
if (!File.Exists(Filepath)) : string.IsNullOrEmpty(value) ? "[empty]"
{ : string.IsNullOrWhiteSpace(value) ? $"[whitespace. Length={value.Length}]"
var msg = "Unrecoverable error. Settings file cannot be found"; : value.Length > 100 ? $"[Length={value.Length}] {value[0..50]}...{value[^50..^0]}"
var ex = new FileNotFoundException(msg, Filepath); : value;
Serilog.Log.Logger.Error(ex, msg);
throw ex;
}
var settingsJsonContents = File.ReadAllText(Filepath); private JObject readFile()
{
if (!File.Exists(Filepath))
{
var msg = "Unrecoverable error. Settings file cannot be found";
var ex = new FileNotFoundException(msg, Filepath);
Serilog.Log.Logger.Error(ex, msg);
throw ex;
}
if (string.IsNullOrWhiteSpace(settingsJsonContents)) var settingsJsonContents = File.ReadAllText(Filepath);
{
createNewFile();
settingsJsonContents = File.ReadAllText(Filepath);
}
var jObject = JsonConvert.DeserializeObject<JObject>(settingsJsonContents); if (string.IsNullOrWhiteSpace(settingsJsonContents))
{
createNewFile();
settingsJsonContents = File.ReadAllText(Filepath);
}
if (jObject is null) var jObject = JsonConvert.DeserializeObject<JObject>(settingsJsonContents);
{
var msg = "Unrecoverable error. Unable to read settings from Settings file";
var ex = new NullReferenceException(msg);
Serilog.Log.Logger.Error(ex, msg);
throw ex;
}
return jObject; if (jObject is null)
} {
var msg = "Unrecoverable error. Unable to read settings from Settings file";
var ex = new NullReferenceException(msg);
Serilog.Log.Logger.Error(ex, msg);
throw ex;
}
private void createNewFile() return jObject;
{ }
File.WriteAllText(Filepath, "{}");
System.Threading.Thread.Sleep(100); private void createNewFile()
} {
} File.WriteAllText(Filepath, "{}");
System.Threading.Thread.Sleep(100);
}
}
} }

View File

@ -179,6 +179,13 @@ namespace LibationFileManager
get => persistentDictionary.GetNonString<int>(nameof(LameVBRQuality)); get => persistentDictionary.GetNonString<int>(nameof(LameVBRQuality));
set => persistentDictionary.SetNonString(nameof(LameVBRQuality), value); set => persistentDictionary.SetNonString(nameof(LameVBRQuality), value);
} }
[Description("A list of GridView data property names whose columns should be hidden in ProductsGrid")]
public string[] HiddenGridColumns
{
get => persistentDictionary.GetNonString<string[]>(nameof(HiddenGridColumns));
set => persistentDictionary.SetNonString(nameof(HiddenGridColumns), value);
}
public enum BadBookAction public enum BadBookAction
{ {

View File

@ -28,40 +28,41 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components); this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components);
this.gridEntryDataGridView = new System.Windows.Forms.DataGridView(); this.gridEntryDataGridView = new System.Windows.Forms.DataGridView();
this.dataGridViewImageButtonBoxColumn1 = new LibationWinForms.LiberateDataGridViewImageButtonColumn(); this.dataGridViewImageButtonBoxColumn1 = new LibationWinForms.LiberateDataGridViewImageButtonColumn();
this.dataGridViewImageColumn1 = new System.Windows.Forms.DataGridViewImageColumn(); this.dataGridViewImageColumn1 = new System.Windows.Forms.DataGridViewImageColumn();
this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewImageButtonBoxColumn2 = new LibationWinForms.EditTagsDataGridViewImageButtonColumn(); this.dataGridViewImageButtonBoxColumn2 = new LibationWinForms.EditTagsDataGridViewImageButtonColumn();
((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).BeginInit(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).BeginInit();
this.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).BeginInit();
// this.SuspendLayout();
// gridEntryBindingSource //
// // gridEntryBindingSource
this.gridEntryBindingSource.DataSource = typeof(LibationWinForms.GridEntry); //
// this.gridEntryBindingSource.DataSource = typeof(LibationWinForms.GridEntry);
// gridEntryDataGridView //
// // gridEntryDataGridView
this.gridEntryDataGridView.AllowUserToAddRows = false; //
this.gridEntryDataGridView.AllowUserToDeleteRows = false; this.gridEntryDataGridView.AllowUserToAddRows = false;
this.gridEntryDataGridView.AllowUserToResizeRows = false; this.gridEntryDataGridView.AllowUserToDeleteRows = false;
this.gridEntryDataGridView.AutoGenerateColumns = false; this.gridEntryDataGridView.AllowUserToResizeRows = false;
this.gridEntryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gridEntryDataGridView.AutoGenerateColumns = false;
this.gridEntryDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.gridEntryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gridEntryDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.dataGridViewImageButtonBoxColumn1, this.dataGridViewImageButtonBoxColumn1,
this.dataGridViewImageColumn1, this.dataGridViewImageColumn1,
this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn1,
@ -76,147 +77,153 @@
this.dataGridViewTextBoxColumn10, this.dataGridViewTextBoxColumn10,
this.dataGridViewTextBoxColumn11, this.dataGridViewTextBoxColumn11,
this.dataGridViewImageButtonBoxColumn2}); this.dataGridViewImageButtonBoxColumn2});
this.gridEntryDataGridView.DataSource = this.gridEntryBindingSource; this.gridEntryDataGridView.ContextMenuStrip = this.contextMenuStrip1;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; this.gridEntryDataGridView.DataSource = this.gridEntryBindingSource;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle1; dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.gridEntryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle1;
this.gridEntryDataGridView.Location = new System.Drawing.Point(0, 0); this.gridEntryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.gridEntryDataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.gridEntryDataGridView.Location = new System.Drawing.Point(0, 0);
this.gridEntryDataGridView.Name = "gridEntryDataGridView"; this.gridEntryDataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.gridEntryDataGridView.ReadOnly = true; this.gridEntryDataGridView.Name = "gridEntryDataGridView";
this.gridEntryDataGridView.RowHeadersVisible = false; this.gridEntryDataGridView.ReadOnly = true;
this.gridEntryDataGridView.RowTemplate.Height = 82; this.gridEntryDataGridView.RowHeadersVisible = false;
this.gridEntryDataGridView.Size = new System.Drawing.Size(1510, 380); this.gridEntryDataGridView.RowTemplate.Height = 82;
this.gridEntryDataGridView.TabIndex = 0; this.gridEntryDataGridView.Size = new System.Drawing.Size(1510, 380);
// this.gridEntryDataGridView.TabIndex = 0;
// dataGridViewImageButtonBoxColumn1 //
// // dataGridViewImageButtonBoxColumn1
this.dataGridViewImageButtonBoxColumn1.DataPropertyName = "Liberate"; //
this.dataGridViewImageButtonBoxColumn1.HeaderText = "Liberate"; this.dataGridViewImageButtonBoxColumn1.DataPropertyName = "Liberate";
this.dataGridViewImageButtonBoxColumn1.Name = "dataGridViewImageButtonBoxColumn1"; this.dataGridViewImageButtonBoxColumn1.HeaderText = "Liberate";
this.dataGridViewImageButtonBoxColumn1.ReadOnly = true; this.dataGridViewImageButtonBoxColumn1.Name = "dataGridViewImageButtonBoxColumn1";
this.dataGridViewImageButtonBoxColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.dataGridViewImageButtonBoxColumn1.ReadOnly = true;
this.dataGridViewImageButtonBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.dataGridViewImageButtonBoxColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridViewImageButtonBoxColumn1.Width = 75; this.dataGridViewImageButtonBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
// this.dataGridViewImageButtonBoxColumn1.Width = 75;
// dataGridViewImageColumn1 //
// // dataGridViewImageColumn1
this.dataGridViewImageColumn1.DataPropertyName = "Cover"; //
this.dataGridViewImageColumn1.HeaderText = "Cover"; this.dataGridViewImageColumn1.DataPropertyName = "Cover";
this.dataGridViewImageColumn1.Name = "dataGridViewImageColumn1"; this.dataGridViewImageColumn1.HeaderText = "Cover";
this.dataGridViewImageColumn1.ReadOnly = true; this.dataGridViewImageColumn1.Name = "dataGridViewImageColumn1";
this.dataGridViewImageColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.dataGridViewImageColumn1.ReadOnly = true;
this.dataGridViewImageColumn1.ToolTipText = "Cover Art"; this.dataGridViewImageColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridViewImageColumn1.Width = 80; this.dataGridViewImageColumn1.ToolTipText = "Cover Art";
// this.dataGridViewImageColumn1.Width = 80;
// dataGridViewTextBoxColumn1 //
// // dataGridViewTextBoxColumn1
this.dataGridViewTextBoxColumn1.DataPropertyName = "Title"; //
this.dataGridViewTextBoxColumn1.HeaderText = "Title"; this.dataGridViewTextBoxColumn1.DataPropertyName = "Title";
this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; this.dataGridViewTextBoxColumn1.HeaderText = "Title";
this.dataGridViewTextBoxColumn1.ReadOnly = true; this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
this.dataGridViewTextBoxColumn1.Width = 200; this.dataGridViewTextBoxColumn1.ReadOnly = true;
// this.dataGridViewTextBoxColumn1.Width = 200;
// dataGridViewTextBoxColumn2 //
// // dataGridViewTextBoxColumn2
this.dataGridViewTextBoxColumn2.DataPropertyName = "Authors"; //
this.dataGridViewTextBoxColumn2.HeaderText = "Authors"; this.dataGridViewTextBoxColumn2.DataPropertyName = "Authors";
this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.HeaderText = "Authors";
this.dataGridViewTextBoxColumn2.ReadOnly = true; this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
// this.dataGridViewTextBoxColumn2.ReadOnly = true;
// dataGridViewTextBoxColumn3 //
// // dataGridViewTextBoxColumn3
this.dataGridViewTextBoxColumn3.DataPropertyName = "Narrators"; //
this.dataGridViewTextBoxColumn3.HeaderText = "Narrators"; this.dataGridViewTextBoxColumn3.DataPropertyName = "Narrators";
this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; this.dataGridViewTextBoxColumn3.HeaderText = "Narrators";
this.dataGridViewTextBoxColumn3.ReadOnly = true; this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
// this.dataGridViewTextBoxColumn3.ReadOnly = true;
// dataGridViewTextBoxColumn4 //
// // dataGridViewTextBoxColumn4
this.dataGridViewTextBoxColumn4.DataPropertyName = "Length"; //
this.dataGridViewTextBoxColumn4.HeaderText = "Length"; this.dataGridViewTextBoxColumn4.DataPropertyName = "Length";
this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; this.dataGridViewTextBoxColumn4.HeaderText = "Length";
this.dataGridViewTextBoxColumn4.ReadOnly = true; this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
this.dataGridViewTextBoxColumn4.ToolTipText = "Recording Length"; this.dataGridViewTextBoxColumn4.ReadOnly = true;
// this.dataGridViewTextBoxColumn4.ToolTipText = "Recording Length";
// dataGridViewTextBoxColumn5 //
// // dataGridViewTextBoxColumn5
this.dataGridViewTextBoxColumn5.DataPropertyName = "Series"; //
this.dataGridViewTextBoxColumn5.HeaderText = "Series"; this.dataGridViewTextBoxColumn5.DataPropertyName = "Series";
this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; this.dataGridViewTextBoxColumn5.HeaderText = "Series";
this.dataGridViewTextBoxColumn5.ReadOnly = true; this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
// this.dataGridViewTextBoxColumn5.ReadOnly = true;
// dataGridViewTextBoxColumn6 //
// // dataGridViewTextBoxColumn6
this.dataGridViewTextBoxColumn6.DataPropertyName = "Description"; //
this.dataGridViewTextBoxColumn6.HeaderText = "Description"; this.dataGridViewTextBoxColumn6.DataPropertyName = "Description";
this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6"; this.dataGridViewTextBoxColumn6.HeaderText = "Description";
this.dataGridViewTextBoxColumn6.ReadOnly = true; this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
// this.dataGridViewTextBoxColumn6.ReadOnly = true;
// dataGridViewTextBoxColumn7 //
// // dataGridViewTextBoxColumn7
this.dataGridViewTextBoxColumn7.DataPropertyName = "Category"; //
this.dataGridViewTextBoxColumn7.HeaderText = "Category"; this.dataGridViewTextBoxColumn7.DataPropertyName = "Category";
this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7"; this.dataGridViewTextBoxColumn7.HeaderText = "Category";
this.dataGridViewTextBoxColumn7.ReadOnly = true; this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
// this.dataGridViewTextBoxColumn7.ReadOnly = true;
// ProductRating //
// // dataGridViewTextBoxColumn8
this.dataGridViewTextBoxColumn8.DataPropertyName = "ProductRating"; //
this.dataGridViewTextBoxColumn8.HeaderText = "Product Rating"; this.dataGridViewTextBoxColumn8.DataPropertyName = "ProductRating";
this.dataGridViewTextBoxColumn8.Name = "ProductRating"; this.dataGridViewTextBoxColumn8.HeaderText = "Product Rating";
this.dataGridViewTextBoxColumn8.ReadOnly = true; this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
this.dataGridViewTextBoxColumn8.Width = 108; this.dataGridViewTextBoxColumn8.ReadOnly = true;
// this.dataGridViewTextBoxColumn8.Width = 108;
// PurchaseDate //
// // dataGridViewTextBoxColumn9
this.dataGridViewTextBoxColumn9.DataPropertyName = "PurchaseDate"; //
this.dataGridViewTextBoxColumn9.HeaderText = "Purchase Date"; this.dataGridViewTextBoxColumn9.DataPropertyName = "PurchaseDate";
this.dataGridViewTextBoxColumn9.Name = "PurchaseDate"; this.dataGridViewTextBoxColumn9.HeaderText = "Purchase Date";
this.dataGridViewTextBoxColumn9.ReadOnly = true; this.dataGridViewTextBoxColumn9.Name = "dataGridViewTextBoxColumn9";
// this.dataGridViewTextBoxColumn9.ReadOnly = true;
// MyRating //
// // dataGridViewTextBoxColumn10
this.dataGridViewTextBoxColumn10.DataPropertyName = "MyRating"; //
this.dataGridViewTextBoxColumn10.HeaderText = "My Rating"; this.dataGridViewTextBoxColumn10.DataPropertyName = "MyRating";
this.dataGridViewTextBoxColumn10.Name = "MyRating"; this.dataGridViewTextBoxColumn10.HeaderText = "My Rating";
this.dataGridViewTextBoxColumn10.ReadOnly = true; this.dataGridViewTextBoxColumn10.Name = "dataGridViewTextBoxColumn10";
this.dataGridViewTextBoxColumn10.Width = 108; this.dataGridViewTextBoxColumn10.ReadOnly = true;
// this.dataGridViewTextBoxColumn10.Width = 108;
// dataGridViewTextBoxColumn11 //
// // dataGridViewTextBoxColumn11
this.dataGridViewTextBoxColumn11.DataPropertyName = "Misc"; //
this.dataGridViewTextBoxColumn11.HeaderText = "Misc"; this.dataGridViewTextBoxColumn11.DataPropertyName = "Misc";
this.dataGridViewTextBoxColumn11.Name = "dataGridViewTextBoxColumn11"; this.dataGridViewTextBoxColumn11.HeaderText = "Misc";
this.dataGridViewTextBoxColumn11.ReadOnly = true; this.dataGridViewTextBoxColumn11.Name = "dataGridViewTextBoxColumn11";
this.dataGridViewTextBoxColumn11.Width = 135; this.dataGridViewTextBoxColumn11.ReadOnly = true;
// this.dataGridViewTextBoxColumn11.Width = 135;
// dataGridViewImageButtonBoxColumn2 //
// // dataGridViewImageButtonBoxColumn2
this.dataGridViewImageButtonBoxColumn2.DataPropertyName = "DisplayTags"; //
this.dataGridViewImageButtonBoxColumn2.HeaderText = "Tags and Details"; this.dataGridViewImageButtonBoxColumn2.DataPropertyName = "DisplayTags";
this.dataGridViewImageButtonBoxColumn2.Name = "dataGridViewImageButtonBoxColumn2"; this.dataGridViewImageButtonBoxColumn2.HeaderText = "Tags and Details";
this.dataGridViewImageButtonBoxColumn2.ReadOnly = true; this.dataGridViewImageButtonBoxColumn2.Name = "dataGridViewImageButtonBoxColumn2";
this.dataGridViewImageButtonBoxColumn2.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.dataGridViewImageButtonBoxColumn2.ReadOnly = true;
this.dataGridViewImageButtonBoxColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.dataGridViewImageButtonBoxColumn2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
// this.dataGridViewImageButtonBoxColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
// ProductsGrid //
// // contextMenuStrip1
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.contextMenuStrip1.Name = "contextMenuStrip1";
this.Controls.Add(this.gridEntryDataGridView); this.contextMenuStrip1.Size = new System.Drawing.Size(181, 26);
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); //
this.Name = "ProductsGrid"; // ProductsGrid
this.Size = new System.Drawing.Size(1510, 380); //
((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).EndInit(); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).EndInit(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ResumeLayout(false); this.Controls.Add(this.gridEntryDataGridView);
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "ProductsGrid";
this.Size = new System.Drawing.Size(1510, 380);
((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).EndInit();
this.ResumeLayout(false);
} }
@ -238,5 +245,6 @@
private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn10; private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn10;
private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn11; private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn11;
private EditTagsDataGridViewImageButtonColumn dataGridViewImageButtonBoxColumn2; private EditTagsDataGridViewImageButtonColumn dataGridViewImageButtonBoxColumn2;
} private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
}
} }

View File

@ -8,6 +8,7 @@ using Dinah.Core;
using Dinah.Core.DataBinding; using Dinah.Core.DataBinding;
using Dinah.Core.Threading; using Dinah.Core.Threading;
using Dinah.Core.Windows.Forms; using Dinah.Core.Windows.Forms;
using LibationFileManager;
using LibationWinForms.Dialogs; using LibationWinForms.Dialogs;
namespace LibationWinForms namespace LibationWinForms
@ -38,12 +39,61 @@ namespace LibationWinForms
{ {
InitializeComponent(); InitializeComponent();
var hiddenGridEntries = Configuration.Instance.HiddenGridColumns;
contextMenuStrip1.Items.Add(new ToolStripLabel("Show / Hide Columns"));
contextMenuStrip1.Items.Add(new ToolStripSeparator());
foreach (DataGridViewColumn column in _dataGridView.Columns)
{
var visible = !hiddenGridEntries.Contains(column.DataPropertyName);
var itemName = column.DataPropertyName;
var menuItem = new ToolStripMenuItem()
{
Text = itemName,
Checked = visible,
Tag = itemName
};
menuItem.Click += HideMenuItem_Click;
contextMenuStrip1.Items.Add(menuItem);
column.Visible = visible;
}
// sorting breaks filters. must reapply filters after sorting // sorting breaks filters. must reapply filters after sorting
_dataGridView.Sorted += Filter; _dataGridView.Sorted += Filter;
_dataGridView.CellContentClick += DataGridView_CellContentClick; _dataGridView.CellContentClick += DataGridView_CellContentClick;
EnableDoubleBuffering(); EnableDoubleBuffering();
} }
private void HideMenuItem_Click(object sender, EventArgs e)
{
var menuItem = sender as ToolStripMenuItem;
var propertyName = menuItem.Tag as string;
var column = _dataGridView.Columns.Cast<DataGridViewColumn>().FirstOrDefault(c => c.DataPropertyName == propertyName);
if (column != null)
{
var visible = menuItem.Checked;
menuItem.Checked = !visible;
column.Visible = !visible;
var config = Configuration.Instance;
var hiddenColumns = new List<string>(config.HiddenGridColumns);
if (column.Visible && hiddenColumns.Contains(propertyName))
hiddenColumns.Remove(propertyName);
else if (!hiddenColumns.Contains(propertyName))
hiddenColumns.Add(propertyName);
config.HiddenGridColumns = hiddenColumns.ToArray();
}
}
private void EnableDoubleBuffering() private void EnableDoubleBuffering()
{ {
var propertyInfo = _dataGridView.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var propertyInfo = _dataGridView.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
@ -225,5 +275,6 @@ namespace LibationWinForms
#region DataGridView Macro #region DataGridView Macro
private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex); private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex);
#endregion #endregion
} }
} }

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
@ -61,4 +60,7 @@
<metadata name="gridEntryBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="gridEntryBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>197, 17</value>
</metadata>
</root> </root>