mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Updating group raise SaveCommand can execute
No need to click twice on history menu Skipped first history entry as it is the same as the current entry Stored SaveException innerexception as it is read more than once
This commit is contained in:
@@ -84,10 +84,11 @@ namespace ModernKeePass
|
||||
|
||||
if (realException is SaveException)
|
||||
{
|
||||
var innerException = realException.InnerException;
|
||||
unhandledExceptionEventArgs.Handled = true;
|
||||
HockeyClient.Current.TrackException(realException.InnerException);
|
||||
HockeyClient.Current.TrackException(innerException);
|
||||
await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("MessageDialogSaveErrorTitle"),
|
||||
realException.InnerException.Message,
|
||||
innerException?.Message,
|
||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"),
|
||||
_resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
|
||||
async command =>
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
@@ -241,7 +242,7 @@ namespace ModernKeePass.ViewModels
|
||||
SelectedItem = _mediator.Send(new GetEntryQuery { Id = entryId }).GetAwaiter().GetResult();
|
||||
_parent = _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId }).GetAwaiter().GetResult();
|
||||
History = new ObservableCollection<EntryVm> { SelectedItem };
|
||||
foreach (var entry in SelectedItem.History)
|
||||
foreach (var entry in SelectedItem.History.Skip(1))
|
||||
{
|
||||
History.Add(entry);
|
||||
}
|
||||
@@ -296,7 +297,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
private async Task RestoreHistory()
|
||||
{
|
||||
await _mediator.Send(new RestoreHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
await _mediator.Send(new RestoreHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex });
|
||||
History.Insert(0, SelectedItem);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
@@ -304,7 +305,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public async Task DeleteHistory()
|
||||
{
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex });
|
||||
History.RemoveAt(SelectedIndex);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
|
@@ -50,13 +50,21 @@ namespace ModernKeePass.ViewModels
|
||||
public string Title
|
||||
{
|
||||
get { return _group.Title; }
|
||||
set { _mediator.Send(new UpdateGroupCommand {Group = _group, Title = value, Icon = _group.Icon}).Wait(); }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new UpdateGroupCommand {Group = _group, Title = value, Icon = _group.Icon}).Wait();
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Symbol Icon
|
||||
{
|
||||
get { return (Symbol) Enum.Parse(typeof(Symbol), _group.Icon.ToString()); }
|
||||
set { _mediator.Send(new UpdateGroupCommand { Group = _group, Title = _group.Title, Icon = (Icon)Enum.Parse(typeof(Icon), value.ToString()) }).Wait(); }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new UpdateGroupCommand { Group = _group, Title = _group.Title, Icon = (Icon)Enum.Parse(typeof(Icon), value.ToString()) }).Wait();
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEditMode
|
||||
|
@@ -1,38 +1,54 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
||||
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Views;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SaveVm
|
||||
{
|
||||
public bool IsSaveEnabled => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsDirty;
|
||||
|
||||
public RelayCommand SaveCommand { get; }
|
||||
public RelayCommand CloseCommand { get; }
|
||||
public Frame Frame { get; set; }
|
||||
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SaveVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public SaveVm(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
SaveCommand = new RelayCommand(async () => await Save(), () => IsSaveEnabled);
|
||||
CloseCommand = new RelayCommand(async () => await Close());
|
||||
}
|
||||
|
||||
public async Task Save(bool close = true)
|
||||
{
|
||||
await _mediator.Send(new SaveDatabaseCommand());
|
||||
if (close) await Close();
|
||||
if (close) await _mediator.Send(new CloseDatabaseCommand());
|
||||
Frame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
public async Task Save(StorageFile file)
|
||||
{
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
|
||||
Frame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
public async Task Close()
|
||||
{
|
||||
await _mediator.Send(new CloseDatabaseCommand());
|
||||
Frame.Navigate(typeof(MainPage));
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
x:Class="ModernKeePass.Views.SaveDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
<Page.DataContext>
|
||||
@@ -11,11 +13,11 @@
|
||||
</Page.DataContext>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Uid="SaveButton" Click="SaveButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<HyperlinkButton x:Uid="SaveButton" Command="{Binding SaveCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<TextBlock x:Uid="SaveDesc" Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" />
|
||||
<HyperlinkButton x:Uid="SaveAsButton" Click="SaveAsButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<TextBlock x:Uid="SaveAsDesc" Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" />
|
||||
<HyperlinkButton x:Uid="CloseButton" Click="CloseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<HyperlinkButton x:Uid="CloseButton" Command="{Binding CloseCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<TextBlock x:Uid="CloseDesc" Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" />
|
||||
</StackPanel>
|
||||
</Page>
|
||||
|
@@ -15,7 +15,6 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class SaveDatabasePage
|
||||
{
|
||||
private Frame _mainFrame;
|
||||
public SaveVm Model => (SaveVm)DataContext;
|
||||
public SaveDatabasePage()
|
||||
{
|
||||
@@ -25,15 +24,9 @@ namespace ModernKeePass.Views
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
Model.Frame = e.Parameter as Frame;
|
||||
}
|
||||
|
||||
private async void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await Model.Save();
|
||||
_mainFrame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
|
||||
private async void SaveAsButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var savePicker = new FileSavePicker
|
||||
@@ -46,14 +39,6 @@ namespace ModernKeePass.Views
|
||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
await Model.Save(file);
|
||||
|
||||
_mainFrame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
private async void CloseButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await Model.Close();
|
||||
_mainFrame.Navigate(typeof(MainPage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -122,7 +122,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
nameof(IsOpen),
|
||||
typeof(bool),
|
||||
typeof(HamburgerMenuUserControl),
|
||||
new PropertyMetadata(true, (o, args) => { }));
|
||||
new PropertyMetadata(false, (o, args) => { }));
|
||||
|
||||
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
|
||||
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
|
Reference in New Issue
Block a user