1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 03:15:48 +02:00

Make an interface for dialogs to avoid hard-coding them in FormManager

This commit is contained in:
chylex 2018-07-06 05:30:12 +02:00
parent 20b1b3c895
commit 377d9c3554
5 changed files with 10 additions and 9 deletions

View File

@ -1,6 +1,5 @@
using System.Linq;
using System.Windows.Forms;
using TweetDuck.Core.Other;
namespace TweetDuck.Core{
static class FormManager{
@ -18,12 +17,14 @@ public static bool TryBringToFront<T>() where T : Form{
else return false;
}
public static bool HasAnyDialogs => Application.OpenForms.OfType<IAppDialog>().Any();
public static void CloseAllDialogs(){
foreach(Form form in Application.OpenForms.Cast<Form>().Reverse()){
if (form is FormSettings || form is FormPlugins || form is FormAbout || form is FormGuide){
form.Close();
}
foreach(IAppDialog dialog in Application.OpenForms.OfType<IAppDialog>().Reverse()){
((Form)dialog).Close();
}
}
public interface IAppDialog{}
}
}

View File

@ -5,7 +5,7 @@
using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Other{
sealed partial class FormAbout : Form{
sealed partial class FormAbout : Form, FormManager.IAppDialog{
private const string TipsLink = "https://github.com/chylex/TweetDuck/wiki";
private const string IssuesLink = "https://github.com/chylex/TweetDuck/issues";

View File

@ -12,7 +12,7 @@
using TweetDuck.Resources;
namespace TweetDuck.Core.Other{
sealed partial class FormGuide : Form{
sealed partial class FormGuide : Form, FormManager.IAppDialog{
private const string GuideUrl = "https://tweetduck.chylex.com/guide/v2/";
private const string GuidePathRegex = @"^guide(?:/v\d+)?(?:/(#.*))?";

View File

@ -7,7 +7,7 @@
using TweetDuck.Plugins.Controls;
namespace TweetDuck.Core.Other{
sealed partial class FormPlugins : Form{
sealed partial class FormPlugins : Form, FormManager.IAppDialog{
private readonly PluginManager pluginManager;
public FormPlugins(){

View File

@ -13,7 +13,7 @@
using TweetDuck.Updates;
namespace TweetDuck.Core.Other{
sealed partial class FormSettings : Form{
sealed partial class FormSettings : Form, FormManager.IAppDialog{
private readonly FormBrowser browser;
private readonly PluginManager plugins;