HistoryItemManager context menu refactoring

This commit is contained in:
Jaex 2020-01-03 16:15:50 +03:00
parent 38e9aaba41
commit 604ade71c7
5 changed files with 76 additions and 164 deletions

View file

@ -423,10 +423,7 @@ private void BtnShowStats_Click(object sender, EventArgs e)
private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) private void lvHistory_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{ {
if (e.IsSelected) UpdateControls();
{
UpdateControls();
}
} }
private void lvHistory_MouseDoubleClick(object sender, MouseEventArgs e) private void lvHistory_MouseDoubleClick(object sender, MouseEventArgs e)

View file

@ -61,7 +61,16 @@ public HistoryItemManager(Action<string> uploadFile, Action<string> editImage)
public HistoryItem UpdateSelectedHistoryItem() public HistoryItem UpdateSelectedHistoryItem()
{ {
HistoryItem = GetSelectedHistoryItem(); HistoryItem[] historyItems = OnGetHistoryItems();
if (historyItems != null && historyItems.Length > 0)
{
HistoryItem = historyItems[0];
}
else
{
HistoryItem = null;
}
if (HistoryItem != null) if (HistoryItem != null)
{ {
@ -76,7 +85,7 @@ public HistoryItem UpdateSelectedHistoryItem()
IsImageFile = IsFileExist && Helpers.IsImageFile(HistoryItem.FilePath); IsImageFile = IsFileExist && Helpers.IsImageFile(HistoryItem.FilePath);
IsTextFile = IsFileExist && Helpers.IsTextFile(HistoryItem.FilePath); IsTextFile = IsFileExist && Helpers.IsTextFile(HistoryItem.FilePath);
UpdateButtons(); UpdateContextMenu(historyItems.Length);
} }
else else
{ {
@ -86,20 +95,6 @@ public HistoryItem UpdateSelectedHistoryItem()
return HistoryItem; 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() public HistoryItem[] OnGetHistoryItems()
{ {
if (GetHistoryItems != null) if (GetHistoryItems != null)

View file

@ -438,99 +438,12 @@ private void InitializeComponent()
cmsHistory.ResumeLayout(false); cmsHistory.ResumeLayout(false);
} }
public void UpdateTexts(int itemsCount) public void UpdateContextMenu(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()
{ {
cmsHistory.SuspendLayout(); cmsHistory.SuspendLayout();
cmsHistory.Enabled = true; 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; if (itemsCount > 1)
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)
{ {
// Open // Open
tsmiOpenURL.Enabled = false; tsmiOpenURL.Enabled = false;
@ -568,6 +481,21 @@ public void UpdateButtons()
tsmiCopyFileNameWithExtension.Enabled = false; tsmiCopyFileNameWithExtension.Enabled = false;
tsmiCopyFolder.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 // Show
tsmiShow.Enabled = false; tsmiShow.Enabled = false;
tsmiShowImagePreview.Enabled = false; tsmiShowImagePreview.Enabled = false;
@ -582,52 +510,68 @@ public void UpdateButtons()
else else
{ {
// Open // Open
tsmiOpenURL.Enabled = false; tsmiOpenURL.Enabled = IsURLExist;
tsmiOpenShortenedURL.Enabled = false; tsmiOpenShortenedURL.Enabled = IsShortenedURLExist;
tsmiOpenThumbnailURL.Enabled = false; tsmiOpenThumbnailURL.Enabled = IsThumbnailURLExist;
tsmiOpenDeletionURL.Enabled = false; tsmiOpenDeletionURL.Enabled = IsDeletionURLExist;
tsmiOpenFile.Enabled = false; tsmiOpenFile.Enabled = IsFileExist;
tsmiOpenFolder.Enabled = false; tsmiOpenFolder.Enabled = IsFileExist;
// Copy // Copy
tsmiCopyURL.Enabled = false; tsmiCopyURL.Enabled = IsURLExist;
tsmiCopyShortenedURL.Enabled = false; tsmiCopyShortenedURL.Enabled = IsShortenedURLExist;
tsmiCopyThumbnailURL.Enabled = false; tsmiCopyThumbnailURL.Enabled = IsThumbnailURLExist;
tsmiCopyDeletionURL.Enabled = false; tsmiCopyDeletionURL.Enabled = IsDeletionURLExist;
tsmiCopyFile.Enabled = false; tsmiCopyFile.Enabled = IsFileExist;
tsmiCopyImage.Enabled = false; tsmiCopyImage.Enabled = IsImageFile;
tsmiCopyText.Enabled = false; tsmiCopyText.Enabled = IsTextFile;
tsmiCopyHTMLLink.Enabled = false; tsmiCopyHTMLLink.Enabled = IsURLExist;
tsmiCopyHTMLImage.Enabled = false; tsmiCopyHTMLImage.Enabled = IsImageURL;
tsmiCopyHTMLLinkedImage.Enabled = false; tsmiCopyHTMLLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist;
tsmiCopyForumLink.Enabled = false; tsmiCopyForumLink.Enabled = IsURLExist;
tsmiCopyForumImage.Enabled = false; tsmiCopyForumImage.Enabled = IsImageURL && IsURLExist;
tsmiCopyForumLinkedImage.Enabled = false; tsmiCopyForumLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist;
tsmiCopyMarkdownLink.Enabled = false; tsmiCopyMarkdownLink.Enabled = IsURLExist;
tsmiCopyMarkdownImage.Enabled = false; tsmiCopyMarkdownImage.Enabled = IsImageURL && IsURLExist;
tsmiCopyMarkdownLinkedImage.Enabled = false; tsmiCopyMarkdownLinkedImage.Enabled = IsImageURL && IsThumbnailURLExist;
tsmiCopyFilePath.Enabled = false; tsmiCopyFilePath.Enabled = IsFilePathValid;
tsmiCopyFileName.Enabled = false; tsmiCopyFileName.Enabled = IsFilePathValid;
tsmiCopyFileNameWithExtension.Enabled = false; tsmiCopyFileNameWithExtension.Enabled = IsFilePathValid;
tsmiCopyFolder.Enabled = false; 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 // Show
tsmiShow.Enabled = false; tsmiShow.Enabled = true;
tsmiShowImagePreview.Enabled = false; tsmiShowImagePreview.Enabled = IsImageFile;
tsmiShowMoreInfo.Enabled = false; tsmiShowMoreInfo.Enabled = true;
// Upload file // Upload file
tsmiUploadFile.Enabled = false; tsmiUploadFile.Enabled = uploadFile != null && IsFileExist;
// Edit image // Edit image
tsmiEditImage.Enabled = false; tsmiEditImage.Enabled = editImage != null && IsImageFile;
} }
cmsHistory.ResumeLayout(); cmsHistory.ResumeLayout();
} }

View file

@ -368,24 +368,6 @@ internal class Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to HTML link ({0}).
/// </summary>
internal static string HistoryItemManager_UpdateTexts_HTML_link___0__ {
get {
return ResourceManager.GetString("HistoryItemManager_UpdateTexts_HTML_link___0__", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to URLs ({0}).
/// </summary>
internal static string HistoryItemManager_UpdateTexts_URLs___0__ {
get {
return ResourceManager.GetString("HistoryItemManager_UpdateTexts_URLs___0__", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Error. /// Looks up a localized string similar to Error.
/// </summary> /// </summary>

View file

@ -154,9 +154,6 @@
<data name="HistoryItemManager_InitializeComponent_Show" xml:space="preserve"> <data name="HistoryItemManager_InitializeComponent_Show" xml:space="preserve">
<value>Show</value> <value>Show</value>
</data> </data>
<data name="HistoryItemManager_UpdateTexts_URLs___0__" xml:space="preserve">
<value>URLs ({0})</value>
</data>
<data name="HistoryItemManager_InitializeComponent_HTML_image" xml:space="preserve"> <data name="HistoryItemManager_InitializeComponent_HTML_image" xml:space="preserve">
<value>HTML image</value> <value>HTML image</value>
</data> </data>
@ -196,9 +193,6 @@
<data name="HistoryItemManager_InitializeComponent_Forum__BBCode__image" xml:space="preserve"> <data name="HistoryItemManager_InitializeComponent_Forum__BBCode__image" xml:space="preserve">
<value>Forum (BBCode) image</value> <value>Forum (BBCode) image</value>
</data> </data>
<data name="HistoryItemManager_UpdateTexts_HTML_link___0__" xml:space="preserve">
<value>HTML link ({0})</value>
</data>
<data name="HistoryItemManager_InitializeComponent_Text" xml:space="preserve"> <data name="HistoryItemManager_InitializeComponent_Text" xml:space="preserve">
<value>Text</value> <value>Text</value>
</data> </data>