diff --git a/ModernKeePass/Views/BasePages/LayoutAwarePageBase.cs b/ModernKeePass/Views/BasePages/LayoutAwarePageBase.cs index 19db292..15f5998 100644 --- a/ModernKeePass/Views/BasePages/LayoutAwarePageBase.cs +++ b/ModernKeePass/Views/BasePages/LayoutAwarePageBase.cs @@ -85,7 +85,7 @@ namespace ModernKeePass.Views.BasePages /// /// Preserves state associated with this page in case the application is suspended or the /// page is discarded from the navigation cache. Values must conform to the serialization - /// requirements of . + /// requirements of . /// /// The source of the event; typically /// Event data that provides an empty dictionary to be populated with diff --git a/ModernKeePass/Views/MainPage.xaml.cs b/ModernKeePass/Views/MainPage.xaml.cs index aa85007..3812f64 100644 --- a/ModernKeePass/Views/MainPage.xaml.cs +++ b/ModernKeePass/Views/MainPage.xaml.cs @@ -13,38 +13,50 @@ namespace ModernKeePass.Views /// public sealed partial class MainPage { - public new MainVm Model => (MainVm)DataContext; + public new MainVm Model => (MainVm) DataContext; public MainPage() { InitializeComponent(); - ListView = MenuListView; + ListView = MenuListView; ListViewSource = MenuItemsSource; } - + private new void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { base.ListView_SelectionChanged(sender, e); var selectedItem = Model.SelectedItem as MainMenuItemVm; - if (selectedItem == null) MenuFrame.Navigate(typeof(WelcomePage)); - else selectedItem.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter); + if (selectedItem == null) + { + MenuFrame.Navigate(typeof(WelcomePage)); + } + else + { + selectedItem.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter); + } } - + protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); FileInfo file; if (e.NavigationMode == NavigationMode.Back) + { file = null; + } else + { file = e.Parameter as FileInfo; + } + await Model.Initialize(Frame, MenuFrame, file); } protected override void OnNavigatedFrom(NavigationEventArgs e) { Model.Cleanup(); + base.OnNavigatedFrom(e); } } } diff --git a/WinAppCommon/Common/NavigationHelper.cs b/WinAppCommon/Common/NavigationHelper.cs index 2347ecd..3ff7110 100644 --- a/WinAppCommon/Common/NavigationHelper.cs +++ b/WinAppCommon/Common/NavigationHelper.cs @@ -120,15 +120,10 @@ namespace ModernKeePass.Common /// public RelayCommand GoBackCommand { - get - { - return _goBackCommand ?? (_goBackCommand = new RelayCommand(GoBack, CanGoBack)); - } - set - { - _goBackCommand = value; - } + get { return _goBackCommand ?? (_goBackCommand = new RelayCommand(GoBack, CanGoBack)); } + set { _goBackCommand = value; } } + /// /// used for navigating to the most recent item in /// the forward navigation history, if a Frame manages its own navigation history. @@ -150,6 +145,7 @@ namespace ModernKeePass.Common { return Frame != null && Frame.CanGoBack; } + /// /// Virtual method used by the property /// to determine if the can go forward. @@ -169,15 +165,22 @@ namespace ModernKeePass.Common /// public virtual void GoBack() { - if (Frame != null && Frame.CanGoBack) Frame.GoBack(); + if (Frame != null && Frame.CanGoBack) + { + Frame.GoBack(); + } } + /// /// Virtual method used by the property /// to invoke the method. /// public virtual void GoForward() { - if (Frame != null && Frame.CanGoForward) Frame.GoForward(); + if (Frame != null && Frame.CanGoForward) + { + Frame.GoForward(); + } } #if WINDOWS_PHONE_APP @@ -203,16 +206,16 @@ namespace ModernKeePass.Common /// Instance that triggered the event. /// Event data describing the conditions that led to the event. private void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender, - AcceleratorKeyEventArgs e) + AcceleratorKeyEventArgs e) { var virtualKey = e.VirtualKey; // Only investigate further when Left, Right, or the dedicated Previous or Next keys // are pressed if ((e.EventType == CoreAcceleratorKeyEventType.SystemKeyDown || - e.EventType == CoreAcceleratorKeyEventType.KeyDown) && + e.EventType == CoreAcceleratorKeyEventType.KeyDown) && (virtualKey == VirtualKey.Left || virtualKey == VirtualKey.Right || - (int)virtualKey == 166 || (int)virtualKey == 167)) + (int) virtualKey == 166 || (int) virtualKey == 167)) { var coreWindow = Window.Current.CoreWindow; const CoreVirtualKeyStates downState = CoreVirtualKeyStates.Down; @@ -222,15 +225,15 @@ namespace ModernKeePass.Common var noModifiers = !menuKey && !controlKey && !shiftKey; var onlyAlt = menuKey && !controlKey && !shiftKey; - if ((int)virtualKey == 166 && noModifiers || + if ((int) virtualKey == 166 && noModifiers || virtualKey == VirtualKey.Left && onlyAlt) { // When the previous key or Alt+Left are pressed navigate back e.Handled = true; GoBackCommand.Execute(null); } - else if ((int)virtualKey == 167 && noModifiers || - virtualKey == VirtualKey.Right && onlyAlt) + else if ((int) virtualKey == 167 && noModifiers || + virtualKey == VirtualKey.Right && onlyAlt) { // When the next key or Alt+Right are pressed navigate forward e.Handled = true; @@ -247,22 +250,32 @@ namespace ModernKeePass.Common /// Instance that triggered the event. /// Event data describing the conditions that led to the event. private void CoreWindow_PointerPressed(CoreWindow sender, - PointerEventArgs e) + PointerEventArgs e) { var properties = e.CurrentPoint.Properties; // Ignore button chords with the left, right, and middle buttons if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed || - properties.IsMiddleButtonPressed) return; + properties.IsMiddleButtonPressed) + { + return; + } // If back or forward are pressed (but not both) navigate appropriately - var backPressed = properties.IsXButton1Pressed; + var backPressed = properties.IsXButton1Pressed; var forwardPressed = properties.IsXButton2Pressed; if (backPressed ^ forwardPressed) { e.Handled = true; - if (backPressed) GoBackCommand.Execute(null); - if (forwardPressed) GoForwardCommand.Execute(null); + if (backPressed) + { + GoBackCommand.Execute(null); + } + + if (forwardPressed) + { + GoForwardCommand.Execute(null); + } } } #endif @@ -279,6 +292,7 @@ namespace ModernKeePass.Common /// state provided when recreating a page from a prior session. /// public event LoadStateEventHandler LoadState; + /// /// Register this event on the current page to preserve /// state associated with the current page in case the @@ -303,7 +317,7 @@ namespace ModernKeePass.Common { // Clear existing state for forward navigation when adding a new page to the // navigation stack - var nextPageKey = _pageKey; + var nextPageKey = _pageKey; var nextPageIndex = Frame.BackStackDepth; while (frameState.Remove(nextPageKey)) { @@ -319,7 +333,7 @@ namespace ModernKeePass.Common // Pass the navigation parameter and preserved page state to the page, using // the same strategy for loading suspended state and recreating pages discarded // from cache - LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, (Dictionary)frameState[_pageKey])); + LoadState?.Invoke(this, new LoadStateEventArgs(e.Parameter, (Dictionary) frameState[_pageKey])); } } @@ -333,7 +347,7 @@ namespace ModernKeePass.Common public void OnNavigatedFrom(NavigationEventArgs e) { var frameState = SuspensionManager.SessionStateForFrame(Frame); - var pageState = new Dictionary(); + var pageState = new Dictionary(); SaveState?.Invoke(this, new SaveStateEventArgs(pageState)); frameState[_pageKey] = pageState; } @@ -345,6 +359,7 @@ namespace ModernKeePass.Common /// Represents the method that will handle the event /// public delegate void LoadStateEventHandler(object sender, LoadStateEventArgs e); + /// /// Represents the method that will handle the event /// @@ -360,6 +375,7 @@ namespace ModernKeePass.Common /// when this page was initially requested. /// public object NavigationParameter { get; private set; } + /// /// A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited. @@ -380,9 +396,10 @@ namespace ModernKeePass.Common public LoadStateEventArgs(object navigationParameter, Dictionary pageState) { NavigationParameter = navigationParameter; - PageState = pageState; + PageState = pageState; } } + /// /// Class used to hold the event data required when a page attempts to save state. /// diff --git a/WinAppCommon/ViewModels/UserControls/BreadcrumbControlVm.cs b/WinAppCommon/ViewModels/UserControls/BreadcrumbControlVm.cs index fefafda..0eb31ef 100644 --- a/WinAppCommon/ViewModels/UserControls/BreadcrumbControlVm.cs +++ b/WinAppCommon/ViewModels/UserControls/BreadcrumbControlVm.cs @@ -15,35 +15,39 @@ namespace ModernKeePass.ViewModels public class BreadcrumbControlVm { public ObservableCollection BreadcrumbItems { get; } - public string ParentGroupName { get; private set; } - public Icon ParentGroupIcon { get; private set; } = Icon.Folder; + public string ParentGroupName { get; private set; } + public Icon ParentGroupIcon { get; private set; } = Icon.Folder; - public RelayCommand GoBackCommand { get; } - public RelayCommand GoUpCommand { get; private set; } - public RelayCommand GoToCommand { get; } + public RelayCommand GoBackCommand { get; } + public RelayCommand GoUpCommand { get; private set; } + public RelayCommand GoToCommand { get; } - private readonly IMediator _mediator; + private readonly IMediator _mediator; private readonly INavigationService _navigation; public BreadcrumbControlVm(IMediator mediator, INavigationService navigation) { - _mediator = mediator; + _mediator = mediator; _navigation = navigation; - + BreadcrumbItems = new ObservableCollection(); - GoBackCommand = new RelayCommand(() => _navigation.GoBack()); - GoToCommand = new RelayCommand(GoTo); - GoUpCommand = new RelayCommand(() => GoTo(BreadcrumbItems.Count - 1), () => !string.IsNullOrEmpty(ParentGroupName)); + GoBackCommand = new RelayCommand(() => _navigation.GoBack()); + GoToCommand = new RelayCommand(GoTo); + GoUpCommand = new RelayCommand(() => GoTo(BreadcrumbItems.Count - 1), () => !string.IsNullOrEmpty(ParentGroupName)); } public async Task Initialize(GroupVm group) { - if (group == null) return; + if (group == null) + { + return; + } + GoBackCommand.RaiseCanExecuteChanged(); ParentGroupName = group.Title; ParentGroupIcon = group.Icon; - BreadcrumbItems.Add(new BreadcrumbItem { Path = group.Id, Name = group.Title, Icon = group.Icon }); + BreadcrumbItems.Add(new BreadcrumbItem {Path = group.Id, Name = group.Title, Icon = group.Icon}); var parentGroup = group; while (!string.IsNullOrEmpty(parentGroup.ParentGroupId)) { @@ -54,9 +58,13 @@ namespace ModernKeePass.ViewModels private void GoTo(int index) { - if (BreadcrumbItems.Count == 0) return; + if (BreadcrumbItems.Count == 0) + { + return; + } + var breadcrumb = BreadcrumbItems[index]; - _navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = breadcrumb.Path }); + _navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem {Id = breadcrumb.Path}); } } -} \ No newline at end of file +}