mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Update groups finally implemented
Code cleanup
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class DeleteEntityAction : DependencyObject, IAction
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public IVmEntity Entity
|
||||
{
|
||||
get { return (IVmEntity)GetValue(EntityProperty); }
|
||||
set { SetValue(EntityProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EntityProperty =
|
||||
DependencyProperty.Register("Entity", typeof(IVmEntity), typeof(DeleteEntityAction),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public ICommand Command
|
||||
{
|
||||
get { return (ICommand)GetValue(CommandProperty); }
|
||||
set { SetValue(CommandProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CommandProperty =
|
||||
DependencyProperty.Register("Command", typeof(ICommand), typeof(DeleteEntityAction),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public DeleteEntityAction() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public DeleteEntityAction(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
var resource = new ResourceHelper();
|
||||
var type = Entity is GroupDetailVm ? "Group" : "Entry";
|
||||
var isRecycleOnDelete = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsRecycleBinEnabled;
|
||||
|
||||
var message = isRecycleOnDelete
|
||||
? resource.GetResourceValue($"{type}RecyclingConfirmation")
|
||||
: resource.GetResourceValue($"{type}DeletingConfirmation");
|
||||
var text = isRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
|
||||
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
|
||||
resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
|
||||
{
|
||||
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
|
||||
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
|
||||
Command.Execute(null);
|
||||
}, null).Wait();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -291,12 +291,12 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public async Task AddHistory()
|
||||
{
|
||||
if (_isDirty) await _mediator.Send(new AddHistoryCommand { EntryId = Id });
|
||||
if (_isDirty) await _mediator.Send(new AddHistoryCommand { Entry = History[0] });
|
||||
}
|
||||
|
||||
private async Task RestoreHistory()
|
||||
{
|
||||
await _mediator.Send(new RestoreHistoryCommand { EntryId = Id, HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
await _mediator.Send(new RestoreHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
History.Insert(0, SelectedItem);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
@@ -304,7 +304,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public async Task DeleteHistory()
|
||||
{
|
||||
await _mediator.Send(new DeleteHistoryCommand { EntryId = Id, HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
||||
History.RemoveAt(SelectedIndex);
|
||||
SelectedIndex = 0;
|
||||
((RelayCommand)SaveCommand).RaiseCanExecuteChanged();
|
||||
|
@@ -21,6 +21,7 @@ using ModernKeePass.Application.Group.Commands.MoveEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveGroup;
|
||||
using ModernKeePass.Application.Group.Commands.SortEntries;
|
||||
using ModernKeePass.Application.Group.Commands.SortGroups;
|
||||
using ModernKeePass.Application.Group.Commands.UpdateGroup;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Application.Group.Queries.SearchEntries;
|
||||
@@ -38,7 +39,7 @@ namespace ModernKeePass.ViewModels
|
||||
public ObservableCollection<GroupVm> Groups { get; }
|
||||
|
||||
public bool IsNotRoot => Database.RootGroupId != _group.Id;
|
||||
|
||||
|
||||
public IOrderedEnumerable<IGrouping<char, EntryVm>> EntriesZoomedOut => from e in Entries
|
||||
group e by e.Title.ToUpper().FirstOrDefault() into grp
|
||||
orderby grp.Key
|
||||
@@ -49,13 +50,13 @@ namespace ModernKeePass.ViewModels
|
||||
public string Title
|
||||
{
|
||||
get { return _group.Title; }
|
||||
set { _group.Title = value; }
|
||||
set { _mediator.Send(new UpdateGroupCommand {Group = _group, Title = value, Icon = _group.Icon}).Wait(); }
|
||||
}
|
||||
|
||||
public Symbol Icon
|
||||
{
|
||||
get { return (Symbol) Enum.Parse(typeof(Symbol), _group.Icon.ToString()); }
|
||||
set { _group.Icon = (Icon) Enum.Parse(typeof(Icon), value.ToString()); }
|
||||
set { _mediator.Send(new UpdateGroupCommand { Group = _group, Title = _group.Title, Icon = (Icon)Enum.Parse(typeof(Icon), value.ToString()) }).Wait(); }
|
||||
}
|
||||
|
||||
public bool IsEditMode
|
||||
@@ -69,6 +70,15 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRecycleOnDelete
|
||||
{
|
||||
get
|
||||
{
|
||||
var database = Database;
|
||||
return database.IsRecycleBinEnabled && _parent != null && _parent.Id != database.RecycleBinId;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<GroupVm> BreadCrumb { get; }
|
||||
|
||||
public ICommand SaveCommand { get; }
|
||||
|
@@ -239,19 +239,16 @@
|
||||
<userControls:TopMenuUserControl x:Name="TopMenu" Grid.Column="2"
|
||||
SortButtonVisibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
IsEditButtonChecked="{Binding IsEditMode, Mode=TwoWay}"
|
||||
IsMoveButtonEnabled="{Binding IsNotRoot}"
|
||||
IsDeleteButtonEnabled="{Binding IsNotRoot}"
|
||||
SaveCommand="{Binding SaveCommand}"
|
||||
MoveCommand="{Binding MoveCommand}"
|
||||
SortEntriesCommand="{Binding SortEntriesCommand}"
|
||||
SortGroupsCommand="{Binding SortGroupsCommand}">
|
||||
SortGroupsCommand="{Binding SortGroupsCommand}"
|
||||
DeleteButtonClick="TopMenu_OnDeleteButtonClick">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="EditButtonClick">
|
||||
<actions:SetupFocusAction TargetObject="{Binding ElementName=TitleTextBox}" />
|
||||
</core:EventTriggerBehavior>
|
||||
<core:EventTriggerBehavior EventName="DeleteButtonClick">
|
||||
<actions:DeleteEntityAction Entity="{Binding}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
|
||||
</core:EventTriggerBehavior>
|
||||
<core:EventTriggerBehavior EventName="MoveButtonClick">
|
||||
<core:InvokeCommandAction Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
|
||||
<!--<actions:ToastAction x:Uid="RestoreGroupCommand" Title="{Binding Title}" />-->
|
||||
|
@@ -148,6 +148,25 @@ namespace ModernKeePass.Views
|
||||
VisualStateManager.GoToState(TopMenu, e.NewSize.Width < 800 ? "Collapsed" : "Overflowed", true);
|
||||
}
|
||||
|
||||
private async void TopMenu_OnDeleteButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var resource = new ResourceHelper();
|
||||
var isRecycleOnDelete = Model.IsRecycleOnDelete;
|
||||
|
||||
var message = isRecycleOnDelete
|
||||
? resource.GetResourceValue("GroupRecyclingConfirmation")
|
||||
: resource.GetResourceValue("GroupDeletingConfirmation");
|
||||
var text = isRecycleOnDelete ? resource.GetResourceValue("GroupRecycled") : resource.GetResourceValue("GroupDeleted");
|
||||
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
|
||||
resource.GetResourceValue("EntityDeleteActionButton"),
|
||||
resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
|
||||
{
|
||||
//ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
|
||||
await Model.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
|
||||
NavigationHelper.GoBack();
|
||||
}, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
@@ -10,7 +11,7 @@ namespace ModernKeePass.Views.UserControls
|
||||
{
|
||||
public sealed partial class SymbolPickerUserControl
|
||||
{
|
||||
public IEnumerable<Symbol> Symbols { get; }
|
||||
public List<Symbol> Symbols { get; }
|
||||
|
||||
public Symbol SelectedSymbol
|
||||
{
|
||||
@@ -27,7 +28,12 @@ namespace ModernKeePass.Views.UserControls
|
||||
public SymbolPickerUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Symbols = Enum.GetValues(typeof(Symbol)).Cast<Symbol>();
|
||||
Symbols = new List<Symbol>();
|
||||
var names = Enum.GetNames(typeof(Icon));
|
||||
foreach (var name in names)
|
||||
{
|
||||
Symbols.Add((Symbol) Enum.Parse(typeof(Symbol), name));
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_OnLoaded(object sender, RoutedEventArgs e)
|
||||
|
@@ -90,7 +90,6 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Actions\ClipboardAction.cs" />
|
||||
<Compile Include="Actions\DeleteEntityAction.cs" />
|
||||
<Compile Include="Actions\NavigateToUrlAction.cs" />
|
||||
<Compile Include="Actions\SetupFocusAction.cs" />
|
||||
<Compile Include="Actions\ToastAction.cs" />
|
||||
|
Reference in New Issue
Block a user