diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 200280207..032d29282 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -423,10 +423,7 @@ private void BtnShowStats_Click(object sender, EventArgs e) private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { - if (e.IsSelected) - { - UpdateControls(); - } + UpdateControls(); } private void lvHistory_MouseDoubleClick(object sender, MouseEventArgs e) diff --git a/ShareX.HistoryLib/HistoryItemManager.cs b/ShareX.HistoryLib/HistoryItemManager.cs index 5d5e19c6a..dbe848668 100644 --- a/ShareX.HistoryLib/HistoryItemManager.cs +++ b/ShareX.HistoryLib/HistoryItemManager.cs @@ -61,7 +61,16 @@ public HistoryItemManager(Action uploadFile, Action editImage) public HistoryItem UpdateSelectedHistoryItem() { - HistoryItem = GetSelectedHistoryItem(); + HistoryItem[] historyItems = OnGetHistoryItems(); + + if (historyItems != null && historyItems.Length > 0) + { + HistoryItem = historyItems[0]; + } + else + { + HistoryItem = null; + } if (HistoryItem != null) { @@ -76,7 +85,7 @@ public HistoryItem UpdateSelectedHistoryItem() IsImageFile = IsFileExist && Helpers.IsImageFile(HistoryItem.FilePath); IsTextFile = IsFileExist && Helpers.IsTextFile(HistoryItem.FilePath); - UpdateButtons(); + UpdateContextMenu(historyItems.Length); } else { @@ -86,20 +95,6 @@ public HistoryItem UpdateSelectedHistoryItem() return HistoryItem; } - private HistoryItem GetSelectedHistoryItem() - { - HistoryItem[] historyItems = OnGetHistoryItems(); - - if (historyItems != null && historyItems.Length > 0) - { - UpdateTexts(historyItems.Length); - - return historyItems[0]; - } - - return null; - } - public HistoryItem[] OnGetHistoryItems() { if (GetHistoryItems != null) diff --git a/ShareX.HistoryLib/HistoryItemManager_ContextMenu.cs b/ShareX.HistoryLib/HistoryItemManager_ContextMenu.cs index 1e79a9ca6..588457058 100644 --- a/ShareX.HistoryLib/HistoryItemManager_ContextMenu.cs +++ b/ShareX.HistoryLib/HistoryItemManager_ContextMenu.cs @@ -438,99 +438,12 @@ private void InitializeComponent() cmsHistory.ResumeLayout(false); } - public void UpdateTexts(int itemsCount) - { - if (itemsCount > 1) - { - tsmiCopyURL.Text = Resources.HistoryItemManager_InitializeComponent_URL + " (" + itemsCount + ")"; - tsmiCopyShortenedURL.Text = Resources.HistoryItemManager_InitializeComponent_Shortened_URL + " (" + itemsCount + ")"; - tsmiCopyThumbnailURL.Text = Resources.HistoryItemManager_InitializeComponent_Thumbnail_URL + " (" + itemsCount + ")"; - tsmiCopyDeletionURL.Text = Resources.HistoryItemManager_InitializeComponent_Deletion_URL + " (" + itemsCount + ")"; - tsmiCopyHTMLLink.Text = Resources.HistoryItemManager_InitializeComponent_HTML_link + " (" + itemsCount + ")"; - tsmiCopyHTMLImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_image + " (" + itemsCount + ")"; - tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image + " (" + itemsCount + ")"; - tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image + " (" + itemsCount + ")"; - tsmiCopyForumLink.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__link + " (" + itemsCount + ")"; - tsmiCopyForumImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__image + " (" + itemsCount + ")"; - tsmiCopyForumLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__linked_image + " (" + itemsCount + ")"; - tsmiCopyMarkdownLink.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__link + " (" + itemsCount + ")"; - tsmiCopyMarkdownImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__image + " (" + itemsCount + ")"; - tsmiCopyMarkdownLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__linked_image + " (" + itemsCount + ")"; - } else - { - tsmiCopyURL.Text = Resources.HistoryItemManager_InitializeComponent_URL; - tsmiCopyShortenedURL.Text = Resources.HistoryItemManager_InitializeComponent_Shortened_URL; - tsmiCopyThumbnailURL.Text = Resources.HistoryItemManager_InitializeComponent_Thumbnail_URL; - tsmiCopyDeletionURL.Text = Resources.HistoryItemManager_InitializeComponent_Deletion_URL; - tsmiCopyHTMLLink.Text = Resources.HistoryItemManager_InitializeComponent_HTML_link; - tsmiCopyHTMLImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_image; - tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image; - tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image; - tsmiCopyForumLink.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__link; - tsmiCopyForumImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__image; - tsmiCopyForumLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__linked_image; - tsmiCopyMarkdownLink.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__link; - tsmiCopyMarkdownImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__image; - tsmiCopyMarkdownLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__linked_image; - } - UpdateButtons(); - } - - public void UpdateButtons() + public void UpdateContextMenu(int itemsCount) { cmsHistory.SuspendLayout(); cmsHistory.Enabled = true; - HistoryItem[] historyItem = OnGetHistoryItems(); - int count = historyItem.Length; - if (count == 1) - { - // Open - tsmiOpenURL.Enabled = IsURLExist; - tsmiOpenShortenedURL.Enabled = IsShortenedURLExist; - tsmiOpenThumbnailURL.Enabled = IsThumbnailURLExist; - tsmiOpenDeletionURL.Enabled = IsDeletionURLExist; - tsmiOpenFile.Enabled = IsFileExist; - tsmiOpenFolder.Enabled = IsFileExist; - - // Copy - tsmiCopyURL.Enabled = IsURLExist; - tsmiCopyShortenedURL.Enabled = IsShortenedURLExist; - tsmiCopyThumbnailURL.Enabled = IsThumbnailURLExist; - tsmiCopyDeletionURL.Enabled = IsDeletionURLExist; - - tsmiCopyFile.Enabled = IsFileExist; - tsmiCopyImage.Enabled = IsImageFile; - tsmiCopyText.Enabled = IsTextFile; - - tsmiCopyHTMLLink.Enabled = IsURLExist; - tsmiCopyHTMLImage.Enabled = IsImageURL; - tsmiCopyHTMLLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - - tsmiCopyForumLink.Enabled = IsURLExist; - tsmiCopyForumImage.Enabled = IsImageURL && IsURLExist; - tsmiCopyForumLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - - tsmiCopyMarkdownLink.Enabled = IsURLExist; - tsmiCopyMarkdownImage.Enabled = IsImageURL && IsURLExist; - tsmiCopyMarkdownLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - - tsmiCopyFilePath.Enabled = IsFilePathValid; - tsmiCopyFileName.Enabled = IsFilePathValid; - tsmiCopyFileNameWithExtension.Enabled = IsFilePathValid; - tsmiCopyFolder.Enabled = IsFilePathValid; - - // Show - tsmiShowImagePreview.Enabled = IsImageFile; - tsmiShowMoreInfo.Enabled = true; - - // Upload file - tsmiUploadFile.Enabled = uploadFile != null && IsFileExist; - - // Edit image - tsmiEditImage.Enabled = editImage != null && IsImageFile; - } - else if (count > 1) + if (itemsCount > 1) { // Open tsmiOpenURL.Enabled = false; @@ -568,6 +481,21 @@ public void UpdateButtons() tsmiCopyFileNameWithExtension.Enabled = false; tsmiCopyFolder.Enabled = false; + tsmiCopyURL.Text = Resources.HistoryItemManager_InitializeComponent_URL + " (" + itemsCount + ")"; + tsmiCopyShortenedURL.Text = Resources.HistoryItemManager_InitializeComponent_Shortened_URL + " (" + itemsCount + ")"; + tsmiCopyThumbnailURL.Text = Resources.HistoryItemManager_InitializeComponent_Thumbnail_URL + " (" + itemsCount + ")"; + tsmiCopyDeletionURL.Text = Resources.HistoryItemManager_InitializeComponent_Deletion_URL + " (" + itemsCount + ")"; + tsmiCopyHTMLLink.Text = Resources.HistoryItemManager_InitializeComponent_HTML_link + " (" + itemsCount + ")"; + tsmiCopyHTMLImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_image + " (" + itemsCount + ")"; + tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image + " (" + itemsCount + ")"; + tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image + " (" + itemsCount + ")"; + tsmiCopyForumLink.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__link + " (" + itemsCount + ")"; + tsmiCopyForumImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__image + " (" + itemsCount + ")"; + tsmiCopyForumLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__linked_image + " (" + itemsCount + ")"; + tsmiCopyMarkdownLink.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__link + " (" + itemsCount + ")"; + tsmiCopyMarkdownImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__image + " (" + itemsCount + ")"; + tsmiCopyMarkdownLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__linked_image + " (" + itemsCount + ")"; + // Show tsmiShow.Enabled = false; tsmiShowImagePreview.Enabled = false; @@ -582,52 +510,68 @@ public void UpdateButtons() else { // Open - tsmiOpenURL.Enabled = false; - tsmiOpenShortenedURL.Enabled = false; - tsmiOpenThumbnailURL.Enabled = false; - tsmiOpenDeletionURL.Enabled = false; + tsmiOpenURL.Enabled = IsURLExist; + tsmiOpenShortenedURL.Enabled = IsShortenedURLExist; + tsmiOpenThumbnailURL.Enabled = IsThumbnailURLExist; + tsmiOpenDeletionURL.Enabled = IsDeletionURLExist; - tsmiOpenFile.Enabled = false; - tsmiOpenFolder.Enabled = false; + tsmiOpenFile.Enabled = IsFileExist; + tsmiOpenFolder.Enabled = IsFileExist; // Copy - tsmiCopyURL.Enabled = false; - tsmiCopyShortenedURL.Enabled = false; - tsmiCopyThumbnailURL.Enabled = false; - tsmiCopyDeletionURL.Enabled = false; + tsmiCopyURL.Enabled = IsURLExist; + tsmiCopyShortenedURL.Enabled = IsShortenedURLExist; + tsmiCopyThumbnailURL.Enabled = IsThumbnailURLExist; + tsmiCopyDeletionURL.Enabled = IsDeletionURLExist; - tsmiCopyFile.Enabled = false; - tsmiCopyImage.Enabled = false; - tsmiCopyText.Enabled = false; + tsmiCopyFile.Enabled = IsFileExist; + tsmiCopyImage.Enabled = IsImageFile; + tsmiCopyText.Enabled = IsTextFile; - tsmiCopyHTMLLink.Enabled = false; - tsmiCopyHTMLImage.Enabled = false; - tsmiCopyHTMLLinkedImage.Enabled = false; + tsmiCopyHTMLLink.Enabled = IsURLExist; + tsmiCopyHTMLImage.Enabled = IsImageURL; + tsmiCopyHTMLLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - tsmiCopyForumLink.Enabled = false; - tsmiCopyForumImage.Enabled = false; - tsmiCopyForumLinkedImage.Enabled = false; + tsmiCopyForumLink.Enabled = IsURLExist; + tsmiCopyForumImage.Enabled = IsImageURL && IsURLExist; + tsmiCopyForumLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - tsmiCopyMarkdownLink.Enabled = false; - tsmiCopyMarkdownImage.Enabled = false; - tsmiCopyMarkdownLinkedImage.Enabled = false; + tsmiCopyMarkdownLink.Enabled = IsURLExist; + tsmiCopyMarkdownImage.Enabled = IsImageURL && IsURLExist; + tsmiCopyMarkdownLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist; - tsmiCopyFilePath.Enabled = false; - tsmiCopyFileName.Enabled = false; - tsmiCopyFileNameWithExtension.Enabled = false; - tsmiCopyFolder.Enabled = false; + tsmiCopyFilePath.Enabled = IsFilePathValid; + tsmiCopyFileName.Enabled = IsFilePathValid; + tsmiCopyFileNameWithExtension.Enabled = IsFilePathValid; + tsmiCopyFolder.Enabled = IsFilePathValid; + + tsmiCopyURL.Text = Resources.HistoryItemManager_InitializeComponent_URL; + tsmiCopyShortenedURL.Text = Resources.HistoryItemManager_InitializeComponent_Shortened_URL; + tsmiCopyThumbnailURL.Text = Resources.HistoryItemManager_InitializeComponent_Thumbnail_URL; + tsmiCopyDeletionURL.Text = Resources.HistoryItemManager_InitializeComponent_Deletion_URL; + tsmiCopyHTMLLink.Text = Resources.HistoryItemManager_InitializeComponent_HTML_link; + tsmiCopyHTMLImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_image; + tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image; + tsmiCopyHTMLLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_HTML_linked_image; + tsmiCopyForumLink.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__link; + tsmiCopyForumImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__image; + tsmiCopyForumLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Forum__BBCode__linked_image; + tsmiCopyMarkdownLink.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__link; + tsmiCopyMarkdownImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__image; + tsmiCopyMarkdownLinkedImage.Text = Resources.HistoryItemManager_InitializeComponent_Markdown__linked_image; // Show - tsmiShow.Enabled = false; - tsmiShowImagePreview.Enabled = false; - tsmiShowMoreInfo.Enabled = false; + tsmiShow.Enabled = true; + tsmiShowImagePreview.Enabled = IsImageFile; + tsmiShowMoreInfo.Enabled = true; // Upload file - tsmiUploadFile.Enabled = false; + tsmiUploadFile.Enabled = uploadFile != null && IsFileExist; // Edit image - tsmiEditImage.Enabled = false; + tsmiEditImage.Enabled = editImage != null && IsImageFile; } + cmsHistory.ResumeLayout(); } diff --git a/ShareX.HistoryLib/Properties/Resources.Designer.cs b/ShareX.HistoryLib/Properties/Resources.Designer.cs index 2a7b3be22..18a8ab73d 100644 --- a/ShareX.HistoryLib/Properties/Resources.Designer.cs +++ b/ShareX.HistoryLib/Properties/Resources.Designer.cs @@ -368,24 +368,6 @@ internal class Resources { } } - /// - /// Looks up a localized string similar to HTML link ({0}). - /// - internal static string HistoryItemManager_UpdateTexts_HTML_link___0__ { - get { - return ResourceManager.GetString("HistoryItemManager_UpdateTexts_HTML_link___0__", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to URLs ({0}). - /// - internal static string HistoryItemManager_UpdateTexts_URLs___0__ { - get { - return ResourceManager.GetString("HistoryItemManager_UpdateTexts_URLs___0__", resourceCulture); - } - } - /// /// Looks up a localized string similar to Error. /// diff --git a/ShareX.HistoryLib/Properties/Resources.resx b/ShareX.HistoryLib/Properties/Resources.resx index c31f9ddbe..f8bc56d9b 100644 --- a/ShareX.HistoryLib/Properties/Resources.resx +++ b/ShareX.HistoryLib/Properties/Resources.resx @@ -154,9 +154,6 @@ Show - - URLs ({0}) - HTML image @@ -196,9 +193,6 @@ Forum (BBCode) image - - HTML link ({0}) - Text