[PR #9629] minor refactor: Move Tab management into its own file #27663

Open
opened 2026-01-31 09:23:21 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/9629

State: closed
Merged: Yes


I think we can all agree that TerminalPage.cpp is an unruly beast of a
file. It's got everything. It does everything. It can sometimes be a bit
hard to work with, because of simply how big it is. This PR tries to
alleviate this by making TerminalPage.cpp just a little smaller. It
does so by moving pretty much everything related to tab management into
its own file, TabManagement.cpp. These methods that have moved are all
the same as they were before, and they're still members of
TerminalPage. But now they're all in one place.

I tried to move all the references to _tabs in TerminalPage.cpp, but
there's still a few that I left behind. Mostly because I felt that
moving those would be too gnarly a code change for an otherwise simple
cut&paste PR.

There are a few new methods I introduced:

  • _TabDragStarted and _TabDragCompleted: These were lambdas before,
    promoted to full methods.
  • _DismissTabContextMenus: Remove all the right-click context menus
    from the tabs
  • _FocusCurrentTab: This one's a bit trickier, we were actually doing
    this in a few different places, so I tried consolidating.
  • _HasMultipleTabs: This doesn't need explaining.
  • _RemoveAllTabs: Really, just encapsulation for the sake of removing
    a _tabs from TerminalPage.cpp
  • _ResizeTabContent: Really, just encapsulation for the sake of
    removing a _tabs from TerminalPage.cpp

In the future, some enterprising young soul could try promoting that
file to its own class, and hiding _tabs (and _mruTabs) inside it.
Probably would need to take a reference to TerminalPage's _tabView and
_newTabButton. I'm not doing that right now, because I already hate
the idea of the ...

920 additions and 847 deletions.

... I'm making you look at already.

Other thoughts

Some of the calls might be a little arbitrary - _OpenNewTab and
_CreateNewTabFromSettings probably should stay in TerminalPage? Or
at least elements of those might need to get split up better. Similarly
TerminalPage::_OpenSettingsUI stayed in TerminalPage.cpp, but it
does a lot of the same work as _CreateNewTabFromSettings. I'm not
saying this is the definitive places for these methods - it's code we're
working with, not stone ☺️

**Original Pull Request:** https://github.com/microsoft/terminal/pull/9629 **State:** closed **Merged:** Yes --- I think we can all agree that `TerminalPage.cpp` is an unruly beast of a file. It's got everything. It does everything. It can sometimes be a bit hard to work with, because of simply how big it is. This PR tries to alleviate this by making `TerminalPage.cpp` just a little smaller. It does so by moving pretty much everything related to tab management into its own file, `TabManagement.cpp`. These methods that have moved are all the same as they were before, and they're still members of `TerminalPage`. But now they're all in one place. I tried to move all the references to `_tabs` in `TerminalPage.cpp`, but there's still a few that I left behind. Mostly because I felt that moving those would be too gnarly a code change for an otherwise simple cut&paste PR. There are a few new methods I introduced: * `_TabDragStarted` and `_TabDragCompleted`: These were lambdas before, promoted to full methods. * `_DismissTabContextMenus`: Remove all the right-click context menus from the tabs * `_FocusCurrentTab`: This one's a bit trickier, we were actually doing this in a few different places, so I tried consolidating. * `_HasMultipleTabs`: This doesn't need explaining. * `_RemoveAllTabs`: Really, just encapsulation for the sake of removing a `_tabs` from `TerminalPage.cpp` * `_ResizeTabContent`: Really, just encapsulation for the sake of removing a `_tabs` from `TerminalPage.cpp` In the future, some enterprising young soul could try promoting that file to its own class, and hiding `_tabs` (and `_mruTabs`) inside it. Probably would need to take a reference to TerminalPage's `_tabView` and `_newTabButton`. I'm not doing that right now, because I already hate the idea of the ... > 920 additions and 847 deletions. ... I'm making you look at already. ## Other thoughts Some of the calls might be a little arbitrary - `_OpenNewTab` and `_CreateNewTabFromSettings` probably should stay in `TerminalPage`? Or at least elements of those might need to get split up better. Similarly `TerminalPage::_OpenSettingsUI` stayed in `TerminalPage.cpp`, but it does a lot of the same work as `_CreateNewTabFromSettings`. I'm not saying this is the definitive places for these methods - it's code we're working with, not stone ☺️
claunia added the pull-request label 2026-01-31 09:23:21 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#27663