using System; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace SourceGit.UI { /// /// Main window for this app. /// public partial class Launcher : Window { /// /// Alert data. /// public class Alert { public string Title { get; set; } public string Message { get; set; } } /// /// Alerts. /// public ObservableCollection Alerts { get; set; } = new ObservableCollection(); /// /// Constructor /// public Launcher() { Git.Repository.OnOpen = ShowDashboard; Git.Repository.OnClose = ShowManager; App.OnError = msg => ShowAlert(new Alert() { Title = "ERROR", Message = msg }); InitializeComponent(); ShowManager(); } #region LAYOUT_CONTENT /// /// Show manager. /// private void ShowManager() { Dispatcher.Invoke(() => { body.Content = new Manager(); }); } /// /// Show dashboard. /// /// private void ShowDashboard(Git.Repository repo) { Dispatcher.Invoke(() => { if (body.Content is Dashboard) return; body.Content = new Dashboard(repo); }); } /// /// Open preference dialog. /// /// /// private void ShowPreference(object sender, RoutedEventArgs e) { Preference.Show(); } /// /// Open about dialog. /// /// /// private void ShowAbout(object sender, RoutedEventArgs e) { var about = new About(); about.Owner = this; about.ShowDialog(); } /// /// Show alert. /// /// private void ShowAlert(Alert alert) { Dispatcher.Invoke(() => Alerts.Add(alert)); } /// /// Remove an alert. /// /// /// private void RemoveAlert(object sender, RoutedEventArgs e) { var alert = (sender as Button).DataContext as Alert; Alerts.Remove(alert); } #endregion #region WINDOW_COMMANDS /// /// Minimize /// private void Minimize(object sender, RoutedEventArgs e) { SystemCommands.MinimizeWindow(this); } /// /// Maximize/Restore /// private void MaximizeOrRestore(object sender, RoutedEventArgs e) { if (WindowState == WindowState.Normal) { SystemCommands.MaximizeWindow(this); } else { SystemCommands.RestoreWindow(this); } } /// /// Quit /// private void Quit(object sender, RoutedEventArgs e) { App.Current.Shutdown(); } /// /// Show system menu when user click logo. /// /// /// private void LogoMouseButtonDown(object sender, MouseButtonEventArgs e) { var element = e.OriginalSource as FrameworkElement; if (element == null) return; var pos = PointToScreen(new Point(0, 33)); SystemCommands.ShowSystemMenu(this, pos); } #endregion } }