mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Added ViewModel property in code behind of all pages
Workaround a bug in Entry password reveal when set for the first time
This commit is contained in:
@@ -11,6 +11,8 @@ namespace ModernKeePass
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class MainPage
|
public sealed partial class MainPage
|
||||||
{
|
{
|
||||||
|
public MainVm Model => (MainVm)DataContext;
|
||||||
|
|
||||||
public MainPage()
|
public MainPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -24,8 +26,7 @@ namespace ModernKeePass
|
|||||||
|
|
||||||
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var mainVm = DataContext as MainVm;
|
Model.SelectedItem?.Destination.Navigate(Model.SelectedItem.PageType, Model.SelectedItem.Parameter);
|
||||||
mainVm?.SelectedItem?.Destination.Navigate(mainVm.SelectedItem.PageType, mainVm.SelectedItem.Parameter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,26 +36,20 @@
|
|||||||
<Setter Property="Margin" Value="0,20,0,0"/>
|
<Setter Property="Margin" Value="0,20,0,0"/>
|
||||||
</Style>
|
</Style>
|
||||||
</StackPanel.Resources>
|
</StackPanel.Resources>
|
||||||
<TextBlock x:Name="userTextBlock" TextWrapping="Wrap" Text="User name or login" FontSize="18"/>
|
<TextBlock TextWrapping="Wrap" Text="User name or login" FontSize="18"/>
|
||||||
<TextBox x:Name="userTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding UserName, Mode=TwoWay}" Width="350" Height="32" />
|
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding UserName, Mode=TwoWay}" Width="350" Height="32" />
|
||||||
<TextBlock x:Name="passwordTextBlock" TextWrapping="Wrap" Text="Password" FontSize="18"/>
|
<TextBlock TextWrapping="Wrap" Text="Password" FontSize="18"/>
|
||||||
<PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Password="{Binding Password, Mode=TwoWay}" Width="350" Height="32" IsPasswordRevealButtonEnabled="True" Visibility="{Binding IsRevealPassword, Converter={StaticResource InverseBooleanToVisibilityConverter}}" />
|
<PasswordBox HorizontalAlignment="Left" Password="{Binding Password, Mode=TwoWay}" Width="350" Height="32" IsPasswordRevealButtonEnabled="True" Visibility="{Binding IsRevealPassword, Converter={StaticResource InverseBooleanToVisibilityConverter}}" />
|
||||||
<TextBox x:Name="passwordTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Password, Mode=TwoWay}" Width="350" Height="32" Visibility="{Binding IsRevealPassword, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Password, Mode=TwoWay}" Width="350" Height="32" Visibility="{Binding IsRevealPassword, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||||
<CheckBox x:Name="checkBox" HorizontalAlignment="Left" Margin="-3,0,0,0" Content="Show password" IsChecked="{Binding IsRevealPassword, Mode=TwoWay}"/>
|
<CheckBox HorizontalAlignment="Left" Margin="-3,0,0,0" Content="Show password" IsChecked="{Binding IsRevealPassword, Mode=TwoWay}" IsEnabled="{Binding IsRevealPasswordEnabled}" />
|
||||||
<TextBlock x:Name="urlTextBlock" TextWrapping="Wrap" Text="URL" FontSize="18"/>
|
<TextBlock TextWrapping="Wrap" Text="URL" FontSize="18"/>
|
||||||
<!--<StackPanel Orientation="Horizontal" Margin="0,-1,0,-1" Width="350" HorizontalAlignment="Left">
|
<local:TextBoxWithButton x:Name="UrlTextBox" HorizontalAlignment="Left" Text="{Binding Url, Mode=TwoWay}" Height="32" Width="350" MaxLength="256" Style="{StaticResource TextBoxWithButtonStyle}" GotoClick="UrlButton_Click" />
|
||||||
<TextBox x:Name="urlTextBox" TextWrapping="Wrap" Text="{Binding Url, Mode=TwoWay}" Height="32" Width="350" MaxLength="256" Padding="0,0,34,0" />
|
<TextBlock TextWrapping="Wrap" Text="Notes" FontSize="18"/>
|
||||||
<Button Click="UrlButton_Click" Height="34" Margin="-34,0,0,0" Background="Transparent" Padding="2,0" >
|
<TextBox HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Notes, Mode=TwoWay}" Width="350" Height="200" AcceptsReturn="True" IsSpellCheckEnabled="True" />
|
||||||
<SymbolIcon Symbol="Forward" VerticalAlignment="Center" />
|
|
||||||
</Button>
|
|
||||||
</StackPanel>-->
|
|
||||||
<local:TextBoxWithButton x:Name="urlTextBox" HorizontalAlignment="Left" Text="{Binding Url, Mode=TwoWay}" Height="32" Width="350" MaxLength="256" Style="{StaticResource TextBoxWithButtonStyle}" GotoClick="UrlButton_Click" />
|
|
||||||
<TextBlock x:Name="notesTextBlock" TextWrapping="Wrap" Text="Notes" FontSize="18"/>
|
|
||||||
<TextBox x:Name="notesTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Notes, Mode=TwoWay}" Width="350" Height="200" AcceptsReturn="True" IsSpellCheckEnabled="True" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- Bouton Précédent et titre de la page -->
|
<!-- Bouton Précédent et titre de la page -->
|
||||||
<Grid>
|
<Grid Grid.Row="0">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="120"/>
|
<ColumnDefinition Width="120"/>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
|
@@ -99,7 +99,7 @@ namespace ModernKeePass.Pages
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var uri = new Uri(urlTextBox.Text);
|
var uri = new Uri(UrlTextBox.Text);
|
||||||
await Windows.System.Launcher.LaunchUriAsync(uri);
|
await Windows.System.Launcher.LaunchUriAsync(uri);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@@ -22,6 +22,7 @@ namespace ModernKeePass.Pages
|
|||||||
/// process lifetime management
|
/// process lifetime management
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NavigationHelper NavigationHelper { get; }
|
public NavigationHelper NavigationHelper { get; }
|
||||||
|
public GroupVm Model => (GroupVm)DataContext;
|
||||||
|
|
||||||
public GroupDetailPage()
|
public GroupDetailPage()
|
||||||
{
|
{
|
||||||
@@ -94,8 +95,7 @@ namespace ModernKeePass.Pages
|
|||||||
case -1:
|
case -1:
|
||||||
return;
|
return;
|
||||||
case 0:
|
case 0:
|
||||||
var currentGroup = DataContext as GroupVm;
|
Model.CreateNewEntry();
|
||||||
currentGroup?.CreateNewEntry();
|
|
||||||
GridView.SelectedIndex = -1;
|
GridView.SelectedIndex = -1;
|
||||||
// TODO: Navigate to new entry?
|
// TODO: Navigate to new entry?
|
||||||
return;
|
return;
|
||||||
@@ -111,8 +111,7 @@ namespace ModernKeePass.Pages
|
|||||||
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
// Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
|
||||||
messageDialog.Commands.Add(new UICommand("Delete", delete =>
|
messageDialog.Commands.Add(new UICommand("Delete", delete =>
|
||||||
{
|
{
|
||||||
var group = DataContext as GroupVm;
|
Model.RemoveGroup();
|
||||||
group?.RemoveGroup();
|
|
||||||
if (Frame.CanGoBack) Frame.GoBack();
|
if (Frame.CanGoBack) Frame.GoBack();
|
||||||
}));
|
}));
|
||||||
messageDialog.Commands.Add(new UICommand("Cancel"));
|
messageDialog.Commands.Add(new UICommand("Cancel"));
|
||||||
@@ -137,9 +136,8 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
private void SearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
|
private void SearchBox_OnSuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
|
||||||
{
|
{
|
||||||
var viewModel = DataContext as GroupVm;
|
|
||||||
var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx://Assets/Logo.scale-80.png"));
|
var imageUri = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx://Assets/Logo.scale-80.png"));
|
||||||
var results = viewModel?.Entries.Skip(1).Where(e => e.Title.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5);
|
var results = Model.Entries.Skip(1).Where(e => e.Title.IndexOf(args.QueryText, StringComparison.OrdinalIgnoreCase) >= 0).Take(5);
|
||||||
foreach (var result in results)
|
foreach (var result in results)
|
||||||
{
|
{
|
||||||
args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Title, result.ParentGroup.Name, result.Id, imageUri, string.Empty);
|
args.Request.SearchSuggestionCollection.AppendResultSuggestion(result.Title, result.ParentGroup.Name, result.Id, imageUri, string.Empty);
|
||||||
@@ -148,8 +146,7 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
|
||||||
{
|
{
|
||||||
var viewModel = DataContext as GroupVm;
|
var entry = Model.Entries.Skip(1).FirstOrDefault(e => e.Id == args.Tag);
|
||||||
var entry = viewModel?.Entries.Skip(1).FirstOrDefault(e => e.Id == args.Tag);
|
|
||||||
Frame.Navigate(typeof(EntryDetailPage), entry);
|
Frame.Navigate(typeof(EntryDetailPage), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,8 @@ namespace ModernKeePass.Pages
|
|||||||
{
|
{
|
||||||
private Frame _mainFrame;
|
private Frame _mainFrame;
|
||||||
|
|
||||||
|
public OpenVm Model => (OpenVm)DataContext;
|
||||||
|
|
||||||
public NewDatabasePage()
|
public NewDatabasePage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -40,8 +42,7 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
var file = await savePicker.PickSaveFileAsync();
|
var file = await savePicker.PickSaveFileAsync();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
var viewModel = DataContext as OpenVm;
|
Model.OpenFile(file);
|
||||||
viewModel?.OpenFile(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
||||||
|
@@ -17,6 +17,8 @@ namespace ModernKeePass.Pages
|
|||||||
{
|
{
|
||||||
private Frame _mainFrame;
|
private Frame _mainFrame;
|
||||||
|
|
||||||
|
public OpenVm Model => (OpenVm)DataContext;
|
||||||
|
|
||||||
public OpenDatabasePage()
|
public OpenDatabasePage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -38,9 +40,8 @@ namespace ModernKeePass.Pages
|
|||||||
};
|
};
|
||||||
picker.FileTypeFilter.Add(".kdbx");
|
picker.FileTypeFilter.Add(".kdbx");
|
||||||
|
|
||||||
var viewModel = DataContext as OpenVm;
|
|
||||||
// Application now has read/write access to the picked file
|
// Application now has read/write access to the picked file
|
||||||
viewModel?.OpenFile(await picker.PickSingleFileAsync());
|
Model.OpenFile(await picker.PickSingleFileAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
private void PasswordUserControl_PasswordChecked(object sender, PasswordEventArgs e)
|
||||||
|
@@ -16,6 +16,8 @@ namespace ModernKeePass.Pages
|
|||||||
{
|
{
|
||||||
private Frame _mainFrame;
|
private Frame _mainFrame;
|
||||||
|
|
||||||
|
public RecentVm Model => (RecentVm)DataContext;
|
||||||
|
|
||||||
public RecentDatabasesPage()
|
public RecentDatabasesPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -34,10 +36,8 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
private void OpenDatabaseUserControl_OnValidationChecking(object sender, EventArgs e)
|
private void OpenDatabaseUserControl_OnValidationChecking(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//throw new NotImplementedException();
|
|
||||||
var viewModel = DataContext as RecentVm;
|
|
||||||
var app = (App)Application.Current;
|
var app = (App)Application.Current;
|
||||||
app.Database.DatabaseFile = viewModel?.SelectedItem.DatabaseFile;
|
app.Database.DatabaseFile = Model.SelectedItem.DatabaseFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ namespace ModernKeePass.Pages
|
|||||||
public sealed partial class SaveDatabasePage
|
public sealed partial class SaveDatabasePage
|
||||||
{
|
{
|
||||||
private Frame _mainFrame;
|
private Frame _mainFrame;
|
||||||
|
public SaveVm Model => (SaveVm)DataContext;
|
||||||
public SaveDatabasePage()
|
public SaveDatabasePage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -29,8 +30,7 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var viewModel = DataContext as SaveVm;
|
Model.Save();
|
||||||
viewModel?.Save();
|
|
||||||
_mainFrame.Navigate(typeof(MainPage));
|
_mainFrame.Navigate(typeof(MainPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +45,7 @@ namespace ModernKeePass.Pages
|
|||||||
|
|
||||||
var file = await savePicker.PickSaveFileAsync();
|
var file = await savePicker.PickSaveFileAsync();
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
var viewModel = DataContext as SaveVm;
|
Model.Save(file);
|
||||||
viewModel?.Save(file);
|
|
||||||
|
|
||||||
_mainFrame.Navigate(typeof(MainPage));
|
_mainFrame.Navigate(typeof(MainPage));
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public System.Drawing.Color? BackgroundColor => Entry?.BackgroundColor;
|
public System.Drawing.Color? BackgroundColor => Entry?.BackgroundColor;
|
||||||
public System.Drawing.Color? ForegroundColor => Entry?.ForegroundColor;
|
public System.Drawing.Color? ForegroundColor => Entry?.ForegroundColor;
|
||||||
|
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
|
@@ -18,7 +18,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
|
|
||||||
public StorageFile DatabaseFile { get; private set; }
|
public StorageFile DatabaseFile { get; private set; }
|
||||||
public string Token { get; private set; }
|
public string Token { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; } = "Recent file";
|
||||||
public string Path => DatabaseFile.Path;
|
public string Path => DatabaseFile.Path;
|
||||||
|
|
||||||
public bool IsSelected
|
public bool IsSelected
|
||||||
|
Reference in New Issue
Block a user