Fixed DeleteWindow and allowed it to close.
This commit is contained in:
1 parent
83a08edb2e
commit
f98ff942bb
13 files changed
+361
-22
No files matched your search
@@ -0,0 +1,47 @@
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
project(PcgsInvUi LANGUAGES CSharp)
|
||||
|
||||
include(CSharpUtilities)
|
||||
|
||||
add_executable(PcgsInvUi
|
||||
App.axaml.cs
|
||||
Program.cs
|
||||
ViewLocator.cs
|
||||
App.axaml
|
||||
app.manifest
|
||||
Models/Coin.cs
|
||||
Services/CoinCollection.cs
|
||||
Services/CoinDatabase.cs
|
||||
Services/PcgsClient.cs
|
||||
ViewModels/CoinListViewModel.cs
|
||||
ViewModels/DeleteWindowViewModel.cs
|
||||
ViewModels/EditViewModel.cs
|
||||
ViewModels/ErrorWindowViewModel.cs
|
||||
ViewModels/FindWindowViewModel.cs
|
||||
ViewModels/MainWindowViewModel.cs
|
||||
ViewModels/NewViewModel.cs
|
||||
ViewModels/ViewModelBase.cs
|
||||
Views/DeleteWindow.axaml
|
||||
Views/DeleteWindow.axaml.cs
|
||||
Views/ErrorWindow.axaml
|
||||
Views/ErrorWindow.axaml.cs
|
||||
Views/FindWindow.axaml
|
||||
Views/FindWindow.axaml.cs
|
||||
Views/MainWindow.axaml
|
||||
Views/MainWindow.axaml.cs
|
||||
Views/NewView.axaml
|
||||
Views/NewView.axaml.cs
|
||||
)
|
||||
|
||||
# Set the .NET Framework version for the executable.
|
||||
set_property(TARGET PcgsInvUi PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
|
||||
# Set the executable to be 64-bit.
|
||||
set_property(TARGET PcgsInvUi PROPERTY WIN64_EXECUTABLE TRUE)
|
||||
# Set the C# language version (defaults to 3.0)
|
||||
set(CMAKE_CSharp_FLAGS "/langversion:latest")
|
||||
|
||||
# Add the .NET reference libraries as dependencies.
|
||||
set_property(TARGET PcgsInvUi PROPERTY VS_DOTNET_REFERENCES
|
||||
"Microsoft.CSharp"
|
||||
)
|
||||
@@ -37,14 +37,16 @@ public class CoinDatabase {
|
||||
|
||||
private SQLiteConnection CreateConnection() {
|
||||
// Check if database exists.
|
||||
if (!System.IO.File.Exists("%USERPROFILE%\\coin_collection")) {
|
||||
if (!System.IO.File.Exists("coin_collection")) {
|
||||
// Create the database.
|
||||
SQLiteConnection.CreateFile("%USERPROFILE%\\coin_collection");
|
||||
Console.Write("Creating database... ");
|
||||
SQLiteConnection.CreateFile("coin_collection");
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
|
||||
// Create a connection to the database.
|
||||
SQLiteConnection connection =
|
||||
new SQLiteConnection("DataSource=%USERPROFILE%\\coin_collection");
|
||||
new SQLiteConnection("DataSource=coin_collection");
|
||||
|
||||
// Open the connection.
|
||||
try {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
using System.Reactive;
|
||||
using PcgsInvUi.Views;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace PcgsInvUi.ViewModels;
|
||||
|
||||
public class DeleteWindowViewModel : ViewModelBase {
|
||||
public ReactiveCommand<Unit, object> OkCommand { get; }
|
||||
public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; }
|
||||
public ReactiveCommand<Unit, object> CancelCommand { get; }
|
||||
|
||||
public DeleteWindowViewModel() {
|
||||
OkCommand = ReactiveCommand.Create(() => (object)true);
|
||||
CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close());
|
||||
CancelCommand = ReactiveCommand.Create(() => (object)false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive;
|
||||
using PcgsInvUi.Models;
|
||||
using ReactiveUI;
|
||||
|
||||
@@ -25,4 +24,4 @@ public class EditViewModel : ViewModelBase {
|
||||
// Setup OkCommand - all Coin-related properties must be non-whitespace.
|
||||
OkCommand = ReactiveCommand.Create(() => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ public class ErrorWindowViewModel : ViewModelBase {
|
||||
|
||||
public ErrorWindowViewModel(string message)
|
||||
{
|
||||
DisplayedMessage = message;
|
||||
_message = message;
|
||||
|
||||
CloseCommand = ReactiveCommand.Create<ErrorWindow>(window => window.Close());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using ReactiveUI;
|
||||
|
||||
namespace PcgsInvUi.ViewModels;
|
||||
|
||||
// TODO Create proper sums for total value.
|
||||
// TODO Error handling for API calls.
|
||||
// TODO Manual handling of API key.
|
||||
// TODO Use CoinFacts link.
|
||||
@@ -67,7 +68,7 @@ public class MainWindowViewModel : ViewModelBase {
|
||||
var result = await ShowDeleteWindow.Handle(deleteViewModel);
|
||||
if (result && SelectedCoin is not null) {
|
||||
ConnectedCoinDatabase.DeleteCoin(SelectedCoin);
|
||||
ConnectedCoinDatabase.Collection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
|
||||
ConnectedCoinDatabase.Collection.Remove(SelectedCoin);
|
||||
}
|
||||
}, deleteEnabled);
|
||||
|
||||
@@ -83,10 +84,10 @@ public class MainWindowViewModel : ViewModelBase {
|
||||
catch (IOException e) {
|
||||
// Something is wrong with the file after it's been created.
|
||||
Console.WriteLine(e.Message);
|
||||
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
|
||||
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.Message);
|
||||
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
|
||||
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -120,4 +121,4 @@ public class MainWindowViewModel : ViewModelBase {
|
||||
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
|
||||
.Subscribe(_ => TotalValue = ConnectedCoinDatabase.Collection.Sum(x => x.TotalPrice));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
<Button Grid.Row="1" Grid.Column="1" Margin="5"
|
||||
Width="100"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Center"
|
||||
HorizontalContentAlignment="Center" IsEnabled="False"
|
||||
Content="Use X button" Command="{Binding CancelCommand}" />
|
||||
HorizontalContentAlignment="Center" IsEnabled="True"
|
||||
Content="No" Command="{Binding CancelCommand}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
||||
@@ -9,5 +9,6 @@ public partial class DeleteWindow : ReactiveWindow<DeleteWindowViewModel> {
|
||||
public DeleteWindow() {
|
||||
InitializeComponent();
|
||||
this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close)));
|
||||
this.WhenActivated(d => d(ViewModel!.CancelCommand.Subscribe(Close)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@
|
||||
xmlns:viewModels="clr-namespace:PcgsInvUi.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="PcgsInvUi.Views.MainWindow" x:DataType="viewModels:MainWindowViewModel"
|
||||
Title="Main Window"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
Title="Main Window" WindowStartupLocation="CenterScreen" WindowState="Maximized" >
|
||||
<SplitView IsPaneOpen="True"
|
||||
DisplayMode="Inline"
|
||||
PanePlacement="Right">
|
||||
|
||||
Reference in new issue
Block a user