mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Add currently opened database to main menu
Save and close reloads the page Design enhancements Some refactoring
This commit is contained in:
@@ -11,16 +11,18 @@ namespace ModernKeePass.Common
|
||||
{
|
||||
public class DatabaseHelper
|
||||
{
|
||||
private PwDatabase _pwDatabase = new PwDatabase();
|
||||
private StorageFile databaseFile;
|
||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||
private readonly StorageFile _databaseFile;
|
||||
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public bool IsOpen { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool IsOpen => _pwDatabase.IsOpen;
|
||||
|
||||
public string Name => _databaseFile.Name;
|
||||
|
||||
public DatabaseHelper(StorageFile databaseFile)
|
||||
{
|
||||
this.databaseFile = databaseFile;
|
||||
this._databaseFile = databaseFile;
|
||||
}
|
||||
public string Open(string password)
|
||||
{
|
||||
@@ -28,14 +30,10 @@ namespace ModernKeePass.Common
|
||||
try
|
||||
{
|
||||
key.AddUserKey(new KcpPassword(password));
|
||||
_pwDatabase.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
|
||||
_pwDatabase.Open(IOConnectionInfo.FromFile(_databaseFile), key, new NullStatusLogger());
|
||||
//_pwDatabase.Open(IOConnectionInfo.FromPath(databaseFile.Path), key, new NullStatusLogger());
|
||||
IsOpen = _pwDatabase.IsOpen;
|
||||
if (IsOpen)
|
||||
{
|
||||
Name = databaseFile.DisplayName;
|
||||
RootGroup = new GroupVm(_pwDatabase.RootGroup);
|
||||
}
|
||||
|
||||
if (IsOpen) RootGroup = new GroupVm(_pwDatabase.RootGroup);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
|
@@ -14,7 +14,7 @@
|
||||
<Page.Resources>
|
||||
<CollectionViewSource
|
||||
x:Name="MenuItemsSource"
|
||||
Source="{Binding MainMenuItems}" />
|
||||
Source="{Binding MainMenuItems}" IsSourceGrouped="True" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
|
||||
@@ -40,6 +40,17 @@
|
||||
<Setter Property="Padding" Value="20,5,0,0" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle HidesIfEmpty="True">
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Background="DarkGray" Margin="20,0,0,0">
|
||||
<Border Height="1" Width="240" HorizontalAlignment="Stretch"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListView.GroupStyle>
|
||||
</controls:ListViewWithDisable>
|
||||
<Frame Grid.Column="2" Name="MenuFrame" Width="auto" Margin="0,60,0,0" />
|
||||
</Grid>
|
||||
|
@@ -1,5 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.Pages;
|
||||
using ModernKeePass.ViewModels;
|
||||
@@ -16,26 +19,35 @@ namespace ModernKeePass
|
||||
public MainPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
var mainMenuItems = new ObservableCollection<MainMenuItem>
|
||||
{
|
||||
new MainMenuItem {Title = "File", PageType = typeof(OpenDatabasePage)},
|
||||
new MainMenuItem {Title = "New" /*, PageType = typeof(NewDatabasePage)*/},
|
||||
new MainMenuItem {Title = "Save" , PageType = typeof(SaveDatabasePage)},
|
||||
new MainMenuItem {Title = "Recent files - Coming soon" /*, PageType = typeof(RecentDatabasesPage)*/},
|
||||
new MainMenuItem {Title = "Url files - Coming soon" /*, PageType = typeof(OpenUrlPage)*/}
|
||||
new MainMenuItem {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = MenuFrame, Parameter = Frame},
|
||||
new MainMenuItem {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = MenuFrame},
|
||||
new MainMenuItem {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = MenuFrame, Parameter = Frame},
|
||||
new MainMenuItem {Title = "Recent" /*, PageType = typeof(RecentDatabasesPage)*/, Destination = MenuFrame}
|
||||
};
|
||||
DataContext = new MainVm {MainMenuItems = mainMenuItems};
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database != null && app.Database.IsOpen)
|
||||
mainMenuItems.Add(new MainMenuItem { Title = app.Database.Name, PageType = typeof(GroupDetailPage), Destination = Frame, Parameter = app.Database.RootGroup, Group = 1});
|
||||
var result = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||
MenuItemsSource.Source = result;
|
||||
//DataContext = new MainVm {MainMenuItems = mainMenuItems};
|
||||
|
||||
MenuListView.SelectedIndex = -1;
|
||||
}
|
||||
|
||||
|
||||
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (Frame == null) return;
|
||||
var listView = sender as ListView;
|
||||
if (listView == null) return;
|
||||
if (listView.SelectedIndex == -1) return;
|
||||
var selectedItem = listView.SelectedItem as MainMenuItem;
|
||||
if (selectedItem != null) MenuFrame.Navigate(selectedItem.PageType, Frame);
|
||||
selectedItem?.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,23 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Models
|
||||
{
|
||||
public class MainMenuItem: IIsEnabled
|
||||
{
|
||||
public string Title { get; set; }
|
||||
private string _title;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return IsEnabled ? _title : _title + " - Coming soon"; }
|
||||
set { _title = value; }
|
||||
}
|
||||
|
||||
public Type PageType { get; set; }
|
||||
public object Parameter { get; set; }
|
||||
public Frame Destination { get; set; }
|
||||
public int Group { get; set; } = 0;
|
||||
public bool IsEnabled => PageType != null;
|
||||
|
||||
public override string ToString()
|
||||
|
@@ -25,13 +25,15 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<HyperlinkButton Grid.Row="0" Grid.ColumnSpan="2" Content="Browse files..." Click="ButtonBase_OnClick" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left" Visibility="{Binding SelectedVisibility}" TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<TextBlock Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Visibility="{Binding SelectedVisibility}" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<PasswordBox Grid.Column="1" Grid.Row="2" x:Name="PasswordBox" VerticalAlignment="Top" HorizontalAlignment=" Right" Visibility="{Binding SelectedVisibility}" Width="500" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
|
||||
<TextBlock Grid.Column="1" Grid.Row="3" x:Name="StatusTextBlock" Visibility="{Binding SelectedVisibility}" Height="auto" Width="auto" Foreground="#FF9E1B1B" FontSize="16" />
|
||||
<Button Grid.Column="1" Grid.Row="4" Content="OK" Visibility="{Binding SelectedVisibility}" HorizontalAlignment="Right" VerticalAlignment="Top" Click="OpenButton_OnClick" Margin="0,0,7,0" Width="auto"/>
|
||||
<HyperlinkButton Grid.Row="1" Grid.ColumnSpan="2" Content="From Url..." IsEnabled="False" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Visibility="{Binding SelectedVisibility}" TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Visibility="{Binding SelectedVisibility}" TextWrapping="Wrap" Text="Password" VerticalAlignment="Center" Height="auto" Width="auto" FontSize="16" Margin="10,7,0,6" />
|
||||
<PasswordBox Grid.Row="3" Grid.Column="1" x:Name="PasswordBox" Visibility="{Binding SelectedVisibility}" Width="500" IsPasswordRevealButtonEnabled="True" Margin="0,0,10,0"/>
|
||||
<TextBlock Grid.Row="4" Grid.Column="1" x:Name="StatusTextBlock" Visibility="{Binding SelectedVisibility}" Height="auto" Width="auto" Foreground="#FF9E1B1B" FontSize="16" />
|
||||
<Button Grid.Row="5" Grid.Column="1" Content="OK" Visibility="{Binding SelectedVisibility}" HorizontalAlignment="Right" VerticalAlignment="Top" Click="OpenButton_OnClick" Margin="0,0,7,0" Width="auto"/>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
@@ -12,21 +12,22 @@ namespace ModernKeePass.Pages
|
||||
/// </summary>
|
||||
public sealed partial class SaveDatabasePage : Page
|
||||
{
|
||||
private Frame _mainFrame;
|
||||
public SaveDatabasePage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
InitializeComponent();
|
||||
DataContext = new DatabaseVm();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database == null) return;
|
||||
var databaseVm = DataContext as DatabaseVm;
|
||||
if (databaseVm == null) return;
|
||||
databaseVm.IsOpen = app.Database.IsOpen;
|
||||
databaseVm.NotifyPropertyChanged("IsOpen");
|
||||
UpdateDatabaseStatus(app, databaseVm);
|
||||
}
|
||||
|
||||
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||
@@ -34,6 +35,14 @@ namespace ModernKeePass.Pages
|
||||
var app = (App) Application.Current;
|
||||
app.Database.Save();
|
||||
app.Database.Close();
|
||||
UpdateDatabaseStatus(app, DataContext as DatabaseVm);
|
||||
_mainFrame.Navigate(typeof(MainPage));
|
||||
}
|
||||
|
||||
private void UpdateDatabaseStatus(App app, DatabaseVm databaseVm)
|
||||
{
|
||||
databaseVm.IsOpen = app.Database.IsOpen;
|
||||
databaseVm.NotifyPropertyChanged("IsOpen");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user