mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Improved IDE exception handling
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
xmlns:local="clr-namespace:ZuneUIXTools"
|
xmlns:local="clr-namespace:ZuneUIXTools"
|
||||||
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Zune UIX Tools" Height="450" Width="800">
|
Title="Zune UIX Tools" Height="800" Width="1000">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
ShowsPreview="True"
|
ShowsPreview="True"
|
||||||
Height="5" />
|
Height="5" />
|
||||||
|
|
||||||
<StackPanel Name="ErrorPanel" Grid.Row="3" Margin="4,4,4,0"/>
|
<ScrollViewer Grid.Row="3">
|
||||||
|
<StackPanel Name="ErrorPanel" Margin="4,4,4,0"/>
|
||||||
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ namespace ZuneUIXTools
|
|||||||
|
|
||||||
private void BuildAndRun()
|
private void BuildAndRun()
|
||||||
{
|
{
|
||||||
|
Dispatcher.Invoke(() => ErrorPanel.Children.Clear());
|
||||||
|
|
||||||
MarkupSystem.Startup(true);
|
MarkupSystem.Startup(true);
|
||||||
ErrorManager.OnErrors += (IList errors) => {
|
ErrorManager.OnErrors += (IList errors) => {
|
||||||
foreach (object obj in errors)
|
foreach (object obj in errors)
|
||||||
@@ -63,24 +65,34 @@ namespace ZuneUIXTools
|
|||||||
|
|
||||||
Dispatcher.Invoke(() =>
|
Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
ErrorPanel.Children.Add(new TextBlock
|
TextBlock errBlock = new TextBlock
|
||||||
{
|
{
|
||||||
Text = $"Ln {err.Line}, Col {err.Column}: {err.Message}",
|
Text = $"Ln {err.Line}, Col {err.Column}: {err.Message}",
|
||||||
Margin = new Thickness(0, 0, 0, 4)
|
Margin = new Thickness(0, 0, 0, 4)
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (err.Line >= 0 && err.Column >= 0)
|
||||||
|
{
|
||||||
|
errBlock.MouseDown += (object sender, MouseButtonEventArgs args) =>
|
||||||
|
{
|
||||||
// Highlight the error in the code editor
|
// Highlight the error in the code editor
|
||||||
int offset = textEditor.Document.GetOffset(err.Line, err.Column);
|
int offset = textEditor.Document.GetOffset(err.Line, err.Column);
|
||||||
textEditor.SelectionStart = offset;
|
textEditor.SelectionStart = offset + 1;
|
||||||
//textEditor.SelectionLength = err.
|
textEditor.SelectionLength = 1;
|
||||||
//var anchor = textEditor.Document.CreateAnchor(offset);
|
textEditor.ScrollTo(err.Line, err.Column);
|
||||||
//textEditor.Document.GetLineByOffset(offset)
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorPanel.Children.Add(errBlock);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string compiledFile = System.IO.Path.ChangeExtension(DocumentPath, "uib");
|
string compiledFile = System.IO.Path.ChangeExtension(DocumentPath, "uib");
|
||||||
bool isSuccess = MarkupCompiler.Compile(
|
bool isSuccess = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
isSuccess = MarkupCompiler.Compile(
|
||||||
new[]
|
new[]
|
||||||
{
|
{
|
||||||
new CompilerInput()
|
new CompilerInput()
|
||||||
@@ -91,6 +103,28 @@ namespace ZuneUIXTools
|
|||||||
},
|
},
|
||||||
new CompilerInput()
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -102,23 +136,24 @@ namespace ZuneUIXTools
|
|||||||
{
|
{
|
||||||
Microsoft.Iris.Application.Window.SetBackgroundColor(new WindowColor(0xE6, 0xE6, 0xE6));
|
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.Window.RequestLoad("file://" + compiledFile + (string.IsNullOrEmpty(UIRoot) ? string.Empty : "#" + UIRoot));
|
||||||
|
Microsoft.Iris.Application.Window.CloseRequested += (object sender, WindowCloseRequestedEventArgs args) =>
|
||||||
|
{
|
||||||
|
args.BlockCloseRequest();
|
||||||
|
Microsoft.Iris.Application.Window.Visible = false;
|
||||||
|
};
|
||||||
Microsoft.Iris.Application.Run();
|
Microsoft.Iris.Application.Run();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(() =>
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
ErrorPanel.Children.Add(new TextBlock
|
ErrorPanel.Children.Add(new TextBlock
|
||||||
{
|
{
|
||||||
Text = $"Load Failed: {ex.Message}",
|
Text = $"Load failed: {ex.Message}",
|
||||||
Margin = new Thickness(0, 0, 0, 4)
|
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)
|
private void Build_Click(object sender, RoutedEventArgs e)
|
||||||
@@ -131,10 +166,10 @@ namespace ZuneUIXTools
|
|||||||
// Set UI root
|
// Set UI root
|
||||||
UIRoot = UIRootBox.Text;
|
UIRoot = UIRootBox.Text;
|
||||||
|
|
||||||
Thread newWindowThread = new Thread(new ThreadStart(BuildAndRun));
|
var _buildThread = new Thread(new ThreadStart(BuildAndRun));
|
||||||
newWindowThread.SetApartmentState(ApartmentState.STA);
|
_buildThread.SetApartmentState(ApartmentState.STA);
|
||||||
newWindowThread.IsBackground = true;
|
_buildThread.IsBackground = true;
|
||||||
newWindowThread.Start();
|
_buildThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Open_Click(object sender, RoutedEventArgs e)
|
private void Open_Click(object sender, RoutedEventArgs e)
|
||||||
@@ -150,4 +185,23 @@ namespace ZuneUIXTools
|
|||||||
textEditor.Load(DocumentPath);
|
textEditor.Load(DocumentPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal class MyScheduler : TaskScheduler
|
||||||
|
{
|
||||||
|
protected override System.Collections.Generic.IEnumerable<Task> GetScheduledTasks()
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<Task>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void QueueTask(Task task)
|
||||||
|
{
|
||||||
|
base.TryExecuteTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||||
|
{
|
||||||
|
base.TryExecuteTask(task);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user