ShareReadability
MainWindow.xaml.cs
Go to the documentation of this file.
1 using System.Windows;
2 using CefSharp;
4 using System.Text.RegularExpressions;
6 
7 namespace ShareReadability
8 {
9  /// @file MainWindow.xaml.cs
10  /// <inheritdoc cref="Window" />
11  /// <summary>
12  /// Interaction logic for MainWindow.xaml
13  /// </summary>
14  public partial class MainWindow : Window
15  {
16  private const string TargetUrl = "https://www.sharelatex.com/project/(.+)";
17  private SettingsWindow _settingsWindow;
18  public Settings Settings { get; set; }
19 
20  /// <inheritdoc />
21  /// <summary>
22  /// Constructor of the main window.
23  /// </summary>
24  public MainWindow()
25  {
26  InitializeComponent();
27 
28  // Initialize CefSharp browser
29  ChromiumWebBrowser.DownloadHandler = new DownloadHandler();
30  ChromiumWebBrowser.LifeSpanHandler = new LifeSpanHandler();
31  ChromiumWebBrowser.FrameLoadEnd += ChromiumWebBrowserOnFrameLoadEnd;
32 
33  // Initialize Settings
34  Settings = new Settings();
35 
36  // Initialize Readability Analysis
37  ReadabilityAnalysis.ReadabilityAnalysisPipeline.MainWindow = this;
38  ReadabilityAnalysis.ReadabilityAnalysisPipeline.Settings = Settings;
39  ReadabilityAnalysis.ReadabilityAnalysisPipeline.Initialize();
40  }
41 
42  /// <summary>
43  /// Enables the main menu if the URL is equal some specified target URL.
44  /// So the main menu is only active at the LaTeX Editor.
45  /// </summary>
46  /// <param name="sender">The sender.</param>
47  /// <param name="frameLoadEndEventArgs">The event.</param>
48  private void ChromiumWebBrowserOnFrameLoadEnd(object sender, FrameLoadEndEventArgs frameLoadEndEventArgs)
49  {
50  var currentUrl = frameLoadEndEventArgs.Url;
51  ChromiumWebBrowser.Dispatcher.InvokeAsync(() => MainMenu.IsEnabled = Regex.IsMatch(currentUrl, TargetUrl));
52  }
53 
54  /// <summary>
55  /// Executes the readability analysis pipeline.
56  /// </summary>
57  /// <param name="sender">The sender.</param>
58  /// <param name="e">The event.</param>
59  private void MenuItem_OnClick_Analyze(object sender, RoutedEventArgs e)
60  {
61  ReadabilityAnalysis.ReadabilityAnalysisPipeline.ExecutePipeline(ChromiumWebBrowser);
62  }
63 
64  /// <summary>
65  /// Opens the settings window.
66  /// </summary>
67  /// <param name="sender">The sender.</param>
68  /// <param name="e">The event.</param>
69  private void MenuItem_OnClick_Settings(object sender, RoutedEventArgs e)
70  {
71  _settingsWindow = new SettingsWindow {Settings = Settings};
72  _settingsWindow.InitializeSlider();
73  _settingsWindow.ShowDialog();
74  }
75 
76  /// <summary>
77  /// Enables/Disables the main menu.
78  /// </summary>
79  /// <param name="enabled">If the main menu should be enabled.</param>
80  public void EnableMainMenu(bool enabled)
81  {
82  MainMenu.IsEnabled = enabled;
83  }
84  }
85 }
void InitializeSlider()
Initializes the sliders.
MainWindow()
Constructor of the main window.
void EnableMainMenu(bool enabled)
Enables/Disables the main menu.
void MenuItem_OnClick_Settings(object sender, RoutedEventArgs e)
Opens the settings window.
void MenuItem_OnClick_Analyze(object sender, RoutedEventArgs e)
Executes the readability analysis pipeline.
void ChromiumWebBrowserOnFrameLoadEnd(object sender, FrameLoadEndEventArgs frameLoadEndEventArgs)
Enables the main menu if the URL is equal some specified target URL. So the main menu is only active ...