Added basic edit-and-run functionality to IDE

This commit is contained in:
Joshua Askharoun
2021-04-04 01:15:52 -05:00
parent fcb2d5643c
commit 29c5d85c49
11 changed files with 146 additions and 23 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

+38 -1
View File
@@ -4,9 +4,46 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZuneUIXTools" xmlns:local="clr-namespace:ZuneUIXTools"
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="Zune UIX Tools" Height="450" Width="800">
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MaxHeight="400"/>
</Grid.RowDefinitions>
<Ribbon Title="Microsoft Iris IDE">
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu SmallImageSource="Images/ZuneShell.ico" Background="Black" BorderBrush="Black">
<RibbonApplicationMenuItem Header="Open" ImageSource="Images/OpenProject_16x.png"
KeyTip="O" Click="Open_Click" />
<RibbonApplicationMenuItem Header="Save" ImageSource="Images/Save_16x.png" KeyTip="S" />
<RibbonApplicationSplitMenuItem Header="Save As" ImageSource="Images/SaveAs_16x.png" KeyTip="Shift+S"/>
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab Header="Home">
<RibbonGroup Header="Build">
<RibbonButton Label="Build" SmallImageSource="Images/BuildSolution_16x.png" Click="Build_Click"/>
<RibbonButton Label="Start Without Debugging" SmallImageSource="Images/StartWithoutDebug_16x.png"/>
<RibbonTextBox Name="UIRootBox" Label="UI Root" ToolTip="The UI element to load and display"/>
</RibbonGroup>
</RibbonTab>
</Ribbon>
<avalonEdit:TextEditor Name="textEditor" Grid.Row="1" Padding="4" ShowLineNumbers="True"
SyntaxHighlighting="XML" FontFamily="JetBrains Mono" FontSize="10pt"/>
<GridSplitter Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="LightGray"
ShowsPreview="True"
Height="5" />
<StackPanel Name="ErrorPanel" Grid.Row="3" Margin="4,4,4,0"/>
</Grid> </Grid>
</Window> </Window>
+86 -17
View File
@@ -1,8 +1,13 @@
using Microsoft.Iris; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.AvalonEdit.Rendering;
using Microsoft.Iris;
using Microsoft.Iris.Markup; using Microsoft.Iris.Markup;
using Microsoft.Iris.Session; using Microsoft.Iris.Session;
using System; using System;
using System.Collections; using System.Collections;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@@ -11,6 +16,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -25,6 +31,9 @@ namespace ZuneUIXTools
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public string DocumentPath { get; set; }
public string UIRoot { get; set; }
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
@@ -34,51 +43,111 @@ namespace ZuneUIXTools
private void MainWindow_Loaded(object sender, RoutedEventArgs e) private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ {
Thread newWindowThread = new Thread(new ThreadStart(TestCompile));
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
newWindowThread.Start();
} }
private void TestCompile() private void BuildAndRun()
{ {
MarkupSystem.Startup(true); MarkupSystem.Startup(true);
ErrorManager.OnErrors += (IList errors) => { ErrorManager.OnErrors += (IList errors) => {
foreach (object obj in errors) foreach (object obj in errors)
{ {
var err = obj as ErrorRecord; if (!(obj is ErrorRecord err)) continue;
if (err == null) continue;
#if DEBUG #if DEBUG
System.Diagnostics.Debug.WriteLine(err.Message); System.Diagnostics.Debug.WriteLine(err.Message);
System.Diagnostics.Debugger.Break(); //System.Diagnostics.Debugger.Break();
#else #else
Console.WriteLine(err.Message); Console.WriteLine(err.Message);
#endif #endif
Dispatcher.Invoke(() =>
{
ErrorPanel.Children.Add(new TextBlock
{
Text = $"Ln {err.Line}, Col {err.Column}: {err.Message}",
Margin = new Thickness(0, 0, 0, 4)
});
// Highlight the error in the code editor
int offset = textEditor.Document.GetOffset(err.Line, err.Column);
textEditor.SelectionStart = offset;
//textEditor.SelectionLength = err.
//var anchor = textEditor.Document.CreateAnchor(offset);
//textEditor.Document.GetLineByOffset(offset)
});
} }
}; };
string testDir = @"D:\Repos\yoshiask\ZuneUIXTools\test\"; string compiledFile = System.IO.Path.ChangeExtension(DocumentPath, "uib");
string testName = "text";
string sourceFile = System.IO.Path.Combine(testDir, testName) + ".uix";
string compiledFile = System.IO.Path.Combine(testDir, testName) + ".uib";
bool isSuccess = MarkupCompiler.Compile( bool isSuccess = MarkupCompiler.Compile(
new[] new[]
{ {
new CompilerInput() new CompilerInput()
{ {
SourceFileName = sourceFile, SourceFileName = DocumentPath,
OutputFileName = compiledFile OutputFileName = compiledFile
} }
}, },
new CompilerInput() new CompilerInput()
); );
try
{
Microsoft.Iris.Application.Initialize(); Microsoft.Iris.Application.Initialize();
Microsoft.Iris.Application.Window.SetBackgroundColor(new WindowColor(80, 0, 0)); }
Microsoft.Iris.Application.Window.RequestLoad("file://" + compiledFile + "#TextDisplay"); catch { }
try
{
Microsoft.Iris.Application.Window.SetBackgroundColor(new WindowColor(0xE6, 0xE6, 0xE6));
Microsoft.Iris.Application.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(UIRoot) ? string.Empty : "#" + UIRoot));
Microsoft.Iris.Application.Run(); Microsoft.Iris.Application.Run();
} }
catch (Exception ex)
{
Dispatcher.Invoke(() =>
ErrorPanel.Children.Add(new TextBlock
{
Text = $"Load Failed: {ex.Message}",
Margin = new Thickness(0, 0, 0, 4)
})
);
}
//Microsoft.Iris.Application.Window.
//Microsoft.Iris.Application.Shutdown();
// This code is run AFTER the Iris window is closed
}
private void Build_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(DocumentPath))
return;
// Save changes before running
textEditor.Save(DocumentPath);
// Set UI root
UIRoot = UIRootBox.Text;
Thread newWindowThread = new Thread(new ThreadStart(BuildAndRun));
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
newWindowThread.Start();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Microsoft Iris UI (*.uix)|*.uix|XML files (*.xml)|*.xml"
};
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
DocumentPath = openFileDialog.FileName;
textEditor.Load(DocumentPath);
}
} }
} }
+10
View File
@@ -6,6 +6,16 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Include="Images\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.1.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZuneShell\UIX\UIX.csproj" /> <ProjectReference Include="..\..\ZuneShell\UIX\UIX.csproj" />
</ItemGroup> </ItemGroup>
BIN
View File
Binary file not shown.
+10 -3
View File
@@ -1,9 +1,16 @@
<UIX xmlns="http://schemas.microsoft.com/2007/uix"> <UIX xmlns="http://schemas.microsoft.com/2007/uix">
<UI Name="UIRootTest"> <UI Name="Default">
<Content> <Content>
<Text> <Text Color="Red">
<Content>Howdy from Microsoft.Iris!</Content> <Content>Howdy from Microsoft.Iris!</Content>
<Color>white</Color> </Text>
</Content>
</UI>
<UI Name="Alt">
<Content>
<Text Color="Blue" Font="JetBrains Mono">
<Content>This is some blue text</Content>
</Text> </Text>
</Content> </Content>
</UI> </UI>