mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Creating groups and entries now navigates to the related detail page, in edit mode
Code cleanup
This commit is contained in:
@@ -63,13 +63,15 @@
|
||||
AutomationProperties.ItemType="Navigation Button"/>
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
x:Name="TitleTextBox"
|
||||
Text="{Binding Title, Mode=TwoWay}"
|
||||
Style="{StaticResource HeaderTextBoxStyle}"
|
||||
Foreground="{ThemeResource DefaultTextForegroundThemeBrush}"
|
||||
IsHitTestVisible="{Binding IsEditMode}"
|
||||
TextWrapping="NoWrap"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,30,0"/>
|
||||
Margin="0,0,30,0"
|
||||
PlaceholderText="New entry name..."/>
|
||||
<CommandBar Grid.Column="2" Background="Transparent" IsOpen="True" VerticalAlignment="Center" Margin="0,20,0,0">
|
||||
<AppBarToggleButton Icon="Edit" Label="Edit" IsChecked="{Binding IsEditMode, Mode=TwoWay}" />
|
||||
<AppBarButton Icon="Delete" Label="Delete" Click="AppBarButton_Click" />
|
||||
|
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Popups;
|
||||
using ModernKeePass.Common;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// Pour en savoir plus sur le modèle d'élément Page Détail de l'élément, consultez la page http://go.microsoft.com/fwlink/?LinkId=234232
|
||||
@@ -16,7 +18,9 @@ namespace ModernKeePass.Pages
|
||||
/// </summary>
|
||||
public sealed partial class EntryDetailPage
|
||||
{
|
||||
private NavigationHelper navigationHelper;
|
||||
private NavigationHelper navigationHelper;
|
||||
|
||||
public EntryVm Model => (EntryVm) DataContext;
|
||||
|
||||
/// <summary>
|
||||
/// NavigationHelper est utilisé sur chaque page pour faciliter la navigation et
|
||||
@@ -58,10 +62,12 @@ namespace ModernKeePass.Pages
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
navigationHelper.OnNavigatedTo(e);
|
||||
if (e.Parameter is EntryVm)
|
||||
{
|
||||
DataContext = e.Parameter as EntryVm;
|
||||
}
|
||||
if (!(e.Parameter is EntryVm)) return;
|
||||
DataContext = (EntryVm)e.Parameter;
|
||||
if (Model.IsEditMode)
|
||||
Task.Factory.StartNew(
|
||||
() => Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
||||
() => TitleTextBox.Focus(FocusState.Programmatic)));
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
|
@@ -220,13 +220,15 @@
|
||||
AutomationProperties.ItemType="Navigation Button"/>
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
x:Name="TitleTextBox"
|
||||
Text="{Binding Name, Mode=TwoWay}"
|
||||
Style="{StaticResource HeaderTextBoxStyle}"
|
||||
Foreground="{ThemeResource DefaultTextForegroundThemeBrush}"
|
||||
IsHitTestVisible="{Binding IsEditMode}"
|
||||
TextWrapping="NoWrap"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,30,0"/>
|
||||
Margin="0,0,30,0"
|
||||
PlaceholderText="New group name..."/>
|
||||
<CommandBar Grid.Column="2" Background="Transparent" IsOpen="True" VerticalAlignment="Center" Margin="0,20,0,0">
|
||||
<AppBarButton Icon="Find" Label="Search">
|
||||
<AppBarButton.Flyout>
|
||||
|
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Popups;
|
||||
using ModernKeePass.Common;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229
|
||||
@@ -61,6 +64,10 @@ namespace ModernKeePass.Pages
|
||||
|
||||
if (!(e.Parameter is GroupVm)) return;
|
||||
DataContext = (GroupVm) e.Parameter;
|
||||
if (Model.IsEditMode)
|
||||
Task.Factory.StartNew(
|
||||
() => Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
||||
() => TitleTextBox.Focus(FocusState.Programmatic)));
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
@@ -75,32 +82,36 @@ namespace ModernKeePass.Pages
|
||||
|
||||
private void groups_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (LeftListView.SelectedIndex == 0)
|
||||
GroupVm group;
|
||||
switch (LeftListView.SelectedIndex)
|
||||
{
|
||||
var currentGroup = DataContext as GroupVm;
|
||||
currentGroup?.CreateNewGroup();
|
||||
LeftListView.SelectedIndex = -1;
|
||||
// TODO: Navigate to new group?
|
||||
return;
|
||||
case -1:
|
||||
return;
|
||||
case 0:
|
||||
group = Model.CreateNewGroup();
|
||||
break;
|
||||
default:
|
||||
group = LeftListView.SelectedItem as GroupVm;
|
||||
break;
|
||||
}
|
||||
var selectedItem = LeftListView.SelectedItem as GroupVm;
|
||||
if (selectedItem == null) return;
|
||||
Frame.Navigate(typeof(GroupDetailPage), selectedItem);
|
||||
Frame.Navigate(typeof(GroupDetailPage), group);
|
||||
}
|
||||
|
||||
private void entries_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
EntryVm entry;
|
||||
switch (GridView.SelectedIndex)
|
||||
{
|
||||
case -1:
|
||||
return;
|
||||
case 0:
|
||||
Model.CreateNewEntry();
|
||||
GridView.SelectedIndex = -1;
|
||||
// TODO: Navigate to new entry?
|
||||
return;
|
||||
entry = Model.CreateNewEntry();
|
||||
break;
|
||||
default:
|
||||
entry = GridView.SelectedItem as EntryVm;
|
||||
break;
|
||||
}
|
||||
Frame.Navigate(typeof(EntryDetailPage), GridView.SelectedItem as EntryVm);
|
||||
Frame.Navigate(typeof(EntryDetailPage), entry);
|
||||
}
|
||||
|
||||
private async void DeleteButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
||||
@@ -128,6 +139,7 @@ namespace ModernKeePass.Pages
|
||||
|
||||
private void SemanticZoom_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
|
||||
{
|
||||
// We need to synchronize the two lists (zoomed-in and zoomed-out) because the source is different
|
||||
if (e.IsSourceZoomedInView == false)
|
||||
{
|
||||
e.DestinationItem.Item = e.SourceItem.Item;
|
||||
|
@@ -76,18 +76,22 @@ namespace ModernKeePass.ViewModels
|
||||
Groups.Insert(0, new GroupVm ());
|
||||
}
|
||||
|
||||
public void CreateNewGroup()
|
||||
public GroupVm CreateNewGroup()
|
||||
{
|
||||
var pwGroup = new PwGroup(true, true, "New group", PwIcon.Folder);
|
||||
var pwGroup = new PwGroup(true, true, string.Empty, PwIcon.Folder);
|
||||
_pwGroup.AddGroup(pwGroup, true);
|
||||
Groups.Add(new GroupVm(pwGroup, this));
|
||||
var newGroup = new GroupVm(pwGroup, this) {IsEditMode = true};
|
||||
Groups.Add(newGroup);
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public void CreateNewEntry()
|
||||
public EntryVm CreateNewEntry()
|
||||
{
|
||||
var pwEntry = new PwEntry(true, true);
|
||||
_pwGroup.AddEntry(pwEntry, true);
|
||||
Entries.Add(new EntryVm(pwEntry, this));
|
||||
var newEntry = new EntryVm(pwEntry, this) {IsEditMode = true};
|
||||
Entries.Add(newEntry);
|
||||
return newEntry;
|
||||
}
|
||||
|
||||
public void RemoveGroup()
|
||||
|
Reference in New Issue
Block a user