Skip to content

Commit

Permalink
Make WizardWindow wider and re-sizable (#17)
Browse files Browse the repository at this point in the history
* Make WizardWindow wider and re sizable
* Show version
* Replace Mvvm.Async
  • Loading branch information
vov4uk authored Jun 21, 2022
1 parent fb10504 commit fb14773
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 59 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ dotnet_diagnostic.CS8603.severity = none

# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = none

# CS8769: Nullability of reference types in type of parameter doesn't match implemented member (possibly because of nullability attributes).
dotnet_diagnostic.CS8769.severity = none

# CS8615: Nullability of reference types in type doesn't match implemented member.
dotnet_diagnostic.CS8615.severity = none
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
| Sonar | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=vov4uk_Financier.Desktop&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=vov4uk_Financier.Desktop)|

# Financier Desktop
[**Install the .NET Desktop Runtime.**](https://dotnet.microsoft.com/en-us/download/dotnet/6.0/runtime)

MVP (minimum viable product) application, with enough functions to work with Financier .backup on Windows.
More info on [Github pages](https://vov4uk.github.io/Financier.Desktop/)

## About
Desktop version of [Financier](https://github.com/handydevcom/financier "Financier") which is a fork of the great [Financisto](https://github.com/dsolonenko/financisto) app. Financisto is an open-source personal finance tracker for Android platform.

Expand Down
132 changes: 132 additions & 0 deletions src/Financier.Common/AsyncCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Financier.Common
{
[ExcludeFromCodeCoverage]
public class AsyncCommand : ICommand, IAsyncCommand
{
private readonly Func<Task> _action;
private readonly SynchronizationContext _context;
private readonly Func<bool> _predicate;
public AsyncCommand(Func<Task> action, Func<bool> predicate = null)
{
_action = action;
_predicate = predicate;
_context = SynchronizationContext.Current;
}

event EventHandler ICommand.CanExecuteChanged
{
add { _canExecuteChanged += value; }
remove { _canExecuteChanged -= value; }
}

private event EventHandler _canExecuteChanged;
public bool CanExecute()
{
return _predicate == null || _predicate();
}

// ----- Implement ICommand
bool ICommand.CanExecute(object parameter)
{
return CanExecute();
}

async void ICommand.Execute(object parameter)
{
await ExecuteAsync();
}

public async Task ExecuteAsync()
{
if (CanExecute())
{
await _action();
}
}
public void RaiseCanExecuteChanged()
{
if (_context != null)
{
_context.Post(state => OnCanExecuteChanged(), null);
}
else
{
OnCanExecuteChanged();
}
}
private void OnCanExecuteChanged()
{
var handler = _canExecuteChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}

[ExcludeFromCodeCoverage]
public class AsyncCommand<T> : ICommand, IAsyncCommand<T>
{
private readonly Predicate<T> _canExecute;
private readonly SynchronizationContext _context;
private readonly Func<T, Task> _parameterizedAction;
public AsyncCommand(Func<T, Task> parameterizedAction, Predicate<T> canExecute = null)
{
_parameterizedAction = parameterizedAction;
_canExecute = canExecute;
_context = SynchronizationContext.Current;
}

event EventHandler ICommand.CanExecuteChanged
{
add { _canExecuteChanged += value; }
remove { _canExecuteChanged -= value; }
}

private event EventHandler _canExecuteChanged;
public bool CanExecute(T parameter)
{
return _canExecute == null || _canExecute(parameter);
}

// ----- Explicit implementations
bool ICommand.CanExecute(object parameter)
{
return CanExecute((T)parameter);
}

async void ICommand.Execute(object parameter)
{
await ExecuteAsync((T)parameter);
}

public async Task ExecuteAsync(T parameter)
{
if (CanExecute(parameter))
{
await _parameterizedAction(parameter);
}
}
public void RaiseCanExecuteChanged()
{
if (_context != null)
{
_context.Post(state => OnCanExecuteChanged(), null);
}
else
{
OnCanExecuteChanged();
}
}
private void OnCanExecuteChanged()
{
var handler = _canExecuteChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
}
1 change: 0 additions & 1 deletion src/Financier.Common/BaseViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Financier.Common.Model;
using Financier.DataAccess.Abstractions;
using Mvvm.Async;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
Expand Down
9 changes: 5 additions & 4 deletions src/Financier.Common/Entities/DbManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ public static void ResetAllManuals()
_location = null;
}

public static void ReseManuals(string manual)
public static void ResetManuals(string manual)
{
switch (manual)
{
case nameof(Payee): _payee = null; break;
case nameof(Location):_location = null; break;
case nameof(Project):_project = null; break;
case nameof(Payee): _payee = null; break;
case nameof(Location): _location = null; break;
case nameof(Project): _project = null; break;
case nameof(Account): _accounts = null; break;
default:
break;
}
Expand Down
1 change: 0 additions & 1 deletion src/Financier.Common/Financier.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<ItemGroup>
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" Version="5.0.100" />
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Mvvm.Async" Version="0.0.1" />
<PackageReference Include="Prism.Core" Version="8.1.97" />
<PackageReference Include="WPFChromeTabsMVVM" Version="1.4.0" />
</ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/Financier.Common/IAsyncCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Threading.Tasks;

namespace Financier.Common
{
public interface IAsyncCommand
{
Task ExecuteAsync();
bool CanExecute();
void RaiseCanExecuteChanged();
}

public interface IAsyncCommand<in T>
{
Task ExecuteAsync(T parameter);
bool CanExecute(T parameter);
void RaiseCanExecuteChanged();
}
}
4 changes: 1 addition & 3 deletions src/Financier.Common/IDataRefresh.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Mvvm.Async;

namespace Financier.Common
namespace Financier.Common
{
public interface IDataRefresh
{
Expand Down
5 changes: 4 additions & 1 deletion src/Financier.Desktop/Financier.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Images\ic_launcher.ico</ApplicationIcon>
<StartupObject>Financier.Desktop.App</StartupObject>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -87,7 +91,6 @@
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" Version="5.0.103" />
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Mvvm.Async" Version="0.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog" Version="5.0.0-rc2" />
<PackageReference Include="Prism.Core" Version="8.1.97" />
Expand Down
1 change: 0 additions & 1 deletion src/Financier.Desktop/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Icon="pack://application:,,,/Images/ic_launcher.png"
xmlns:ViewModel="clr-namespace:Financier.Desktop.ViewModel"
xmlns:View="clr-namespace:Financier.Desktop.Views"
Title="Financier Desktop"
Loaded="RibbonWindow_Loaded">
<Window.Resources>
<ResourceDictionary>
Expand Down
3 changes: 3 additions & 0 deletions src/Financier.Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Financier.Adapter;
using Financier.DataAccess.View;
using Financier.Common.Model;
using System.Reflection;

namespace Financier.Desktop
{
Expand All @@ -36,6 +37,8 @@ public MainWindow()
ViewModel = new MainWindowVM(new DialogHelper(), new FinancierDatabaseFactory(), new EntityReader(), new BackupWriter(), new BankHelperFactory());

DataContext = ViewModel;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Title = $"Financier Desktop v.{version}";
Logger.Info("App started");
}

Expand Down
4 changes: 3 additions & 1 deletion src/Financier.Desktop/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.IO;
using System.Collections.Concurrent;
using Financier.Desktop.Data;
using Mvvm.Async;
using Financier.Reports;
using Financier.Common.Entities;
using Financier.Common.Model;
Expand Down Expand Up @@ -338,6 +337,9 @@ private async Task RefreshAffectedAccounts(List<Transaction> transactions)
{
await db.RebuildAccountBalanceAsync(accId);
}

DbManual.ResetManuals(nameof(DbManual.Account));
await DbManual.SetupAsync(db);
}

private async Task RefreshCurrentPage()
Expand Down
2 changes: 1 addition & 1 deletion src/Financier.Desktop/Pages/BlotterVM.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Financier.Desktop.ViewModel
{
using Financier.Common;
using Financier.Common.Entities;
using Financier.Common.Model;
using Financier.Converters;
Expand All @@ -11,7 +12,6 @@
using Financier.Desktop.Helpers;
using Financier.Desktop.ViewModel.Dialog;
using Financier.Desktop.Views;
using Mvvm.Async;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down
1 change: 0 additions & 1 deletion src/Financier.Desktop/Pages/EntityBaseVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Financier.Common.Model;
using Financier.DataAccess.Abstractions;
using Financier.Desktop.Helpers;
using Mvvm.Async;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

Expand Down
2 changes: 1 addition & 1 deletion src/Financier.Desktop/Pages/LocationsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LocationsVM(IFinancierDatabase db, IDialogWrapper dialogWrapper) : base(d

protected override async Task RefreshData()
{
DbManual.ReseManuals(nameof(DbManual.Location));
DbManual.ResetManuals(nameof(DbManual.Location));
await DbManual.SetupAsync(db);
Entities = new System.Collections.ObjectModel.ObservableCollection<LocationModel>(DbManual.Location.Where(x => x.Id > 0).OrderByDescending(x => x.IsActive).ThenBy(x => x.Id));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Financier.Desktop/Pages/PayeesVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PayeesVM(IFinancierDatabase db, IDialogWrapper dialogWrapper) : base(db,

protected override async Task RefreshData()
{
DbManual.ReseManuals(nameof(DbManual.Payee));
DbManual.ResetManuals(nameof(DbManual.Payee));
await DbManual.SetupAsync(db);
Entities = new ObservableCollection<PayeeModel>(DbManual.Payee.Where(x => x.Id > 0).OrderByDescending(x => x.IsActive).ThenBy(x => x.Id));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Financier.Desktop/Pages/ProjectsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ProjectsVM(IFinancierDatabase db, IDialogWrapper dialogWrapper) : base(db

protected override async Task RefreshData()
{
DbManual.ReseManuals(nameof(DbManual.Project));
DbManual.ResetManuals(nameof(DbManual.Project));
await DbManual.SetupAsync(db);
Entities = new ObservableCollection<ProjectModel>(DbManual.Project.Where(x => x.Id > 0).OrderByDescending(x => x.IsActive).ThenBy(x => x.Id));
}
Expand Down
9 changes: 9 additions & 0 deletions src/Financier.Desktop/Properties/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//2022.6.21.6
using System.Reflection;

[assembly: AssemblyCompany("Financier.Desktop")]
[assembly: AssemblyProduct("Financier.Desktop")]
[assembly: AssemblyTitle("Financier.Desktop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2022.6.21.6")]
[assembly: AssemblyVersion("2022.6.21.6")]
36 changes: 32 additions & 4 deletions src/Financier.Desktop/Wizards/MonoWizard/Page3.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
xmlns:fcrd="clr-namespace:Financier.Common.Entities;assembly=Financier.Common"
xmlns:dgx="clr-namespace:DataGridExtensions;assembly=DataGridExtensions"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
d:DesignHeight="300"
d:DesignWidth="900">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand All @@ -22,16 +23,43 @@
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="24"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" FontSize="12"
<Grid Grid.Column="0"
Grid.Row="0"
Height="24">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="12"
Text="Please select Category, From\To Account, Location ..."/>
<DataGrid Grid.Row="1"
<Button Grid.Column="1"
Margin="2"
Width="65"
HorizontalAlignment="Stretch"
Content="Delete row"
ToolTip="Delete selected row (Del)"
Command="{Binding Path=DeleteCommand}"
CommandParameter="{Binding SelectedItem, ElementName=MainGrid}"
/>
<Button Grid.Column="2"
Margin="2"
Width="65"
HorizontalAlignment="Stretch"
Content="Clear notes"
ToolTip="Clear note for all transactions"
Command="{Binding Path=ClearAllNotesCommand}"
/>
</Grid>
<DataGrid Grid.Row="2"
ItemsSource="{Binding Path=FinancierTransactions}"
AutoGenerateColumns="False"
ScrollViewer.CanContentScroll="True"
DataContext="{Binding}"
x:Name="MainGrid"
CanUserAddRows="false">
<DataGrid.InputBindings>
<KeyBinding Key="Delete"
Expand Down
Loading

0 comments on commit fb14773

Please sign in to comment.