diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs index d287190f..63818d6d 100644 --- a/Source/AppScaffolding/LibationScaffolding.cs +++ b/Source/AppScaffolding/LibationScaffolding.cs @@ -125,6 +125,9 @@ namespace AppScaffolding if (!config.Exists(nameof(config.AutoScan))) config.AutoScan = true; + + if (!config.Exists(nameof(config.HiddenGridColumns))) + config.HiddenGridColumns = Array.Empty(); } /// Initialize logging. Run after migration diff --git a/Source/FileManager/PersistentDictionary.cs b/Source/FileManager/PersistentDictionary.cs index 53e87c9a..0073a705 100644 --- a/Source/FileManager/PersistentDictionary.cs +++ b/Source/FileManager/PersistentDictionary.cs @@ -7,236 +7,237 @@ using Newtonsoft.Json.Linq; namespace FileManager { - public class PersistentDictionary - { - public string Filepath { get; } - public bool IsReadOnly { get; } + public class PersistentDictionary + { + public string Filepath { get; } + public bool IsReadOnly { get; } - // optimize for strings. expectation is most settings will be strings and a rare exception will be something else - private Dictionary stringCache { get; } = new Dictionary(); - private Dictionary objectCache { get; } = new Dictionary(); + // optimize for strings. expectation is most settings will be strings and a rare exception will be something else + private Dictionary stringCache { get; } = new Dictionary(); + private Dictionary objectCache { get; } = new Dictionary(); - public PersistentDictionary(string filepath, bool isReadOnly = false) - { - Filepath = filepath; - IsReadOnly = isReadOnly; + public PersistentDictionary(string filepath, bool isReadOnly = false) + { + Filepath = filepath; + IsReadOnly = isReadOnly; - if (File.Exists(Filepath)) - return; + if (File.Exists(Filepath)) + return; - // will create any missing directories, incl subdirectories. if all already exist: no action - Directory.CreateDirectory(Path.GetDirectoryName(filepath)); + // will create any missing directories, incl subdirectories. if all already exist: no action + Directory.CreateDirectory(Path.GetDirectoryName(filepath)); - if (IsReadOnly) - return; + if (IsReadOnly) + return; - createNewFile(); - } + createNewFile(); + } - public string GetString(string propertyName) - { - if (!stringCache.ContainsKey(propertyName)) - { - var jObject = readFile(); - if (!jObject.ContainsKey(propertyName)) - return null; - stringCache[propertyName] = jObject[propertyName].Value(); - } + public string GetString(string propertyName) + { + if (!stringCache.ContainsKey(propertyName)) + { + var jObject = readFile(); + if (!jObject.ContainsKey(propertyName)) + return null; + stringCache[propertyName] = jObject[propertyName].Value(); + } - return stringCache[propertyName]; - } + return stringCache[propertyName]; + } - public T GetNonString(string propertyName) - { - var obj = GetObject(propertyName); - if (obj is null) return default; - if (obj is JValue jValue) return jValue.Value(); - if (obj is JObject jObject) return jObject.ToObject(); - return (T)obj; - } + public T GetNonString(string propertyName) + { + var obj = GetObject(propertyName); + if (obj is null) return default; + if (obj is JValue jValue) return jValue.Value(); + if (obj is JObject jObject) return jObject.ToObject(); + if (obj is JArray jArray && typeof(T).IsArray) return jArray.ToObject(); + return (T)obj; + } - public object GetObject(string propertyName) - { - if (!objectCache.ContainsKey(propertyName)) - { - var jObject = readFile(); - if (!jObject.ContainsKey(propertyName)) - return null; - objectCache[propertyName] = jObject[propertyName].Value(); - } + public object GetObject(string propertyName) + { + if (!objectCache.ContainsKey(propertyName)) + { + var jObject = readFile(); + if (!jObject.ContainsKey(propertyName)) + return null; + objectCache[propertyName] = jObject[propertyName].Value(); + } - return objectCache[propertyName]; - } + return objectCache[propertyName]; + } - public string GetStringFromJsonPath(string jsonPath, string propertyName) => GetStringFromJsonPath($"{jsonPath}.{propertyName}"); - public string GetStringFromJsonPath(string jsonPath) - { - if (!stringCache.ContainsKey(jsonPath)) - { - try - { - var jObject = readFile(); - var token = jObject.SelectToken(jsonPath); - if (token is null) - return null; - stringCache[jsonPath] = (string)token; - } - catch - { - return null; - } - } + public string GetStringFromJsonPath(string jsonPath, string propertyName) => GetStringFromJsonPath($"{jsonPath}.{propertyName}"); + public string GetStringFromJsonPath(string jsonPath) + { + if (!stringCache.ContainsKey(jsonPath)) + { + try + { + var jObject = readFile(); + var token = jObject.SelectToken(jsonPath); + if (token is null) + return null; + stringCache[jsonPath] = (string)token; + } + catch + { + 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(); - public void SetString(string propertyName, string newValue) - { - // only do this check in string cache, NOT object cache - if (stringCache.ContainsKey(propertyName) && stringCache[propertyName] == newValue) - return; + private object locker { get; } = new object(); + public void SetString(string propertyName, string newValue) + { + // only do this check in string cache, NOT object cache + if (stringCache.ContainsKey(propertyName) && stringCache[propertyName] == newValue) + return; - // set cache - stringCache[propertyName] = newValue; + // set cache + stringCache[propertyName] = newValue; - writeFile(propertyName, newValue); - } + writeFile(propertyName, newValue); + } - public void SetNonString(string propertyName, object newValue) - { - // set cache - objectCache[propertyName] = newValue; + public void SetNonString(string propertyName, object newValue) + { + // set cache + objectCache[propertyName] = newValue; - var parsedNewValue = JToken.Parse(JsonConvert.SerializeObject(newValue)); - writeFile(propertyName, parsedNewValue); - } + var parsedNewValue = JToken.Parse(JsonConvert.SerializeObject(newValue)); + writeFile(propertyName, parsedNewValue); + } - private void writeFile(string propertyName, JToken newValue) - { - if (IsReadOnly) - return; + private void writeFile(string propertyName, JToken newValue) + { + if (IsReadOnly) + return; - // write new setting to file - lock (locker) - { - var jObject = readFile(); - var startContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); + // write new setting to file + lock (locker) + { + var jObject = readFile(); + var startContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); - jObject[propertyName] = newValue; - var endContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); + jObject[propertyName] = newValue; + var endContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); - if (startContents == endContents) - return; - - File.WriteAllText(Filepath, endContents); - } + if (startContents == endContents) + return; - try - { - var str = formatValueForLog(newValue?.ToString()); - Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { propertyName, newValue = str }); - } - catch { } - } + File.WriteAllText(Filepath, endContents); + } - /// WILL ONLY set if already present. WILL NOT create new - /// Value was changed - public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false) - { - if (IsReadOnly) - return false; + try + { + var str = formatValueForLog(newValue?.ToString()); + Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { propertyName, newValue = str }); + } + catch { } + } - var path = $"{jsonPath}.{propertyName}"; + /// WILL ONLY set if already present. WILL NOT create new + /// Value was changed + public bool SetWithJsonPath(string jsonPath, string propertyName, string newValue, bool suppressLogging = false) + { + if (IsReadOnly) + return false; - { - // only do this check in string cache, NOT object cache - if (stringCache.ContainsKey(path) && stringCache[path] == newValue) - return false; + var path = $"{jsonPath}.{propertyName}"; - // 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 - { - lock (locker) - { - var jObject = readFile(); - var token = jObject.SelectToken(jsonPath); - if (token is null || token[propertyName] is null) - return false; + // set cache + stringCache[path] = newValue; + } - var oldValue = token.Value(propertyName); - if (oldValue == newValue) - return false; + try + { + lock (locker) + { + var jObject = readFile(); + var token = jObject.SelectToken(jsonPath); + if (token is null || token[propertyName] is null) + return false; - token[propertyName] = newValue; - File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); - } - } - catch (Exception exDebug) - { - return false; - } + var oldValue = token.Value(propertyName); + if (oldValue == newValue) + return false; - if (!suppressLogging) - { - try - { - var str = formatValueForLog(newValue?.ToString()); - Serilog.Log.Logger.Information("Config changed. {@DebugInfo}", new { jsonPath, propertyName, newValue = str }); - } - catch { } - } + token[propertyName] = newValue; + File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); + } + } + catch (Exception exDebug) + { + return false; + } - 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) - => 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; + return true; + } - 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; - } + private static string formatValueForLog(string value) + => 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; - 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)) - { - createNewFile(); - settingsJsonContents = File.ReadAllText(Filepath); - } + var settingsJsonContents = File.ReadAllText(Filepath); - var jObject = JsonConvert.DeserializeObject(settingsJsonContents); + if (string.IsNullOrWhiteSpace(settingsJsonContents)) + { + createNewFile(); + settingsJsonContents = File.ReadAllText(Filepath); + } - 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; - } + var jObject = JsonConvert.DeserializeObject(settingsJsonContents); - 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() - { - File.WriteAllText(Filepath, "{}"); - System.Threading.Thread.Sleep(100); - } - } + return jObject; + } + + private void createNewFile() + { + File.WriteAllText(Filepath, "{}"); + System.Threading.Thread.Sleep(100); + } + } } diff --git a/Source/LibationFileManager/Configuration.cs b/Source/LibationFileManager/Configuration.cs index 89ab5f9f..0a18b770 100644 --- a/Source/LibationFileManager/Configuration.cs +++ b/Source/LibationFileManager/Configuration.cs @@ -179,6 +179,13 @@ namespace LibationFileManager get => persistentDictionary.GetNonString(nameof(LameVBRQuality)); 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(nameof(HiddenGridColumns)); + set => persistentDictionary.SetNonString(nameof(HiddenGridColumns), value); + } public enum BadBookAction { diff --git a/Source/LibationWinForms/grid/ProductsGrid.Designer.cs b/Source/LibationWinForms/grid/ProductsGrid.Designer.cs index 689bd848..0aec4e05 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.Designer.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.Designer.cs @@ -28,40 +28,41 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components); - this.gridEntryDataGridView = new System.Windows.Forms.DataGridView(); - this.dataGridViewImageButtonBoxColumn1 = new LibationWinForms.LiberateDataGridViewImageButtonColumn(); - this.dataGridViewImageColumn1 = new System.Windows.Forms.DataGridViewImageColumn(); - this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewTextBoxColumn11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.dataGridViewImageButtonBoxColumn2 = new LibationWinForms.EditTagsDataGridViewImageButtonColumn(); - ((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).BeginInit(); - this.SuspendLayout(); - // - // gridEntryBindingSource - // - this.gridEntryBindingSource.DataSource = typeof(LibationWinForms.GridEntry); - // - // gridEntryDataGridView - // - this.gridEntryDataGridView.AllowUserToAddRows = false; - this.gridEntryDataGridView.AllowUserToDeleteRows = false; - this.gridEntryDataGridView.AllowUserToResizeRows = false; - this.gridEntryDataGridView.AutoGenerateColumns = false; - this.gridEntryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.gridEntryDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + this.gridEntryBindingSource = new LibationWinForms.SyncBindingSource(this.components); + this.gridEntryDataGridView = new System.Windows.Forms.DataGridView(); + this.dataGridViewImageButtonBoxColumn1 = new LibationWinForms.LiberateDataGridViewImageButtonColumn(); + this.dataGridViewImageColumn1 = new System.Windows.Forms.DataGridViewImageColumn(); + this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn6 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn7 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn8 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn9 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn10 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn11 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewImageButtonBoxColumn2 = new LibationWinForms.EditTagsDataGridViewImageButtonColumn(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + ((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).BeginInit(); + this.SuspendLayout(); + // + // gridEntryBindingSource + // + this.gridEntryBindingSource.DataSource = typeof(LibationWinForms.GridEntry); + // + // gridEntryDataGridView + // + this.gridEntryDataGridView.AllowUserToAddRows = false; + this.gridEntryDataGridView.AllowUserToDeleteRows = false; + this.gridEntryDataGridView.AllowUserToResizeRows = false; + this.gridEntryDataGridView.AutoGenerateColumns = false; + this.gridEntryDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gridEntryDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewImageButtonBoxColumn1, this.dataGridViewImageColumn1, this.dataGridViewTextBoxColumn1, @@ -76,147 +77,153 @@ this.dataGridViewTextBoxColumn10, this.dataGridViewTextBoxColumn11, this.dataGridViewImageButtonBoxColumn2}); - this.gridEntryDataGridView.DataSource = this.gridEntryBindingSource; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle1; - this.gridEntryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; - this.gridEntryDataGridView.Location = new System.Drawing.Point(0, 0); - this.gridEntryDataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.gridEntryDataGridView.Name = "gridEntryDataGridView"; - this.gridEntryDataGridView.ReadOnly = true; - this.gridEntryDataGridView.RowHeadersVisible = false; - this.gridEntryDataGridView.RowTemplate.Height = 82; - this.gridEntryDataGridView.Size = new System.Drawing.Size(1510, 380); - this.gridEntryDataGridView.TabIndex = 0; - // - // dataGridViewImageButtonBoxColumn1 - // - this.dataGridViewImageButtonBoxColumn1.DataPropertyName = "Liberate"; - this.dataGridViewImageButtonBoxColumn1.HeaderText = "Liberate"; - this.dataGridViewImageButtonBoxColumn1.Name = "dataGridViewImageButtonBoxColumn1"; - this.dataGridViewImageButtonBoxColumn1.ReadOnly = true; - this.dataGridViewImageButtonBoxColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; - this.dataGridViewImageButtonBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - this.dataGridViewImageButtonBoxColumn1.Width = 75; - // - // dataGridViewImageColumn1 - // - this.dataGridViewImageColumn1.DataPropertyName = "Cover"; - this.dataGridViewImageColumn1.HeaderText = "Cover"; - this.dataGridViewImageColumn1.Name = "dataGridViewImageColumn1"; - this.dataGridViewImageColumn1.ReadOnly = true; - this.dataGridViewImageColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; - this.dataGridViewImageColumn1.ToolTipText = "Cover Art"; - this.dataGridViewImageColumn1.Width = 80; - // - // dataGridViewTextBoxColumn1 - // - this.dataGridViewTextBoxColumn1.DataPropertyName = "Title"; - this.dataGridViewTextBoxColumn1.HeaderText = "Title"; - this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; - this.dataGridViewTextBoxColumn1.ReadOnly = true; - this.dataGridViewTextBoxColumn1.Width = 200; - // - // dataGridViewTextBoxColumn2 - // - this.dataGridViewTextBoxColumn2.DataPropertyName = "Authors"; - this.dataGridViewTextBoxColumn2.HeaderText = "Authors"; - this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; - this.dataGridViewTextBoxColumn2.ReadOnly = true; - // - // dataGridViewTextBoxColumn3 - // - this.dataGridViewTextBoxColumn3.DataPropertyName = "Narrators"; - this.dataGridViewTextBoxColumn3.HeaderText = "Narrators"; - this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; - this.dataGridViewTextBoxColumn3.ReadOnly = true; - // - // dataGridViewTextBoxColumn4 - // - this.dataGridViewTextBoxColumn4.DataPropertyName = "Length"; - this.dataGridViewTextBoxColumn4.HeaderText = "Length"; - this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; - this.dataGridViewTextBoxColumn4.ReadOnly = true; - this.dataGridViewTextBoxColumn4.ToolTipText = "Recording Length"; - // - // dataGridViewTextBoxColumn5 - // - this.dataGridViewTextBoxColumn5.DataPropertyName = "Series"; - this.dataGridViewTextBoxColumn5.HeaderText = "Series"; - this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; - this.dataGridViewTextBoxColumn5.ReadOnly = true; - // - // dataGridViewTextBoxColumn6 - // - this.dataGridViewTextBoxColumn6.DataPropertyName = "Description"; - this.dataGridViewTextBoxColumn6.HeaderText = "Description"; - this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6"; - this.dataGridViewTextBoxColumn6.ReadOnly = true; - // - // dataGridViewTextBoxColumn7 - // - this.dataGridViewTextBoxColumn7.DataPropertyName = "Category"; - this.dataGridViewTextBoxColumn7.HeaderText = "Category"; - this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7"; - this.dataGridViewTextBoxColumn7.ReadOnly = true; - // - // ProductRating - // - this.dataGridViewTextBoxColumn8.DataPropertyName = "ProductRating"; - this.dataGridViewTextBoxColumn8.HeaderText = "Product Rating"; - this.dataGridViewTextBoxColumn8.Name = "ProductRating"; - this.dataGridViewTextBoxColumn8.ReadOnly = true; - this.dataGridViewTextBoxColumn8.Width = 108; - // - // PurchaseDate - // - this.dataGridViewTextBoxColumn9.DataPropertyName = "PurchaseDate"; - this.dataGridViewTextBoxColumn9.HeaderText = "Purchase Date"; - this.dataGridViewTextBoxColumn9.Name = "PurchaseDate"; - this.dataGridViewTextBoxColumn9.ReadOnly = true; - // - // MyRating - // - this.dataGridViewTextBoxColumn10.DataPropertyName = "MyRating"; - this.dataGridViewTextBoxColumn10.HeaderText = "My Rating"; - this.dataGridViewTextBoxColumn10.Name = "MyRating"; - this.dataGridViewTextBoxColumn10.ReadOnly = true; - this.dataGridViewTextBoxColumn10.Width = 108; - // - // dataGridViewTextBoxColumn11 - // - this.dataGridViewTextBoxColumn11.DataPropertyName = "Misc"; - this.dataGridViewTextBoxColumn11.HeaderText = "Misc"; - this.dataGridViewTextBoxColumn11.Name = "dataGridViewTextBoxColumn11"; - this.dataGridViewTextBoxColumn11.ReadOnly = true; - this.dataGridViewTextBoxColumn11.Width = 135; - // - // dataGridViewImageButtonBoxColumn2 - // - this.dataGridViewImageButtonBoxColumn2.DataPropertyName = "DisplayTags"; - this.dataGridViewImageButtonBoxColumn2.HeaderText = "Tags and Details"; - this.dataGridViewImageButtonBoxColumn2.Name = "dataGridViewImageButtonBoxColumn2"; - this.dataGridViewImageButtonBoxColumn2.ReadOnly = true; - this.dataGridViewImageButtonBoxColumn2.Resizable = System.Windows.Forms.DataGridViewTriState.False; - this.dataGridViewImageButtonBoxColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - // - // ProductsGrid - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - 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); + this.gridEntryDataGridView.ContextMenuStrip = this.contextMenuStrip1; + this.gridEntryDataGridView.DataSource = this.gridEntryBindingSource; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.gridEntryDataGridView.DefaultCellStyle = dataGridViewCellStyle1; + this.gridEntryDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.gridEntryDataGridView.Location = new System.Drawing.Point(0, 0); + this.gridEntryDataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.gridEntryDataGridView.Name = "gridEntryDataGridView"; + this.gridEntryDataGridView.ReadOnly = true; + this.gridEntryDataGridView.RowHeadersVisible = false; + this.gridEntryDataGridView.RowTemplate.Height = 82; + this.gridEntryDataGridView.Size = new System.Drawing.Size(1510, 380); + this.gridEntryDataGridView.TabIndex = 0; + // + // dataGridViewImageButtonBoxColumn1 + // + this.dataGridViewImageButtonBoxColumn1.DataPropertyName = "Liberate"; + this.dataGridViewImageButtonBoxColumn1.HeaderText = "Liberate"; + this.dataGridViewImageButtonBoxColumn1.Name = "dataGridViewImageButtonBoxColumn1"; + this.dataGridViewImageButtonBoxColumn1.ReadOnly = true; + this.dataGridViewImageButtonBoxColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridViewImageButtonBoxColumn1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + this.dataGridViewImageButtonBoxColumn1.Width = 75; + // + // dataGridViewImageColumn1 + // + this.dataGridViewImageColumn1.DataPropertyName = "Cover"; + this.dataGridViewImageColumn1.HeaderText = "Cover"; + this.dataGridViewImageColumn1.Name = "dataGridViewImageColumn1"; + this.dataGridViewImageColumn1.ReadOnly = true; + this.dataGridViewImageColumn1.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridViewImageColumn1.ToolTipText = "Cover Art"; + this.dataGridViewImageColumn1.Width = 80; + // + // dataGridViewTextBoxColumn1 + // + this.dataGridViewTextBoxColumn1.DataPropertyName = "Title"; + this.dataGridViewTextBoxColumn1.HeaderText = "Title"; + this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + this.dataGridViewTextBoxColumn1.ReadOnly = true; + this.dataGridViewTextBoxColumn1.Width = 200; + // + // dataGridViewTextBoxColumn2 + // + this.dataGridViewTextBoxColumn2.DataPropertyName = "Authors"; + this.dataGridViewTextBoxColumn2.HeaderText = "Authors"; + this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; + this.dataGridViewTextBoxColumn2.ReadOnly = true; + // + // dataGridViewTextBoxColumn3 + // + this.dataGridViewTextBoxColumn3.DataPropertyName = "Narrators"; + this.dataGridViewTextBoxColumn3.HeaderText = "Narrators"; + this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; + this.dataGridViewTextBoxColumn3.ReadOnly = true; + // + // dataGridViewTextBoxColumn4 + // + this.dataGridViewTextBoxColumn4.DataPropertyName = "Length"; + this.dataGridViewTextBoxColumn4.HeaderText = "Length"; + this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; + this.dataGridViewTextBoxColumn4.ReadOnly = true; + this.dataGridViewTextBoxColumn4.ToolTipText = "Recording Length"; + // + // dataGridViewTextBoxColumn5 + // + this.dataGridViewTextBoxColumn5.DataPropertyName = "Series"; + this.dataGridViewTextBoxColumn5.HeaderText = "Series"; + this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5"; + this.dataGridViewTextBoxColumn5.ReadOnly = true; + // + // dataGridViewTextBoxColumn6 + // + this.dataGridViewTextBoxColumn6.DataPropertyName = "Description"; + this.dataGridViewTextBoxColumn6.HeaderText = "Description"; + this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6"; + this.dataGridViewTextBoxColumn6.ReadOnly = true; + // + // dataGridViewTextBoxColumn7 + // + this.dataGridViewTextBoxColumn7.DataPropertyName = "Category"; + this.dataGridViewTextBoxColumn7.HeaderText = "Category"; + this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7"; + this.dataGridViewTextBoxColumn7.ReadOnly = true; + // + // dataGridViewTextBoxColumn8 + // + this.dataGridViewTextBoxColumn8.DataPropertyName = "ProductRating"; + this.dataGridViewTextBoxColumn8.HeaderText = "Product Rating"; + this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8"; + this.dataGridViewTextBoxColumn8.ReadOnly = true; + this.dataGridViewTextBoxColumn8.Width = 108; + // + // dataGridViewTextBoxColumn9 + // + this.dataGridViewTextBoxColumn9.DataPropertyName = "PurchaseDate"; + this.dataGridViewTextBoxColumn9.HeaderText = "Purchase Date"; + this.dataGridViewTextBoxColumn9.Name = "dataGridViewTextBoxColumn9"; + this.dataGridViewTextBoxColumn9.ReadOnly = true; + // + // dataGridViewTextBoxColumn10 + // + this.dataGridViewTextBoxColumn10.DataPropertyName = "MyRating"; + this.dataGridViewTextBoxColumn10.HeaderText = "My Rating"; + this.dataGridViewTextBoxColumn10.Name = "dataGridViewTextBoxColumn10"; + this.dataGridViewTextBoxColumn10.ReadOnly = true; + this.dataGridViewTextBoxColumn10.Width = 108; + // + // dataGridViewTextBoxColumn11 + // + this.dataGridViewTextBoxColumn11.DataPropertyName = "Misc"; + this.dataGridViewTextBoxColumn11.HeaderText = "Misc"; + this.dataGridViewTextBoxColumn11.Name = "dataGridViewTextBoxColumn11"; + this.dataGridViewTextBoxColumn11.ReadOnly = true; + this.dataGridViewTextBoxColumn11.Width = 135; + // + // dataGridViewImageButtonBoxColumn2 + // + this.dataGridViewImageButtonBoxColumn2.DataPropertyName = "DisplayTags"; + this.dataGridViewImageButtonBoxColumn2.HeaderText = "Tags and Details"; + this.dataGridViewImageButtonBoxColumn2.Name = "dataGridViewImageButtonBoxColumn2"; + this.dataGridViewImageButtonBoxColumn2.ReadOnly = true; + this.dataGridViewImageButtonBoxColumn2.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.dataGridViewImageButtonBoxColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(181, 26); + // + // ProductsGrid + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + 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 dataGridViewTextBoxColumn11; private EditTagsDataGridViewImageButtonColumn dataGridViewImageButtonBoxColumn2; - } + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + } } diff --git a/Source/LibationWinForms/grid/ProductsGrid.cs b/Source/LibationWinForms/grid/ProductsGrid.cs index d5c0dc52..e6d71366 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.cs +++ b/Source/LibationWinForms/grid/ProductsGrid.cs @@ -8,6 +8,7 @@ using Dinah.Core; using Dinah.Core.DataBinding; using Dinah.Core.Threading; using Dinah.Core.Windows.Forms; +using LibationFileManager; using LibationWinForms.Dialogs; namespace LibationWinForms @@ -38,12 +39,61 @@ namespace LibationWinForms { 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 _dataGridView.Sorted += Filter; _dataGridView.CellContentClick += DataGridView_CellContentClick; 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().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(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() { var propertyInfo = _dataGridView.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); @@ -225,5 +275,6 @@ namespace LibationWinForms #region DataGridView Macro private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem(rowIndex); #endregion + } } diff --git a/Source/LibationWinForms/grid/ProductsGrid.resx b/Source/LibationWinForms/grid/ProductsGrid.resx index 6ee0745a..cc951239 100644 --- a/Source/LibationWinForms/grid/ProductsGrid.resx +++ b/Source/LibationWinForms/grid/ProductsGrid.resx @@ -1,5 +1,4 @@ - - + @@ -61,4 +60,7 @@ 17, 17 + + 197, 17 + \ No newline at end of file