Skip to content

Commit

Permalink
Lots of changes: more MVVM - Prism interactions instead of MessageBox…
Browse files Browse the repository at this point in the history
…, better error handling, UI improvements, status bar, about dialog.

A bit much for a single commit but had a flow ...
  • Loading branch information
prof79 committed Jun 15, 2018
1 parent b49ee4b commit 24c5d32
Show file tree
Hide file tree
Showing 21 changed files with 1,563 additions and 69 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ A simple ["THEC64 Mini"](https://thec64.com) USB disk swap utility to make setti

## History

### v0.8.0 Pre-Release

Probably already production-ready. A lot of changes/improvements.

* Embracing MVVM: Use of Prism's `InteractionRequest` and `InteractionRequestTrigger` plus custom classes to get rid of `System.Windows.MessageBox` in the view models and mimic its behavior.

* Proper error handling for the activation/overwrite operation.

* Status bar functional/re-worked.

* New about dialog with source links and license information. Accessible via status bar.

* Debug button hidden in release versions.

* Cosmetic changes in disc image list.

**Known issues**

* UI may block due to non-asynchronous I/O.

* Overwrite dialog should better be a `Yes`/`No` than `OK`/`Cancel` dialog. Requires more effort in the custom action/window template classes.

### v0.7.0 Pre-Release

Test release. Fully working but not optimal error handling/user interaction. UI may block due to non-asynchronous I/O.
Expand Down
29 changes: 26 additions & 3 deletions TheC64Disker/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<cvt:BooleanToFontWeightConverter x:Key="BooleanToFontWeightConverter" />

<cvt:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

<!-- Styling for the application -->

<Style TargetType="TextBlock">
Expand All @@ -30,6 +32,11 @@
<Setter Property="Margin" Value="4" />
</Style>

<Style TargetType="Image">
<Setter Property="Margin" Value="4" />
<Setter Property="Stretch" Value="UniformToFill" />
</Style>

<Style TargetType="StatusBar">
<Setter Property="Margin" Value="0,4,0,0" />
</Style>
Expand All @@ -38,9 +45,25 @@

<DataTemplate x:Key="DiskImageTemplate">

<TextBlock
FontWeight="{Binding IsActive, Mode=OneWay, Converter={StaticResource BooleanToFontWeightConverter}}"
Text="{Binding Name, Mode=OneWay}" />
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Image
Grid.Column="0"
Width="16"
Height="16"
Source="/Assets/Floppy.ico" />

<TextBlock
Grid.Column="1"
FontWeight="{Binding IsActive, Mode=OneWay, Converter={StaticResource BooleanToFontWeightConverter}}"
Text="{Binding Name, Mode=OneWay}" />

</Grid>

</DataTemplate>

Expand Down
50 changes: 50 additions & 0 deletions TheC64Disker/Converters/BooleanToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//----------------------------------------------------------------------------
// <copyright file="BooleanToVisibilityConverter.cs"
// company="Markus M. Egger">
// Copyright (C) 2018 Markus M. Egger. All rights reserved.
// </copyright>
// <author>Markus M. Egger</author>
// <description>
// Value converter to convert from Boolean to Visibility.
// </description>
// <version>v0.8.0 2018-06-15T02:55:00+02</version>
//----------------------------------------------------------------------------

namespace at.markusegger.Application.TheC64Disker.Converters
{
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

/// <summary>
/// Value converter to convert from <see cref="Boolean"/> to <see cref="Visibility"/>
/// </summary>
public class BooleanToVisibilityConverter : IValueConverter
{
#region IValueConverter

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool booleanValue)
{
if (targetType == typeof(Visibility))
{
return
(booleanValue ? Visibility.Visible : Visibility.Collapsed);
}
}

throw new InvalidOperationException(
$"Combination of {nameof(value)}/{nameof(targetType)} not supported by {nameof(BooleanToVisibilityConverter)}.");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException(
$"{nameof(ConvertBack)} not supported by {nameof(BooleanToVisibilityConverter)}.");
}

#endregion
}
}
23 changes: 23 additions & 0 deletions TheC64Disker/Events/CloseEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//----------------------------------------------------------------------------
// <copyright file="CloseEvent.cs"
// company="Markus M. Egger">
// Copyright (C) 2018 Markus M. Egger. All rights reserved.
// </copyright>
// <author>Markus M. Egger</author>
// <description>
// A Prism event to signal UI elements like windows to close.
// </description>
// <version>v1.0.0 2018-06-15T02:07:00+02</version>
//----------------------------------------------------------------------------

namespace at.markusegger.Application.TheC64Disker.Events
{
using Prism.Events;

/// <summary>
/// A Prism event to signal UI elements like windows to close.
/// </summary>
public class CloseEvent : PubSubEvent
{
}
}
42 changes: 42 additions & 0 deletions TheC64Disker/Interactivity/InteractionRequest/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//----------------------------------------------------------------------------
// <copyright file="Error.cs"
// company="Markus M. Egger">
// Copyright (C) 2018 Markus M. Egger. All rights reserved.
// </copyright>
// <author>Markus M. Egger</author>
// <description>
// Basic implementation of INotification for error messages.
// </description>
// <version>v1.0.0 2018-06-14T22:59:00+02</version>
//
// Based on:
//
// Prism's Notification
//
//----------------------------------------------------------------------------

