From a1466b8aeb9aee073e932d7d846d80a9a1ad379a Mon Sep 17 00:00:00 2001 From: fedejeanne <2205684+fedejeanne@users.noreply.github.com> Date: Wed, 8 May 2024 14:37:07 +0200 Subject: [PATCH] Take default tab in LaunchConfigurationTabGroupViewer from CTabFolder When setting the active tab of the LaunchConfigurationTabGroupViewer for the first time (right after setting its input), activate the tab that the CTabFolder considers as the default tab. Add a missing test too. --- ...LaunchConfigurationTabGroupViewerTest.java | 20 +++++++++++++++++++ .../LaunchConfigurationTabGroupViewer.java | 7 ++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/LaunchConfigurationTabGroupViewerTest.java b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/LaunchConfigurationTabGroupViewerTest.java index 6771696799e..b5cb36a97a2 100644 --- a/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/LaunchConfigurationTabGroupViewerTest.java +++ b/debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/ui/LaunchConfigurationTabGroupViewerTest.java @@ -194,6 +194,26 @@ public void testOtherTabIsActivated() { assertThat(((SpyTab) tabs[secondTabIndex])).matches(SpyTab::isActivated, "should have been activated"); } + @Test + public void testActivateAllTabs() { + ThrowingRunnable activateSeveralTab = () -> { + // Create and select launch config + fLaunchConfigurationsDialog.getTabViewer().setInput(createLaunchConfigurationInstance()); + + // Select all tabs + for (int i = 0; i < fLaunchConfigurationsDialog.getTabViewer().getTabs().length; i++) { + fLaunchConfigurationsDialog.getTabViewer().setActiveTab(i); + } + }; + + final ILaunchConfigurationTab[] tabs = runOnDialog(activateSeveralTab); + + // All tabs should have been activated exactly once + for (int i = 0; i < tabs.length; i++) { + assertThat(((SpyTab) tabs[i])).matches(SpyTab::isActivatedExactlyOnce, "Tab '" + i + "' should have been activated exactly once"); + } + } + private ILaunchConfigurationWorkingCopy createLaunchConfigurationInstance() throws CoreException { return fLaunchConfigurationType.newInstance(null, "MyLaunchConfiguration_" + System.currentTimeMillis()); } diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java index b2882e9958e..b2600b5e32b 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java @@ -867,15 +867,16 @@ protected void displayInstanceTabs(boolean redrawTabs) { // Update the name field fNameWidget.setText(getWorkingCopy().getName()); - fCurrentTabIndex = fTabFolder.getSelectionIndex(); + fCurrentTabIndex = -1; // Turn off initializing flag to update message fInitializingTabs = false; // Try to activate the same (type of) tab that was active before. if (!setActiveTab(lastActiveTabKind)) { - // The tab with the wanted class wasn't found. Try to activate the first one - setActiveTab(0); + // The tab with the wanted class wasn't found. Try to activate the default tab + int defaultTabIndex = Math.max(fTabFolder.getSelectionIndex(), 0); + setActiveTab(defaultTabIndex); } if (!fViewform.isVisible()) {