2017-09-26 14:32:15 +02:00
|
|
|
|
using System;
|
2017-10-11 11:20:05 +02:00
|
|
|
|
using System.Linq;
|
2017-10-13 15:46:41 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
using Windows.ApplicationModel.Background;
|
|
|
|
|
using Windows.Data.Xml.Dom;
|
2017-10-11 11:20:05 +02:00
|
|
|
|
using Windows.Storage.Streams;
|
2017-10-13 15:46:41 +02:00
|
|
|
|
using Windows.UI.Core;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
using Windows.UI.Notifications;
|
2017-10-11 14:30:07 +02:00
|
|
|
|
using Windows.UI.Popups;
|
2017-10-13 15:46:41 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
2017-09-11 18:25:00 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
using Microsoft.QueryStringDotNET;
|
|
|
|
|
using Microsoft.Toolkit.Uwp.Notifications;
|
2017-10-13 15:46:41 +02:00
|
|
|
|
using ModernKeePass.Common;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
using ModernKeePass.ViewModels;
|
2017-09-11 18:25:00 +02:00
|
|
|
|
|
2017-09-12 18:20:32 +02:00
|
|
|
|
// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229
|
2017-09-11 18:25:00 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Pages
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-09-12 18:20:32 +02:00
|
|
|
|
/// A page that displays an overview of a single group, including a preview of the items
|
|
|
|
|
/// within the group.
|
2017-09-11 18:25:00 +02:00
|
|
|
|
/// </summary>
|
2017-10-12 17:45:37 +02:00
|
|
|
|
public sealed partial class GroupDetailPage
|
2017-09-11 18:25:00 +02:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// NavigationHelper is used on each page to aid in navigation and
|
|
|
|
|
/// process lifetime management
|
|
|
|
|
/// </summary>
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public NavigationHelper NavigationHelper { get; }
|
2017-10-12 18:37:49 +02:00
|
|
|
|
public GroupVm Model => (GroupVm)DataContext;
|
|
|
|
|
|
2017-09-13 18:37:44 +02:00
|
|
|
|
public GroupDetailPage()
|
2017-09-11 18:25:00 +02:00
|
|
|
|
{
|
2017-09-15 11:47:43 +02:00
|
|
|
|
InitializeComponent();
|
2017-10-02 18:40:54 +02:00
|
|
|
|
NavigationHelper = new NavigationHelper(this);
|
|
|
|
|
NavigationHelper.LoadState += navigationHelper_LoadState;
|
2017-09-11 18:25:00 +02:00
|
|
|
|
}
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
2017-09-11 18:25:00 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Populates the page with content passed during navigation. Any saved state is also
|
|
|
|
|
/// provided when recreating a page from a prior session.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">
|
|
|
|
|
/// The source of the event; typically <see cref="Common.NavigationHelper"/>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="e">Event data that provides both the navigation parameter passed to
|
2017-09-26 14:32:15 +02:00
|
|
|
|
/// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
|
2017-09-11 18:25:00 +02:00
|
|
|
|
/// a dictionary of state preserved by this page during an earlier
|
|
|
|
|
/// session. The state will be null the first time a page is visited.</param>
|
2017-10-03 18:38:31 +02:00
|
|
|
|
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) {}
|
2017-09-11 18:25:00 +02:00
|
|
|
|
|
|
|
|
|
#region NavigationHelper registration
|
|
|
|
|
|
|
|
|
|
/// The methods provided in this section are simply used to allow
|
|
|
|
|
/// NavigationHelper to respond to the page's navigation methods.
|
|
|
|
|
///
|
|
|
|
|
/// Page specific logic should be placed in event handlers for the
|
|
|
|
|
/// <see cref="Common.NavigationHelper.LoadState"/>
|
|
|
|
|
/// and <see cref="Common.NavigationHelper.SaveState"/>.
|
|
|
|
|
/// The navigation parameter is available in the LoadState method
|
|
|
|
|
/// in addition to page state preserved during an earlier session.
|
2017-09-15 11:47:43 +02:00
|
|
|
|
///
|
2017-09-11 18:25:00 +02:00
|
|
|
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
NavigationHelper.OnNavigatedTo(e);
|
2017-09-27 18:01:21 +02:00
|
|
|
|
|
|
|
|
|
if (!(e.Parameter is GroupVm)) return;
|
|
|
|
|
DataContext = (GroupVm) e.Parameter;
|
2017-10-13 15:46:41 +02:00
|
|
|
|
if (Model.IsEditMode)
|
|
|
|
|
Task.Factory.StartNew(
|
|
|
|
|
() => Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
|
|
|
|
() => TitleTextBox.Focus(FocusState.Programmatic)));
|
2017-09-11 18:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
NavigationHelper.OnNavigatedFrom(e);
|
2017-09-11 18:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-09-15 15:58:51 +02:00
|
|
|
|
|
2017-10-11 14:30:07 +02:00
|
|
|
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
private void groups_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
2017-09-15 15:58:51 +02:00
|
|
|
|
{
|
2017-10-13 15:46:41 +02:00
|
|
|
|
GroupVm group;
|
|
|
|
|
switch (LeftListView.SelectedIndex)
|
2017-10-02 18:40:54 +02:00
|
|
|
|
{
|
2017-10-13 15:46:41 +02:00
|
|
|
|
case -1:
|
|
|
|
|
return;
|
|
|
|
|
case 0:
|
|
|
|
|
group = Model.CreateNewGroup();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
group = LeftListView.SelectedItem as GroupVm;
|
|
|
|
|
break;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
}
|
2017-10-13 15:46:41 +02:00
|
|
|
|
Frame.Navigate(typeof(GroupDetailPage), group);
|
2017-09-15 15:58:51 +02:00
|
|
|
|
}
|
2017-09-17 10:00:03 -04:00
|
|
|
|
|
2017-10-03 18:38:31 +02:00
|
|
|
|
private void entries_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
2017-09-15 18:15:48 +02:00
|
|
|
|
{
|
2017-10-13 15:46:41 +02:00
|
|
|
|
EntryVm entry;
|
2017-10-03 18:38:31 +02:00
|
|
|
|
switch (GridView.SelectedIndex)
|
2017-10-02 18:40:54 +02:00
|
|
|
|
{
|
2017-10-03 18:38:31 +02:00
|
|
|
|
case -1:
|
|
|
|
|
return;
|
|
|
|
|
case 0:
|
2017-10-13 15:46:41 +02:00
|
|
|
|
entry = Model.CreateNewEntry();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
entry = GridView.SelectedItem as EntryVm;
|
|
|
|
|
break;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
}
|
2017-10-13 15:46:41 +02:00
|
|
|
|
Frame.Navigate(typeof(EntryDetailPage), entry);
|
2017-09-15 18:15:48 +02:00
|
|
|
|
}
|
2017-10-02 18:40:54 +02:00
|
|
|
|
|
2017-10-17 18:46:05 +02:00
|
|
|
|
private async void DeleteButton_Click(object sender, RoutedEventArgs e)
|
2017-10-02 18:40:54 +02:00
|
|
|
|
{
|
2017-10-11 14:30:07 +02:00
|
|
|
|
// Create the message dialog and set its content
|
|
|
|
|
var messageDialog = new MessageDialog("Are you sure you want to delete the whole group and all its entries?");
|
|
|
|
|
|
|
|
|
|
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
|
|
|
|
messageDialog.Commands.Add(new UICommand("Delete", delete =>
|
|
|
|
|
{
|
2017-10-17 18:46:05 +02:00
|
|
|
|
ShowToast("Group", Model);
|
|
|
|
|
Model.MarkForDelete();
|
2017-10-11 14:30:07 +02:00
|
|
|
|
if (Frame.CanGoBack) Frame.GoBack();
|
|
|
|
|
}));
|
|
|
|
|
messageDialog.Commands.Add(new UICommand("Cancel"));
|
|
|
|
|
|
|
|
|
|
// Set the command that will be invoked by default
|
|
|
|
|
messageDialog.DefaultCommandIndex = 1;
|
2017-10-09 18:40:02 +02:00
|
|
|
|
|
2017-10-11 14:30:07 +02:00
|
|
|
|
// Set the command to be invoked when escape is pressed
|
|
|
|
|
messageDialog.CancelCommandIndex = 1;
|
|
|
|
|
|
|
|
|
|
// Show the message dialog
|
|
|
|
|
await messageDialog.ShowAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 18:40:02 +02:00
|
|
|
|
private void SemanticZoom_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
|
|
|
|
|
{
|
2017-10-13 15:46:41 +02:00
|
|
|
|
// We need to synchronize the two lists (zoomed-in and zoomed-out) because the source is different
|
2017-10-09 18:40:02 +02:00
|
|
|
|
if (e.IsSourceZoomedInView == false)
|
|
|
|
|
{
|
|
|
|
|
e.DestinationItem.Item = e.SourceItem.Item;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-11 11:20:05 +02:00
|
|
|
|
|
|
|
|
|
private void SearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx://Assets/Logo.scale-80.png"));
|
2017-10-17 18:46:05 +02:00
|
|
|
|
var results = Model.Entries.Skip(1).Where(e => e.Name.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5);
|
2017-10-11 11:20:05 +02:00
|
|
|
|
foreach (var result in results)
|
|
|
|
|
{
|
2017-10-17 18:46:05 +02:00
|
|
|
|
args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Name, result.ParentGroup.Name, result.Id, imageUri, string.Empty);
|
2017-10-11 11:20:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
|
|
|
|
{
|
2017-10-12 18:37:49 +02:00
|
|
|
|
var entry = Model.Entries.Skip(1).FirstOrDefault(e => e.Id == args.Tag);
|
2017-10-11 11:20:05 +02:00
|
|
|
|
Frame.Navigate(typeof(EntryDetailPage), entry);
|
|
|
|
|
}
|
2017-10-11 14:30:07 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
2017-10-17 18:46:05 +02:00
|
|
|
|
|
|
|
|
|
private async void ShowToast(string entityType, IPwEntity entity)
|
|
|
|
|
{
|
|
|
|
|
// Construct the visuals of the toast
|
|
|
|
|
var visual = new ToastVisual
|
|
|
|
|
{
|
|
|
|
|
BindingGeneric = new ToastBindingGeneric
|
|
|
|
|
{
|
|
|
|
|
Children =
|
|
|
|
|
{
|
|
|
|
|
new AdaptiveText
|
|
|
|
|
{
|
|
|
|
|
Text = $"{entityType} {entity.Name} deleted."
|
|
|
|
|
}
|
|
|
|
|
}/*,
|
|
|
|
|
|
|
|
|
|
AppLogoOverride = new ToastGenericAppLogo()
|
|
|
|
|
{
|
|
|
|
|
Source = logo,
|
|
|
|
|
HintCrop = ToastGenericAppLogoCrop.Circle
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Construct the actions for the toast (inputs and buttons)
|
|
|
|
|
var actions = new ToastActionsCustom
|
|
|
|
|
{
|
|
|
|
|
Buttons =
|
|
|
|
|
{
|
|
|
|
|
new ToastButton("Undo", new QueryString
|
|
|
|
|
{
|
|
|
|
|
{ "action", "undo" },
|
|
|
|
|
{ "entityType", entityType },
|
|
|
|
|
{ "entityId", entity.Id }
|
|
|
|
|
|
|
|
|
|
}.ToString())
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Now we can construct the final toast content
|
|
|
|
|
var toastContent = new ToastContent
|
|
|
|
|
{
|
|
|
|
|
Visual = visual,
|
|
|
|
|
Actions = actions,
|
|
|
|
|
// Arguments when the user taps body of toast
|
|
|
|
|
Launch = new QueryString()
|
|
|
|
|
{
|
|
|
|
|
{ "action", "undo" },
|
|
|
|
|
{ "entityType", "group" },
|
|
|
|
|
{ "entityId", entity.Id }
|
|
|
|
|
|
|
|
|
|
}.ToString()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// And create the toast notification
|
|
|
|
|
var toastXml = new XmlDocument();
|
|
|
|
|
toastXml.LoadXml(toastContent.GetContent());
|
|
|
|
|
|
|
|
|
|
var visualXml = toastXml.GetElementsByTagName("visual")[0];
|
|
|
|
|
((XmlElement)visualXml.ChildNodes[0]).SetAttribute("template", "ToastText02");
|
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(toastXml) {ExpirationTime = DateTime.Now.AddSeconds(5)};
|
|
|
|
|
toast.Dismissed += Toast_Dismissed;
|
|
|
|
|
|
|
|
|
|
/*var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
|
|
|
|
|
var toastElements = notificationXml.GetElementsByTagName("text");
|
|
|
|
|
toastElements[0].AppendChild(notificationXml.CreateTextNode($"{entityType} deleted"));
|
|
|
|
|
toastElements[1].AppendChild(notificationXml.CreateTextNode("Click me to undo"));
|
|
|
|
|
|
|
|
|
|
var toast = new ToastNotification(notificationXml)
|
|
|
|
|
{
|
|
|
|
|
ExpirationTime = DateTime.Now.AddSeconds(5)
|
|
|
|
|
};*/
|
|
|
|
|
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Toast_Dismissed(ToastNotification sender, ToastDismissedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var app = (App)Application.Current;
|
|
|
|
|
if (app.PendingDeleteQueue.Count == 0) return;
|
|
|
|
|
var entity = app.PendingDeleteQueue.Dequeue();
|
|
|
|
|
if (entity is GroupVm)
|
|
|
|
|
{
|
|
|
|
|
entity.CommitDelete();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-11 18:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|