From 81ca11a955b057e189426450ed8019b2d771801d Mon Sep 17 00:00:00 2001 From: BONNEVILLE Geoffroy Date: Wed, 11 Jul 2018 12:15:56 +0200 Subject: [PATCH] WIP Top Menu - sort buttons present but not working Removed flyout from textbox with button Generating a new password creates a new history entry Top Menu edit mode now works as intended --- ModernKeePass/Controls/TextBoxWithButton.cs | 14 +--- .../TextBoxWithButtonStyle.xaml | 3 - ModernKeePass/Strings/en-US/Resources.resw | 3 + ModernKeePass/Strings/fr-FR/Resources.resw | 3 + ModernKeePass/ViewModels/EntryVm.cs | 16 ++--- ModernKeePass/Views/EntryDetailPage.xaml | 43 ++++++++++-- ModernKeePass/Views/GroupDetailPage.xaml | 5 +- .../UserControls/TopMenuUserControl.xaml | 19 +++++- .../UserControls/TopMenuUserControl.xaml.cs | 67 +++++++++++++++++-- 9 files changed, 136 insertions(+), 37 deletions(-) diff --git a/ModernKeePass/Controls/TextBoxWithButton.cs b/ModernKeePass/Controls/TextBoxWithButton.cs index 99f0e5f..3db0bd1 100644 --- a/ModernKeePass/Controls/TextBoxWithButton.cs +++ b/ModernKeePass/Controls/TextBoxWithButton.cs @@ -43,19 +43,7 @@ namespace ModernKeePass.Controls typeof(bool), typeof(TextBoxWithButton), new PropertyMetadata(true, (o, args) => { })); - - public FlyoutBase ButtonFlyout - { - get { return (FlyoutBase)GetValue(ButtonFlyoutProperty); } - set { SetValue(ButtonFlyoutProperty, value); } - } - public static readonly DependencyProperty ButtonFlyoutProperty = - DependencyProperty.Register( - "ButtonFlyout", - typeof(FlyoutBase), - typeof(TextBoxWithButton), - new PropertyMetadata(null, (o, args) => { })); - + protected override void OnApplyTemplate() { base.OnApplyTemplate(); diff --git a/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml b/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml index 973338a..3664575 100644 --- a/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml +++ b/ModernKeePass/ResourceDictionaries/TextBoxWithButtonStyle.xaml @@ -246,9 +246,6 @@ Content="{TemplateBinding ButtonSymbol}" IsEnabled="{TemplateBinding IsButtonEnabled}" VerticalAlignment="Stretch"> - - - diff --git a/ModernKeePass/Strings/en-US/Resources.resw b/ModernKeePass/Strings/en-US/Resources.resw index 184bbec..8c4517a 100644 --- a/ModernKeePass/Strings/en-US/Resources.resw +++ b/ModernKeePass/Strings/en-US/Resources.resw @@ -447,4 +447,7 @@ Save + + Sort + \ No newline at end of file diff --git a/ModernKeePass/Strings/fr-FR/Resources.resw b/ModernKeePass/Strings/fr-FR/Resources.resw index 60736f6..56b6fad 100644 --- a/ModernKeePass/Strings/fr-FR/Resources.resw +++ b/ModernKeePass/Strings/fr-FR/Resources.resw @@ -447,4 +447,7 @@ Sauvegarder + + Trier + \ No newline at end of file diff --git a/ModernKeePass/ViewModels/EntryVm.cs b/ModernKeePass/ViewModels/EntryVm.cs index 43fbc49..457bf3f 100644 --- a/ModernKeePass/ViewModels/EntryVm.cs +++ b/ModernKeePass/ViewModels/EntryVm.cs @@ -51,14 +51,14 @@ namespace ModernKeePass.ViewModels public string Name { get { return GetEntryValue(PwDefs.TitleField); } - set { SetEntryValue(PwDefs.TitleField, value); } + set { SetEntryValue(PwDefs.TitleField, new ProtectedString(true, value)); } } public string UserName { get { return GetEntryValue(PwDefs.UserNameField); } - set { SetEntryValue(PwDefs.UserNameField, value); } + set { SetEntryValue(PwDefs.UserNameField, new ProtectedString(true, value)); } } public string Password @@ -66,7 +66,7 @@ namespace ModernKeePass.ViewModels get { return GetEntryValue(PwDefs.PasswordField); } set { - SetEntryValue(PwDefs.PasswordField, value); + SetEntryValue(PwDefs.PasswordField, new ProtectedString(true, value)); NotifyPropertyChanged("Password"); NotifyPropertyChanged("PasswordComplexityIndicator"); } @@ -75,13 +75,13 @@ namespace ModernKeePass.ViewModels public string Url { get { return GetEntryValue(PwDefs.UrlField); } - set { SetEntryValue(PwDefs.UrlField, value); } + set { SetEntryValue(PwDefs.UrlField, new ProtectedString(true, value)); } } public string Notes { get { return GetEntryValue(PwDefs.NotesField); } - set { SetEntryValue(PwDefs.NotesField, value); } + set { SetEntryValue(PwDefs.NotesField, new ProtectedString(true, value)); } } public int IconId @@ -239,7 +239,7 @@ namespace ModernKeePass.ViewModels ProtectedString password; PwGenerator.Generate(out password, pwProfile, null, new CustomPwGeneratorPool()); - _pwEntry?.Strings.Set(PwDefs.PasswordField, password); + SetEntryValue(PwDefs.PasswordField, password); NotifyPropertyChanged("Password"); NotifyPropertyChanged("IsRevealPasswordEnabled"); NotifyPropertyChanged("PasswordComplexityIndicator"); @@ -291,14 +291,14 @@ namespace ModernKeePass.ViewModels return _pwEntry?.Strings.GetSafe(key).ReadString(); } - private void SetEntryValue(string key, string newValue) + private void SetEntryValue(string key, ProtectedString newValue) { if (!_isDirty) { _pwEntry.Touch(true); _pwEntry?.CreateBackup(null); } - _pwEntry?.Strings.Set(key, new ProtectedString(true, newValue)); + _pwEntry?.Strings.Set(key, newValue); _isDirty = true; } } diff --git a/ModernKeePass/Views/EntryDetailPage.xaml b/ModernKeePass/Views/EntryDetailPage.xaml index ca1991a..a211b44 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml +++ b/ModernKeePass/Views/EntryDetailPage.xaml @@ -454,6 +454,7 @@ + @@ -463,6 +464,7 @@ + @@ -518,6 +520,7 @@ + diff --git a/ModernKeePass/Views/UserControls/TopMenuUserControl.xaml.cs b/ModernKeePass/Views/UserControls/TopMenuUserControl.xaml.cs index c5d9894..873ecca 100644 --- a/ModernKeePass/Views/UserControls/TopMenuUserControl.xaml.cs +++ b/ModernKeePass/Views/UserControls/TopMenuUserControl.xaml.cs @@ -54,7 +54,31 @@ namespace ModernKeePass.Views.UserControls typeof(ICommand), typeof(TopMenuUserControl), new PropertyMetadata(null, (o, args) => { })); + + public ICommand SortEntriesCommand + { + get { return (ICommand)GetValue(SortEntriesCommandProperty); } + set { SetValue(SortEntriesCommandProperty, value); } + } + public static readonly DependencyProperty SortEntriesCommandProperty = + DependencyProperty.Register( + "SortEntriesCommand", + typeof(ICommand), + typeof(TopMenuUserControl), + new PropertyMetadata(null, (o, args) => { })); + public ICommand SortGroupsCommand + { + get { return (ICommand)GetValue(SortGroupsCommandProperty); } + set { SetValue(SortGroupsCommandProperty, value); } + } + public static readonly DependencyProperty SortGroupsCommandProperty = + DependencyProperty.Register( + "SortGroupsCommand", + typeof(ICommand), + typeof(TopMenuUserControl), + new PropertyMetadata(null, (o, args) => { })); + public Visibility RestoreButtonVisibility { get { return (Visibility)GetValue(RestoreButtonVisibilityProperty); } @@ -65,7 +89,7 @@ namespace ModernKeePass.Views.UserControls "RestoreButtonVisibility", typeof(Visibility), typeof(TopMenuUserControl), - new PropertyMetadata(false, (o, args) => { })); + new PropertyMetadata(Visibility.Collapsed, (o, args) => { })); public Visibility DeleteButtonVisibility { @@ -77,7 +101,7 @@ namespace ModernKeePass.Views.UserControls "DeleteButtonVisibility", typeof(Visibility), typeof(TopMenuUserControl), - new PropertyMetadata(false, (o, args) => { })); + new PropertyMetadata(Visibility.Collapsed, (o, args) => { })); public Visibility MoreButtonVisibility { @@ -89,7 +113,7 @@ namespace ModernKeePass.Views.UserControls "MoreButtonVisibility", typeof(Visibility), typeof(TopMenuUserControl), - new PropertyMetadata(false, (o, args) => { })); + new PropertyMetadata(Visibility.Collapsed, (o, args) => { })); public Visibility OverflowButtonsVisibility { @@ -101,7 +125,19 @@ namespace ModernKeePass.Views.UserControls "OverflowButtonsVisibility", typeof(Visibility), typeof(TopMenuUserControl), - new PropertyMetadata(false, (o, args) => { })); + new PropertyMetadata(Visibility.Collapsed, (o, args) => { })); + + public Visibility SortButtonVisibility + { + get { return (Visibility)GetValue(SortButtonVisibilityProperty); } + set { SetValue(SortButtonVisibilityProperty, value); } + } + public static readonly DependencyProperty SortButtonVisibilityProperty = + DependencyProperty.Register( + "SortButtonVisibility", + typeof(Visibility), + typeof(TopMenuUserControl), + new PropertyMetadata(Visibility.Collapsed, (o, args) => { })); public bool IsDeleteButtonEnabled { @@ -126,6 +162,18 @@ namespace ModernKeePass.Views.UserControls typeof(bool), typeof(TopMenuUserControl), new PropertyMetadata(false, (o, args) => { })); + + public bool IsRestoreButtonEnabled + { + get { return (bool)GetValue(IsRestoreButtonEnabledProperty); } + set { SetValue(IsRestoreButtonEnabledProperty, value); } + } + public static readonly DependencyProperty IsRestoreButtonEnabledProperty = + DependencyProperty.Register( + "IsRestoreButtonEnabled", + typeof(bool), + typeof(TopMenuUserControl), + new PropertyMetadata(false, (o, args) => { })); public event EditButtonClickEventHandler EditButtonClick; public delegate void EditButtonClickEventHandler(object sender, RoutedEventArgs e); @@ -137,6 +185,13 @@ namespace ModernKeePass.Views.UserControls public TopMenuUserControl() { InitializeComponent(); + EditFlyout.Click += EditFlyout_Click; + } + + private void EditFlyout_Click(object sender, RoutedEventArgs e) + { + IsEditButtonChecked = EditFlyout.IsChecked; + EditButton_Click(sender, e); } private void EditButton_Click(object sender, RoutedEventArgs e) @@ -161,7 +216,11 @@ namespace ModernKeePass.Views.UserControls EditFlyout.IsChecked = IsEditButtonChecked; + RestoreFlyout.IsEnabled = IsRestoreButtonEnabled; RestoreFlyout.Visibility = RestoreButtonVisibility; + + SortEntriesFlyout.Visibility = SortButtonVisibility; + SortGroupsFlyout.Visibility = SortButtonVisibility; } } }