Database file is now handled by each page, instead of a central place

Opening a database while another one is open triggers a warning message
This commit is contained in:
BONNEVILLE Geoffroy
2018-06-20 11:52:17 +02:00
parent 408b4eed90
commit 188233cc81
8 changed files with 17 additions and 16 deletions

View File

@@ -199,7 +199,7 @@ namespace ModernKeePass
base.OnFileActivated(args); base.OnFileActivated(args);
var rootFrame = new Frame(); var rootFrame = new Frame();
var file = args.Files[0] as StorageFile; var file = args.Files[0] as StorageFile;
rootFrame.Navigate(typeof(OpenDatabasePage), file); rootFrame.Navigate(typeof(MainPage), file);
Window.Current.Content = rootFrame; Window.Current.Content = rootFrame;
Window.Current.Activate(); Window.Current.Activate();
} }

View File

@@ -3,7 +3,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.Storage; using Windows.Storage;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Exceptions;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
using ModernKeePass.Services; using ModernKeePass.Services;
using ModernKeePassLib.Cryptography; using ModernKeePassLib.Cryptography;

View File

@@ -1,6 +1,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.Storage;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
@@ -44,11 +45,11 @@ namespace ModernKeePass.ViewModels
public MainVm() {} public MainVm() {}
internal MainVm(Frame referenceFrame, Frame destinationFrame) : this(referenceFrame, destinationFrame, internal MainVm(Frame referenceFrame, Frame destinationFrame, StorageFile databaseFile = null) : this(referenceFrame, destinationFrame,
DatabaseService.Instance, new ResourcesService(), RecentService.Instance) DatabaseService.Instance, new ResourcesService(), RecentService.Instance, databaseFile)
{ } { }
public MainVm(Frame referenceFrame, Frame destinationFrame, IDatabaseService database, IResourceService resource, IRecentService recent) public MainVm(Frame referenceFrame, Frame destinationFrame, IDatabaseService database, IResourceService resource, IRecentService recent, StorageFile databaseFile = null)
{ {
var isDatabaseOpen = database != null && database.IsOpen; var isDatabaseOpen = database != null && database.IsOpen;
@@ -59,8 +60,9 @@ namespace ModernKeePass.ViewModels
Title = resource.GetResourceValue("MainMenuItemOpen"), Title = resource.GetResourceValue("MainMenuItemOpen"),
PageType = typeof(OpenDatabasePage), PageType = typeof(OpenDatabasePage),
Destination = destinationFrame, Destination = destinationFrame,
Parameter = referenceFrame, Parameter = databaseFile,
SymbolIcon = Symbol.Page2 SymbolIcon = Symbol.Page2,
IsSelected = databaseFile != null
}, },
new MainMenuItemVm new MainMenuItemVm
{ {

View File

@@ -9,7 +9,7 @@ namespace ModernKeePass.ViewModels
{ {
public bool IsFileSelected => DatabaseFile != null; public bool IsFileSelected => DatabaseFile != null;
public string Name => DatabaseFile.DisplayName; public string Name => DatabaseFile?.DisplayName;
public StorageFile DatabaseFile { get; private set; } public StorageFile DatabaseFile { get; private set; }
@@ -31,6 +31,7 @@ namespace ModernKeePass.ViewModels
DatabaseFile = file; DatabaseFile = file;
OnPropertyChanged("Name"); OnPropertyChanged("Name");
OnPropertyChanged("IsFileSelected"); OnPropertyChanged("IsFileSelected");
OnPropertyChanged("DatabaseFile");
AddToRecentList(file, recent); AddToRecentList(file, recent);
} }

View File

@@ -1,4 +1,5 @@
using Windows.UI.Xaml.Controls; using Windows.Storage;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
@@ -32,7 +33,8 @@ namespace ModernKeePass.Views
protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedTo(NavigationEventArgs e)
{ {
base.OnNavigatedTo(e); base.OnNavigatedTo(e);
DataContext = new MainVm(Frame, MenuFrame); var file = e.Parameter as StorageFile;
DataContext = new MainVm(Frame, MenuFrame, file);
} }
} }
} }

View File

@@ -20,7 +20,7 @@
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<HyperlinkButton x:Uid="NewCreateButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" /> <HyperlinkButton x:Uid="NewCreateButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" /> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}"> <Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="25,0,25,0"> <StackPanel Margin="25,0,25,0">
<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFile="{Binding DatabaseFile}"> <userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFile="{Binding DatabaseFile}">

View File

@@ -21,7 +21,7 @@
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" /> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
<HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" /> <HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenUrlDesc" /> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenUrlDesc" />
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding ShowPasswordBox, Converter={StaticResource BooleanToVisibilityConverter}}"> <Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="25,0,25,0"> <StackPanel Margin="25,0,25,0">
<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFile="{Binding DatabaseFile}"> <userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFile="{Binding DatabaseFile}">

View File

@@ -50,11 +50,8 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Name}" Padding="5,0,0,0" /> <TextBlock Grid.Row="0" Text="{Binding Name}" Padding="5,0,0,0" />
<TextBlock Grid.Row="1" Text="{Binding Path}" Padding="5,0,0,0" FontSize="10" /> <TextBlock Grid.Row="1" Text="{Binding Path}" Padding="5,0,0,0" FontSize="10" />
<userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"> <userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" DatabaseFile="{Binding DatabaseFile}">
<interactivity:Interaction.Behaviors> <interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="ValidationChecking">
<core:CallMethodAction TargetObject="{Binding}" MethodName="OpenDatabaseFile" />
</core:EventTriggerBehavior>
<core:EventTriggerBehavior EventName="ValidationChecked"> <core:EventTriggerBehavior EventName="ValidationChecked">
<core:CallMethodAction TargetObject="{Binding}" MethodName="UpdateAccessTime" /> <core:CallMethodAction TargetObject="{Binding}" MethodName="UpdateAccessTime" />
<core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" /> <core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />