Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When interfaces breaks, be more gentle #1341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions XrmToolBox/New/NewForm.Community.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@ private void displayXrmToolBoxHelpToolStripMenuItem_Click(object sender, System.

private void donateDollarPluginMenuItem_Click(object sender, System.EventArgs e)
{
if (((PluginForm)dpMain.ActiveContent).Control is IPayPalPlugin payPal)
{
Donate("EN", "USD", payPal.EmailAccount, payPal.DonationDescription);
}
DonatePlugin("USD");
}

private void donateEuroPluginMenuItem_Click(object sender, System.EventArgs e)
{
if (((PluginForm)dpMain.ActiveContent).Control is IPayPalPlugin payPal)
{
Donate("EN", "EUR", payPal.EmailAccount, payPal.DonationDescription);
}
DonatePlugin("EUR");
}

private void donateGbpPluginMenuItem_Click(object sender, System.EventArgs e)
{
if (((PluginForm)dpMain.ActiveContent).Control is IPayPalPlugin payPal)
{
Donate("EN", "GBP", payPal.EmailAccount, payPal.DonationDescription);
}
DonatePlugin("GBP");
}

private void donateInEuroToolStripMenuItem_Click(object sender, System.EventArgs e)
Expand Down Expand Up @@ -86,7 +77,8 @@ private string GetAdditionalInfo()
private void githubPluginMenuItem_Click(object sender, System.EventArgs e)
{
var url = GetGithubBaseUrl("issues/new");

if (string.IsNullOrEmpty(url))
return;
var additionalInfo = GetAdditionalInfo();

if (currentContent is PluginForm pf)
Expand All @@ -107,7 +99,10 @@ private void GithubXrmToolBoxMenuItem_Click(object sender, System.EventArgs e)

private void HelpSelectedPluginToolStripMenuItem_Click(object sender, System.EventArgs e)
{
Process.Start(GetHelpUrl());
var url = GetHelpUrl();
if (string.IsNullOrEmpty(url))
return;
Process.Start(url);
}

private void helpToolStripMenuItem_Click(object sender, System.EventArgs e)
Expand Down Expand Up @@ -224,16 +219,37 @@ private void Donate(string language, string currency, string emailAccount, strin
Process.Start(url);
}

private void DonatePlugin(string currency)
{
if (dpMain.ActiveContent is PluginForm pluginForm && pluginForm.Control is IPayPalPlugin payPal)
{
Donate("EN", currency, payPal.EmailAccount, payPal.DonationDescription);
}
else
{
MessageBox.Show("There is internal issue, cannot find the PayPal account.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

private string GetGithubBaseUrl(string page)
{
var plugin = (IGitHubPlugin)((PluginForm)dpMain.ActiveContent).Control;
return $"https://github.com/{plugin.UserName}/{plugin.RepositoryName}/{page}";
if (dpMain.ActiveContent is PluginForm plugin &&
plugin.Control is IGitHubPlugin gitplugin)
{
return $"https://github.com/{gitplugin.UserName}/{gitplugin.RepositoryName}/{page}";
}
MessageBox.Show("There is internal issue, cannot find the GitHub repository.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}

private string GetHelpUrl()
{
var plugin = (IHelpPlugin)((PluginForm)dpMain.ActiveContent).Control;
return plugin.HelpUrl;
if (dpMain.ActiveContent is PluginForm pluginForm && pluginForm.Control is IHelpPlugin helpPlugin)
{
return helpPlugin.HelpUrl;
}
MessageBox.Show("There is internal issue, cannot find the Help URL.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return null;
}

private void tsmiAbout_Click(object sender, System.EventArgs e)
Expand All @@ -246,8 +262,15 @@ private void tsmiAbout_Click(object sender, System.EventArgs e)

private void tsmiAboutSelectedPlugin_Click(object sender, System.EventArgs e)
{
var plugin = (IAboutPlugin)((PluginForm)dpMain.ActiveContent).Control;
plugin.ShowAboutDialog();
if (dpMain.ActiveContent is PluginForm plugin &&
plugin.Control is IAboutPlugin aboutPlugin)
{
aboutPlugin.ShowAboutDialog();
}
else
{
MessageBox.Show("There is internal issue, cannot find the About window.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}