Skip to content

Commit 098d886

Browse files
authored
basic tabs (#42)
* basic tabs * themed, but closable * fix padding * non closable * cleanup
1 parent b131ca1 commit 098d886

File tree

7 files changed

+144
-12
lines changed

7 files changed

+144
-12
lines changed

JitExplorer.Engine.UnitTests/RuntimeDisassemblerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void SimpleProgramProducesDissassembledOutput()
3939
JitMode = JitMode.Default,
4040
};
4141

42-
string jitOut = jit.CompileJitAndDisassemble(correctSource, config).Text;
42+
string jitOut = jit.CompileJitAndDisassemble(correctSource, config).AsmText;
4343

4444
output.WriteLine(jitOut);
4545

JitExplorer.Engine/Dissassembly.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Dissassembly
99
public Dissassembly(string text)
1010
{
1111
this.IsSuccess = false;
12-
this.Text = text;
12+
this.OutputText = text;
1313
this.AsmLineAddressIndex = new Dictionary<int, string>();
1414
this.AsmToSourceLineIndex = new Dictionary<int, int>();
1515
this.AsmLineToAsmLineIndex = new Dictionary<int, int>();
@@ -18,7 +18,7 @@ public Dissassembly(string text)
1818
public Dissassembly(string text, Dictionary<int, string> lineAddressIndex, Dictionary<int, int> asmToSourceLineIndex, Dictionary<int, int> asmLineToAsmLineIndex)
1919
{
2020
this.IsSuccess = true;
21-
this.Text = text;
21+
this.AsmText = text;
2222
this.AsmLineAddressIndex = lineAddressIndex;
2323
this.AsmToSourceLineIndex = asmToSourceLineIndex;
2424
this.AsmLineToAsmLineIndex = asmLineToAsmLineIndex;
@@ -41,6 +41,8 @@ public Dissassembly(string text, Dictionary<int, string> lineAddressIndex, Dicti
4141
/// </summary>
4242
public Dictionary<int, int> AsmLineToAsmLineIndex { get; }
4343

44-
public string Text { get; }
44+
public string AsmText { get; }
45+
46+
public string OutputText { get; }
4547
}
4648
}

JitExplorer/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<!-- Control styling -->
3131
<ResourceDictionary Source="Component/Styles/CompletionWindow.xaml" />
32+
<ResourceDictionary Source="Component/Styles/TabItem.xaml" />
3233
<ResourceDictionary Source="Component/Styles/TextEditor.xaml" />
3334
<ResourceDictionary Source="Component/Styles/ToggleButton.xaml" />
3435
</ResourceDictionary.MergedDictionaries>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:Actions="clr-namespace:MahApps.Metro.Actions"
4+
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro">
5+
6+
7+
<!--https://github.com/MahApps/MahApps.Metro/blob/0dffed2b9a98ed928d3ac0b5c8d5c7708f1aa413/src/MahApps.Metro/Styles/VS/TabControl.xaml-->
8+
9+
<ResourceDictionary.MergedDictionaries>
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TabControl.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
13+
<Style x:Key="NonClosableTabItem" BasedOn="{StaticResource {x:Type controls:MetroTabItem}}" TargetType="{x:Type controls:MetroTabItem}">
14+
<Setter Property="CloseButtonEnabled" Value="False"></Setter>
15+
16+
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrushNormal}" />
17+
<!-- special property for header font size -->
18+
<!--<Setter Property="controls:ControlsHelper.HeaderFontSize" Value="12" />-->
19+
<Setter Property="controls:TabControlHelper.CloseButtonEnabled" Value="True" />
20+
<Setter Property="Padding" Value="12 5 12 5" />
21+
<!--<Setter Property="controls:ControlsHelper.HeaderFontSize" Value="20"></Setter>-->
22+
<Setter Property="Template">
23+
<Setter.Value>
24+
<ControlTemplate TargetType="{x:Type TabItem}">
25+
<Border x:Name="Border"
26+
HorizontalAlignment="Stretch"
27+
Background="{TemplateBinding Background}"
28+
BorderBrush="{TemplateBinding BorderBrush}"
29+
BorderThickness="{TemplateBinding BorderThickness}"
30+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
31+
<StackPanel x:Name="PART_Content"
32+
HorizontalAlignment="Stretch"
33+
VerticalAlignment="Stretch"
34+
Orientation="Horizontal">
35+
<controls:ContentControlEx x:Name="ContentSite"
36+
Padding="{TemplateBinding Padding}"
37+
Content="{TemplateBinding Header}"
38+
ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(controls:ControlsHelper.ContentCharacterCasing)}"
39+
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
40+
ContentTemplate="{TemplateBinding HeaderTemplate}"
41+
ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
42+
DockPanel.Dock="Top"
43+
FontFamily="{TemplateBinding FontFamily}"
44+
FontStyle="{TemplateBinding FontStyle}"
45+
46+
Foreground="{TemplateBinding Foreground}"
47+
RecognizesAccessKey="True"
48+
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
49+
<Button x:Name="PART_CloseButton"
50+
VerticalAlignment="Center"
51+
IsTabStop="False"
52+
Style="{DynamicResource StandardTabItemCloseButtonStyle}"
53+
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(controls:TabControlHelper.CloseButtonEnabled), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
54+
</Button>
55+
</StackPanel>
56+
</Border>
57+
<ControlTemplate.Triggers>
58+
<Trigger Property="TabStripPlacement" Value="Left">
59+
<Setter TargetName="PART_Content" Property="LayoutTransform">
60+
<Setter.Value>
61+
<TransformGroup>
62+
<ScaleTransform />
63+
<SkewTransform />
64+
<RotateTransform Angle="-90" />
65+
<TranslateTransform />
66+
</TransformGroup>
67+
</Setter.Value>
68+
</Setter>
69+
</Trigger>
70+
<Trigger Property="TabStripPlacement" Value="Right">
71+
<Setter TargetName="PART_Content" Property="LayoutTransform">
72+
<Setter.Value>
73+
<TransformGroup>
74+
<ScaleTransform />
75+
<SkewTransform />
76+
<RotateTransform Angle="90" />
77+
<TranslateTransform />
78+
</TransformGroup>
79+
</Setter.Value>
80+
</Setter>
81+
</Trigger>
82+
<Trigger Property="IsSelected" Value="true">
83+
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.BackgroundSelected}" />
84+
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Border.Selected}" />
85+
</Trigger>
86+
<Trigger Property="IsMouseOver" Value="True">
87+
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.BackgroundHighlighted}" />
88+
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Border.Highlighted}" />
89+
</Trigger>
90+
<MultiTrigger>
91+
<MultiTrigger.Conditions>
92+
<Condition Property="IsMouseOver" Value="False" />
93+
<Condition Property="IsSelected" Value="False" />
94+
<Condition Property="controls:TabControlHelper.CloseButtonEnabled" Value="True" />
95+
</MultiTrigger.Conditions>
96+
<Setter TargetName="PART_CloseButton" Property="Visibility" Value="Hidden" />
97+
</MultiTrigger>
98+
<MultiTrigger>
99+
<MultiTrigger.Conditions>
100+
<Condition Property="IsMouseOver" Value="True" />
101+
<Condition Property="IsSelected" Value="True" />
102+
</MultiTrigger.Conditions>
103+
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.BackgroundSelected}" />
104+
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Border.Selected}" />
105+
</MultiTrigger>
106+
</ControlTemplate.Triggers>
107+
</ControlTemplate>
108+
</Setter.Value>
109+
</Setter>
110+
</Style>
111+
112+
</ResourceDictionary>

JitExplorer/Component/Styles/TextEditor.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<Style TargetType="avalonedit:TextEditor" x:Key="TextEditorStyle" >
6161
<Setter Property="FontFamily" Value="Consolas" />
6262
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Background}" />
63-
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Foreground}" />
63+
<Setter Property="Foreground" Value="#d4d4d4" />
6464
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Border.Normal}" />
6565
<Setter Property="BorderThickness" Value="{DynamicResource ComboBoxBorderThemeThickness}" />
6666

JitExplorer/MainWindow.xaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,21 @@
143143
Grid.Column="0"
144144
SyntaxHighlighting="C#"
145145
ShowLineNumbers="True"
146-
MinWidth="5">
147-
</avalonedit:TextEditor>
146+
MinWidth="5"/>
148147
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Background="{DynamicResource MahApps.Brushes.WindowTitle}" />
149-
<jitcontrols:AssemblyTextEditor x:Name="AssemblerView"
148+
<Controls:MetroTabControl Grid.Column="2" Name="OutputTab" Style="{DynamicResource MahApps.Styles.TabControl.VisualStudio}">
149+
<Controls:MetroTabItem x:Name="AsmTab" Header="Asm" Style="{StaticResource NonClosableTabItem}" >
150+
<jitcontrols:AssemblyTextEditor x:Name="AssemblerView"
150151
Style="{StaticResource TextEditorStyle}"
151-
Grid.Column="2"
152-
MinWidth="5">
153-
</jitcontrols:AssemblyTextEditor>
152+
MinWidth="5" />
153+
</Controls:MetroTabItem>
154+
<Controls:MetroTabItem Header="Output" Style="{StaticResource NonClosableTabItem}" >
155+
<avalonedit:TextEditor x:Name="OutputEditor"
156+
Style="{StaticResource TextEditorStyle}"
157+
WordWrap="True"
158+
MinWidth="5"/>
159+
</Controls:MetroTabItem>
160+
</Controls:MetroTabControl>
154161
</Grid>
155162

156163
<!-- Status bar -->

JitExplorer/MainWindow.xaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public static void Execute()
9595
var i = (ComboBoxItem)this.Platform.Items[0];
9696
i.IsEnabled = false;
9797
}
98+
99+
this.AsmTab.CloseButtonEnabled = true;
98100
}
99101

100102
void a_Loaded(object sender, EventArgs e)
@@ -299,7 +301,15 @@ private void JitIt(string source, Config config)
299301

300302
this.Dispatcher.Invoke(
301303
() =>
302-
this.AssemblerView.Update(this.dissassembly.Text, new LineAddressResolver(this.dissassembly.AsmLineAddressIndex)));
304+
this.AssemblerView.Update(this.dissassembly.AsmText, new LineAddressResolver(this.dissassembly.AsmLineAddressIndex)));
305+
306+
this.Dispatcher.Invoke(
307+
() =>
308+
this.OutputEditor.Text = this.dissassembly.OutputText);
309+
310+
this.Dispatcher.Invoke(
311+
() =>
312+
OutputTab.SelectedIndex = this.dissassembly.IsSuccess ? 0 : 1);
303313
}
304314
catch (Exception ex)
305315
{

0 commit comments

Comments
 (0)