diff --git a/Icon.png b/Icon.png new file mode 100644 index 00000000..a2eb4171 Binary files /dev/null and b/Icon.png differ diff --git a/src/Tools/Avalonia.PreviewHost/Assets/avalonia-logo.ico b/src/Tools/Avalonia.PreviewHost/Assets/avalonia-logo.ico deleted file mode 100644 index da8d49ff..00000000 Binary files a/src/Tools/Avalonia.PreviewHost/Assets/avalonia-logo.ico and /dev/null differ diff --git a/src/Tools/Avalonia.PreviewHost/Assets/consolonia-logo.ico b/src/Tools/Avalonia.PreviewHost/Assets/consolonia-logo.ico new file mode 100644 index 00000000..34d4a73c Binary files /dev/null and b/src/Tools/Avalonia.PreviewHost/Assets/consolonia-logo.ico differ diff --git a/src/Tools/Avalonia.PreviewHost/Views/MainWindow.axaml b/src/Tools/Avalonia.PreviewHost/Views/MainWindow.axaml index a2fb7530..87738b52 100644 --- a/src/Tools/Avalonia.PreviewHost/Views/MainWindow.axaml +++ b/src/Tools/Avalonia.PreviewHost/Views/MainWindow.axaml @@ -8,7 +8,7 @@ mc:Ignorable="d" x:Class="PreviewHost.Views.MainWindow" x:DataType="vm:MainViewModel" - Icon="/Assets/avalonia-logo.ico" + Icon="/Assets/consolonia-logo.ico" Title="PreviewHost"> diff --git a/src/Tools/Consolonia.PreviewHost/App.axaml.cs b/src/Tools/Consolonia.PreviewHost/App.axaml.cs index 963d5cf7..0cc3b815 100644 --- a/src/Tools/Consolonia.PreviewHost/App.axaml.cs +++ b/src/Tools/Consolonia.PreviewHost/App.axaml.cs @@ -1,12 +1,9 @@ using System.Globalization; -using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Avalonia.Media; using Consolonia.Core.Infrastructure; using Consolonia.PreviewHost.Views; using Consolonia.PreviewHost.ViewModels; -using Consolonia.Themes.TurboVision.Templates; namespace Consolonia.PreviewHost { @@ -38,15 +35,24 @@ public override void OnFrameworkInitializationCompleted() var path = applicationLifetime.Args!.FirstOrDefault(); if (!String.IsNullOrEmpty(path)) { - path = Path.GetFullPath(path); - var projectFile = FindProjectFileFromPath(path); + string folder; + if (Path.IsPathFullyQualified(path)) + { + folder = Path.GetDirectoryName(path)!; + } + else + folder = Environment.CurrentDirectory; + ArgumentNullException.ThrowIfNull(folder); + var projectFile = FindProjectFileFromPath(folder); appViewModel.Project = new ProjectViewModel(projectFile); if (path.EndsWith(".axaml", StringComparison.OrdinalIgnoreCase)) { applicationLifetime!.MainWindow = new HeadlessWindow() { - DataContext = appViewModel.Project.Files.Single(f => f.FullName!.Equals(path, StringComparison.OrdinalIgnoreCase)) + DataContext = appViewModel.Project.Files.SingleOrDefault(f => f.FullName!.Equals(path, StringComparison.OrdinalIgnoreCase)) + ?? appViewModel.Project.Files.SingleOrDefault(f => f.Name!.Equals(Path.GetFileName(path), StringComparison.OrdinalIgnoreCase)) + ?? throw new ArgumentException($"{path} not found in project", nameof(path)) }; } } diff --git a/src/Tools/Consolonia.PreviewHost/Consolonia.PreviewHost.csproj b/src/Tools/Consolonia.PreviewHost/Consolonia.PreviewHost.csproj index 1bd46584..d9b8bc36 100644 --- a/src/Tools/Consolonia.PreviewHost/Consolonia.PreviewHost.csproj +++ b/src/Tools/Consolonia.PreviewHost/Consolonia.PreviewHost.csproj @@ -9,6 +9,16 @@ Consolonia.PreviewHost + + Icon.png + readme.md + + + + + + + @@ -23,14 +33,4 @@ - - - HeadlessWindow.axaml - - - MainWindow.axaml - - - - diff --git a/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json b/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json index 9012424f..27103143 100644 --- a/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json +++ b/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json @@ -6,7 +6,7 @@ }, "Consolonia.PreviewHost": { "commandName": "Project", - "commandLineArgs": "S:\\github\\Consolonia\\src\\Consolonia.Gallery", + "commandLineArgs": "GalleryTextBlock.axaml", "workingDirectory": "S:\\github\\Consolonia\\src\\Consolonia.Gallery" } } diff --git a/src/Tools/Consolonia.PreviewHost/ViewModels/XamlFileViewModel.cs b/src/Tools/Consolonia.PreviewHost/ViewModels/XamlFileViewModel.cs index 55dc2da9..76dca900 100644 --- a/src/Tools/Consolonia.PreviewHost/ViewModels/XamlFileViewModel.cs +++ b/src/Tools/Consolonia.PreviewHost/ViewModels/XamlFileViewModel.cs @@ -56,6 +56,7 @@ public Control? Content public Control LoadXAML() { +#pragma warning disable CA1031 // Do not catch general exception types try { string xaml = null!; @@ -83,11 +84,11 @@ public Control LoadXAML() var content = AvaloniaRuntimeXamlLoader.Load(xaml, Assembly, designMode: true); if (content is Control control) { - Application.Current.TryGetResource("ThemeBorderBrush", null, out var borderBrush); + Application.Current!.TryGetResource("ThemeBorderBrush", null, out var borderBrush); var panel = new Border() { BorderThickness = new Thickness(0,0,0,0), - BorderBrush = (IBrush)borderBrush + BorderBrush = (IBrush)borderBrush! }; panel.Child = control; @@ -114,10 +115,11 @@ public Control LoadXAML() return new TextBlock() { Text = "Root element is not a control" }; } } - catch (XmlException e) + catch (Exception e) { return new TextBlock() { Text = e.Message }; } +#pragma warning restore CA1031 // Do not catch general exception types } private void WatchFileChanges() diff --git a/src/Tools/Consolonia.PreviewHost/readme.md b/src/Tools/Consolonia.PreviewHost/readme.md new file mode 100644 index 00000000..ad5c8ac8 --- /dev/null +++ b/src/Tools/Consolonia.PreviewHost/readme.md @@ -0,0 +1,39 @@ +# Consolonia.PreviewHost +This is a tool which enables a live view of a consolonia axaml file, or a consolonia project. + +## Installation +To install the tool, you can use the following command: +``` +dotnet tool install -g Consolonia.PreviewHost +``` + +## Usage +To use the tool, you can use the following command: +``` +Consolonia.PreviewHost || +``` + +It will monitor the file or directory for changes, and will automatically update the preview when changes are detected. + +Run the following command to monitor the project or folder: + +``` Conoslonia.PreviewHost ``` + +Run following command to monitor a given .axaml file. + +``` Conoslonia.PreviewHost <.axaml file name> ``` + +> NOTE: In single file mode the tool will exit when you hit escape key + +### Running inside Visual Studio +1. Open the solution in Visual Studio. +1. Open a Terminal (View -> Terminal). +3. run the following command +``` Consolonia.PreviewHost . ``` + +### Running inside Visual Studio Code +To integrate the tool with Visual Studio Code, you can use the following steps: +1. Open the project directory in Visual Studio Code. +2. Open a terminal inside of visual studio code +3. run the following command +``` Consolonia.PreviewHost . ```