Created Import/Export page (stub)

Changed some dependency properties from Interfaces to implementations
Used CanExecute on Commands
This commit is contained in:
BONNEVILLE Geoffroy
2018-08-02 17:40:30 +02:00
parent b2dd028fc7
commit 6f96e698ec
13 changed files with 127 additions and 94 deletions

View File

@@ -1,46 +0,0 @@
using System.Windows.Input;
using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Actions
{
public class RestoreEntityAction : DependencyObject, IAction
{
public IPwEntity Entity
{
get { return (IPwEntity)GetValue(EntityProperty); }
set { SetValue(EntityProperty, value); }
}
public static readonly DependencyProperty EntityProperty =
DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(RestoreEntityAction),
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(RestoreEntityAction),
new PropertyMetadata(null));
public object Execute(object sender, object parameter)
{
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityRestoredTitle"),
resource.GetResourceValue($"{type}Restored"));
Command.Execute(null);
return null;
}
}
}

View File

@@ -1,6 +1,4 @@
using System;
using System.Linq;
using System.Reflection;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

View File

@@ -110,7 +110,6 @@
<Compile Include="Actions\ClipboardAction.cs" />
<Compile Include="Actions\DeleteEntityAction.cs" />
<Compile Include="Actions\NavigateToUrlAction.cs" />
<Compile Include="Actions\RestoreEntityAction.cs" />
<Compile Include="Actions\SetupFocusAction.cs" />
<Compile Include="Actions\ToastAction.cs" />
<Compile Include="App.xaml.cs">
@@ -149,6 +148,9 @@
<Compile Include="Interfaces\IHasSelectableObject.cs" />
<Compile Include="Interfaces\ISelectableModel.cs" />
<Compile Include="Views\BasePages\LayoutAwarePageBase.cs" />
<Compile Include="Views\MainPageFrames\ImportExportPage.xaml.cs">
<DependentUpon>ImportExportPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsPageFrames\SettingsDatabasePage.xaml.cs">
<DependentUpon>SettingsDatabasePage.xaml</DependentUpon>
</Compile>
@@ -267,6 +269,10 @@
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="Views\MainPageFrames\ImportExportPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SettingsPageFrames\SettingsSavePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@@ -477,4 +477,10 @@
<data name="UrlTextBox.ButtonTooltip" xml:space="preserve">
<value>Navigate to URL</value>
</data>
<data name="RestoreEntryCommand.Message" xml:space="preserve">
<value>Entry restored to its original position</value>
</data>
<data name="RestoreGroupCommand.Message" xml:space="preserve">
<value>Group restored to its original position</value>
</data>
</root>

View File

@@ -477,4 +477,10 @@
<data name="UrlTextBox.ButtonTooltip" xml:space="preserve">
<value>Naviguer vers l'URL</value>
</data>
<data name="RestoreEntryCommand.Message" xml:space="preserve">
<value>Entrée replacée à son emplacement d'origine</value>
</data>
<data name="RestoreGroupCommand.Message" xml:space="preserve">
<value>Groupe replacée à son emplacement d'origine</value>
</data>
</root>

View File

@@ -228,7 +228,7 @@ namespace ModernKeePass.ViewModels
SaveCommand = new RelayCommand(() => _database.Save());
GeneratePasswordCommand = new RelayCommand(GeneratePassword);
UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup));
UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup), () => PreviousGroup != null);
}
public void GeneratePassword()

View File

@@ -84,7 +84,12 @@ namespace ModernKeePass.ViewModels
public bool IsEditMode
{
get { return _isEditMode; }
set { SetProperty(ref _isEditMode, value); }
set
{
SetProperty(ref _isEditMode, value);
((RelayCommand)SortEntriesCommand).RaiseCanExecuteChanged();
((RelayCommand)SortGroupsCommand).RaiseCanExecuteChanged();
}
}
public bool IsMenuClosed
@@ -136,10 +141,10 @@ namespace ModernKeePass.ViewModels
SaveCommand = new RelayCommand(() => _database.Save());
SortEntriesCommand = new RelayCommand(async () =>
await SortEntriesAsync().ConfigureAwait(false));
await SortEntriesAsync().ConfigureAwait(false), () => IsEditMode);
SortGroupsCommand = new RelayCommand(async () =>
await SortGroupsAsync().ConfigureAwait(false));
UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup));
await SortGroupsAsync().ConfigureAwait(false), () => IsEditMode);
UndoDeleteCommand = new RelayCommand(() => Move(PreviousGroup), () => PreviousGroup != null);
if (recycleBinId != null && _pwGroup.Uuid.Equals(recycleBinId)) _database.RecycleBin = this;
Entries = new ObservableCollection<EntryVm>(pwGroup.Entries.Select(e => new EntryVm(e, this)));
@@ -186,6 +191,7 @@ namespace ModernKeePass.ViewModels
if (_database.RecycleBinEnabled && _database.RecycleBin?.IdUuid == null)
_database.CreateRecycleBin(recycleBinTitle);
Move(_database.RecycleBinEnabled && !IsSelected ? _database.RecycleBin : null);
((RelayCommand)UndoDeleteCommand).RaiseCanExecuteChanged();
}
public void UndoDelete()

View File

@@ -529,7 +529,6 @@
RestoreButtonVisibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
DeleteButtonVisibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEditButtonChecked="{Binding IsEditMode, Mode=TwoWay}"
IsRestoreButtonEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}"
SaveCommand="{Binding SaveCommand}"
RestoreCommand="{Binding UndoDeleteCommand}">
<interactivity:Interaction.Behaviors>
@@ -540,7 +539,8 @@
<actions:DeleteEntityAction Entity="{Binding}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="RestoreButtonClick">
<actions:RestoreEntityAction Entity="{Binding}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
<core:InvokeCommandAction Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
<actions:ToastAction x:Uid="RestoreEntryCommand" Title="{Binding Name}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</userControls:TopMenuUserControl>

View File

@@ -239,7 +239,6 @@
SortButtonVisibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEditButtonChecked="{Binding IsEditMode, Mode=TwoWay}"
IsDeleteButtonEnabled="{Binding IsNotRoot}"
IsRestoreButtonEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}"
SaveCommand="{Binding SaveCommand}"
RestoreCommand="{Binding UndoDeleteCommand}"
SortEntriesCommand="{Binding SortEntriesCommand}"
@@ -252,7 +251,8 @@
<actions:DeleteEntityAction Entity="{Binding}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="RestoreButtonClick">
<actions:RestoreEntityAction Entity="{Binding}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
<core:InvokeCommandAction Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" />
<actions:ToastAction x:Uid="RestoreGroupCommand" Title="{Binding Name}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</userControls:TopMenuUserControl>

View File

@@ -0,0 +1,35 @@
<Page
x:Class="ModernKeePass.Views.ImportExportPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Import" Style="{StaticResource SubheaderTextBlockStyle}" />
<HyperlinkButton Grid.Column="0" Grid.Row="1" Content="Select file..." Style="{StaticResource MainColorHyperlinkButton}" Click="ImportFileButton_OnClick" />
<StackPanel Grid.Column="1" Grid.Row="1" >
<TextBlock Text="Format" Style="{StaticResource BodyTextBlockStyle}" Margin="0,0,0,10" />
<ComboBox Style="{StaticResource MainColorComboBox}" />
</StackPanel>
<StackPanel Grid.Column="2" Grid.Row="1" >
<TextBlock Text="Import into..." Style="{StaticResource BodyTextBlockStyle}" Margin="0,0,0,10" />
<RadioButton GroupName="ImportDestination" Content="New database" />
<RadioButton GroupName="ImportDestination" Content="Currently opened database" />
</StackPanel>
<Button Grid.Column="3" Grid.Row="1" Content="Import" Style="{StaticResource MainColorButton}" />
</Grid>
</Page>

View File

@@ -0,0 +1,35 @@
using System;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ModernKeePass.Views
{
/// <summary>
/// The import/export page.
/// </summary>
public sealed partial class ImportExportPage
{
public ImportExportPage()
{
InitializeComponent();
}
private async void ImportFileButton_OnClick(object sender, RoutedEventArgs e)
{
var picker =
new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
};
picker.FileTypeFilter.Add(".csv");
// Application now has read/write access to the picked file
var file = await picker.PickSingleFileAsync();
if (file == null) return;
}
}
}

View File

@@ -18,7 +18,7 @@
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Visibility="{Binding OverflowButtonsVisibility, ElementName=UserControl}">
<Button Command="{Binding RestoreCommand, ElementName=UserControl}" Visibility="{Binding RestoreButtonVisibility, ElementName=UserControl}" IsEnabled="{Binding IsRestoreButtonEnabled,ElementName=UserControl}" Click="RestoreButton_Click" Style="{StaticResource MenuButtonStyle}">
<Button Command="{Binding RestoreCommand, ElementName=UserControl}" Visibility="{Binding RestoreButtonVisibility, ElementName=UserControl}" Click="RestoreButton_Click" Style="{StaticResource MenuButtonStyle}">
<SymbolIcon Symbol="Undo">
<ToolTipService.ToolTip>
<ToolTip x:Uid="TopMenuRestoreButton" />
@@ -64,7 +64,7 @@
<SymbolIcon Symbol="More" />
<Button.Flyout>
<MenuFlyout Opening="OverflowFlyout_OnOpening">
<MenuFlyoutItem x:Uid="TopMenuRestoreFlyout" x:Name="RestoreFlyout" Command="{Binding RestoreCommand, ElementName=UserControl}" IsEnabled="{Binding IsRestoreButtonEnabled,ElementName=UserControl}" Click="RestoreButton_Click" Visibility="{Binding RestoreButtonVisibility, ElementName=UserControl}" />
<MenuFlyoutItem x:Uid="TopMenuRestoreFlyout" x:Name="RestoreFlyout" Command="{Binding RestoreCommand, ElementName=UserControl}" Click="RestoreButton_Click" Visibility="{Binding RestoreButtonVisibility, ElementName=UserControl}" />
<MenuFlyoutItem x:Uid="TopMenuSaveFlyout" Command="{Binding SaveCommand, ElementName=UserControl}" />
<ToggleMenuFlyoutItem x:Uid="TopMenuEditFlyout" x:Name="EditFlyout" Command="{Binding EditCommand, ElementName=UserControl}" IsChecked="{Binding IsEditButtonChecked, ElementName=UserControl, Mode=TwoWay}" Click="EditButton_Click" />
<MenuFlyoutItem x:Uid="TopMenuDeleteFlyout" x:Name="DeleteFlyout" Command="{Binding DeleteCommand, ElementName=UserControl}" Click="DeleteButton_Click" Visibility="{Binding DeleteButtonVisibility, ElementName=UserControl}" IsEnabled="{Binding IsDeleteButtonEnabled, ElementName=UserControl}" />

