From 1ea5dce64811e3a580ed3e3c2bab340f7a274863 Mon Sep 17 00:00:00 2001 From: fedejeanne Date: Wed, 25 Oct 2023 13:17:49 +0200 Subject: [PATCH] Activate the current tab when switching between run configurations Make sure that the selected tab is activated (i.e. that its "activate" method is called) when switching between existing run configurations in the "Run configurations" dialog. Contributes to https://github.com/eclipse-pde/eclipse.pde/pull/674 --- .../LaunchConfigurationTabGroupViewer.java | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) 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 83c74b62b5e..b9b8b5784bf 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 @@ -842,8 +842,9 @@ protected void displayInstanceTabs(boolean redrawTabs) { fInitializingTabs = false; return; } + Class lastActiveTabKind = null; if(redrawTabs) { - showInstanceTabsFor(type); + lastActiveTabKind = showInstanceTabsFor(type); } // show the name area updateVisibleControls(true); @@ -875,17 +876,25 @@ protected void displayInstanceTabs(boolean redrawTabs) { // 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); + } + if (!fViewform.isVisible()) { fViewform.setVisible(true); } } /** - * Populate the tabs in the configuration edit area to be appropriate to the current - * launch configuration type. + * Populate the tabs in the configuration edit area to be appropriate to the + * current launch configuration type. + * * @param configType the type to show tabs for + * @return The class of the last active tab. */ - private void showInstanceTabsFor(ILaunchConfigurationType configType) { + private Class showInstanceTabsFor(ILaunchConfigurationType configType) { // try to keep on same tab Class tabKind = null; if (getActiveTab() != null) { @@ -897,7 +906,7 @@ private void showInstanceTabsFor(ILaunchConfigurationType configType) { group = createGroup(); } catch (CoreException ce) { DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_Exception_occurred_creating_launch_configuration_tabs_27,ce); // - return; + return null; } disposeExistingTabs(); fTabGroup = group; @@ -926,18 +935,8 @@ private void showInstanceTabsFor(ILaunchConfigurationType configType) { tab.setControl(control.getParent()); } } - //set the default tab as the first one - if (tabs.length > 0) { - setActiveTab(tabs[0]); - } - // select same tab as before, if possible - for (ILaunchConfigurationTab t : tabs) { - if (t.getClass().equals(tabKind)) { - setActiveTab(t); - break; - } - } fDescription = getDescription(configType); + return tabKind; } /** @@ -1606,6 +1605,29 @@ protected void errorDialog(CoreException exception) { ErrorDialog.openError(getShell(), null, null, exception.getStatus()); } + /** + * @param tabKind The class of the tab that has to be activated. + * @return true if a tab was activated, false + * otherwise. + */ + private boolean setActiveTab(Class tabKind) { + if (tabKind == null) { + return false; + } + + ILaunchConfigurationTab[] tabs = getTabs(); + + // select same tab as before, if possible + for (ILaunchConfigurationTab t : tabs) { + if (t.getClass().equals(tabKind)) { + setActiveTab(t); + return true; + } + } + + return false; + } + /** * Sets the displayed tab to the given tab. Has no effect if the specified * tab is not one of the tabs being displayed in the dialog currently.