Skip to content

Commit

Permalink
Add Avalonia skeleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
claunia committed Apr 17, 2020
1 parent 8cb8f6a commit 142f824
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 36 deletions.
53 changes: 20 additions & 33 deletions .idea/.idea.Aaru/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Aaru.Gui/Aaru.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<PackageReference Include="Eto.Forms" Version="2.5.0" />
<PackageReference Include="Eto.Serialization.Xaml" Version="2.5.0" />
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.3.0" />
<PackageReference Include="Avalonia" Version="0.9.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aaru.Core\Aaru.Core.csproj" />
Expand Down Expand Up @@ -304,6 +307,20 @@
<EmbeddedResource Include="Assets\Icons\oxygen\32x32\media-flash-sd-mmc.png" />
<EmbeddedResource Include="Assets\Icons\oxygen\32x32\media-tape.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Assets" />
<Folder Include="Models\" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<AvaloniaResource Include="**\*.xaml">
<SubType>Designer</SubType>
</AvaloniaResource>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Views\MainWindow.xaml" />
</ItemGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4')) and '$(OS)' == 'Unix'">
<!-- When compiling .NET SDK 2.0 projects targeting .NET 4.x on Mono using 'dotnet build' you -->
<!-- have to teach MSBuild where the Mono copy of the reference asssemblies is -->
Expand Down
13 changes: 13 additions & 0 deletions Aaru.Gui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gui="clr-namespace:Aaru.Gui"
x:Class="Aaru.Gui.App">
<Application.DataTemplates>
<gui:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
</Application.Styles>
</Application>
29 changes: 29 additions & 0 deletions Aaru.Gui/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Aaru.Gui.ViewModels;
using Aaru.Gui.Views;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace Aaru.Gui
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
}
Binary file added Aaru.Gui/Assets/avalonia-logo.ico
Binary file not shown.
32 changes: 32 additions & 0 deletions Aaru.Gui/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Aaru.Gui.ViewModels;
using Avalonia.Controls;
using Avalonia.Controls.Templates;

namespace Aaru.Gui
{
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;

public IControl Build(object data)
{
var name = data.GetType().FullName.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null)
{
return (Control)Activator.CreateInstance(type);
}
else
{
return new TextBlock { Text = "Not Found: " + name };
}
}

public bool Match(object data)
{
return data is ViewModelBase;
}
}
}
7 changes: 7 additions & 0 deletions Aaru.Gui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Aaru.Gui.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
public string Greeting => "Welcome to Avalonia!";
}
}
8 changes: 8 additions & 0 deletions Aaru.Gui/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using ReactiveUI;

namespace Aaru.Gui.ViewModels
{
public class ViewModelBase : ReactiveObject
{
}
}
17 changes: 17 additions & 0 deletions Aaru.Gui/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Aaru.Gui.ViewModels;assembly=Aaru.Gui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Aaru.Gui.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="Aaru.Gui">

<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>

<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

</Window>
22 changes: 22 additions & 0 deletions Aaru.Gui/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace Aaru.Gui.Views
{
public class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
11 changes: 10 additions & 1 deletion Aaru.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29102.190
Expand Down Expand Up @@ -35,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aaru.Database", "Aaru.Datab
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aaru.Dto", "Aaru.Dto\Aaru.Dto.csproj", "{F4399FF5-9BD0-475A-9EA7-3DAE45291FE2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aaru.Gui", "Aaru.Gui\Aaru.Gui.csproj", "{18C4C44D-2562-4B6D-8181-32D7EA067D96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -171,6 +172,14 @@ Global
{F4399FF5-9BD0-475A-9EA7-3DAE45291FE2}.Release|Any CPU.Build.0 = Release|Any CPU
{F4399FF5-9BD0-475A-9EA7-3DAE45291FE2}.Release|x86.ActiveCfg = Release|Any CPU
{F4399FF5-9BD0-475A-9EA7-3DAE45291FE2}.Release|x86.Build.0 = Release|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Debug|x86.ActiveCfg = Debug|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Debug|x86.Build.0 = Debug|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|Any CPU.Build.0 = Release|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|x86.ActiveCfg = Release|Any CPU
{18C4C44D-2562-4B6D-8181-32D7EA067D96}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion Aaru/Aaru.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<Name>Aaru.Checksums</Name>
</ProjectReference>
<ProjectReference Include="..\Aaru.Database\Aaru.Database.csproj" />
<ProjectReference Include="..\Aaru.Gui\Aaru.Gui.csproj" />
<ProjectReference Include="..\Aaru.Helpers\Aaru.Helpers.csproj">
<Project>{F8BDF57B-1571-4CD0-84B3-B422088D359A}</Project>
<Name>Aaru.Helpers</Name>
Expand Down Expand Up @@ -281,8 +282,10 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="Avalonia" Version="0.9.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.0" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugPackage>-dbg</DebugPackage>
<Optimize>false</Optimize>
Expand Down
19 changes: 18 additions & 1 deletion Aaru/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Aaru.Gui;
using Aaru.Commands;
using Aaru.Commands.Device;
using Aaru.Commands.Filesystem;
Expand All @@ -46,6 +47,9 @@
using Aaru.Database;
using Aaru.Settings;
using Microsoft.EntityFrameworkCore;
using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.ReactiveUI;

namespace Aaru
{
Expand All @@ -55,7 +59,6 @@ internal class MainClass
static string _assemblyTitle;
static AssemblyInformationalVersionAttribute _assemblyVersion;

[STAThread]
public static int Main(string[] args)
{
object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
Expand All @@ -68,6 +71,13 @@ public static int Main(string[] args)

_assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;

if(args.Length == 1 &&
args[0].ToLowerInvariant() == "gui")
{
return BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}

AaruConsole.WriteLineEvent += System.Console.WriteLine;
AaruConsole.WriteEvent += System.Console.Write;
AaruConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;
Expand Down Expand Up @@ -157,5 +167,12 @@ internal static void PrintCopyright()
AaruConsole.WriteLine("{0}", _assemblyCopyright);
AaruConsole.WriteLine();
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToDebug()
.UseReactiveUI();
}
}

0 comments on commit 142f824

Please sign in to comment.