mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 18:21:20 +00:00
New source debug window, WPF based
This commit is contained in:
parent
4ebc8e2c76
commit
f6e26512db
7 changed files with 69 additions and 78 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<Application x:Class="Kudzu_SourceView.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="Window1.xaml">
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="Window1.xaml">
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
|
|
@ -66,8 +66,8 @@
|
|||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Window1.xaml.cs">
|
||||
<DependentUpon>Window1.xaml</DependentUpon>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Window1" Height="300" Width="300">
|
||||
<Grid>
|
||||
|
||||
<Button Height="23" HorizontalAlignment="Left" Margin="4,13,0,0" Name="button1" VerticalAlignment="Top" Width="75">Button</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
@ -13,12 +13,18 @@ using System.Windows.Navigation;
|
|||
using System.Windows.Shapes;
|
||||
|
||||
namespace Kudzu_SourceView {
|
||||
/// <summary>
|
||||
/// Interaction logic for Window1.xaml
|
||||
/// </summary>
|
||||
public partial class Window1 : Window {
|
||||
public Window1() {
|
||||
InitializeComponent();
|
||||
button1.Click += new RoutedEventHandler(button1_Click);
|
||||
}
|
||||
|
||||
void button1_Click(object sender, RoutedEventArgs e) {
|
||||
var xView = new Cosmos.Build.Windows.ViewSourceWindow();
|
||||
xView.LoadSourceFile(@"C:\source\Cosmos\source\Cosmos\Cosmos.Kernel\Keyboard.cs");
|
||||
xView.SelectText(1, 4, 3, 8);
|
||||
xView.Show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -82,38 +82,6 @@ namespace Cosmos.Build.Windows {
|
|||
|
||||
}
|
||||
|
||||
private static void GetLineInfo(string aData, int aLineStart, int aColumnStart, int aLineEnd, int aColumnEnd, out int oCharStart, out int oCharCount) {
|
||||
int xCurrentPos = 0;
|
||||
int xCurrentLine = 1;
|
||||
oCharCount = 0;
|
||||
oCharStart = 0;
|
||||
while (xCurrentPos < aData.Length) {
|
||||
int xTempPos = aData.IndexOfAny(new char[] { '\r', '\n' }, xCurrentPos);
|
||||
if (xTempPos == -1) {
|
||||
if (oCharStart > 0) {
|
||||
oCharCount = xCurrentPos - oCharStart;
|
||||
}
|
||||
return;
|
||||
}
|
||||
xCurrentLine += 1;
|
||||
xCurrentPos = xTempPos;
|
||||
if (aData[xCurrentPos] == '\r' && aData.Length > (xCurrentPos + 1) && aData[xCurrentPos + 1] == '\n') {
|
||||
xCurrentPos += 2;
|
||||
} else {
|
||||
xCurrentPos += 1;
|
||||
}
|
||||
if (xCurrentLine == aLineStart) {
|
||||
oCharStart = xCurrentPos + aColumnStart;
|
||||
}
|
||||
if (xCurrentLine == aLineEnd) {
|
||||
oCharCount = (xCurrentPos + aColumnEnd) - oCharStart;
|
||||
}
|
||||
if (oCharCount > 0 && oCharStart > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void lboxLog_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
var xItem = lboxLog.SelectedItem;
|
||||
string xItemStr = xItem as String;
|
||||
|
|
@ -122,27 +90,12 @@ namespace Cosmos.Build.Windows {
|
|||
if (mDebugMode == DebugModeEnum.Source) {
|
||||
var xSourceInfo = mSourceMappings.GetMapping(UInt32.Parse(xItemStr.Substring(2), System.Globalization.NumberStyles.HexNumber));
|
||||
var xViewSrc = new ViewSourceWindow();
|
||||
//int xCharStart;
|
||||
//int xCharCount;
|
||||
//GetLineInfo(xViewSrc.tboxSource.Text, xSourceInfo.Line, xSourceInfo.Column, xSourceInfo.LineEnd, xSourceInfo.ColumnEnd, out xCharStart, out xCharCount);
|
||||
//if(
|
||||
//int xCharStart = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.Line);
|
||||
//int xCharEnd = xViewSrc.tboxSource.GetCharacterIndexFromLineIndex(xSourceInfo.LineEnd);
|
||||
//xCharStart += xSourceInfo.Column;
|
||||
//xCharEnd += xSourceInfo.ColumnEnd;
|
||||
int xCharStart;
|
||||
int xCharLength;
|
||||
xViewSrc.LoadSourceFile(xSourceInfo.SourceFile);
|
||||
GetLineInfo(xViewSrc.tboxSource.Text, xSourceInfo.Line, xSourceInfo.Column, xSourceInfo.LineEnd, xSourceInfo.ColumnEnd, out xCharStart, out xCharLength);
|
||||
//xViewSrc.tboxSource.ScrollToLine(xSourceInfo.Line);
|
||||
//xViewSrc.tboxSource.Select(xCharStart, xCharEnd - xCharStart);
|
||||
xViewSrc.CharStart = xCharStart - 1;
|
||||
xViewSrc.CharLength = xCharLength;
|
||||
xViewSrc.SelectText(xSourceInfo.Line, xSourceInfo.Column, xSourceInfo.LineEnd, xSourceInfo.ColumnEnd);
|
||||
xViewSrc.ShowDialog();
|
||||
} else {
|
||||
throw new Exception("Debug mode not supported!");
|
||||
}
|
||||
//xViewSrc.tboxSource.s
|
||||
}
|
||||
} else {
|
||||
var xViewSrc = new ViewSourceWindow();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
<Window x:Class="Cosmos.Build.Windows.ViewSourceWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="View Source" Height="500" Width="500" Loaded="Window_Loaded">
|
||||
<Canvas>
|
||||
<TextBox
|
||||
x:Name="tboxSource"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
IsReadOnly="True" Height="210" Width="478" />
|
||||
<FlowDocumentScrollViewer Canvas.Left="0" Canvas.Top="211" Height="251" Name="fdsvSource" Width="478" />
|
||||
</Canvas>
|
||||
Title="View Source" Height="500" Width="500">
|
||||
<DockPanel LastChildFill="True">
|
||||
<FlowDocumentScrollViewer Name="fdsvSource" />
|
||||
</DockPanel>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -13,32 +13,69 @@ using System.Windows.Shapes;
|
|||
|
||||
namespace Cosmos.Build.Windows {
|
||||
public partial class ViewSourceWindow: Window {
|
||||
protected List<Run> mLines = new List<Run>();
|
||||
|
||||
public ViewSourceWindow() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public int CharStart;
|
||||
public int CharLength;
|
||||
|
||||
public void LoadSourceFile(string aPathname) {
|
||||
// Old
|
||||
tboxSource.Text = System.IO.File.ReadAllText(aPathname);
|
||||
// New
|
||||
var xSourceCode = System.IO.File.ReadAllLines(aPathname);
|
||||
var xPara = new Paragraph();
|
||||
fdsvSource.Document = new FlowDocument();
|
||||
fdsvSource.Document.Blocks.Add(xPara);
|
||||
foreach (var xLine in xSourceCode) {
|
||||
xPara.Inlines.Add(xLine);
|
||||
var xRun = new Run(xLine);
|
||||
mLines.Add(xRun);
|
||||
xPara.Inlines.Add(xRun);
|
||||
xPara.Inlines.Add(new LineBreak());
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
// Old
|
||||
tboxSource.Focus();
|
||||
tboxSource.Select(CharStart, CharLength);
|
||||
// New
|
||||
}
|
||||
protected void Select(int aLine, int aColBegin, int aLength) {
|
||||
if (aLength != 0) {
|
||||
var xPara = (Paragraph)fdsvSource.Document.Blocks.FirstBlock;
|
||||
var xSelectedLine = mLines[aLine];
|
||||
string xText = xSelectedLine.Text;
|
||||
if (aLength == -1) {
|
||||
aLength = xText.Length - aColBegin;
|
||||
}
|
||||
string xSubText;
|
||||
|
||||
if (aColBegin > 0) {
|
||||
var xRunLeft = new Run(xText.Substring(0, aColBegin - 1));
|
||||
xPara.Inlines.InsertBefore(xSelectedLine, xRunLeft);
|
||||
}
|
||||
|
||||
var xRunSelected = new Run(xText.Substring(aColBegin, aLength));
|
||||
xRunSelected.Background = Brushes.Red;
|
||||
xPara.Inlines.InsertBefore(xSelectedLine, xRunSelected);
|
||||
|
||||
if (aColBegin + aLength < xText.Length) {
|
||||
var xRunRight = new Run(xText.Substring(aColBegin + aLength));
|
||||
xPara.Inlines.InsertBefore(xSelectedLine, xRunRight);
|
||||
}
|
||||
|
||||
xPara.Inlines.Remove(xSelectedLine);
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectText(int aLineBegin, int aColBegin, int aLineEnd, int aColEnd) {
|
||||
aLineBegin--;
|
||||
aColBegin--;
|
||||
aLineEnd--;
|
||||
aColEnd--;
|
||||
//Currently can only be called once - need to fix it to reset so it can be called multiple times
|
||||
if (aLineBegin == aLineEnd) {
|
||||
Select(aLineBegin, aColBegin, aColEnd - aColBegin);
|
||||
} else {
|
||||
Select(aLineBegin, aColBegin, -1);
|
||||
for (int i = aLineBegin + 1; i <= aLineEnd - 1; i++) {
|
||||
Select(i, 0, -1);
|
||||
}
|
||||
Select(aLineEnd, 0, aColEnd + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue