Switched to Gemini for UI

This commit is contained in:
Yoshi Askharoun
2022-05-03 11:53:36 -05:00
parent d738b04a38
commit c0fb203104
19 changed files with 586 additions and 17 deletions
+8 -2
View File
@@ -2,8 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ZuneUIXTools" xmlns:local="clr-namespace:ZuneUIXTools"
StartupUri="MainWindow.xaml"> xmlns:gemini="http://schemas.timjones.io/gemini">
<Application.Resources> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<gemini:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>
+6 -5
View File
@@ -231,18 +231,19 @@ namespace ZuneUIXTools
try try
{ {
Microsoft.Iris.Debug.Trace.EnableAllCategories(true);
Application.Initialize(); Application.Initialize();
} }
catch { } catch { }
try try
{ {
Application.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(uiRoot) ? string.Empty : "#" + uiRoot)); Application.Window.RequestLoad("res://ZuneShellResources!Frame.uix#Frame");
InterpreterContext.UseDecompile = true;
Application.Run();
InterpreterContext.UseDecompile = false;
File.WriteAllText(System.IO.Path.ChangeExtension(compiledFile, $".decomp.uix"), InterpreterContext.DecompileResults.Last().InnerXml); //Application.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(uiRoot) ? string.Empty : "#" + uiRoot));
Application.DebugSettings.UseDecompiler = true;
Application.Run();
Application.DebugSettings.UseDecompiler = false;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -0,0 +1,24 @@
using Gemini.Framework.Commands;
using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
namespace ZuneUIXTools.Modules.Shell.Commands
{
[CommandDefinition]
public class BuildAndRunCommandDefinition : CommandDefinition
{
public const string CommandName = "Project.BuildAndRun";
public override string Name => CommandName;
public override string Text => "Build and Run";
public override string ToolTip => "Compiles the current UIX document and runs it.";
public override Uri IconSource => new("pack://application:,,,/ZuneUIXTools;component/Images/StartWithoutDebug_16x.png");
[Export]
public static CommandKeyboardShortcut KeyGesture = new CommandKeyboardShortcut<BuildAndRunCommandDefinition>(new KeyGesture(Key.F5));
}
}
@@ -0,0 +1,24 @@
using Gemini.Framework.ToolBars;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZuneUIXTools.Modules.Shell.Commands;
namespace ZuneUIXTools.Modules.Shell
{
internal static class ToolBarDefinitions
{
[Export]
public static ToolBarDefinition StandardToolBar = new(0, "Standard");
[Export]
public static ToolBarItemGroupDefinition StandardOpenSaveToolBarGroup = new(StandardToolBar, 8);
[Export]
public static ToolBarItemDefinition OpenFileToolBarItem = new CommandToolBarItemDefinition<BuildAndRunCommandDefinition>(
StandardOpenSaveToolBarGroup, 0);
}
}
@@ -0,0 +1,48 @@
using Caliburn.Micro;
using Gemini.Framework.Services;
using Gemini.Framework.Threading;
using Gemini.Modules.Shell.Views;
using Gemini.Modules.ToolBars;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
namespace ZuneUIXTools.Modules.Shell.ViewModels
{
[Export(typeof(IShell))]
public class ShellViewModel : Gemini.Modules.Shell.ViewModels.ShellViewModel
{
static ShellViewModel()
{
ViewLocator.AddNamespaceMapping(typeof(ShellViewModel).Namespace, typeof(ShellView).Namespace);
}
public override Task<bool> CanCloseAsync(CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource<bool>();
Coroutine.BeginExecute(CanClose().GetEnumerator(), null, (s, e) => tcs.SetResult(!e.WasCancelled));
return tcs.Task;
}
private IEnumerable<IResult> CanClose()
{
yield return new MessageBoxResult();
}
private class MessageBoxResult : IResult
{
public event EventHandler<ResultCompletionEventArgs> Completed;
public void Execute(CoroutineExecutionContext context)
{
var result = System.Windows.MessageBoxResult.Yes;
Completed(this, new ResultCompletionEventArgs { WasCancelled = (result != System.Windows.MessageBoxResult.Yes) });
}
}
}
}
+62
View File
@@ -0,0 +1,62 @@
using Gemini.Framework;
using Gemini.Modules.ErrorList;
using Gemini.Modules.Output;
using Microsoft.Iris.Markup;
using Microsoft.Iris.Session;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
namespace ZuneUIXTools.Modules.Startup
{
[Export(typeof(IModule))]
public class Module : ModuleBase
{
private readonly IOutput _output;
private readonly IErrorList _errorList;
[ImportingConstructor]
public Module(IOutput output, IErrorList errorList)
{
_output = output;
_errorList = errorList;
}
public override void Initialize()
{
Shell.ShowFloatingWindowsInTaskbar = true;
Shell.ToolBars.Visible = true;
//MainWindow.WindowState = WindowState.Maximized;
MainWindow.Title = "Zune UIX Tools";
MainWindow.Icon = new BitmapImage(new Uri("pack://application:,,,/ZuneUIXTools;component/Images/VCSIrisProject.ico"));
MarkupSystem.Startup(true);
ErrorManager.OnErrors += (IList errors) => {
foreach (object obj in errors)
{
if (obj is not ErrorRecord err) continue;
#if DEBUG
System.Diagnostics.Debug.WriteLine(err.Message);
#else
Console.WriteLine(err.Message);
#endif
_errorList.AddItem(err.Warning ? ErrorListItemType.Warning : ErrorListItemType.Error,
err.Message, err.Context, err.Line < 0 ? null : err.Line, err.Column < 0 ? null : err.Column);
}
};
Shell.StatusBar.AddItem("UIX ready", new GridLength(1, GridUnitType.Star));
_output.AppendLine("Initialized UIX markup system");
}
}
}
@@ -0,0 +1,38 @@
using Gemini.Framework;
using Gemini.Framework.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks;
namespace ZuneUIXTools.Modules.UIXCompiled
{
[Export(typeof(IEditorProvider))]
public class UIBEditorProvider : IEditorProvider
{
private static readonly List<string> _extensions = new()
{
".uib",
};
public IEnumerable<EditorFileType> FileTypes
{
get { yield return new EditorFileType("Compiled Microsoft Iris UI", ".uib"); }
}
public bool CanCreateNew => false;
public bool Handles(string path)
{
var extension = Path.GetExtension(path);
return _extensions.Contains(extension.ToLowerInvariant());
}
public IDocument Create() => new UIXCompiledEditorViewModel();
public async Task New(IDocument document, string name) => await ((UIXCompiledEditorViewModel)document).New(name);
public async Task Open(IDocument document, string path) => await ((UIXCompiledEditorViewModel)document).Load(path);
}
}
@@ -0,0 +1,11 @@
<UserControl x:Class="ZuneUIXTools.Modules.UIXCompiled.UIXCompiledEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZuneUIXTools.Modules.UIXCompiled"
xmlns:hexa="clr-namespace:WpfHexaEditor;assembly=WPFHexaEditor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<hexa:HexEditor x:Name="HexEditor" x:FieldModifier="public"/>
</UserControl>
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ZuneUIXTools.Modules.UIXCompiled
{
/// <summary>
/// Interaction logic for UIXCompiledEditorView.xaml
/// </summary>
public partial class UIXCompiledEditorView : UserControl
{
public UIXCompiledEditorView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,65 @@
using Gemini.Framework;
using Gemini.Framework.Threading;
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace ZuneUIXTools.Modules.UIXCompiled
{
[Export(typeof(UIXCompiledEditorViewModel))]
#pragma warning disable 659
public class UIXCompiledEditorViewModel : PersistedDocument
#pragma warning restore 659
{
private UIXCompiledEditorView _view;
private byte[] _originalBytes;
protected override Task DoNew()
{
_originalBytes = Array.Empty<byte>();
ApplyOriginalText();
return TaskUtility.Completed;
}
protected override Task DoLoad(string filePath)
{
_originalBytes = File.ReadAllBytes(filePath);
ApplyOriginalText();
return TaskUtility.Completed;
}
protected override Task DoSave(string filePath)
{
_view.HexEditor.SaveCurrentState(filePath);
_originalBytes = _view.HexEditor.GetAllBytes();
return TaskUtility.Completed;
}
private void ApplyOriginalText()
{
_view.HexEditor.Stream?.Dispose();
_view.HexEditor.Stream = new MemoryStream(_originalBytes);
_view.HexEditor.UpdateVisual();
_view.HexEditor.BytesModified += delegate
{
IsDirty = !_originalBytes.SequenceEqual(_view.HexEditor.GetAllBytes());
};
}
protected override void OnViewLoaded(object view)
{
_view = (UIXCompiledEditorView)view;
}
public override bool Equals(object obj)
{
var other = obj as UIXCompiledEditorViewModel;
return other != null
&& string.Equals(FilePath, other.FilePath, StringComparison.InvariantCultureIgnoreCase)
&& string.Equals(FileName, other.FileName, StringComparison.InvariantCultureIgnoreCase);
}
}
}
@@ -0,0 +1,38 @@
using Gemini.Framework;
using Gemini.Framework.Services;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks;
namespace ZuneUIXTools.Modules.UIXSource
{
[Export(typeof(IEditorProvider))]
public class UIXEditorProvider : IEditorProvider
{
private static readonly List<string> _extensions = new()
{
".uix",
".xml"
};
public IEnumerable<EditorFileType> FileTypes
{
get { yield return new EditorFileType("Microsoft Iris UI", ".uix"); }
}
public bool CanCreateNew => true;
public bool Handles(string path)
{
var extension = Path.GetExtension(path);
return _extensions.Contains(extension.ToLowerInvariant());
}
public IDocument Create() => new UIXSourceEditorViewModel();
public async Task New(IDocument document, string name) => await ((UIXSourceEditorViewModel)document).New(name);
public async Task Open(IDocument document, string path) => await ((UIXSourceEditorViewModel)document).Load(path);
}
}
@@ -0,0 +1,14 @@
<UserControl x:Class="ZuneUIXTools.Modules.UIXSource.UIXSourceEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZuneUIXTools.Modules.UIXSource"
xmlns:codeeditor="clr-namespace:Gemini.Modules.CodeEditor.Controls;assembly=Gemini.Modules.CodeEditor"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<codeeditor:CodeEditor x:Name="CodeEditor" x:FieldModifier="public" SyntaxHighlighting="XML"
ShowLineNumbers="True" />
</Grid>
</UserControl>
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ZuneUIXTools.Modules.UIXSource
{
/// <summary>
/// Interaction logic for UIXSourceEditorView.xaml
/// </summary>
public partial class UIXSourceEditorView : UserControl
{
public UIXSourceEditorView()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,157 @@
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Gemini.Framework;
using Gemini.Framework.Commands;
using Gemini.Framework.Threading;
using Microsoft.Iris;
using Microsoft.Iris.Markup;
using ZuneUIXTools.Modules.Shell.Commands;
using Application = Microsoft.Iris.Application;
using Command = Gemini.Framework.Commands.Command;
namespace ZuneUIXTools.Modules.UIXSource
{
[Export(typeof(UIXSourceEditorViewModel))]
#pragma warning disable 659
public class UIXSourceEditorViewModel : PersistedDocument, ICommandHandler<BuildAndRunCommandDefinition>
#pragma warning restore 659
{
private UIXSourceEditorView _view;
private string _originalText;
protected override Task DoNew()
{
_originalText = string.Empty;
ApplyOriginalText();
return TaskUtility.Completed;
}
protected override Task DoLoad(string filePath)
{
_originalText = File.ReadAllText(filePath);
ApplyOriginalText();
return TaskUtility.Completed;
}
protected override Task DoSave(string filePath)
{
_view.CodeEditor.Save(filePath);
_originalText = _view.CodeEditor.Text;
return TaskUtility.Completed;
}
private void ApplyOriginalText()
{
_view.CodeEditor.Text = _originalText;
_view.CodeEditor.TextChanged += delegate
{
IsDirty = string.Compare(_originalText, _view.CodeEditor.Text) != 0;
};
}
protected override void OnViewLoaded(object view)
{
_view = (UIXSourceEditorView)view;
}
public override bool Equals(object obj)
{
var other = obj as UIXSourceEditorViewModel;
return other != null
&& string.Equals(FilePath, other.FilePath, StringComparison.InvariantCultureIgnoreCase)
&& string.Equals(FileName, other.FileName, StringComparison.InvariantCultureIgnoreCase);
}
void ICommandHandler<BuildAndRunCommandDefinition>.Update(Command command)
{
command.Enabled = !string.IsNullOrWhiteSpace(_view.CodeEditor.Text);
}
Task ICommandHandler<BuildAndRunCommandDefinition>.Run(Command command)
{
var _buildThread = new Thread(new ThreadStart(BuildAndRun));
_buildThread.SetApartmentState(ApartmentState.STA);
_buildThread.IsBackground = true;
_buildThread.Start();
return TaskUtility.Completed;
}
private void BuildAndRun()
{
string sourceFile = FilePath;
string compiledFile = Path.ChangeExtension(sourceFile, "uib");
bool isSuccess = false;
try
{
isSuccess = MarkupCompiler.Compile(
new[]
{
new CompilerInput()
{
SourceFileName = sourceFile,
OutputFileName = compiledFile
}
},
new CompilerInput()
);
}
catch (Exception ex)
{
//Dispatcher.Invoke(() =>
//{
// ErrorPanel.Children.Add(new TextBlock
// {
// Text = $"Build failed: {ex.Message}",
// Margin = new Thickness(0, 0, 0, 4)
// });
//});
}
if (!isSuccess)
{
var dialogResult = MessageBox.Show(
"There were build errors. Would you like to contine and run the last successful build?",
"Zune UIX Tools", MessageBoxButton.YesNo, MessageBoxImage.Information
);
if (dialogResult != MessageBoxResult.Yes)
return;
}
try
{
Application.Initialize();
}
catch { }
try
{
string uiRoot = null;// (IrisProject.SelectedDocument as UIXDocumentViewModel)?.UIRoot;
Application.Window.SetBackgroundColor(new WindowColor(0xE6, 0xE6, 0xE6));
Application.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(uiRoot) ? string.Empty : "#" + uiRoot));
Application.Window.CloseRequested += (object sender, WindowCloseRequestedEventArgs args) =>
{
args.BlockCloseRequest();
Application.Window.Visible = false;
};
Application.Run();
}
catch (Exception ex)
{
//Dispatcher.Invoke(() =>
//{
// ErrorPanel.Children.Add(new TextBlock
// {
// Text = $"Load failed: {ex.Message}",
// Margin = new Thickness(0, 0, 0, 4)
// });
//});
}
}
}
}
+9 -10
View File
@@ -21,21 +21,20 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.1.1" /> <PackageReference Include="GeminiWpf" Version="1.0.44-beta" />
<PackageReference Include="Syncfusion.SfSkinManager.WPF" Version="19.1.0.54" /> <PackageReference Include="Gemini.Modules.Output" Version="1.0.44-beta" />
<PackageReference Include="Syncfusion.Themes.Blend.WPF" Version="19.1.0.54" /> <PackageReference Include="Gemini.Modules.ErrorList" Version="1.0.44-beta" />
<PackageReference Include="Syncfusion.Themes.FluentDark.WPF" Version="19.1.0.54" /> <PackageReference Include="Gemini.Modules.CodeEditor" Version="1.0.44-beta" />
<PackageReference Include="Syncfusion.Themes.MaterialLight.WPF" Version="19.1.0.54" /> <PackageReference Include="WPFHexaEditor" Version="2.1.7" />
<PackageReference Include="Syncfusion.Themes.Metro.WPF" Version="19.1.0.54" />
<PackageReference Include="Syncfusion.Themes.Office2019Colorful.WPF" Version="19.1.0.54" />
<PackageReference Include="Syncfusion.Themes.VisualStudio2015.WPF" Version="19.1.0.54" />
<PackageReference Include="Syncfusion.Tools.WPF" Version="19.1.0.54" />
<ProjectReference Include="..\..\..\ZuneDev\ZuneShell.dll\UIX\UIX.csproj" /> <ProjectReference Include="..\..\..\ZuneDev\ZuneShell.dll\UIX\UIX.csproj" />
<ProjectReference Include="..\ZuneUIXTools.ViewModels\ZuneUIXTools.ViewModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<LibFiles Include="lib\**\*.*" /> <LibFiles Include="lib\**\*.*" />
<Compile Remove="MainWindow.xaml.cs" />
<Page Remove="MainWindow.xaml" />
<None Include="MainWindow.xaml" />
<None Include="MainWindow.xaml.cs" />
<None Update="lib\UIX.renderapi.dll" /> <None Update="lib\UIX.renderapi.dll" />
<None Update="lib\UIXrender.dll" /> <None Update="lib\UIXrender.dll" />
<None Update="lib\UIXsup.dll" /> <None Update="lib\UIXsup.dll" />
+8
View File
@@ -0,0 +1,8 @@
<UIX xmlns="http://schemas.microsoft.com/2007/uix">
<UI Name="Default" />
<UI Name="Dialog">
<Properties>
<ProxyObject Name="Helper" />
</Properties>
</UI>
</UIX>
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
<UIX xmlns="http://schemas.microsoft.com/2007/uix"
xmlns:dialog="res://ZuneShellResources!Dialog.uix"
xmlns:ctrDialog="res://UIXControls!Dialog.uix"
xmlns:zune="assembly://ZuneShell/ZuneUI">
<UI Name="Default">
<Content>
<zune:ZuneShell>
<Content>
<dialog:DarkDialogUI Model="{zune:StringId.IDS_PLAYLIST_EMPTY}">
<Popup>
<ctrDialog:Dialog/>
</Popup>
</dialog:DarkDialogUI>
</Content>
</zune:ZuneShell>
</Content>
</UI>
</UIX>
BIN
View File
Binary file not shown.