Skip to content

Commit

Permalink
New approach for design data
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Nov 28, 2024
1 parent 52859f4 commit f442c25
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Vocup.WinForms/Forms/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AboutBox()
Icon = Icon.FromHandle(Icons.Info.GetHicon());
AvaloniaControlHost.Content = new AboutView
{
DataContext = new AboutViewModel(AppInfo.Version, AppInfo.GetDeployment(), AppInfo.CopyrightInfo)
DataContext = new AboutViewModel(AppInfo.GetDeployment())
};
}
}
2 changes: 1 addition & 1 deletion src/Vocup/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override void OnFrameworkInitializationCompleted()
{
singleViewPlatform.MainView = new MainView
{
DataContext = new MainViewModel()
DataContext = new MainViewModel(null)

Check warning on line 35 in src/Vocup/App.axaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Cannot convert null literal to non-nullable reference type.

Check warning on line 35 in src/Vocup/App.axaml.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 35 in src/Vocup/App.axaml.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 35 in src/Vocup/App.axaml.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.

Check warning on line 35 in src/Vocup/App.axaml.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Cannot convert null literal to non-nullable reference type.
};
}

Expand Down
31 changes: 25 additions & 6 deletions src/Vocup/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Vocup.ViewModels;

public class AboutViewModel : ViewModelBase
{
public AboutViewModel()
: this(new Version(), "Development", "Copyright © 2011 Florian Amstutz, © 2018-present Daniel Lerch.") { }
protected const string DefaultCopyright = "Copyright © 2011 Florian Amstutz, © 2018-present Daniel Lerch.";
protected const string DefaultAppVersion = "0.0.0";

public AboutViewModel(Version appVersion, string deployment, string copyright)
public AboutViewModel(string deployment)
{
string prefix = Lang.Resources.AboutView_Version;
string architecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
Version = $"{prefix} {appVersion} ({architecture}, {deployment})";

Copyright = copyright;
Version = $"{prefix} {AppVersion} ({architecture}, {deployment})";

Copyright = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright
?? DefaultCopyright;

if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 10240))
MicrosoftStoreLink = "ms-windows-store://pdp/?productid=9N6W2H3QJQMM";
Expand All @@ -23,7 +26,23 @@ public AboutViewModel(Version appVersion, string deployment, string copyright)
}

public string Version { get; }
public string Copyright { get; }
public virtual string Copyright { get; }
public string MicrosoftStoreLink { get; }
public LicensesViewModel Licenses { get; } = new();

protected virtual string AppVersion => Assembly.GetEntryAssembly()?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion?
.Split('+')[0]
?? DefaultAppVersion;
}

public class DesignAboutViewModel : AboutViewModel
{
public DesignAboutViewModel() : base("Design Mode")
{
}

public override string Copyright => DefaultCopyright;
protected override string AppVersion => DefaultAppVersion;
}
2 changes: 1 addition & 1 deletion src/Vocup/ViewModels/HostWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async void Initialize()
services.AddSingleton(settingsContext.Value);
configureServices(serviceProvider, services);

MainView = new MainViewModel();
MainView = new MainViewModel(settingsContext.Value);
Settings = settingsContext.Value;
}
}
19 changes: 12 additions & 7 deletions src/Vocup/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ namespace Vocup.ViewModels;

public class MainViewModel : ViewModelBase
{
private readonly VocupSettings? settings;

public MainViewModel()
public MainViewModel(VocupSettings settings)
{
About = new("Development");
RecentFiles = new(settings.RecentFiles);
}

public MainViewModel(VocupSettings settings)
public virtual AboutViewModel About { get; }
public virtual RecentFilesViewModel RecentFiles { get; }
}

public class DesignMainViewModel : MainViewModel
{
public DesignMainViewModel() : base(new VocupSettings())
{
this.settings = settings;
}

public AboutViewModel About { get; } = new();
public RecentFilesViewModel RecentFiles => new(settings?.RecentFiles ?? []);
public override AboutViewModel About { get; } = new DesignAboutViewModel();
public override RecentFilesViewModel RecentFiles { get; } = new DesignRecentFilesViewModel();
}
17 changes: 11 additions & 6 deletions src/Vocup/ViewModels/RecentFilesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using Vocup.Settings.Model;

namespace Vocup.ViewModels;

public class RecentFilesViewModel
{
public RecentFilesViewModel()
{
Files = [];
}

public RecentFilesViewModel(ObservableCollection<RecentFile> files)
{
Files = files;
}

public ObservableCollection<RecentFile> Files { get; }
}

public class DesignRecentFilesViewModel : RecentFilesViewModel
{
public DesignRecentFilesViewModel() : base(
[
new("C:\\Users\\maxmu\\Documents\\Englisch - Deutsch.vhf", DateTime.Now, DateTime.Now),
])
{ }
}
2 changes: 1 addition & 1 deletion src/Vocup/Views/AboutView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
x:Class="Vocup.Views.AboutView"
x:DataType="vm:AboutViewModel">
<Design.DataContext>
<vm:AboutViewModel />
<vm:DesignAboutViewModel />
</Design.DataContext>

<UserControl.Styles>
Expand Down
2 changes: 1 addition & 1 deletion src/Vocup/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
x:Class="Vocup.Views.MainView"
x:DataType="vm:MainViewModel">
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
<vm:DesignMainViewModel />
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainViewModel />
</Design.DataContext>
Expand Down

0 comments on commit f442c25

Please sign in to comment.