mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
WIP ViewModelLocator - Messenger and Recent issues
Refactoring Code cleanup
This commit is contained in:
@@ -5,15 +5,14 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=New}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:NewVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
|
@@ -20,7 +20,7 @@ namespace ModernKeePass.Views
|
||||
public sealed partial class NewDatabasePage
|
||||
{
|
||||
private readonly IResourceProxy _resource;
|
||||
private NewVm Model => (NewVm)Resources["ViewModel"];
|
||||
private NewVm Model => (NewVm)DataContext;
|
||||
|
||||
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
|
||||
public NewDatabasePage(IResourceProxy resource)
|
||||
@@ -41,7 +41,7 @@ namespace ModernKeePass.Views
|
||||
var file = await savePicker.PickSaveFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
|
@@ -3,17 +3,16 @@
|
||||
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"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
x:Class="ModernKeePass.Views.OpenDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Open}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:OpenVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Uid="OpenBrowseButton" Click="ButtonBase_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="OpenBrowseDesc" />
|
||||
<!--<HyperlinkButton x:Uid="OpenUrlButton" IsEnabled="False" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
|
@@ -3,13 +3,7 @@ using Windows.Storage.AccessCache;
|
||||
using Windows.Storage.Pickers;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
@@ -21,24 +15,11 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class OpenDatabasePage
|
||||
{
|
||||
private readonly INavigationService _navigation;
|
||||
private OpenVm Model => (OpenVm)Resources["ViewModel"];
|
||||
|
||||
public OpenDatabasePage(): this(
|
||||
App.Services.GetRequiredService<INavigationService>(),
|
||||
App.Services.GetRequiredService<IMessenger>()) { }
|
||||
|
||||
public OpenDatabasePage(INavigationService navigation, IMessenger messenger)
|
||||
private OpenVm Model => (OpenVm)DataContext;
|
||||
|
||||
public OpenDatabasePage()
|
||||
{
|
||||
_navigation = navigation;
|
||||
InitializeComponent();
|
||||
|
||||
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
||||
}
|
||||
|
||||
private void NavigateToPage(DatabaseOpenedMessage message)
|
||||
{
|
||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
||||
}
|
||||
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
@@ -64,8 +45,7 @@ namespace ModernKeePass.Views
|
||||
var file = await picker.PickSingleFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = file.Path,
|
||||
|
@@ -3,16 +3,15 @@
|
||||
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"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
xmlns:converters="using:ModernKeePass.Converters"
|
||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||
x:Class="ModernKeePass.Views.RecentDatabasesPage"
|
||||
mc:Ignorable="d">
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Recent}">
|
||||
<Page.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<viewModels:RecentVm x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
|
||||
<Grid x:Name="Grid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition Height="*" />
|
||||
|
@@ -1,11 +1,5 @@
|
||||
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using GalaSoft.MvvmLight.Views;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
namespace ModernKeePass.Views
|
||||
@@ -15,29 +9,11 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class RecentDatabasesPage
|
||||
{
|
||||
private RecentVm Model => (RecentVm)Resources["ViewModel"];
|
||||
|
||||
private readonly INavigationService _navigation;
|
||||
private readonly IMessenger _messenger;
|
||||
|
||||
public RecentDatabasesPage(): this(
|
||||
App.Services.GetRequiredService<INavigationService>(),
|
||||
App.Services.GetRequiredService<IMessenger>())
|
||||
{ }
|
||||
|
||||
public RecentDatabasesPage(INavigationService navigation, IMessenger messenger)
|
||||
{
|
||||
_navigation = navigation;
|
||||
_messenger = messenger;
|
||||
InitializeComponent();
|
||||
|
||||
messenger.Register<DatabaseOpeningMessage>(this, action => Model.UpdateAccessTime(action.Token));
|
||||
messenger.Register<DatabaseOpenedMessage>(this, NavigateToPage);
|
||||
}
|
||||
private RecentVm Model => (RecentVm)DataContext;
|
||||
|
||||
private void NavigateToPage(DatabaseOpenedMessage message)
|
||||
public RecentDatabasesPage()
|
||||
{
|
||||
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = message.RootGroupId });
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,12 +3,9 @@
|
||||
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"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
x:Class="ModernKeePass.Views.SaveDatabasePage"
|
||||
mc:Ignorable="d">
|
||||
<Page.DataContext>
|
||||
<viewModels:SaveVm/>
|
||||
</Page.DataContext>
|
||||
mc:Ignorable="d"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=Save}">
|
||||
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Uid="SaveButton" Command="{Binding SaveCommand}" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
|
||||
|
Reference in New Issue
Block a user