2023-02-12 12:49:01 +00:00
using DataModel.Database ;
using Processor ;
using UI_WinForms.Dialogs ;
2023-01-22 18:35:57 +00:00
namespace UI_WinForms.Components ;
2022-07-09 13:06:30 +00:00
public partial class Main : UserControl
{
public Main ( )
{
this . InitializeComponent ( ) ;
2022-09-20 19:36:45 +00:00
Program . RestartMainApp = false ;
2023-01-22 18:35:57 +00:00
// Register the something changed event to trigger the export:
AppEvents . WhenSomethingChanged + = async ( _ , _ ) = > await ExportProcessor . TriggerExport ( ) ;
2023-02-12 12:49:01 +00:00
// Check, if the DeepL integration is enabled, but no API key is set:
this . Load + = async ( sender , args ) = >
{
var deepLAPIKey = await AppSettings . GetDeepLAPIKey ( ) ;
var deepLMode = await AppSettings . GetDeepLMode ( ) ;
if ( deepLMode is not SettingDeepLMode . DISABLED & & string . IsNullOrWhiteSpace ( deepLAPIKey ) )
{
// Show the input dialog to ask the user for the DeepL API key:
var inputDialog = InputDialog . Show ( new InputDialog . Options
{
Title = "I18NCommander - DeepL API Key" ,
Message = "The DeepL integration is enabled, but there is no API key set. Do you want to set one now?" ,
OkButtonText = "Set API key" ,
CancelButtonText = "No, thanks" ,
ShowQuestionCheckbox = false ,
} ) ;
if ( inputDialog . DialogResult = = DialogResult . OK )
{
await AppSettings . SetDeepLAPIKey ( inputDialog . Text ) ;
AppEvents . SettingsChanged ( ) ;
}
}
} ;
2022-09-20 19:36:45 +00:00
}
private void tabControl_SelectedIndexChanged ( object sender , EventArgs e )
{
if ( this . settings . NeedRestart ( ) )
{
var result = MessageBox . Show ( "You need to restart the app for the changes to take effect. Do you want to restart?" , "Restart required" , MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button1 ) ;
if ( result = = DialogResult . Yes )
{
Program . RestartMainApp = true ;
2022-11-01 11:26:31 +00:00
AppEvents . ResetAllSubscriptions ( ) ;
2022-09-20 19:36:45 +00:00
this . ParentForm ! . Close ( ) ;
}
}
2022-07-09 13:06:30 +00:00
}
}