From e4fca3f47f27244e94b9b39f5877c67fd70792d5 Mon Sep 17 00:00:00 2001 From: maforget <11904426+maforget@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:28:54 -0500 Subject: [PATCH] Moved the check to enable Paste Data to a separate method --- ComicRack/Views/ComicBrowserControl.cs | 145 +++++++++++++------------ 1 file changed, 75 insertions(+), 70 deletions(-) diff --git a/ComicRack/Views/ComicBrowserControl.cs b/ComicRack/Views/ComicBrowserControl.cs index bd438f3..e18b083 100644 --- a/ComicRack/Views/ComicBrowserControl.cs +++ b/ComicRack/Views/ComicBrowserControl.cs @@ -2652,7 +2652,20 @@ public void UpdateFiles() }); } - public void PasteComicData() + private bool isPasteComicDataEnabled() + { + //Check if the clipboard contains data, if so enable the paste button. + try + { + return ComicEditMode.CanEditProperties() && Clipboard.ContainsData("ComicBook") && !GetBookList(ComicBookFilterType.Selected).IsEmpty(); + } + catch (Exception) + { + return false; + } + } + + public void PasteComicData() { try { @@ -2674,78 +2687,70 @@ private void tsListLayouts_DropDownOpening(object sender, EventArgs e) } private void contextMenuItems_Opening(object sender, CancelEventArgs e) - { - IEnumerable enumerable = GetBookList(ComicBookFilterType.Selected); - IEnumerable enumerable2 = GetBookList(ComicBookFilterType.Library | ComicBookFilterType.Selected); - IEnumerable list = GetBookList(ComicBookFilterType.NotInLibrary | ComicBookFilterType.Selected); - CoverViewItem coverViewItem = itemView.FocusedItem as CoverViewItem; - bool flag = ComicEditMode.CanEditProperties(); - bool flag2 = ComicEditMode.CanEditList(); - bool flag3 = !enumerable2.IsEmpty(); - miAddLibrary.Visible = !list.IsEmpty(); - miEdit.Visible = flag && itemView.ItemViewMode == ItemViewMode.Detail; - miShowWeb.Visible = coverViewItem != null && coverViewItem.Comic != null && !string.IsNullOrEmpty(coverViewItem.Comic.Web); - ToolStripMenuItem toolStripMenuItem = miMarkAs; - bool visible = (miRateMenu.Visible = flag && flag3); - toolStripMenuItem.Visible = visible; - miSetTopOfStack.Visible = openStackPanel.Visible; - miSetStackThumbnail.Visible = itemView.IsStack(itemView.SelectedItems.FirstOrDefault()); - miRemoveStackThumbnail.Visible = stacksConfig != null && !string.IsNullOrEmpty(stacksConfig.GetStackCustomThumbnail(itemView.GetStackCaption(itemView.SelectedItems.FirstOrDefault()))); - ComicLibrary comicLibrary = enumerable2.Select((ComicBook cb) => cb.Container as ComicLibrary).FirstOrDefault(); - miAddList.Visible = comicLibrary != null && !comicLibrary.ComicLists.GetItems().IsEmpty() && flag3; - miEditList.Visible = CanReorderList(mustBeOrdered: false); - miExportComics.Visible = ComicEditMode.CanExport(); - miSetListBackground.Visible = BookList is ComicListItem; - ToolStripMenuItem toolStripMenuItem2 = miCopyData; - visible = (miPasteData.Visible = ComicEditMode.CanEditProperties()); - toolStripMenuItem2.Visible = visible; - FormUtility.SafeToolStripClear(miShowOnly.DropDownItems); - for (int j = 0; j < 3; j++) - { - SearchBrowserControl.SelectionEntry selectionColumn = bookSelectorPanel.GetSelectionColumn(j); - string text = null; - if (selectionColumn == null) - { - continue; - } - foreach (ComicBook item in enumerable) - { - string stringPropertyValue = item.GetStringPropertyValue(selectionColumn.Property); - if (text == null) - { - text = stringPropertyValue; - } - else if (text != stringPropertyValue) - { - text = null; - break; - } - } - if (!string.IsNullOrEmpty(text)) - { - int i = j; - miShowOnly.DropDownItems.Add(string.Format("{0} '{1}'", selectionColumn.Caption, text.Ellipsis(60 - selectionColumn.Caption.Length, "...")), null, delegate - { - SearchBrowserVisible = true; - bookSelectorPanel.SelectEntry(i, text); - }); - } - } - miShowOnly.Visible = miShowOnly.DropDownItems.Count != 0; - miUpdateComicFiles.Visible = enumerable.Any((ComicBook cb) => cb.ComicInfoIsDirty); - contextMenuItems.FixSeparators(); - //Check if the clipboard contains data, if so enable the paste button. - try - { - miPasteData.Enabled = ComicEditMode.CanEditProperties() && Clipboard.ContainsData("ComicBook") && !GetBookList(ComicBookFilterType.Selected).IsEmpty(); - } - catch (Exception) - { - miPasteData.Enabled = false; + { + IEnumerable enumerable = GetBookList(ComicBookFilterType.Selected); + IEnumerable enumerable2 = GetBookList(ComicBookFilterType.Library | ComicBookFilterType.Selected); + IEnumerable list = GetBookList(ComicBookFilterType.NotInLibrary | ComicBookFilterType.Selected); + CoverViewItem coverViewItem = itemView.FocusedItem as CoverViewItem; + bool flag = ComicEditMode.CanEditProperties(); + bool flag2 = ComicEditMode.CanEditList(); + bool flag3 = !enumerable2.IsEmpty(); + miAddLibrary.Visible = !list.IsEmpty(); + miEdit.Visible = flag && itemView.ItemViewMode == ItemViewMode.Detail; + miShowWeb.Visible = coverViewItem != null && coverViewItem.Comic != null && !string.IsNullOrEmpty(coverViewItem.Comic.Web); + ToolStripMenuItem toolStripMenuItem = miMarkAs; + bool visible = (miRateMenu.Visible = flag && flag3); + toolStripMenuItem.Visible = visible; + miSetTopOfStack.Visible = openStackPanel.Visible; + miSetStackThumbnail.Visible = itemView.IsStack(itemView.SelectedItems.FirstOrDefault()); + miRemoveStackThumbnail.Visible = stacksConfig != null && !string.IsNullOrEmpty(stacksConfig.GetStackCustomThumbnail(itemView.GetStackCaption(itemView.SelectedItems.FirstOrDefault()))); + ComicLibrary comicLibrary = enumerable2.Select((ComicBook cb) => cb.Container as ComicLibrary).FirstOrDefault(); + miAddList.Visible = comicLibrary != null && !comicLibrary.ComicLists.GetItems().IsEmpty() && flag3; + miEditList.Visible = CanReorderList(mustBeOrdered: false); + miExportComics.Visible = ComicEditMode.CanExport(); + miSetListBackground.Visible = BookList is ComicListItem; + ToolStripMenuItem toolStripMenuItem2 = miCopyData; + visible = (miPasteData.Visible = ComicEditMode.CanEditProperties()); + toolStripMenuItem2.Visible = visible; + FormUtility.SafeToolStripClear(miShowOnly.DropDownItems); + for (int j = 0; j < 3; j++) + { + SearchBrowserControl.SelectionEntry selectionColumn = bookSelectorPanel.GetSelectionColumn(j); + string text = null; + if (selectionColumn == null) + { + continue; + } + foreach (ComicBook item in enumerable) + { + string stringPropertyValue = item.GetStringPropertyValue(selectionColumn.Property); + if (text == null) + { + text = stringPropertyValue; + } + else if (text != stringPropertyValue) + { + text = null; + break; + } + } + if (!string.IsNullOrEmpty(text)) + { + int i = j; + miShowOnly.DropDownItems.Add(string.Format("{0} '{1}'", selectionColumn.Caption, text.Ellipsis(60 - selectionColumn.Caption.Length, "...")), null, delegate + { + SearchBrowserVisible = true; + bookSelectorPanel.SelectEntry(i, text); + }); + } } + miShowOnly.Visible = miShowOnly.DropDownItems.Count != 0; + miUpdateComicFiles.Visible = enumerable.Any((ComicBook cb) => cb.ComicInfoIsDirty); + contextMenuItems.FixSeparators(); + miPasteData.Enabled = isPasteComicDataEnabled(); } - private void LayoutMenuOpening(object sender, CancelEventArgs e) + private void LayoutMenuOpening(object sender, CancelEventArgs e) { try {