Edit mode works in Groups and Entries

This commit is contained in:
2017-10-06 14:56:16 +02:00
committed by BONNEVILLE Geoffroy
parent 4aa3b17398
commit 11fb82573b
5 changed files with 56 additions and 26 deletions

View File

@@ -40,6 +40,13 @@
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="20" />
</Style>
<Style x:Key="HeaderTextBoxStyle" TargetType="TextBox">
<Setter Property="FontSize" Value="56"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<!--<Setter Property="LineHeight" Value="40"/>-->
</Style>
</Application.Resources>
</Application>

View File

@@ -56,10 +56,16 @@
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock Text="{Binding Title}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
<TextBox
Grid.Column="1"
Text="{Binding Title, Mode=TwoWay}"
Style="{StaticResource HeaderTextBoxStyle}"
IsHitTestVisible="{Binding IsEditMode}"
TextWrapping="NoWrap"
VerticalAlignment="Center"
Margin="0,0,30,0"/>
<CommandBar Grid.Column="2" Margin="0,40,0,0" Background="Transparent" IsOpen="True">
<AppBarButton Icon="Edit" Label="Edit" />
<AppBarToggleButton Icon="Edit" Label="Edit" IsChecked="{Binding IsEditMode, Mode=TwoWay}" />
<AppBarButton Icon="Delete" Label="Delete" Click="AppBarButton_Click" />
</CommandBar>
</Grid>

View File

@@ -187,24 +187,21 @@
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock
<TextBox
Grid.Column="1"
Text="{Binding Name}"
Style="{StaticResource HeaderTextBlockStyle}"
IsHitTestVisible="false"
Text="{Binding Name, Mode=TwoWay}"
Style="{StaticResource HeaderTextBoxStyle}"
IsHitTestVisible="{Binding IsEditMode}"
TextWrapping="NoWrap"
VerticalAlignment="Bottom"
Margin="0,0,30,40"/>
VerticalAlignment="Center"
Margin="0,0,30,0"/>
<CommandBar
Grid.Column="2"
Margin="0,40,0,0"
Background="Transparent"
IsOpen="True">
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Edit" Label="Edit" />
<AppBarToggleButton Icon="Edit" Label="Edit" IsChecked="{Binding IsEditMode, Mode=TwoWay}" />
<AppBarButton Icon="Delete" Label="Delete" IsEnabled="{Binding IsNotRoot}" Click="AppBarButton_Click" />
</CommandBar.SecondaryCommands>
<AppBarButton Icon="Save" Label="Save" />
</CommandBar>
</Grid>
</Grid>

View File

@@ -1,17 +1,19 @@
using Windows.UI.Text;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Common;
using ModernKeePass.Mappings;
using ModernKeePassLib;
using ModernKeePassLib.Security;
namespace ModernKeePass.ViewModels
{
public class EntryVm
public class EntryVm: NotifyPropertyChangedBase
{
public GroupVm ParentGroup { get; }
public PwEntry Entry => _pwEntry;
public System.Drawing.Color? BackgroundColor => _pwEntry?.BackgroundColor;
public System.Drawing.Color? ForegroundColor => _pwEntry?.ForegroundColor;
public PwEntry Entry { get; }
public System.Drawing.Color? BackgroundColor => Entry?.BackgroundColor;
public System.Drawing.Color? ForegroundColor => Entry?.ForegroundColor;
public string Title
{
@@ -47,18 +49,24 @@ namespace ModernKeePass.ViewModels
{
get
{
if (_pwEntry == null) return Symbol.Add;
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwEntry.IconId);
if (Entry == null) return Symbol.Add;
var result = PwIconToSegoeMapping.GetSymbolFromIcon(Entry.IconId);
return result == Symbol.More ? Symbol.Permissions : result;
}
}
private readonly PwEntry _pwEntry;
public bool IsEditMode
{
get { return _isEditMode; }
set { SetProperty(ref _isEditMode, value); }
}
private bool _isEditMode;
public EntryVm() { }
public EntryVm(PwEntry entry, GroupVm parent)
{
_pwEntry = entry;
Entry = entry;
ParentGroup = parent;
}
@@ -69,12 +77,12 @@ namespace ModernKeePass.ViewModels
private string GetEntryValue(string key)
{
return _pwEntry?.Strings.GetSafe(key).ReadString();
return Entry?.Strings.GetSafe(key).ReadString();
}
private void SetEntryValue(string key, string newValue)
{
_pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
Entry?.Strings.Set(key, new ProtectedString(true, newValue));
}
}
}

View File

@@ -13,12 +13,17 @@ namespace ModernKeePass.ViewModels
public GroupVm ParentGroup { get; }
public ObservableCollection<EntryVm> Entries { get; set; } = new ObservableCollection<EntryVm>();
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
public string Name => _pwGroup == null ? "New group" : _pwGroup.Name;
public int EntryCount => Entries.Count - 1;
public int GroupCount => Groups.Count - 1;
public bool IsNotRoot => ParentGroup != null;
public FontWeight FontWeight => _pwGroup == null ? FontWeights.Bold : FontWeights.Normal;
public string Name
{
get { return _pwGroup == null ? "New group" : _pwGroup.Name; }
set { _pwGroup.Name = value; }
}
public Symbol IconSymbol
{
get
@@ -35,8 +40,15 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _isLeftPaneOpen, value); }
}
public bool IsEditMode
{
get { return _isEditMode; }
set { SetProperty(ref _isEditMode, value); }
}
private readonly PwGroup _pwGroup;
private bool _isLeftPaneOpen;
private bool _isEditMode;
public GroupVm() {}