2018-07-25 18:39:03 +02:00
|
|
|
|
using System;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
using System.Linq;
|
2018-08-03 17:41:52 +02:00
|
|
|
|
using System.Windows.Input;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
using Windows.Storage.Streams;
|
2018-07-02 18:23:43 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using ModernKeePass.ViewModels;
|
2018-07-02 18:23:43 +02:00
|
|
|
|
|
|
|
|
|
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Views.UserControls
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class TopMenuUserControl
|
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public TopMenuVm Model => (TopMenuVm)StackPanel.DataContext;
|
|
|
|
|
|
2018-08-03 17:41:52 +02:00
|
|
|
|
public ICommand SaveCommand
|
2018-07-02 18:23:43 +02:00
|
|
|
|
{
|
2018-08-03 17:41:52 +02:00
|
|
|
|
get { return (ICommand)GetValue(SaveCommandProperty); }
|
2018-07-02 18:23:43 +02:00
|
|
|
|
set { SetValue(SaveCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SaveCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(SaveCommand),
|
2018-08-03 17:41:52 +02:00
|
|
|
|
typeof(ICommand),
|
2018-07-02 18:23:43 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2018-08-03 17:41:52 +02:00
|
|
|
|
public ICommand EditCommand
|
2018-07-02 18:23:43 +02:00
|
|
|
|
{
|
2018-08-03 17:41:52 +02:00
|
|
|
|
get { return (ICommand)GetValue(EditCommandProperty); }
|
2018-07-02 18:23:43 +02:00
|
|
|
|
set { SetValue(EditCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty EditCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(EditCommand),
|
2018-08-03 17:41:52 +02:00
|
|
|
|
typeof(ICommand),
|
2018-07-02 18:23:43 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2018-08-03 17:41:52 +02:00
|
|
|
|
public ICommand DeleteCommand
|
2018-07-02 18:23:43 +02:00
|
|
|
|
{
|
2018-08-03 17:41:52 +02:00
|
|
|
|
get { return (ICommand)GetValue(DeleteCommandProperty); }
|
2018-07-02 18:23:43 +02:00
|
|
|
|
set { SetValue(DeleteCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty DeleteCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(DeleteCommand),
|
2018-08-03 17:41:52 +02:00
|
|
|
|
typeof(ICommand),
|
2018-07-02 18:23:43 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public RelayCommand<string> MoveCommand
|
2018-07-02 18:23:43 +02:00
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
get { return (RelayCommand<string>)GetValue(MoveCommandProperty); }
|
2020-04-14 13:44:07 +02:00
|
|
|
|
set { SetValue(MoveCommandProperty, value); }
|
2018-07-02 18:23:43 +02:00
|
|
|
|
}
|
2020-04-14 13:44:07 +02:00
|
|
|
|
public static readonly DependencyProperty MoveCommandProperty =
|
2018-07-02 18:23:43 +02:00
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(MoveCommand),
|
2020-04-28 15:20:47 +02:00
|
|
|
|
typeof(RelayCommand<string>),
|
2018-07-02 18:23:43 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
2020-04-28 15:20:47 +02:00
|
|
|
|
|
2020-04-15 19:06:13 +02:00
|
|
|
|
public ICommand RestoreCommand
|
|
|
|
|
{
|
|
|
|
|
get { return (ICommand)GetValue(RestoreCommandProperty); }
|
|
|
|
|
set { SetValue(RestoreCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty RestoreCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(RestoreCommand),
|
|
|
|
|
typeof(ICommand),
|
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2018-08-03 17:41:52 +02:00
|
|
|
|
public ICommand SortEntriesCommand
|
2018-07-11 12:15:56 +02:00
|
|
|
|
{
|
2018-08-03 17:41:52 +02:00
|
|
|
|
get { return (ICommand)GetValue(SortEntriesCommandProperty); }
|
2018-07-11 12:15:56 +02:00
|
|
|
|
set { SetValue(SortEntriesCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SortEntriesCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(SortEntriesCommand),
|
2018-08-03 17:41:52 +02:00
|
|
|
|
typeof(ICommand),
|
2018-07-11 12:15:56 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
2018-07-02 18:23:43 +02:00
|
|
|
|
|
2018-08-03 17:41:52 +02:00
|
|
|
|
public ICommand SortGroupsCommand
|
2018-07-11 12:15:56 +02:00
|
|
|
|
{
|
2018-08-03 17:41:52 +02:00
|
|
|
|
get { return (ICommand)GetValue(SortGroupsCommandProperty); }
|
2018-07-11 12:15:56 +02:00
|
|
|
|
set { SetValue(SortGroupsCommandProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SortGroupsCommandProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(SortGroupsCommand),
|
2018-08-03 17:41:52 +02:00
|
|
|
|
typeof(ICommand),
|
2018-07-11 12:15:56 +02:00
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
2018-09-10 18:26:55 +02:00
|
|
|
|
|
2018-07-11 12:15:56 +02:00
|
|
|
|
public Visibility SortButtonVisibility
|
|
|
|
|
{
|
|
|
|
|
get { return (Visibility)GetValue(SortButtonVisibilityProperty); }
|
|
|
|
|
set { SetValue(SortButtonVisibilityProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty SortButtonVisibilityProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(SortButtonVisibility),
|
2018-07-11 12:15:56 +02:00
|
|
|
|
typeof(Visibility),
|
|
|
|
|
typeof(TopMenuUserControl),
|
2018-09-04 15:07:31 +02:00
|
|
|
|
new PropertyMetadata(Visibility.Collapsed, (o, args) => { }));
|
2018-07-05 18:32:42 +02:00
|
|
|
|
|
2020-04-15 19:06:13 +02:00
|
|
|
|
public Visibility MoveButtonVisibility
|
|
|
|
|
{
|
|
|
|
|
get { return (Visibility)GetValue(MoveButtonVisibilityProperty); }
|
|
|
|
|
set { SetValue(MoveButtonVisibilityProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty MoveButtonVisibilityProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(MoveButtonVisibility),
|
|
|
|
|
typeof(Visibility),
|
|
|
|
|
typeof(TopMenuUserControl),
|
2020-04-28 15:20:47 +02:00
|
|
|
|
new PropertyMetadata(Visibility.Visible, (o, args) => { }));
|
2020-04-15 19:06:13 +02:00
|
|
|
|
|
|
|
|
|
public Visibility RestoreButtonVisibility
|
|
|
|
|
{
|
|
|
|
|
get { return (Visibility)GetValue(RestoreButtonVisibilityProperty); }
|
|
|
|
|
set { SetValue(RestoreButtonVisibilityProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty RestoreButtonVisibilityProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(RestoreButtonVisibility),
|
|
|
|
|
typeof(Visibility),
|
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(Visibility.Collapsed, (o, args) => { }));
|
2020-04-21 19:12:26 +02:00
|
|
|
|
|
2018-07-05 18:32:42 +02:00
|
|
|
|
public bool IsEditButtonChecked
|
|
|
|
|
{
|
|
|
|
|
get { return (bool)GetValue(IsEditButtonCheckedProperty); }
|
|
|
|
|
set { SetValue(IsEditButtonCheckedProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty IsEditButtonCheckedProperty =
|
|
|
|
|
DependencyProperty.Register(
|
2020-04-14 13:44:07 +02:00
|
|
|
|
nameof(IsEditButtonChecked),
|
2018-07-05 18:32:42 +02:00
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(TopMenuUserControl),
|
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
|
|
|
|
|
2018-07-25 18:39:03 +02:00
|
|
|
|
public event EventHandler<RoutedEventArgs> EditButtonClick;
|
2018-09-09 20:01:56 +02:00
|
|
|
|
|
2018-07-02 18:23:43 +02:00
|
|
|
|
public TopMenuUserControl()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-07-11 12:15:56 +02:00
|
|
|
|
EditFlyout.Click += EditFlyout_Click;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditFlyout_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IsEditButtonChecked = EditFlyout.IsChecked;
|
|
|
|
|
EditButton_Click(sender, e);
|
2018-07-02 18:23:43 +02:00
|
|
|
|
}
|
2018-07-05 18:32:42 +02:00
|
|
|
|
|
|
|
|
|
private void EditButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EditButtonClick?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 13:48:15 +02:00
|
|
|
|
private void OverflowFlyout_OnOpening(object sender, object e)
|
2018-07-10 18:26:27 +02:00
|
|
|
|
{
|
|
|
|
|
EditFlyout.IsChecked = IsEditButtonChecked;
|
2020-05-11 19:22:41 +02:00
|
|
|
|
|
2020-04-15 19:06:13 +02:00
|
|
|
|
RestoreFlyout.Visibility = RestoreButtonVisibility;
|
2018-07-11 12:15:56 +02:00
|
|
|
|
SortEntriesFlyout.Visibility = SortButtonVisibility;
|
|
|
|
|
SortGroupsFlyout.Visibility = SortButtonVisibility;
|
2020-04-28 18:54:37 +02:00
|
|
|
|
|
|
|
|
|
SaveFlyout.Command = SaveCommand;
|
|
|
|
|
DeleteFlyout.Command = DeleteCommand;
|
|
|
|
|
RestoreFlyout.Command = RestoreCommand;
|
2018-07-11 13:48:15 +02:00
|
|
|
|
SortEntriesFlyout.Command = SortEntriesCommand;
|
|
|
|
|
SortGroupsFlyout.Command = SortGroupsCommand;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 18:54:37 +02:00
|
|
|
|
// These are somehow necessary as otherwise, the command is not bound
|
|
|
|
|
private void MoveButtonFlyout_OnOpening(object sender, object e)
|
|
|
|
|
{
|
|
|
|
|
MoveButton.Command = MoveCommand;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-11 13:48:15 +02:00
|
|
|
|
private void SortFlyout_OnOpening(object sender, object e)
|
|
|
|
|
{
|
|
|
|
|
SortEntriesButtonFlyout.Command = SortEntriesCommand;
|
|
|
|
|
SortGroupsButtonFlyout.Command = SortGroupsCommand;
|
2018-07-10 18:26:27 +02:00
|
|
|
|
}
|
2020-04-28 15:20:47 +02:00
|
|
|
|
|
2020-05-04 20:56:19 +02:00
|
|
|
|
private void GroupSearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
|
2020-04-28 15:20:47 +02:00
|
|
|
|
{
|
2020-05-11 19:22:41 +02:00
|
|
|
|
var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appdata:/Assets/ModernKeePass-SmallLogo.scale-80.png"));
|
2020-04-28 18:54:37 +02:00
|
|
|
|
var groups = Model.Groups.Where(g => g.Title.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5);
|
|
|
|
|
foreach (var group in groups)
|
2020-04-28 15:20:47 +02:00
|
|
|
|
{
|
2020-04-28 18:54:37 +02:00
|
|
|
|
args.Request.SearchSuggestionCollection.AppendResultSuggestion(
|
|
|
|
|
group.Title,
|
2020-04-30 19:40:48 +02:00
|
|
|
|
group.ParentGroupName ?? string.Empty,
|
2020-04-28 18:54:37 +02:00
|
|
|
|
group.Id,
|
|
|
|
|
imageUri,
|
|
|
|
|
string.Empty);
|
2020-04-28 15:20:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-15 19:06:13 +02:00
|
|
|
|
|
2020-05-04 20:56:19 +02:00
|
|
|
|
private void GroupSearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
2020-04-28 15:20:47 +02:00
|
|
|
|
{
|
2020-04-28 18:54:37 +02:00
|
|
|
|
MoveButton.CommandParameter = args.Tag;
|
2020-04-28 15:20:47 +02:00
|
|
|
|
MoveCommand.RaiseCanExecuteChanged();
|
|
|
|
|
}
|
2020-06-04 16:29:26 +02:00
|
|
|
|
|
2020-05-04 20:56:19 +02:00
|
|
|
|
private async void EntrySearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
|
|
|
|
|
{
|
2020-05-11 19:22:41 +02:00
|
|
|
|
var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appdata:/Assets/ModernKeePass-SmallLogo.scale-80.png"));
|
2020-05-04 20:56:19 +02:00
|
|
|
|
var results = (await Model.Search(args.QueryText)).Take(5);
|
|
|
|
|
foreach (var result in results)
|
|
|
|
|
{
|
2020-05-12 17:14:30 +02:00
|
|
|
|
args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Title.Value, result.ParentGroupName, result.Id, imageUri, string.Empty);
|
2020-05-04 20:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EntrySearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Model.GoToEntry(args.Tag);
|
|
|
|
|
}
|
2018-07-02 18:23:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|