mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-11 11:05:24 +02:00
LaunchBar: use o.e.debug control to manage lc tabs
- current wizard page tries to replicate functionality of lc editor in regards to tabs but it does not work the same which creates issues for contributed tabs - for example it never calls "activate" on the tab - we also have rendering problem - pages are not resized correctly and show up empty until resized - I switched to use standard control called LaunchConfigurationTabGroupViewer to show tabs. Hack with fake LaunchConfigurationDialog has to remain to interact with this control. - If we move it to o.e.debug we have to fix these classes to remove some of the hacks and expose proper APIs to re-use this control Change-Id: Ia39706fb5972883167f5f39751985d97e1815c86
This commit is contained in:
parent
117074d323
commit
50e08bc7d5
4 changed files with 92 additions and 199 deletions
|
@ -17,43 +17,28 @@ import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.debug.core.ILaunchManager;
|
|
||||||
import org.eclipse.debug.internal.core.LaunchManager;
|
|
||||||
import org.eclipse.debug.internal.ui.DebugUIPlugin;
|
import org.eclipse.debug.internal.ui.DebugUIPlugin;
|
||||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog;
|
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog;
|
||||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
|
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTabGroupViewer;
|
||||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
|
|
||||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
|
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
|
||||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
|
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
|
||||||
import org.eclipse.debug.ui.ILaunchConfigurationTab;
|
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
|
||||||
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
|
|
||||||
import org.eclipse.debug.ui.ILaunchGroup;
|
import org.eclipse.debug.ui.ILaunchGroup;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
import org.eclipse.jface.resource.ColorRegistry;
|
|
||||||
import org.eclipse.jface.resource.JFaceResources;
|
|
||||||
import org.eclipse.jface.wizard.WizardPage;
|
import org.eclipse.jface.wizard.WizardPage;
|
||||||
import org.eclipse.launchbar.ui.internal.Activator;
|
import org.eclipse.launchbar.ui.internal.Activator;
|
||||||
import org.eclipse.launchbar.ui.internal.Messages;
|
import org.eclipse.launchbar.ui.internal.Messages;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.custom.CTabFolder;
|
|
||||||
import org.eclipse.swt.custom.CTabItem;
|
|
||||||
import org.eclipse.swt.events.ModifyEvent;
|
|
||||||
import org.eclipse.swt.events.ModifyListener;
|
|
||||||
import org.eclipse.swt.graphics.Color;
|
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Label;
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
|
||||||
|
|
||||||
@SuppressWarnings("restriction")
|
@SuppressWarnings("restriction")
|
||||||
public class NewLaunchConfigEditPage extends WizardPage {
|
public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
ILaunchConfigurationWorkingCopy workingCopy;
|
private ILaunchConfigurationWorkingCopy workingCopy;
|
||||||
ILaunchConfigurationTabGroup tabGroup;
|
private LaunchConfigurationDialogExt launchConfigurationDialog = new LaunchConfigurationDialogExt();
|
||||||
private Text nameText;
|
private LaunchConfigurationTabGroupViewerExt tabViewer;
|
||||||
private CTabFolder tabFolder;
|
private ILaunchConfigurationType type;
|
||||||
private LaunchConfigurationDialog launchConfigurationDialog = new LaunchConfigurationDialogFake();
|
|
||||||
private LaunchConfigurationManager launchConfigurationMgr = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
|
|
||||||
|
|
||||||
public NewLaunchConfigEditPage() {
|
public NewLaunchConfigEditPage() {
|
||||||
super(Messages.NewLaunchConfigEditPage_0);
|
super(Messages.NewLaunchConfigEditPage_0);
|
||||||
|
@ -64,111 +49,50 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
@Override
|
@Override
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
Composite comp = new Composite(parent, SWT.NONE);
|
Composite comp = new Composite(parent, SWT.NONE);
|
||||||
comp.setLayout(new GridLayout(2, false));
|
comp.setLayout(new GridLayout(1, false));
|
||||||
Label label = new Label(comp, SWT.NONE);
|
|
||||||
label.setLayoutData(new GridData());
|
|
||||||
label.setText(Messages.NewLaunchConfigEditPage_3 + ":"); //$NON-NLS-1$
|
|
||||||
nameText = new Text(comp, SWT.BORDER);
|
|
||||||
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
|
||||||
ColorRegistry reg = JFaceResources.getColorRegistry();
|
|
||||||
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
|
|
||||||
c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
|
|
||||||
tabFolder = new CTabFolder(comp, SWT.BORDER | SWT.NO_REDRAW_RESIZE | SWT.FLAT);
|
|
||||||
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
||||||
gridData.horizontalSpan = 2;
|
|
||||||
tabFolder.setLayoutData(gridData);
|
|
||||||
tabFolder.setSimple(false);
|
|
||||||
tabFolder.setSelectionBackground(new Color[] { c1, c2 }, new int[] { 100 }, true);
|
|
||||||
tabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
|
|
||||||
|
|
||||||
setControl(comp);
|
setControl(comp);
|
||||||
nameText.addModifyListener(new ModifyListener() {
|
// create tab viewer
|
||||||
@Override
|
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog);
|
||||||
public void modifyText(ModifyEvent e) {
|
tabViewer = new LaunchConfigurationTabGroupViewerExt(comp, launchConfigurationDialog);
|
||||||
String name = nameText.getText().trim();
|
launchConfigurationDialog.setTabViewer(tabViewer);
|
||||||
workingCopy.rename(name);
|
changeLaunchConfigType(type);
|
||||||
|
GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
|
||||||
String errMessage = checkName(name);
|
data.heightHint = 500;
|
||||||
if (errMessage == null) {
|
tabViewer.getControl().setLayoutData(data);
|
||||||
validateFields();
|
parent.layout(true, true);
|
||||||
} else {
|
|
||||||
setErrorMessage(errMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
validateFields();
|
validateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String checkName(String name) {
|
/**
|
||||||
try {
|
* @return the workingCopy
|
||||||
if (name.isEmpty()) {
|
*/
|
||||||
return Messages.NewLaunchConfigEditPage_4;
|
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
|
||||||
|
return workingCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
|
|
||||||
if (manager.isExistingLaunchConfigurationName(name)) {
|
|
||||||
ILaunchConfiguration config = ((LaunchManager) manager).findLaunchConfiguration(name);
|
|
||||||
if (config != workingCopy.getOriginal()) {
|
|
||||||
return (Messages.NewLaunchConfigEditPage_5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Activator.log(e);
|
|
||||||
return (e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void changeLaunchConfigType(ILaunchConfigurationType type) {
|
void changeLaunchConfigType(ILaunchConfigurationType type) {
|
||||||
if (type == null)
|
if (type == null)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
String initialMode = ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
|
this.type = type;
|
||||||
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
|
|
||||||
String name = manager.generateLaunchConfigurationName("launchConfiguration"); //$NON-NLS-1$
|
|
||||||
workingCopy = type.newInstance(null, name);
|
|
||||||
tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, initialMode);
|
|
||||||
for (CTabItem item : tabFolder.getItems())
|
|
||||||
item.dispose();
|
|
||||||
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog);
|
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(launchConfigurationDialog);
|
||||||
tabGroup.createTabs(launchConfigurationDialog, initialMode);
|
if (tabViewer != null) {
|
||||||
|
String name = launchConfigurationDialog.generateName("launchConfiguration"); //$NON-NLS-1$
|
||||||
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
|
workingCopy = type.newInstance(null, name);
|
||||||
tab.setLaunchConfigurationDialog(launchConfigurationDialog);
|
launchConfigurationDialog.doSetDefaults(workingCopy);
|
||||||
tab.createControl(tabFolder);
|
tabViewer.setInput(workingCopy);
|
||||||
tab.setDefaults(workingCopy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do this after all the tabs have their controls created
|
|
||||||
for (ILaunchConfigurationTab tab : tabGroup.getTabs()) {
|
|
||||||
tab.initializeFrom(workingCopy);
|
|
||||||
|
|
||||||
CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
|
|
||||||
tabItem.setText(tab.getName());
|
|
||||||
tabItem.setImage(!tab.isValid(workingCopy) && tab.getErrorMessage() != null ?
|
|
||||||
launchConfigurationMgr.getErrorTabImage(tab) : tab.getImage());
|
|
||||||
tabItem.setControl(tab.getControl());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up any created configs before we set the name and trigger
|
|
||||||
// any validation
|
|
||||||
((NewLaunchConfigWizard) getWizard()).cleanUpConfigs();
|
|
||||||
|
|
||||||
tabFolder.setSelection(0);
|
|
||||||
nameText.setText(workingCopy.getName());
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean performFinish() {
|
boolean performFinish() {
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return false;
|
return false;
|
||||||
for (ILaunchConfigurationTab tab : tabGroup.getTabs())
|
workingCopy.rename(tabViewer.getWorkingCopy().getName());
|
||||||
tab.performApply(workingCopy);
|
tabViewer.getTabGroup().performApply(workingCopy);
|
||||||
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(null);
|
LaunchConfigurationsDialog.setCurrentlyVisibleLaunchConfigurationDialog(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -183,38 +107,7 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return;
|
return;
|
||||||
String message = null;
|
String message = tabViewer.getErrorMesssage();
|
||||||
String old_msg = getErrorMessage();
|
|
||||||
setErrorMessage(null);
|
|
||||||
message = checkName(workingCopy.getName());
|
|
||||||
if (message == null) {
|
|
||||||
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
|
|
||||||
int tLen = tabs.length;
|
|
||||||
int tfLen = tabFolder.getItems().length;
|
|
||||||
for (int i = 0; i < tLen; i++) {
|
|
||||||
ILaunchConfigurationTab tab = tabs[i];
|
|
||||||
try {
|
|
||||||
tab.isValid(workingCopy);
|
|
||||||
message = tab.getErrorMessage();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// if createControl hasn't been called yet can throw exception..
|
|
||||||
// like the NPE issue in CTestingTab
|
|
||||||
message = e.getMessage();
|
|
||||||
}
|
|
||||||
// this is similar to what LaunchConfigurationTabGroupViewer.refresh() does, which is not available in this case
|
|
||||||
if (tLen == tfLen &&
|
|
||||||
(old_msg == null && message != null || old_msg != null && message == null)) {
|
|
||||||
CTabItem item = tabFolder.getItem(i);
|
|
||||||
if (item != null) {
|
|
||||||
item.setImage(message != null ? launchConfigurationMgr.getErrorTabImage(tab)
|
|
||||||
: tab.getImage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (message != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setErrorMessage(message);
|
setErrorMessage(message);
|
||||||
if (getErrorMessage() != null) {
|
if (getErrorMessage() != null) {
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
|
@ -223,8 +116,8 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LaunchConfigurationDialogFake extends LaunchConfigurationDialog {
|
private class LaunchConfigurationDialogExt extends LaunchConfigurationDialog {
|
||||||
public LaunchConfigurationDialogFake() {
|
public LaunchConfigurationDialogExt() {
|
||||||
super(NewLaunchConfigEditPage.this.getShell(), null, null);
|
super(NewLaunchConfigEditPage.this.getShell(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,24 +143,22 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
return NewLaunchConfigEditPage.this.getMode();
|
return NewLaunchConfigEditPage.this.getMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(boolean fork, boolean cancelable,
|
|
||||||
IRunnableWithProgress runnable)
|
|
||||||
throws InvocationTargetException, InterruptedException {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateButtons() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMessage() {
|
public void updateMessage() {
|
||||||
validateFields();
|
validateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(String name) {
|
public void updateButtons() {
|
||||||
|
// Launch button
|
||||||
|
getTabViewer().refresh();
|
||||||
|
// getButton(ID_LAUNCH_BUTTON).setEnabled(getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(boolean fork, boolean cancelable,
|
||||||
|
IRunnableWithProgress runnable)
|
||||||
|
throws InvocationTargetException, InterruptedException {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,35 +170,26 @@ public class NewLaunchConfigEditPage extends WizardPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfigurationTab[] getTabs() {
|
public void doSetDefaults(ILaunchConfigurationWorkingCopy wc) {
|
||||||
return tabGroup.getTabs();
|
super.doSetDefaults(wc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfigurationTab getActiveTab() {
|
public void setTabViewer(LaunchConfigurationTabGroupViewer viewer) {
|
||||||
int i = tabFolder.getSelectionIndex();
|
super.setTabViewer(viewer);
|
||||||
return tabGroup.getTabs()[i];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class LaunchConfigurationTabGroupViewerExt extends LaunchConfigurationTabGroupViewer {
|
||||||
@Override
|
public LaunchConfigurationTabGroupViewerExt(Composite parent, ILaunchConfigurationDialog dialog) {
|
||||||
public void setActiveTab(ILaunchConfigurationTab tab) {
|
super(parent, dialog);
|
||||||
ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
|
|
||||||
int tLen = tabs.length;
|
|
||||||
for (int i = 0; i < tLen; i++) {
|
|
||||||
ILaunchConfigurationTab tabi = tabs[i];
|
|
||||||
if (tabi.equals(tab)) {
|
|
||||||
setActiveTab(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActiveTab(int index) {
|
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
|
||||||
tabFolder.setSelection(index);
|
return super.getWorkingCopy();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public String getMode() {
|
public String getMode() {
|
||||||
return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
|
return ((NewLaunchConfigWizard) getWizard()).modePage.selectedGroup.getMode();
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.eclipse.swt.widgets.Table;
|
||||||
import org.eclipse.swt.widgets.TableItem;
|
import org.eclipse.swt.widgets.TableItem;
|
||||||
|
|
||||||
public class NewLaunchConfigTypePage extends WizardPage {
|
public class NewLaunchConfigTypePage extends WizardPage {
|
||||||
|
|
||||||
private Table table;
|
private Table table;
|
||||||
|
|
||||||
public NewLaunchConfigTypePage() {
|
public NewLaunchConfigTypePage() {
|
||||||
|
@ -85,9 +84,13 @@ public class NewLaunchConfigTypePage extends WizardPage {
|
||||||
@Override
|
@Override
|
||||||
public IWizardPage getNextPage() {
|
public IWizardPage getNextPage() {
|
||||||
ILaunchConfigurationType type = (ILaunchConfigurationType) table.getSelection()[0].getData();
|
ILaunchConfigurationType type = (ILaunchConfigurationType) table.getSelection()[0].getData();
|
||||||
NewLaunchConfigEditPage editPage = ((NewLaunchConfigWizard)getWizard()).editPage;
|
NewLaunchConfigWizard wiz = (NewLaunchConfigWizard) getWizard();
|
||||||
|
NewLaunchConfigEditPage editPage = wiz.editPage;
|
||||||
|
// lazy page creation
|
||||||
|
if (wiz.getPage(editPage.getName()) == null) {
|
||||||
|
wiz.addPage(editPage);
|
||||||
|
}
|
||||||
editPage.changeLaunchConfigType(type);
|
editPage.changeLaunchConfigType(type);
|
||||||
return editPage;
|
return editPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,19 @@ public class NewLaunchConfigWizard extends Wizard implements ILaunchConfiguratio
|
||||||
public void addPages() {
|
public void addPages() {
|
||||||
addPage(modePage);
|
addPage(modePage);
|
||||||
addPage(typePage);
|
addPage(typePage);
|
||||||
addPage(editPage);
|
//addPage(editPage); // add dynamically on the types page
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canFinish() {
|
||||||
|
if (getPage(editPage.getName()) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.canFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
|
public ILaunchConfigurationWorkingCopy getWorkingCopy() {
|
||||||
return editPage.workingCopy;
|
return editPage.getWorkingCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILaunchMode getLaunchMode() {
|
public ILaunchMode getLaunchMode() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue