Skip to content

Commit

Permalink
feature: Debugger tabs hotkeys
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal committed Aug 31, 2024
1 parent b32b4cc commit 7a10961
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
43 changes: 43 additions & 0 deletions src/Spice86/Controls/HotKeyTabItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Spice86.Controls;

using Avalonia.Controls;
using Avalonia.Input;

using System.Windows.Input;

/// <summary>
/// A TabItem with a hot key.
/// <remarks>Source is: https://github.com/AvaloniaUI/Avalonia/discussions/14836</remarks>
/// </summary>
public class HotKeyTabItem : TabItem, ICommandSource {
protected override Type StyleKeyOverride => typeof(TabItem);

public HotKeyTabItem() {
Command = new TabItemSelectCommand(this);
CommandParameter = null;
}

public void CanExecuteChanged(object sender, EventArgs e) {
}

public ICommand? Command { get; }
public object? CommandParameter { get; }

public class TabItemSelectCommand : ICommand {
private readonly TabItem _tabItem;

public TabItemSelectCommand(TabItem tabItem) {
_tabItem = tabItem;
}

public bool CanExecute(object? parameter) {
return _tabItem.IsEffectivelyEnabled;
}

public void Execute(object? parameter) {
_tabItem.IsSelected = true;
}

public event EventHandler? CanExecuteChanged;
}
}
2 changes: 0 additions & 2 deletions src/Spice86/ViewModels/CfgCpuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public partial class CfgCpuViewModel : ViewModelBase {

[ObservableProperty] private long _averageNodeTime;

[ObservableProperty] private bool _isVisible;

public CfgCpuViewModel(ExecutionContextManager executionContextManager, IPauseHandler pauseHandler,
IPerformanceMeasurer performanceMeasurer) {
_executionContextManager = executionContextManager;
Expand Down
27 changes: 16 additions & 11 deletions src/Spice86/Views/DebugWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:vm="using:Spice86.ViewModels"
xmlns:local="clr-namespace:Spice86"
xmlns:fluent="clr-namespace:FluentIcons.Avalonia.Fluent;assembly=FluentIcons.Avalonia.Fluent"
xmlns:controls="clr-namespace:Spice86.Controls"
x:CompileBindings="True"
x:DataType="vm:DebugWindowViewModel"
WindowStartupLocation="CenterOwner"
Expand Down Expand Up @@ -42,10 +43,10 @@
</Button>
</StackPanel>
<TabControl Grid.Row="1">
<TabItem Header="CPU" Content="{Binding CpuViewModel}" />
<TabItem Header="Code flow" IsVisible="{Binding CfgCpuViewModel.IsVisible}"
Content="{Binding CfgCpuViewModel}"/>
<TabItem Header="Disassembly">
<controls:HotKeyTabItem HotKeyManager.HotKey="F1" Header="CPU (F1)" Content="{Binding CpuViewModel}" />
<controls:HotKeyTabItem HotKeyManager.HotKey="F2" Header="Code flow (F2)"
Content="{Binding CfgCpuViewModel}"/>
<controls:HotKeyTabItem HotKeyManager.HotKey="F3" Header="Disassembly (F3)">
<TabControl ItemsSource="{Binding DisassemblyViewModels}">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:DisassemblyViewModel}">
Expand All @@ -55,8 +56,8 @@
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</TabItem>
<TabItem Header="Memory">
</controls:HotKeyTabItem>
<controls:HotKeyTabItem Header="Memory (F4)" HotKeyManager.HotKey="F4">
<TabControl ItemsSource="{Binding MemoryViewModels}">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:MemoryViewModel}">
Expand All @@ -66,11 +67,15 @@
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</TabItem>
<TabItem Header="Video Card" Content="{Binding VideoCardViewModel}" />
<TabItem Header="Color Palette" Content="{Binding PaletteViewModel}" />
<TabItem Header="General MIDI / MT-32" Content="{Binding MidiViewModel}" />
<TabItem Header="Software Mixer" Content="{Binding SoftwareMixerViewModel}" />
</controls:HotKeyTabItem>
<controls:HotKeyTabItem HotKeyManager.HotKey="F5" Header="Devices (F5)">
<TabControl>
<controls:HotKeyTabItem HotKeyManager.HotKey="F6" Header="Video Card (F6)" Content="{Binding VideoCardViewModel}" />
<controls:HotKeyTabItem HotKeyManager.HotKey="F7" Header="Color Palette (F7)" Content="{Binding PaletteViewModel}" />
<controls:HotKeyTabItem HotKeyManager.HotKey="F8" Header="General MIDI / MT-32 (F8)" Content="{Binding MidiViewModel}" />
<controls:HotKeyTabItem HotKeyManager.HotKey="F9" Header="Software Mixer (F9)" Content="{Binding SoftwareMixerViewModel}" />
</TabControl>
</controls:HotKeyTabItem>
</TabControl>
</Grid>
</Window>

0 comments on commit 7a10961

Please sign in to comment.