New clear all button in recent pages

First-time open of app correctly shows Welcome page
New Home button in group and entry pages
This commit is contained in:
BONNEVILLE Geoffroy
2017-12-04 10:46:01 +01:00
parent 4f69b5cdcc
commit f173283a66
10 changed files with 98 additions and 45 deletions

View File

@@ -10,5 +10,6 @@ namespace ModernKeePass.Interfaces
Task<IStorageItem> GetFileAsync(string token);
ObservableCollection<IRecentItem> GetAllFiles(bool removeIfNonExistant = true);
void Add(IStorageItem file, string metadata);
void ClearAll();
}
}

View File

@@ -377,6 +377,13 @@
<Page.BottomAppBar>
<CommandBar x:Name="CommandBar" VerticalAlignment="Center">
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Home" Label="Home">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction TargetPage="ModernKeePass.Pages.MainPage" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
<AppBarButton Icon="Save" Label="Save">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">

View File

@@ -27,6 +27,13 @@
<Page.BottomAppBar>
<CommandBar x:Name="CommandBar" VerticalAlignment="Center">
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Home" Label="Home">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction TargetPage="ModernKeePass.Pages.MainPage" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
<AppBarButton Icon="Save" Label="Save">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">

View File

@@ -65,7 +65,6 @@
Background="{ThemeResource AppBarBackgroundThemeBrush}"
ItemsSource="{Binding Source={StaticResource MenuItemsSource}}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
IsSynchronizedWithCurrentItem="False"
ItemContainerStyle="{StaticResource ListViewLeftIndicatorItemExpanded}">
<controls:ListViewWithDisable.ItemTemplate>
<DataTemplate>

View File

@@ -17,7 +17,23 @@
<Page.DataContext>
<viewModels:RecentVm/>
</Page.DataContext>
<ListView Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<HyperlinkButton Grid.Row="0" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="Cancel" />
<TextBlock x:Uid="RecentClear" VerticalAlignment="Center" Margin="10,0,0,0" />
</StackPanel>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction TargetObject="{Binding}" MethodName="ClearAll" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</HyperlinkButton>
<ListView Grid.Row="1"
ItemsSource="{Binding Source={StaticResource RecentItemsSource}}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
ItemContainerStyle="{StaticResource ListViewLeftIndicatorItemExpanded}">
@@ -49,4 +65,5 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>

View File

@@ -37,6 +37,11 @@ namespace ModernKeePass.Services
_mru.Add(file, metadata);
}
public void ClearAll()
{
_mru.Clear();
}
public async Task<IStorageItem> GetFileAsync(string token)
{
return await _mru.GetFileAsync(token);

View File

@@ -228,6 +228,9 @@
<data name="PasswordGeneratorUpper.Content" xml:space="preserve">
<value>Upper case (A, B, C, ...)</value>
</data>
<data name="RecentClear.Text" xml:space="preserve">
<value>Clear all</value>
</data>
<data name="SaveAsButton.Content" xml:space="preserve">
<value>Save as...</value>
</data>

View File

@@ -22,16 +22,6 @@ namespace ModernKeePass.ViewModels
Success = 5
}
//private readonly App _app = Application.Current as App;
private bool _hasPassword;
private bool _hasKeyFile;
private string _password = string.Empty;
private string _status;
private StatusTypes _statusType;
private StorageFile _keyFile;
private string _keyFileText;
private readonly IResource _resource;
public IDatabase Database { get; set; }
public bool HasPassword
@@ -54,7 +44,7 @@ namespace ModernKeePass.ViewModels
}
}
public bool IsValid => HasPassword || HasKeyFile && KeyFile != null;
public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFile != null);
public string Status
{
@@ -101,6 +91,16 @@ namespace ModernKeePass.ViewModels
public double PasswordComplexityIndicator => QualityEstimation.EstimatePasswordBits(Password?.ToCharArray());
private bool _hasPassword;
private bool _hasKeyFile;
private bool _isOpening;
private string _password = string.Empty;
private string _status;
private StatusTypes _statusType;
private StorageFile _keyFile;
private string _keyFileText;
private readonly IResource _resource;
public CompositeKeyVm() : this((Application.Current as App)?.Database, new ResourcesService()) { }
public CompositeKeyVm(IDatabase database, IResource resource)
@@ -115,12 +115,17 @@ namespace ModernKeePass.ViewModels
var error = string.Empty;
try
{
_isOpening = true;
Database.Open(CreateCompositeKey(), createNew);
}
catch (Exception e)
{
error = $"{_resource.GetResourceValue("CompositeKeyErrorOpen")}: {e.Message}";
}
finally
{
_isOpening = false;
}
switch ((DatabaseService.DatabaseStatus)Database.Status)
{
case DatabaseService.DatabaseStatus.Opened:

View File

@@ -111,6 +111,8 @@ namespace ModernKeePass.ViewModels
};
// Auto-select the Recent Items menu item if the conditions are met
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
// Add currently opened database to the menu
if (database != null && database.Status == (int) DatabaseService.DatabaseStatus.Opened)
mainMenuItems.Add(new MainMenuItemVm
{

View File

@@ -7,6 +7,7 @@ namespace ModernKeePass.ViewModels
{
public class RecentVm : NotifyPropertyChangedBase, IHasSelectableObject
{
private readonly IRecent _recent;
private ISelectableModel _selectedItem;
private ObservableCollection<IRecentItem> _recentItems = new ObservableCollection<IRecentItem>();
@@ -39,10 +40,16 @@ namespace ModernKeePass.ViewModels
public RecentVm(IRecent recent)
{
RecentItems = recent.GetAllFiles();
_recent = recent;
RecentItems = _recent.GetAllFiles();
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0] as RecentItemVm;
}
public void ClearAll()
{
_recent.ClearAll();
RecentItems.Clear();
}
}
}