View File

@@ -1,6 +1,6 @@
using System;
using System.Windows.Input;
using Windows.UI.Xaml;
using ModernKeePass.Common;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -8,75 +8,75 @@ namespace ModernKeePass.Views.UserControls
{
public sealed partial class TopMenuUserControl
{
public ICommand SaveCommand
public RelayCommand SaveCommand
{
get { return (ICommand)GetValue(SaveCommandProperty); }
get { return (RelayCommand)GetValue(SaveCommandProperty); }
set { SetValue(SaveCommandProperty, value); }
}
public static readonly DependencyProperty SaveCommandProperty =
DependencyProperty.Register(
"SaveCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public ICommand EditCommand
public RelayCommand EditCommand
{
get { return (ICommand)GetValue(EditCommandProperty); }
get { return (RelayCommand)GetValue(EditCommandProperty); }
set { SetValue(EditCommandProperty, value); }
}
public static readonly DependencyProperty EditCommandProperty =
DependencyProperty.Register(
"EditCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public ICommand DeleteCommand
public RelayCommand DeleteCommand
{
get { return (ICommand)GetValue(DeleteCommandProperty); }
get { return (RelayCommand)GetValue(DeleteCommandProperty); }
set { SetValue(DeleteCommandProperty, value); }
}
public static readonly DependencyProperty DeleteCommandProperty =
DependencyProperty.Register(
"DeleteCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public ICommand RestoreCommand
public RelayCommand RestoreCommand
{
get { return (ICommand)GetValue(RestoreCommandProperty); }
get { return (RelayCommand)GetValue(RestoreCommandProperty); }
set { SetValue(RestoreCommandProperty, value); }
}
public static readonly DependencyProperty RestoreCommandProperty =
DependencyProperty.Register(
"RestoreCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public ICommand SortEntriesCommand
public RelayCommand SortEntriesCommand
{
get { return (ICommand)GetValue(SortEntriesCommandProperty); }
get { return (RelayCommand)GetValue(SortEntriesCommandProperty); }
set { SetValue(SortEntriesCommandProperty, value); }
}
public static readonly DependencyProperty SortEntriesCommandProperty =
DependencyProperty.Register(
"SortEntriesCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public ICommand SortGroupsCommand
public RelayCommand SortGroupsCommand
{
get { return (ICommand)GetValue(SortGroupsCommandProperty); }
get { return (RelayCommand)GetValue(SortGroupsCommandProperty); }
set { SetValue(SortGroupsCommandProperty, value); }
}
public static readonly DependencyProperty SortGroupsCommandProperty =
DependencyProperty.Register(
"SortGroupsCommand",
typeof(ICommand),
typeof(RelayCommand),
typeof(TopMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
@@ -138,7 +138,7 @@ namespace ModernKeePass.Views.UserControls
"SortButtonVisibility",
typeof(Visibility),
typeof(TopMenuUserControl),
new PropertyMetadata(Visibility.Collapsed, (o, args) => { }));
new PropertyMetadata(Visibility.Visible, (o, args) => { }));
public bool IsDeleteButtonEnabled
{
@@ -163,18 +163,6 @@ 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 EventHandler<RoutedEventArgs> EditButtonClick;
public event EventHandler<RoutedEventArgs> DeleteButtonClick;
@@ -213,8 +201,7 @@ namespace ModernKeePass.Views.UserControls
DeleteFlyout.Visibility = DeleteButtonVisibility;
EditFlyout.IsChecked = IsEditButtonChecked;
RestoreFlyout.IsEnabled = IsRestoreButtonEnabled;
RestoreFlyout.Visibility = RestoreButtonVisibility;
SortEntriesFlyout.Visibility = SortButtonVisibility;