From ce711a36bac0ec0d544c923990d5b63c00504ae5 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Mon, 12 Dec 2022 15:03:20 -0500 Subject: [PATCH] #398 - new feature: right-click, copy --- .../Views/ProductsDisplay.axaml | 2 + .../LibationFileManager/IInteropFunctions.cs | 1 + Source/LibationFileManager/InteropFactory.cs | 12 +++-- .../NullInteropFunctions.cs | 1 + Source/LibationWinForms/GridView/GridEntry.cs | 14 ++++-- .../GridView/LibraryBookEntry.cs | 8 ++- .../GridView/ProductsGrid.Designer.cs | 3 +- .../LibationWinForms/GridView/ProductsGrid.cs | 49 ++++++++++++++++++- .../LibationWinForms/GridView/SeriesEntry.cs | 6 ++- .../LoadByOS/LinuxConfigApp/LinuxInterop.cs | 1 + .../LoadByOS/MacOSConfigApp/MacOSInterop.cs | 1 + .../LoadByOS/WindowsConfigApp/WinInterop.cs | 3 ++ 12 files changed, 88 insertions(+), 13 deletions(-) diff --git a/Source/LibationAvalonia/Views/ProductsDisplay.axaml b/Source/LibationAvalonia/Views/ProductsDisplay.axaml index 5c3748a3..1371b44a 100644 --- a/Source/LibationAvalonia/Views/ProductsDisplay.axaml +++ b/Source/LibationAvalonia/Views/ProductsDisplay.axaml @@ -44,6 +44,7 @@ diff --git a/Source/LibationFileManager/IInteropFunctions.cs b/Source/LibationFileManager/IInteropFunctions.cs index a6ba31c7..423d438d 100644 --- a/Source/LibationFileManager/IInteropFunctions.cs +++ b/Source/LibationFileManager/IInteropFunctions.cs @@ -6,5 +6,6 @@ namespace LibationFileManager { void SetFolderIcon(string image, string directory); void DeleteFolderIcon(string directory); + void CopyTextToClipboard(string text); } } diff --git a/Source/LibationFileManager/InteropFactory.cs b/Source/LibationFileManager/InteropFactory.cs index b05919c9..ac2928a9 100644 --- a/Source/LibationFileManager/InteropFactory.cs +++ b/Source/LibationFileManager/InteropFactory.cs @@ -19,10 +19,16 @@ namespace LibationFileManager //public static IInteropFunctions Create(string str, int i) => _create(str, i); //public static IInteropFunctions Create(params object[] values) => _create(values); + private static IInteropFunctions instance { get; set; } private static IInteropFunctions _create(params object[] values) - => InteropFunctionsType is null ? new NullInteropFunctions() - //: values is null || values.Length == 0 ? Activator.CreateInstance(InteropFunctionsType) as IInteropFunctions - : Activator.CreateInstance(InteropFunctionsType, values) as IInteropFunctions; + { + instance ??= + InteropFunctionsType is null + ? new NullInteropFunctions() + //: values is null || values.Length == 0 ? Activator.CreateInstance(InteropFunctionsType) as IInteropFunctions + : Activator.CreateInstance(InteropFunctionsType, values) as IInteropFunctions; + return instance; + } #region load types diff --git a/Source/LibationFileManager/NullInteropFunctions.cs b/Source/LibationFileManager/NullInteropFunctions.cs index 74e891b1..7f0e6908 100644 --- a/Source/LibationFileManager/NullInteropFunctions.cs +++ b/Source/LibationFileManager/NullInteropFunctions.cs @@ -9,5 +9,6 @@ namespace LibationFileManager public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException(); public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException(); + public void CopyTextToClipboard(string text) => throw new PlatformNotSupportedException(); } } diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index 54afcc24..18a86e8a 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -28,9 +28,13 @@ namespace LibationWinForms.GridView [Browsable(false)] public abstract DateTime DateAdded { get; } [Browsable(false)] protected Book Book => LibraryBook.Book; - #region Model properties exposed to the view + [Browsable(false)] public abstract bool IsSeries { get; } + [Browsable(false)] public abstract bool IsEpisode { get; } + [Browsable(false)] public abstract bool IsBook { get; } - protected RemoveStatus _remove = RemoveStatus.NotRemoved; + #region Model properties exposed to the view + + protected RemoveStatus _remove = RemoveStatus.NotRemoved; public abstract RemoveStatus Remove { get; set; } public abstract LiberateButtonStatus Liberate { get; } @@ -56,11 +60,11 @@ namespace LibationWinForms.GridView public string MyRating { get; protected set; } public abstract string DisplayTags { get; } - #endregion + #endregion - #region Sorting + #region Sorting - public GridEntry() => _memberValues = CreateMemberValueDictionary(); + public GridEntry() => _memberValues = CreateMemberValueDictionary(); // These methods are implementation of Dinah.Core.DataBinding.IMemberComparable // Used by GridEntryBindingList for all sorting diff --git a/Source/LibationWinForms/GridView/LibraryBookEntry.cs b/Source/LibationWinForms/GridView/LibraryBookEntry.cs index ce1670fb..c37aef3e 100644 --- a/Source/LibationWinForms/GridView/LibraryBookEntry.cs +++ b/Source/LibationWinForms/GridView/LibraryBookEntry.cs @@ -14,9 +14,13 @@ namespace LibationWinForms.GridView [Browsable(false)] public override DateTime DateAdded => LibraryBook.DateAdded; [Browsable(false)] public SeriesEntry Parent { get; init; } - #region Model properties exposed to the view + [Browsable(false)] public override bool IsSeries => false; + [Browsable(false)] public override bool IsEpisode => Parent is not null; + [Browsable(false)] public override bool IsBook => Parent is null; - private DateTime lastStatusUpdate = default; + #region Model properties exposed to the view + + private DateTime lastStatusUpdate = default; private LiberatedStatus _bookStatus; private LiberatedStatus? _pdfStatus; diff --git a/Source/LibationWinForms/GridView/ProductsGrid.Designer.cs b/Source/LibationWinForms/GridView/ProductsGrid.Designer.cs index bca1dec0..7f14884a 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.Designer.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.Designer.cs @@ -94,7 +94,8 @@ this.gridEntryDataGridView.Size = new System.Drawing.Size(1570, 380); this.gridEntryDataGridView.TabIndex = 0; this.gridEntryDataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellContentClick); - this.gridEntryDataGridView.CellToolTipTextNeeded += new System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler(this.gridEntryDataGridView_CellToolTipTextNeeded); + this.gridEntryDataGridView.CellContextMenuStripNeeded += new System.Windows.Forms.DataGridViewCellContextMenuStripNeededEventHandler(this.gridEntryDataGridView_CellContextMenuStripNeeded); + this.gridEntryDataGridView.CellToolTipTextNeeded += new System.Windows.Forms.DataGridViewCellToolTipTextNeededEventHandler(this.gridEntryDataGridView_CellToolTipTextNeeded); // // removeGVColumn // diff --git a/Source/LibationWinForms/GridView/ProductsGrid.cs b/Source/LibationWinForms/GridView/ProductsGrid.cs index ab4507be..835e0984 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.cs @@ -100,7 +100,54 @@ namespace LibationWinForms.GridView } } - private GridEntry getGridEntry(int rowIndex) => gridEntryDataGridView.GetBoundItem(rowIndex); + private void gridEntryDataGridView_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e) + { + var dgv = (DataGridView)sender; + + // cover + if (e.ColumnIndex == coverGVColumn.Index) + return; + + // any non-stop light + if (e.ColumnIndex != liberateGVColumn.Index) + { + var copyContextMenu = new ContextMenuStrip(); + copyContextMenu.Items.Add("Copy", null, (_, __) => + { + try + { + var text = dgv[e.ColumnIndex, e.RowIndex].Value.ToString(); + InteropFactory.Create().CopyTextToClipboard(text); + } + catch { } + }); + + e.ContextMenuStrip = copyContextMenu; + return; + } + + // else: stop light + + var entry = getGridEntry(e.RowIndex); + if (entry.IsSeries) + return; + + // \Visual Studio 2022\Libation\Source\LibationAvalonia\Views\ProductsDisplay.axaml + /* + + + + + + */ + //var contextMenu = new ContextMenuStrip(); + //contextMenu.Items.Add("Item 1"); + //contextMenu.Items.Add("Item 2"); + //contextMenu.Items.Add("Item 3"); + //e.ContextMenuStrip = contextMenu; + } + + private GridEntry getGridEntry(int rowIndex) => gridEntryDataGridView.GetBoundItem(rowIndex); #endregion diff --git a/Source/LibationWinForms/GridView/SeriesEntry.cs b/Source/LibationWinForms/GridView/SeriesEntry.cs index e1221009..1ebe5e4f 100644 --- a/Source/LibationWinForms/GridView/SeriesEntry.cs +++ b/Source/LibationWinForms/GridView/SeriesEntry.cs @@ -13,7 +13,11 @@ namespace LibationWinForms.GridView [Browsable(false)] public List Children { get; } [Browsable(false)] public override DateTime DateAdded => Children.Max(c => c.DateAdded); - private bool suspendCounting = false; + [Browsable(false)] public override bool IsSeries => true; + [Browsable(false)] public override bool IsEpisode => false; + [Browsable(false)] public override bool IsBook => false; + + private bool suspendCounting = false; public void ChildRemoveUpdate() { if (suspendCounting) return; diff --git a/Source/LoadByOS/LinuxConfigApp/LinuxInterop.cs b/Source/LoadByOS/LinuxConfigApp/LinuxInterop.cs index a2963f1e..08324141 100644 --- a/Source/LoadByOS/LinuxConfigApp/LinuxInterop.cs +++ b/Source/LoadByOS/LinuxConfigApp/LinuxInterop.cs @@ -9,5 +9,6 @@ namespace LinuxConfigApp public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException(); public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException(); + public void CopyTextToClipboard(string text) => throw new PlatformNotSupportedException(); } } diff --git a/Source/LoadByOS/MacOSConfigApp/MacOSInterop.cs b/Source/LoadByOS/MacOSConfigApp/MacOSInterop.cs index 2fafef09..378e7323 100644 --- a/Source/LoadByOS/MacOSConfigApp/MacOSInterop.cs +++ b/Source/LoadByOS/MacOSConfigApp/MacOSInterop.cs @@ -9,5 +9,6 @@ namespace MacOSConfigApp public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException(); public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException(); + public void CopyTextToClipboard(string text) => throw new PlatformNotSupportedException(); } } diff --git a/Source/LoadByOS/WindowsConfigApp/WinInterop.cs b/Source/LoadByOS/WindowsConfigApp/WinInterop.cs index fe3eef35..ff4ef910 100644 --- a/Source/LoadByOS/WindowsConfigApp/WinInterop.cs +++ b/Source/LoadByOS/WindowsConfigApp/WinInterop.cs @@ -35,5 +35,8 @@ namespace WindowsConfigApp public void DeleteFolderIcon(string directory) => new DirectoryInfo(directory)?.DeleteIcon(); + + public void CopyTextToClipboard(string text) + => Clipboard.SetText(text); } }