Skip to content

Commit

Permalink
Add readme and fix look up bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 17, 2024
1 parent 9741315 commit 8253d3f
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 21 deletions.
Binary file added Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Tools/Avalonia.PreviewHost/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<Grid RowDefinitions="Auto *" Background="#ff09161e">
Expand Down
18 changes: 12 additions & 6 deletions src/Tools/Consolonia.PreviewHost/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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))
};
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Tools/Consolonia.PreviewHost/Consolonia.PreviewHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
<ToolCommandName>Consolonia.PreviewHost</ToolCommandName>
</PropertyGroup>

<PropertyGroup>
<PackageIcon>Icon.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\..\Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Consolonia.Core\Consolonia.Core.csproj" />
<ProjectReference Include="..\..\Consolonia.PlatformSupport\Consolonia.PlatformSupport.csproj" />
Expand All @@ -23,14 +33,4 @@
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="$(AvaloniaVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\HeadlessWindow.axaml.cs">
<DependentUpon>HeadlessWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\MainWindow.axaml.cs">
<DependentUpon>MainWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Control? Content

public Control LoadXAML()
{
#pragma warning disable CA1031 // Do not catch general exception types
try
{
string xaml = null!;
Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down
39 changes: 39 additions & 0 deletions src/Tools/Consolonia.PreviewHost/readme.md
Original file line number Diff line number Diff line change
@@ -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 <path-to-axaml-file>|<path-to-project-file>|<path-to-project-directory>
```

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 <path-to-project-file-or-folder> ```

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 . ```

0 comments on commit 8253d3f

Please sign in to comment.