Skip to content

Commit

Permalink
Activate the current tab when switching between run configurations
Browse files Browse the repository at this point in the history
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 eclipse-pde/eclipse.pde#674
  • Loading branch information
fedejeanne committed Nov 3, 2023
1 parent bf89859 commit 1ea5dce
Showing 1 changed file with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,9 @@ protected void displayInstanceTabs(boolean redrawTabs) {
fInitializingTabs = false;
return;
}
Class<? extends ILaunchConfigurationTab> lastActiveTabKind = null;
if(redrawTabs) {
showInstanceTabsFor(type);
lastActiveTabKind = showInstanceTabsFor(type);
}
// show the name area
updateVisibleControls(true);
Expand Down Expand Up @@ -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<? extends ILaunchConfigurationTab> showInstanceTabsFor(ILaunchConfigurationType configType) {
// try to keep on same tab
Class<? extends ILaunchConfigurationTab> tabKind = null;
if (getActiveTab() != null) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 <code>true</code> if a tab was activated, <code>false</code>
* otherwise.
*/
private boolean setActiveTab(Class<? extends ILaunchConfigurationTab> 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.
Expand Down

0 comments on commit 1ea5dce

Please sign in to comment.