diff --git a/ILSpy.Tests/Docking/DocumentTabStripModeTests.cs b/ILSpy.Tests/Docking/DocumentTabStripModeTests.cs index 6743f4316..6af21efc1 100644 --- a/ILSpy.Tests/Docking/DocumentTabStripModeTests.cs +++ b/ILSpy.Tests/Docking/DocumentTabStripModeTests.cs @@ -134,6 +134,31 @@ public class DocumentTabStripModeTests { Settings.MultiLineDocumentTabs = saved; } } + [AvaloniaTest] + public async Task Mouse_Wheel_Does_Not_Toggle_The_Mode_When_The_Setting_Is_Off() + { + var savedMode = Settings.MultiLineDocumentTabs; + var savedGate = Settings.MouseWheelTogglesTabStripRows; + try + { + var (window, strip) = await BootWithTabsAsync(multiLine: false); + Settings.MouseWheelTogglesTabStripRows = false; + await Pump(window); + var point = strip.TranslatePoint(new Point(8, 8), window) ?? new Point(8, 8); + + window.MouseWheel(point, new Vector(0, 1)); + await Pump(window); + + Settings.MultiLineDocumentTabs.Should().BeFalse( + "with the 'mouse wheel toggles' setting off, the wheel must not flip the tab-strip mode"); + } + finally + { + Settings.MultiLineDocumentTabs = savedMode; + Settings.MouseWheelTogglesTabStripRows = savedGate; + } + } + [AvaloniaTest] public async Task Clicking_The_Dropdown_Opens_A_Populated_Menu() { diff --git a/ILSpy.Tests/Options/TabOptionsGroupTests.cs b/ILSpy.Tests/Options/TabOptionsGroupTests.cs new file mode 100644 index 000000000..91e260b04 --- /dev/null +++ b/ILSpy.Tests/Options/TabOptionsGroupTests.cs @@ -0,0 +1,100 @@ +// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System.Linq; + +using Avalonia.Controls; +using Avalonia.Headless.NUnit; +using Avalonia.Threading; +using Avalonia.VisualTree; + +using AwesomeAssertions; + +using ICSharpCode.ILSpy.Properties; + +using ILSpy.AppEnv; +using ILSpy.Commands; +using ILSpy.Options; +using ILSpy.ViewModels; +using ILSpy.Views; + +using NUnit.Framework; + +namespace ICSharpCode.ILSpy.Tests; + +/// +/// The Display options page exposes a "Tab options" group with two checkboxes that bind two-way to +/// the persisted document-tab-strip settings on SessionSettings: one toggles multi-row tabs, the +/// other gates the mouse-wheel toggle gesture. +/// +[TestFixture] +public class TabOptionsGroupTests +{ + const string MultiRowLabel = "Enable multiple rows in tab strip"; + const string WheelGateLabel = "Mouse wheel scroll toggles single/multiple row tab strip"; + + [AvaloniaTest] + public void Tab_Options_Checkboxes_Two_Way_Bind_To_SessionSettings() + { + var window = AppComposition.Current.GetExport(); + window.Width = 900; + window.Height = 600; + window.Show(); + Dispatcher.UIThread.RunJobs(); + + var command = AppComposition.Current.GetExport() + .GetCommand(nameof(Resources._Options)); + command.Execute(null); + Dispatcher.UIThread.RunJobs(); + + var view = window.GetVisualDescendants().OfType().Single(); + var model = (OptionsPageModel)((ContentTabPage)((MainWindowViewModel)window.DataContext!) + .DockWorkspace.Documents!.VisibleDockables! + .OfType().Single(t => t.Content is OptionsPageModel)).Content!; + var page = model.Pages.OfType().Single(); + model.SelectedPage = page; + Dispatcher.UIThread.RunJobs(); + + var multiRow = view.GetVisualDescendants().OfType() + .FirstOrDefault(cb => cb.Content?.ToString() == MultiRowLabel); + var wheelGate = view.GetVisualDescendants().OfType() + .FirstOrDefault(cb => cb.Content?.ToString() == WheelGateLabel); + + multiRow.Should().NotBeNull("the Tab options group must expose the multi-row toggle checkbox"); + wheelGate.Should().NotBeNull("the Tab options group must expose the mouse-wheel-gate checkbox"); + + var session = page.SessionSettings; + + // Checkbox 1 <-> MultiLineDocumentTabs + session.MultiLineDocumentTabs = false; + Dispatcher.UIThread.RunJobs(); + multiRow!.IsChecked.Should().BeFalse("the checkbox reflects the current MultiLineDocumentTabs"); + multiRow.IsChecked = true; + Dispatcher.UIThread.RunJobs(); + session.MultiLineDocumentTabs.Should().BeTrue("checking the box flows back to MultiLineDocumentTabs"); + + // Checkbox 2 <-> MouseWheelTogglesTabStripRows + session.MouseWheelTogglesTabStripRows = true; + Dispatcher.UIThread.RunJobs(); + wheelGate!.IsChecked.Should().BeTrue("the checkbox reflects the current MouseWheelTogglesTabStripRows"); + wheelGate.IsChecked = false; + Dispatcher.UIThread.RunJobs(); + session.MouseWheelTogglesTabStripRows.Should().BeFalse( + "unchecking the box flows back to MouseWheelTogglesTabStripRows"); + } +} diff --git a/ILSpy/Options/DisplaySettingsPanel.axaml b/ILSpy/Options/DisplaySettingsPanel.axaml index ff4e624a1..a33aff383 100644 --- a/ILSpy/Options/DisplaySettingsPanel.axaml +++ b/ILSpy/Options/DisplaySettingsPanel.axaml @@ -99,6 +99,15 @@ + + + + + + + + /// When true (the default) the mouse wheel over the document tab strip toggles + /// (wheel up flows to multiple rows, wheel down collapses + /// to one). When false the wheel gesture is ignored. Persisted across sessions. + /// + [ObservableProperty] + private bool mouseWheelTogglesTabStripRows = true; + /// /// Path to the previously-selected tree node (one ToString() per ancestor, root-first). /// Used to restore the selection on the next launch. @@ -100,6 +108,7 @@ namespace ILSpy var culture = (string?)section.Element(nameof(CurrentCulture)); CurrentCulture = string.IsNullOrEmpty(culture) ? null : culture; MultiLineDocumentTabs = (bool?)section.Element(nameof(MultiLineDocumentTabs)) ?? false; + MouseWheelTogglesTabStripRows = (bool?)section.Element(nameof(MouseWheelTogglesTabStripRows)) ?? true; var bounds = section.Element("WindowBounds"); if (bounds != null) @@ -151,6 +160,7 @@ namespace ILSpy if (!string.IsNullOrEmpty(CurrentCulture)) section.Add(new XElement(nameof(CurrentCulture), CurrentCulture)); section.Add(new XElement(nameof(MultiLineDocumentTabs), MultiLineDocumentTabs)); + section.Add(new XElement(nameof(MouseWheelTogglesTabStripRows), MouseWheelTogglesTabStripRows)); if (FilterStates.Count > 0) { diff --git a/ILSpy/Themes/MultiRowTabStripBehavior.cs b/ILSpy/Themes/MultiRowTabStripBehavior.cs index 7b200584f..7f3736c5c 100644 --- a/ILSpy/Themes/MultiRowTabStripBehavior.cs +++ b/ILSpy/Themes/MultiRowTabStripBehavior.cs @@ -93,7 +93,7 @@ namespace ILSpy.Themes static void OnPointerWheel(object? sender, PointerWheelEventArgs e) { var settings = TryGetSessionSettings(); - if (settings is null || e.Delta.Y == 0) + if (settings is null || e.Delta.Y == 0 || !settings.MouseWheelTogglesTabStripRows) return; // Idempotent set: rolling further in the same direction keeps the same mode rather than // flip-flopping, so a multi-detent gesture settles cleanly.