namespace at.markusegger.Application.TheC64Disker.Interactivity.InteractionRequest
{
using Prism.Interactivity.InteractionRequest;

/// <summary>
/// Basic implementation of Prism.Interactivity.InteractionRequest.INotification
/// for error messages.
/// </summary>
public class Error : INotification
{
#region Properties

/// <summary>
/// Gets or sets the title to use for the notification.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the content of the notification.
/// </summary>
public object Content { get; set; }

#endregion
}
}
42 changes: 42 additions & 0 deletions TheC64Disker/Interactivity/InteractionRequest/Warning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//----------------------------------------------------------------------------
// <copyright file="Warning.cs"
// company="Markus M. Egger">
// Copyright (C) 2018 Markus M. Egger. All rights reserved.
// </copyright>
// <author>Markus M. Egger</author>
// <description>
// Basic implementation of INotification for warning messages.
// </description>
// <version>v1.0.0 2018-06-14T22:58:00+02</version>
//
// Based on:
//
// Prism's Notification
//
//----------------------------------------------------------------------------

namespace at.markusegger.Application.TheC64Disker.Interactivity.InteractionRequest
{
using Prism.Interactivity.InteractionRequest;

/// <summary>
/// Basic implementation of Prism.Interactivity.InteractionRequest.INotification
/// for warning messages.
/// </summary>
public class Warning : INotification
{
#region Properties

/// <summary>
/// Gets or sets the title to use for the notification.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the content of the notification.
/// </summary>
public object Content { get; set; }

#endregion
}
}
6 changes: 3 additions & 3 deletions TheC64Disker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.0.*")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0.0-prerelease")]
[assembly: AssemblyVersion("0.8.0.*")]
[assembly: AssemblyFileVersion("0.8.0.0")]
[assembly: AssemblyInformationalVersion("0.8.0.0-prerelease")]
31 changes: 30 additions & 1 deletion TheC64Disker/TheC64Disker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Prism.Wpf.6.3.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
Expand All @@ -88,10 +89,22 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="Views\AboutView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DiskSelectionView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Popups\MyConfirmationWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Popups\MyNotificationWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ShellView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -102,16 +115,32 @@
</Compile>
<Compile Include="Bootstrappers\TheC64DiskerBootstrapper.cs" />
<Compile Include="Converters\BooleanToFontWeightConverter.cs" />
<Compile Include="Converters\BooleanToVisibilityConverter.cs" />
<Compile Include="Events\CloseEvent.cs" />
<Compile Include="Interactivity\InteractionRequest\Error.cs" />
<Compile Include="Interactivity\InteractionRequest\Warning.cs" />
<Compile Include="Interfaces\IShell.cs" />
<Compile Include="Models\DiskImage.cs" />
<Compile Include="Modules\DiskSelectionModule.cs" />
<Compile Include="Utility\IOExtensions.cs" />
<Compile Include="Utility\OperationResult.cs" />
<Compile Include="Utility\SettingKey.cs" />
<Compile Include="Utility\TheC64Helper.cs" />
<Compile Include="ViewModels\AboutViewModel.cs" />
<Compile Include="ViewModels\DiskSelectionViewModel.cs" />
<Compile Include="Views\AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\DiskSelectionView.xaml.cs">
<DependentUpon>DiskSelectionView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Popups\MyConfirmationWindow.xaml.cs">
<DependentUpon>MyConfirmationWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Popups\MyNotificationWindow.xaml.cs">
<DependentUpon>MyNotificationWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Popups\MyPopupWindowAction.cs" />
<Compile Include="Views\ShellView.xaml.cs">
<DependentUpon>ShellView.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down Expand Up @@ -156,7 +185,7 @@
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\Floppy.ico" />
<Resource Include="Assets\Floppy.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.targets" />
Expand Down
26 changes: 26 additions & 0 deletions TheC64Disker/Utility/IOExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ public static class IOExtensions
{
#region Extension Methods

public static FileInfo GetFileInfo(this string fileSystemPath)
=> new FileInfo(fileSystemPath);

public static DirectoryInfo GetDirectoryInfo(this string fileSystemPath)
=> new DirectoryInfo(fileSystemPath);

public static DirectoryInfo GetParentDirectory(this string fileSystemPath)
{
if (fileSystemPath.IsFile())
{
var fileInfo = fileSystemPath.GetFileInfo();

return fileInfo.Directory;
}
else if (fileSystemPath.IsDirectory())
{
var directoryInfo = fileSystemPath.GetDirectoryInfo();

return directoryInfo.Parent;
}
else
{
return null;
}
}

public static string GetDriveForPath(this string fileSystemPath)
{
var info = new FileInfo(fileSystemPath);
Expand Down
24 changes: 24 additions & 0 deletions TheC64Disker/Utility/OperationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//----------------------------------------------------------------------------
// <copyright file="OperationResult.cs"
// company="Markus M. Egger">
// Copyright (C) 2018 Markus M. Egger. All rights reserved.
// </copyright>
// <author>Markus M. Egger</author>
// <description>
// An enumeration of results a general operation can yield.
// </description>
// <version>v1.0.0 2018-06-14T23:39:00+02</version>
//----------------------------------------------------------------------------

namespace at.markusegger.Application.TheC64Disker.Utility
{
/// <summary>
/// An enumeration of results a general operation can yield.
/// </summary>
public enum OperationResult
{
Cancelled,
Error,
Success,
}
}
Loading

0 comments on commit 24c5d32

Please sign in to comment.