Remove ignored MainWindow

This commit is contained in:
Yoshi Askharoun
2023-05-22 21:42:41 -05:00
parent e675f23cc1
commit bc6ba48e24
3 changed files with 0 additions and 466 deletions
-93
View File
@@ -1,93 +0,0 @@
<Window x:Class="ZuneUIXTools.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZuneUIXTools"
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:syncfusionskin="clr-namespace:Syncfusion.SfSkinManager;assembly=Syncfusion.SfSkinManager.WPF"
mc:Ignorable="d"
Title="Zune UIX Tools" Height="800" Width="1000"
syncfusionskin:SfSkinManager.Theme="{syncfusionskin:SkinManagerExtension ThemeName=VisualStudio2015}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<syncfusion:MenuAdv>
<syncfusion:MenuItemAdv Header="File">
<syncfusion:MenuItemAdv Header="Open..." Click="Open_Click">
<syncfusion:MenuItemAdv.Icon>
<Image Source="Images/OpenProject_16x.png" Height="16" Width="16"/>
</syncfusion:MenuItemAdv.Icon>
</syncfusion:MenuItemAdv>
<syncfusion:MenuItemAdv Header="Save" Click="Save_Click">
<syncfusion:MenuItemAdv.Icon>
<Image Source="Images/Save_16x.png" Height="16" Width="16"/>
</syncfusion:MenuItemAdv.Icon>
</syncfusion:MenuItemAdv>
<syncfusion:MenuItemAdv Header="Save As..." Click="SaveAs_Click">
<syncfusion:MenuItemAdv.Icon>
<Image Source="Images/SaveAs_16x.png" Height="16" Width="16"/>
</syncfusion:MenuItemAdv.Icon>
</syncfusion:MenuItemAdv>
</syncfusion:MenuItemAdv>
<syncfusion:MenuItemAdv Header="Edit" />
<syncfusion:MenuItemAdv Header="Build">
<syncfusion:MenuItemAdv Header="Build" Click="Build_Click">
<syncfusion:MenuItemAdv.Icon>
<Image Source="Images/BuildSolution_16x.png" Height="16" Width="16"/>
</syncfusion:MenuItemAdv.Icon>
</syncfusion:MenuItemAdv>
<syncfusion:MenuItemAdv Header="Build and Run" Click="BuildAndRun_Click">
<syncfusion:MenuItemAdv.Icon>
<Image Source="Images/StartWithoutDebug_16x.png" Height="16" Width="16"/>
</syncfusion:MenuItemAdv.Icon>
</syncfusion:MenuItemAdv>
</syncfusion:MenuItemAdv>
</syncfusion:MenuAdv>
<syncfusion:ToolBarAdv Name="ToolBar" Grid.Row="1">
<syncfusion:SplitButton ToolTip="Build and Run" SmallIcon="Images/StartWithoutDebug_16x.png" Label="Build and Run"
Click="BuildAndRun_Click"/>
<syncfusion:ButtonAdv ToolTip="Decompile" SmallIcon="Images/SaveAs_16x.png" Label="Decompile"
Click="Decompile_Click"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="UI Root" VerticalAlignment="Center" Margin="8,0,4,0"/>
<TextBox Name="UIRootBox" ToolTip="The UI element to load and display" MinWidth="150"/>
</StackPanel>
</syncfusion:ToolBarAdv>
<syncfusion:DockingManager x:Name="DockingManager" Grid.Row="2" ContainerMode="TDI">
<ContentControl x:Name="SolutionExplorer" syncfusion:DockingManager.Header="Solution Explorer"
syncfusion:DockingManager.State="Dock" syncfusion:DockingManager.SideInDockedMode="Right"
syncfusion:DockingManager.DesiredWidthInDockedMode="200">
<syncfusion:TreeViewAdv>
<syncfusion:TreeViewItemAdv Header="Hello">
<syncfusion:TreeViewItemAdv Header="Subhello"/>
</syncfusion:TreeViewItemAdv>
</syncfusion:TreeViewAdv>
</ContentControl>
<ContentControl x:Name="ToolBox" syncfusion:DockingManager.Header="Toolbox"
syncfusion:DockingManager.State="AutoHidden"/>
<ContentControl x:Name="Properties" syncfusion:DockingManager.Header="Properties" syncfusion:DockingManager.State="AutoHidden">
<StackPanel>
<CheckBox x:Name="IncludeInProject" Content="Include in project"/>
</StackPanel>
</ContentControl>
<ContentControl x:Name="ErrorList" syncfusion:DockingManager.Header="Error List" syncfusion:DockingManager.DesiredHeightInDockedMode="200"
syncfusion:DockingManager.State="Dock" syncfusion:DockingManager.SideInDockedMode="Bottom">
<ScrollViewer Grid.Row="3">
<StackPanel Name="ErrorPanel" Margin="4,4,4,0"/>
</ScrollViewer>
</ContentControl>
</syncfusion:DockingManager>
</Grid>
</Window>
-369
View File
@@ -1,369 +0,0 @@
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using Microsoft.Iris;
using Microsoft.Iris.Markup;
using Microsoft.Iris.Session;
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using ZuneUIXTools.ViewModels;
using Application = Microsoft.Iris.Application;
using Window = System.Windows.Window;
namespace ZuneUIXTools
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private const string FILE_FORMAT_FILTER = "Microsoft Iris UI (*.uix)|*.uix|Microsoft Iris Compiled UI (*.uib)|*.uib|XML files (*.xml)|*.xml|All Files|*.*";
private readonly FontFamily CODE_FONT = new FontFamily("JetBrains Mono");
public IrisProjectViewModel IrisProject { get; } = new IrisProjectViewModel
{
Name = "IrisApp1",
UIXDocuments = new System.Collections.ObjectModel.ObservableCollection<DocumentViewModelBase>()
};
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private void RemoveDocument(string fileName)
{
FrameworkElement elem = GetDocumentUI(fileName);
if (elem != null)
DockingManager.Children.Remove(elem);
}
private void AddDocument(DocumentViewModelBase doc)
{
// <avalonEdit:TextEditor Name="textEditor" Grid.Row="1" Padding="4" ShowLineNumbers="True"
// SyntaxHighlighting="XML" FontFamily="JetBrains Mono" FontSize="10pt" />
var editor = new TextEditor()
{
Tag = doc.FileName,
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML"),
Padding = new Thickness(4),
ShowLineNumbers = true,
FontFamily = CODE_FONT,
FontSize = 15
};
editor.Load(doc.FileName);
DockingManager.Children.Add(editor);
editor.GotFocus += EditorGotFocus;
Syncfusion.Windows.Tools.Controls.DockingManager.ChangeState(editor, Syncfusion.Windows.Tools.Controls.DockState.Document);
Syncfusion.Windows.Tools.Controls.DockingManager.SetHeader(editor, System.IO.Path.GetFileName(doc.FileName));
}
private FrameworkElement GetDocumentUI(string fileName)
{
FrameworkElement elem = null;
foreach (FrameworkElement candidate in DockingManager.Children)
{
if (candidate.Tag?.ToString() == fileName)
{
elem = candidate;
break;
}
}
return elem;
}
private void SetSelectedDocument(string fileName)
{
IrisProject.SelectedDocument = IrisProject.UIXDocuments.First(doc => doc.FileName == fileName);
}
private void EditorGotFocus(object sender, RoutedEventArgs e)
{
if (sender is FrameworkElement elem)
SetSelectedDocument(elem.Tag.ToString());
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
IrisProject.UIXDocuments.CollectionChanged += UIXDocuments_CollectionChanged;
MarkupSystem.Startup(true);
ErrorManager.OnErrors += (IList errors) => {
foreach (object obj in errors)
{
if (!(obj is ErrorRecord err)) continue;
#if DEBUG
System.Diagnostics.Debug.WriteLine(err.Message);
#else
Console.WriteLine(err.Message);
#endif
Dispatcher.Invoke(() =>
{
TextBlock errBlock = new TextBlock
{
Text = $"{err.Context}, Ln {err.Line}, Col {err.Column}: {err.Message}",
Margin = new Thickness(0, 0, 0, 4)
};
if (err.Line >= 0 && err.Column >= 0)
{
errBlock.MouseDown += (object s, MouseButtonEventArgs args) =>
{
try
{
string fileName = new Uri(err.Context).LocalPath;
var editor = (TextEditor)GetDocumentUI(fileName);
// Highlight the error in the code editor
int offset = editor.Document.GetOffset(err.Line, err.Column);
editor.SelectionStart = offset;
editor.SelectionLength = 1;
editor.ScrollTo(err.Line, err.Column);
}
catch { }
};
}
ErrorPanel.Children.Add(errBlock);
});
}
};
}
private void UIXDocuments_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
foreach (DocumentViewModelBase doc in e.OldItems)
RemoveDocument(doc.FileName);
if (e.NewItems != null)
foreach (DocumentViewModelBase doc in e.NewItems)
AddDocument(doc);
}
private void BuildAndRun()
{
string sourceFile = IrisProject.SelectedDocument.FileName;
string compiledFile = System.IO.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 = System.Windows.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 = (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)
});
});
}
}
private void Decompile()
{
string compiledFile = IrisProject.SelectedDocument.FileName;
string uiRoot = (IrisProject.SelectedDocument as CompiledUIXDocumentViewModel)?.UIRoot;
try
{
Microsoft.Iris.Debug.Trace.EnableAllCategories(true);
Application.Initialize();
}
catch { }
try
{
Application.Window.RequestLoad("res://ZuneShellResources!Frame.uix#Frame");
//Application.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(uiRoot) ? string.Empty : "#" + uiRoot));
Application.DebugSettings.UseDecompiler = true;
Application.Run();
Application.DebugSettings.UseDecompiler = false;
}
catch (Exception ex)
{
Dispatcher.Invoke(() =>
{
System.Windows.MessageBox.Show(
$"Failed to decompile '{compiledFile}'",
"Zune UIX Tools", MessageBoxButton.OK, MessageBoxImage.Error
);
System.Diagnostics.Debug.WriteLine(ex.ToString());
TextBlock errBlock = new TextBlock
{
Text = ex.ToString(),
Margin = new Thickness(0, 0, 0, 4)
};
ErrorPanel.Children.Add(errBlock);
});
}
finally
{
// Even if there were errors, save the decomp results.
var results = Application.DebugSettings.DecompileResults;
if (results != null && results.Count > 0)
{
for (int i = 0; i < results.Count; i++)
{
var result = results[i];
File.WriteAllText(Path.ChangeExtension(compiledFile, $"{i}.decomp.uix"), result.InnerXml);
}
}
}
}
private void Build_Click(object sender, RoutedEventArgs e)
{
// TODO: Build the project without running it
BuildAndRun_Click(sender, e);
}
private void BuildAndRun_Click(object sender, RoutedEventArgs e)
{
var doc = IrisProject.SelectedDocument;
if (doc == null)
return;
// Save changes before running
((TextEditor)GetDocumentUI(doc.FileName)).Save(doc.FileName);
// Set UI root
if (doc is UIXDocumentViewModel uixDoc)
uixDoc.UIRoot = UIRootBox.Text;
else if (doc is CompiledUIXDocumentViewModel uibDoc)
uibDoc.UIRoot = UIRootBox.Text;
else
throw new ArgumentException();
// Clear error list
ErrorPanel.Children.Clear();
var _buildThread = new Thread(new ThreadStart(BuildAndRun));
_buildThread.SetApartmentState(ApartmentState.STA);
_buildThread.IsBackground = true;
_buildThread.Start();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = FILE_FORMAT_FILTER
};
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
IrisProject.LoadDocument(openFileDialog.FileName);
}
private void Save_Click(object sender, RoutedEventArgs e)
{
var doc = IrisProject.SelectedDocument;
if (doc == null)
return;
var editor = GetDocumentUI(doc.FileName) as TextEditor;
editor.Save(doc.FileName);
}
private void SaveAs_Click(object sender, RoutedEventArgs e)
{
if (IrisProject.SelectedDocument == null)
return;
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = FILE_FORMAT_FILTER,
FileName = IrisProject.SelectedDocument.FileName
};
if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
var editor = GetDocumentUI(IrisProject.SelectedDocument.FileName) as TextEditor;
editor.Save(saveFileDialog.FileName);
IrisProject.LoadDocument(saveFileDialog.FileName);
}
private void Decompile_Click(object sender, RoutedEventArgs e)
{
if (!(IrisProject.SelectedDocument is CompiledUIXDocumentViewModel doc))
return;
// Set UI root
doc.UIRoot = UIRootBox.Text;
// Clear error list
ErrorPanel.Children.Clear();
var _decompThread = new Thread(new ThreadStart(Decompile));
_decompThread.SetApartmentState(ApartmentState.STA);
_decompThread.IsBackground = true;
_decompThread.Start();
}
}
}
-4
View File
@@ -33,10 +33,6 @@
<ItemGroup>
<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\UIXrender.dll" />
<None Update="lib\UIXsup.dll" />