Skip to content

Conversation

@tig
Copy link
Collaborator

@tig tig commented Jun 4, 2025

Fixes

Proposed Changes/Todos

  • Command.Select->Activate
  • Rename Selecting event to Activating, OnSelecting to OnActivating, and RaiseSelecting to RaiseActivating in the View class and all derived classes (e.g., Menuv2, MenuItemv2, CheckBox, FlagSelector).
  • Update related code:
    • Modify SetupCommands in View to use Command.Activate.
    • Update Shortcut.DispatchCommand and other command handlers to reference Activating.
    • Ensure all event handlers and documentation reflect the new terminology.
  • Update Documentation
    • Clarify Activating vs. Accepting:
    • Update view-specific docs
  • Refactor OptionSelector & FlagSelector -> less duplicated code.
  • Revisit how Activate and Accept propogate - esp w/in Shortcut etc...
  • Go through built-in Views and ensure Selected / Activated terminology is correct (e.g. TreeView, TableView, ...)

For another PR

I was going to do this here, but I'll do it in another PR:

  • Introduce Targeted Propagation Model with PropagateActivating
    • Document propagation: Explain the targeted model with PropagateActivating, providing examples for MenuBarv2 and potential Toplevel use cases.
  • Delete RadioGroup - OptionSelector is now a 100% compatible clone

@tig tig requested review from BDisp, Copilot and tznind June 4, 2025 21:07

This comment was marked as outdated.

@tig tig requested a review from Copilot June 4, 2025 21:21

This comment was marked as outdated.

@tig
Copy link
Collaborator Author

tig commented Jun 4, 2025

I'm not convinced we don't still need a Command.Select in ADDITION to Command.Accept.

Code like this in TableView...

        // BUGBUG: OnCellActivated is misnamed, it should be OnCellAccepted? Or is it OnCellSelected?
        // BUGBUG: Does this mean we still need Command.Select?
        AddCommand (Command.Accept, () => OnCellActivated (new (Table, SelectedColumn, SelectedRow)));

And TreeView:

    /// <summary>
    ///     <para>Triggers the <see cref="ObjectActivated"/> event with the <see cref="SelectedObject"/>.</para>
    ///     <para>This method also ensures that the selected object is visible.</para>
    /// </summary>
    /// <returns><see langword="true"/> if <see cref="ObjectActivated"/> was fired.</returns>
    public bool? ActivateSelectedObjectIfAny (ICommandContext commandContext)
    {
        // By default, Command.Accept calls OnAccept, so we need to call it here to ensure that the event is fired.
        if (RaiseAccepting (commandContext) == true)
        {
            return true;
        }

        T o = SelectedObject;

        if (o is { })
        {
            // TODO: Should this be cancelable?
            ObjectActivatedEventArgs<T> e = new (this, o);
            OnObjectActivated (e);

            return true;
        }

        return false;
    }

???

@BDisp
Copy link
Collaborator

BDisp commented Jun 4, 2025

I think it make sense to have both. Command.Select doesn't mean it was accepted. So, adding Command.Accept will mean it was confirmed and will perform some action, like closing or opening a view, etc.... Command.Select also may perform some action but not definitely. Both must raise the respective events.

tig added 5 commits June 4, 2025 17:04
Updated `PopoverBaseImpl.cs` to clarify mouse event handling in popovers.

Modified `View.Layout.cs` to adjust view count checks for active popovers. Corrected documentation in `ViewportSettingsFlags.cs` regarding the `TransparentMouse` flag.

Added a new test method in `ApplicationPopoverTests.cs` to validate view retrieval under mouse coordinates when a popover is active, with multiple test cases included.

See: gui-cs#4122
- Updated `MouseBinding` struct to include a new constructor for `MouseEventArgs`.
- Enhanced documentation in `View.Mouse.cs` to clarify low-level API methods.
- Refined command handling in `CheckBox` to improve state management.
- Renamed method in `Label` for better clarity in hotkey handling.
- Updated `command.md` to reflect changes in the `Command` system.
- Restructured `mouse.md` for clearer understanding of mouse APIs and best practices.
Working through FlagSelector as an example.
tig added 29 commits October 21, 2025 02:38
Refactored the assignment of `Application.ForceDriver` and `_forceDriver` by removing the conditional check for null or empty values in `options.Driver`. The new implementation directly assigns `options.Driver`, simplifying the logic and assuming it is always valid.
Uncommented and activated `Command.Accept`, `Command.HotKey`, and `Command.Activate` in the `AddCommands` method of `Shortcut.cs`, enabling previously disabled functionality.

Commented out test cases for `MouseFlags.Button2Pressed`, `MouseFlags.Button3Pressed`, and `MouseFlags.Button4Pressed` in `MouseTests.cs`, temporarily disabling these tests while retaining the `MouseFlags.Button1Pressed` test case.
Ensure mouse events are consistently routed to MouseGrabView.

- Updated `MouseImpl.cs` to always set `viewRelativeMouseEvent.View` to `MouseGrabView`, addressing Issue gui-cs#4370.
- Adjusted conditional logic to handle single-click events properly.
- Added a new test case `MouseGrab_EventSentToGrabView_HasCorrectView` in `ApplicationMouseTests.cs` to validate the fix.
- Documented behavior before and after the fix in the test case.

These changes ensure correct event routing and improve test coverage.
The `[Fact]` attribute for the `MouseEvent_Test` method was updated to include a `Skip` parameter with the message "See Issue gui-cs#4370. Not gonna try to fix menu v1." This change temporarily disables the test while the issue remains unresolved. The `[AutoInitShutdown]` attribute is retained, ensuring the test can be re-enabled in the future.
The `Add` method in the `TimedEvents` class was updated to accept a `Timeout` object, call `AddTimeout` with `timeout.Span` and the `timeout` object, and return the `timeout` object.

XML documentation comments were adjusted for consistency:
- `<inheritdoc />` was changed to `<inheritdoc/>` in the `Add` method.
- The `<inheritdoc/>` comment was removed from the `CheckTimers` method, with no functional changes to the method itself.
The namespace of the `OptionSelectorTests` class was updated from `UnitTests.ViewsTests` to `UnitTests_Parallelizable.ViewsTests`. This change reflects a reorganization or renaming of the namespace, potentially to indicate parallelizable tests or align with a new project structure. No functional changes were made to the test class itself.
Added `#nullable enable` to improve null safety and static analysis. Introduced the `Terminal.Gui.ViewBase` namespace to reorganize the codebase for better modularity. Marked the `View` class as `partial` to split its implementation across multiple files, enhancing maintainability. Added a private `_canFocus` field to manage focus state. Included `System.Diagnostics` for potential debugging or diagnostics.
Removed multiple redundant and outdated tests from `FlagSelectorTests` to streamline the test suite. These include tests for hotkey behavior, default constructors, and null value handling. Added a new test, `Mouse_Click_On_NotActivated_NoneFlag_Toggles`, to validate checkbox toggle behavior. Simplified the test structure by removing the `Mouse Tests` region and associated tests.
Refactored mouse event handling in `TableEditor` by replacing
`MouseClick` with `MouseEvent` for more generic handling.
Standardized command handling across `CheckBox`, `FlagSelector`,
and `OptionSelector` by replacing `Command.Select` with
`Command.Activate`. Updated associated methods and event handlers
to align with the new activation model.

Removed `OnSelecting` from `SelectorBase` and replaced its
functionality with `Command.Activate`. Updated tests to reflect
these changes, including replacing `MouseClick` with `MouseEvent`
and simplifying test setups by removing `SetupFakeDriver`.

Performed general refactoring for consistency, ensuring all
methods and event names align with the new activation terminology.
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 73.12500% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.39%. Comparing base (fc818b0) to head (1f6825b).

Files with missing lines Patch % Lines
Terminal.Gui/Views/FileDialogs/FileDialog.cs 23.80% 15 Missing and 1 partial ⚠️
Terminal.Gui/ViewBase/View.Mouse.cs 88.37% 8 Missing and 2 partials ⚠️
Terminal.Gui/Views/ListView.cs 58.82% 3 Missing and 4 partials ⚠️
Terminal.Gui/Views/Shortcut.cs 83.72% 5 Missing and 2 partials ⚠️
Terminal.Gui/Views/ScrollBar/ScrollBar.cs 28.57% 4 Missing and 1 partial ⚠️
Terminal.Gui/ViewBase/View.Command.cs 71.42% 0 Missing and 4 partials ⚠️
Terminal.Gui/Views/Color/ColorPicker.16.cs 20.00% 0 Missing and 4 partials ⚠️
Terminal.Gui/Views/Label.cs 69.23% 2 Missing and 2 partials ⚠️
Terminal.Gui/Views/Selectors/OptionSelector.cs 20.00% 1 Missing and 3 partials ⚠️
....Gui/Views/TableView/CheckBoxTableSourceWrapper.cs 33.33% 4 Missing ⚠️
... and 13 more
Additional details and impacted files
@@              Coverage Diff               @@
##           v2_develop    #4126      +/-   ##
==============================================
- Coverage       74.41%   73.39%   -1.02%     
==============================================
  Files             388      388              
  Lines           46568    46586      +18     
  Branches         6548     6540       -8     
==============================================
- Hits            34653    34192     -461     
- Misses          10053    10519     +466     
- Partials         1862     1875      +13     
Files with missing lines Coverage Δ
Terminal.Gui/ViewBase/View.Keyboard.cs 84.23% <100.00%> (-1.19%) ⬇️
Terminal.Gui/Views/Bar.cs 84.15% <100.00%> (+0.17%) ⬆️
Terminal.Gui/Views/ComboBox.cs 80.00% <100.00%> (ø)
Terminal.Gui/Views/Menu/MenuBarv2.cs 76.70% <100.00%> (-5.23%) ⬇️
Terminal.Gui/Views/Menu/PopoverMenu.cs 75.83% <ø> (-13.10%) ⬇️
Terminal.Gui/Views/Menuv1/MenuItem.cs 48.18% <100.00%> (ø)
Terminal.Gui/Views/MessageBox.cs 63.71% <100.00%> (ø)
Terminal.Gui/Views/NumericUpDown.cs 85.05% <100.00%> (ø)
Terminal.Gui/Views/ScrollBar/ScrollSlider.cs 71.00% <100.00%> (ø)
Terminal.Gui/Views/Slider/Slider.cs 56.19% <100.00%> (ø)
... and 31 more

... and 38 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc818b0...1f6825b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants