Skip to content

Commit

Permalink
Support right click menu for About window links
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Apr 17, 2019
1 parent 4eb1fc3 commit 8defd30
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
10 changes: 5 additions & 5 deletions GUI/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public AboutDialog()

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/KSP-CKAN/CKAN/blob/master/LICENSE.md");
Util.HandleLinkClicked("https://github.com/KSP-CKAN/CKAN/blob/master/LICENSE.md", e);
}

private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/KSP-CKAN/CKAN/graphs/contributors");
Util.HandleLinkClicked("https://github.com/KSP-CKAN/CKAN/graphs/contributors", e);
}

private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/KSP-CKAN/CKAN/");
Util.HandleLinkClicked("https://github.com/KSP-CKAN/CKAN/", e);
}

private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://forum.kerbalspaceprogram.com/index.php?/topic/154922-ckan");
Util.HandleLinkClicked("http://forum.kerbalspaceprogram.com/index.php?/topic/154922-ckan", e);
}

private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://ksp-ckan.space");
Util.HandleLinkClicked("http://ksp-ckan.space", e);
}
}
}
11 changes: 1 addition & 10 deletions GUI/MainModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,7 @@ private void ContentsDownloadButton_Click(object sender, EventArgs e)

private void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
Util.OpenLinkFromLinkLabel(sender as LinkLabel);
break;

case MouseButtons.Right:
Util.LinkContextMenu(sender as LinkLabel, e);
break;
}
Util.HandleLinkClicked((sender as LinkLabel).Text, e);
}

private void UpdateModInfo(GUIMod gui_module)
Expand Down
27 changes: 21 additions & 6 deletions GUI/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ public static bool CheckURLValid(string source)
return Uri.TryCreate(source, UriKind.Absolute, out uri_result) && uri_result.Scheme == Uri.UriSchemeHttp;
}

public static void OpenLinkFromLinkLabel(LinkLabel link_label)
/// <summary>
/// Open a URL, unless it's "N/A"
/// </summary>
/// <param name="url">The URL</param>
public static void OpenLinkFromLinkLabel(string url)
{
if (link_label.Text == "N/A")
if (url == "N/A")
{
return;
}

TryOpenWebPage(link_label.Text);
TryOpenWebPage(url);
}

/// <summary>
Expand Down Expand Up @@ -117,21 +121,32 @@ public static bool TryOpenWebPage(string url, IEnumerable<string> prefixes = nul
}
}

/// <summary>
/// React to the user clicking a mouse button on a link.
/// Opens the URL in browser on left click, presents a
/// right click menu on right click.
/// </summary>
/// <param name="url">The link's URL</param>
/// <param name="e">The click event</param>
public static void HandleLinkClicked(string url, LinkLabelLinkClickedEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
Util.OpenLinkFromLinkLabel(sender as LinkLabel);
Util.OpenLinkFromLinkLabel(url);
break;

case MouseButtons.Right:
Util.LinkContextMenu(url, e);
Util.LinkContextMenu(url);
break;
}
}

public static void LinkContextMenu(string url, LinkLabelLinkClickedEventArgs e)
/// <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)
{
ToolStripMenuItem copyLink = new ToolStripMenuItem("&Copy link address");
copyLink.Click += new EventHandler((sender, ev) => Clipboard.SetText(url));
Expand Down

0 comments on commit 8defd30

Please sign in to comment.