Skip to content

Commit

Permalink
Added shortcut to about page in hamburger menu
Browse files Browse the repository at this point in the history
  • Loading branch information
felixse committed Oct 27, 2018
1 parent 30ad004 commit c4a04bc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
10 changes: 10 additions & 0 deletions FluentTerminal.App.ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public MainViewModel(ISettingsService settingsService, ITrayProcessCommunication
TabsPosition = _applicationSettings.TabsPosition;

AddTerminalCommand = new RelayCommand(() => AddTerminal(null, false));
ShowAboutCommand = new RelayCommand(ShowAbout);
ShowSettingsCommand = new RelayCommand(ShowSettings);

_applicationView.CloseRequested += OnCloseRequest;
Expand All @@ -84,6 +85,8 @@ private void OnTerminalsCollectionChanged(object sender, NotifyCollectionChanged

public event EventHandler ShowSettingsRequested;

public event EventHandler ShowAboutRequested;

public RelayCommand AddTerminalCommand { get; }

public bool ShowTabsOnTop
Expand Down Expand Up @@ -128,6 +131,8 @@ public TerminalViewModel SelectedTerminal
}
}

public RelayCommand ShowAboutCommand { get; }

public RelayCommand ShowSettingsCommand { get; }

public TabsPosition TabsPosition
Expand Down Expand Up @@ -276,6 +281,11 @@ private void SelectPreviousTab()
SelectedTerminal = Terminals[previousIndex];
}

private void ShowAbout()
{
ShowAboutRequested?.Invoke(this, EventArgs.Empty);
}

private void ShowSettings()
{
ShowSettingsRequested?.Invoke(this, EventArgs.Empty);
Expand Down
6 changes: 6 additions & 0 deletions FluentTerminal.App.ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public SettingsViewModel(ISettingsService settingsService, IDefaultValueProvider
}

public event EventHandler Closed;
public event EventHandler AboutPageRequested;

public GeneralPageViewModel General { get; }
public KeyBindingsPageViewModel KeyBindings { get; }
Expand All @@ -30,6 +31,11 @@ public SettingsViewModel(ISettingsService settingsService, IDefaultValueProvider
public MousePageViewModel Mouse { get; }
public AboutPageViewModel About { get; }

public void NavigateToAboutPage()
{
AboutPageRequested?.Invoke(this, EventArgs.Empty);
}

public void Close()
{
Closed?.Invoke(this, EventArgs.Empty);
Expand Down
13 changes: 13 additions & 0 deletions FluentTerminal.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private async Task CreateMainView(Type pageType, INotifyPropertyChanged viewMode
mainViewModel.Closed += OnMainViewModelClosed;
mainViewModel.NewWindowRequested += OnNewWindowRequested;
mainViewModel.ShowSettingsRequested += OnShowSettingsRequested;
mainViewModel.ShowAboutRequested += OnShowAboutRequested;
_mainViewModels.Add(mainViewModel);
}

Expand Down Expand Up @@ -241,6 +242,7 @@ await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority
mainViewModel.Closed += OnMainViewModelClosed;
mainViewModel.NewWindowRequested += OnNewWindowRequested;
mainViewModel.ShowSettingsRequested += OnShowSettingsRequested;
mainViewModel.ShowAboutRequested += OnShowAboutRequested;
_mainViewModels.Add(mainViewModel);
await mainViewModel.AddTerminal(directory, false).ConfigureAwait(true);
}
Expand Down Expand Up @@ -283,11 +285,22 @@ private void OnSettingsClosed(object sender, EventArgs e)
_settingsWindowId = null;
}

private void OnShowAboutRequested(object sender, EventArgs e)
{
ShowAbout().ConfigureAwait(true);
}

private async void OnShowSettingsRequested(object sender, EventArgs e)
{
await ShowSettings().ConfigureAwait(true);
}

private async Task ShowAbout()
{
await ShowSettings().ConfigureAwait(true);
_settingsViewModel.NavigateToAboutPage();
}

private async Task ShowSettings()
{
if (_settingsViewModel == null)
Expand Down
11 changes: 11 additions & 0 deletions FluentTerminal.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
<SymbolIcon Symbol="Setting" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
Width="160"
Command="{x:Bind ViewModel.ShowAboutCommand}"
Text="About">
<MenuFlyoutItem.Icon>
<FontIcon
FontFamily="Segoe MDL2 Assets"
Glyph="&#xE946;"
ToolTipService.ToolTip="About" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</Button.Flyout>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion FluentTerminal.App/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</NavigationViewItem>
</NavigationView.MenuItems>
<NavigationView.PaneFooter>
<NavigationViewItem Content="About" Tapped="NavigationViewItem_Tapped">
<NavigationViewItem Content="About" Tapped="AboutTapped">
<NavigationViewItem.Icon>
<FontIcon
FontFamily="Segoe MDL2 Assets"
Expand Down
26 changes: 18 additions & 8 deletions FluentTerminal.App/Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentTerminal.App.Utilities;
using FluentTerminal.App.ViewModels;
using FluentTerminal.App.Views.SettingsPages;
using System;
using System.Linq;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
Expand Down Expand Up @@ -71,9 +72,24 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
if (e.Parameter is SettingsViewModel viewModel)
{
ViewModel = viewModel;
ViewModel.AboutPageRequested += OnAboutPageRequested;
}
}

private void OnAboutPageRequested(object sender, System.EventArgs e)
{
_dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
ContentFrame.Navigate(typeof(About), ViewModel.About);
// Deselect item in NavigationView (https://stackoverflow.com/a/49082640/4132379)
NavigationView.MenuItems.Add(hiddenNavigationItem);
NavigationView.SelectedItem = hiddenNavigationItem;
NavigationView.SelectedItem = null;
NavigationView.MenuItems.Remove(hiddenNavigationItem);
});
}

private void NavigationView_Loaded(object sender, RoutedEventArgs e)
{
NavigationView.SelectedItem = NavigationView.MenuItems.Cast<NavigationViewItemBase>().FirstOrDefault(m => m.Tag.ToString() == "general");
Expand Down Expand Up @@ -120,15 +136,9 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi
}
}

private void NavigationViewItem_Tapped(object sender, TappedRoutedEventArgs e)
private void AboutTapped(object sender, TappedRoutedEventArgs e)
{
ContentFrame.Navigate(typeof(About), ViewModel.About);

// Deselect item in NavigationView (https://stackoverflow.com/a/49082640/4132379)
NavigationView.MenuItems.Add(hiddenNavigationItem);
NavigationView.SelectedItem = hiddenNavigationItem;
NavigationView.SelectedItem = null;
NavigationView.MenuItems.Remove(hiddenNavigationItem);
OnAboutPageRequested(sender, EventArgs.Empty);
}

private void SettingsPage_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
Expand Down

0 comments on commit c4a04bc

Please sign in to comment.