Skip to content

Commit

Permalink
Fix broken version label in About dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 13, 2024
1 parent 08c70a1 commit b3c28fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 3 additions & 3 deletions GUI/Controls/ModInfoTabs/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ private void LinkLabel_KeyDown(object? sender, KeyEventArgs? e)
{
if (sender is LinkLabel lbl)
{
switch (e?.KeyCode)
switch (e)
{
case Keys.Apps:
Util.LinkContextMenu(lbl.Text);
case {KeyCode: Keys.Apps}:
Util.LinkContextMenu(lbl.Text, lbl);
e.Handled = true;
break;
}
Expand Down
22 changes: 19 additions & 3 deletions GUI/Dialogs/AboutDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions GUI/Dialogs/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public AboutDialog()
{
InitializeComponent();
ApplyFormCompatibilityFixes();
StartPosition = FormStartPosition.CenterScreen;
versionLabel.Text = string.Format(Properties.Resources.AboutDialogLabel2Text, Meta.GetVersion());
}

Expand All @@ -30,10 +29,10 @@ private void linkLabel_KeyDown(object? sender, KeyEventArgs? e)
{
if (sender is LinkLabel l)
{
switch (e?.KeyCode)
switch (e)
{
case Keys.Apps:
Util.LinkContextMenu(l.Text);
case {KeyCode: Keys.Apps}:
Util.LinkContextMenu(l.Text, l);
e.Handled = true;
break;
}
Expand Down
22 changes: 16 additions & 6 deletions GUI/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Timer = System.Windows.Forms.Timer;
#if NET5_0_OR_GREATER
using System.Runtime.Versioning;
Expand Down Expand Up @@ -130,22 +130,32 @@ public static void HandleLinkClicked(string url, LinkLabelLinkClickedEventArgs?
}
}

/// <summary>
/// Show a link right-click menu under a control,
/// meant for keyboard access
/// </summary>
/// <param name="url">The URL of the link</param>
/// <param name="c">The menu will be shown below the bottom of this control</param>
public static void LinkContextMenu(string url, Control c)
=> LinkContextMenu(url, c.PointToScreen(new Point(0, c.Height)));

/// <summary>
/// Show a context menu when the user right clicks a link
/// </summary>
/// <param name="url">The URL of the link</param>
public static void LinkContextMenu(string url)
/// <param name="where">Screen coordinates for the menu</param>
public static void LinkContextMenu(string url, Point? where = null)
{
ToolStripMenuItem copyLink = new ToolStripMenuItem(Properties.Resources.UtilCopyLink);
copyLink.Click += new EventHandler((sender, ev) => Clipboard.SetText(url));
var copyLink = new ToolStripMenuItem(Properties.Resources.UtilCopyLink);
copyLink.Click += (sender, ev) => Clipboard.SetText(url);

ContextMenuStrip menu = new ContextMenuStrip();
var menu = new ContextMenuStrip();
if (Platform.IsMono)
{
menu.Renderer = new FlatToolStripRenderer();
}
menu.Items.Add(copyLink);
menu.Show(Cursor.Position);
menu.Show(where ?? Cursor.Position);
}

/// <summary>
Expand Down

0 comments on commit b3c28fd

Please sign in to comment.