using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace PDFViewer
{
///
/// Interaction logic for SettingsDialog.xaml
///
public partial class SettingsDialog : Window
{
public event EventHandler LanguageChanged;
public SettingsDialog()
{
InitializeComponent();
Closing += MainWindow_Closing;
}
private void MainWindow_Closing(object sender, CancelEventArgs e)
{
Properties.Settings.Default.Save();
Compdfkit_Tools.Data.CPDFAnnotationData.Author = Properties.Settings.Default.DocumentAuthor;
}
private void EventSetter_ClickHandler(object sender, RoutedEventArgs e)
{
var webLocation = (sender as Button)?.Tag.ToString();
if (!string.IsNullOrEmpty(webLocation))
{
Process.Start(webLocation);
}
}
private void SettingsDialog_Loaded(object sender, RoutedEventArgs e)
{
HighlightFormTog.IsChecked = Properties.Settings.Default.IsHighlightFormArea;
HighlightLinkTog.IsChecked = Properties.Settings.Default.IsHighlightLinkArea;
AuthorTxb.Text = Properties.Settings.Default.DocumentAuthor;
((ComboBoxItem)LanguageCmb.Items[0]).Content = Properties.Settings.Default.Language;
LanguageCmb.SelectedIndex = 0;
}
private void AuthorTxb_TextChanged(object sender, TextChangedEventArgs e)
{
Properties.Settings.Default.DocumentAuthor = AuthorTxb.Text;
}
private void HighlightLinkTog_Click(object sender, RoutedEventArgs e)
{
if (HighlightLinkTog.IsChecked != null)
Properties.Settings.Default.IsHighlightLinkArea = HighlightLinkTog.IsChecked.Value;
}
private void HighlightFormTog_Click(object sender, RoutedEventArgs e)
{
if (HighlightFormTog.IsChecked != null)
Properties.Settings.Default.IsHighlightFormArea = HighlightFormTog.IsChecked.Value;
}
private void LanguageCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string language = ((ComboBoxItem)LanguageCmb.SelectedItem).Content.ToString();
if (language.Equals(Properties.Settings.Default.Language))
{
return;
}
MessageBoxResult result = MessageBox.Show("You need to restart the application to apply the language change.\nDo you want to restart now?",
"Restart Application",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
Properties.Settings.Default.Language = language;
Properties.Settings.Default.Save();
LanguageChanged?.Invoke(this, language);
}
else
{
LanguageCmb.SelectedIndex = 0;
}
}
}
}