1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Bug 515296: Create all CSourceNotFound controls unconditionally

When the editor is first opened, if it is not opened on something
that resolves isDebugElement = true, the set of controls to be visible
is different. This change ensures that the same editor can be reused
between isDebugElement = true and isDebugElement = false cases.

Change-Id: I153433de1716c8c8eeffd6ec49d0b1422b04921e
This commit is contained in:
Jonah Graham 2017-05-09 14:34:25 +01:00
parent fb8e792478
commit 2f3dbb123a

View file

@ -66,6 +66,23 @@ import org.eclipse.ui.dialogs.PreferencesUtil;
* modifies the source locator accordingly. * modifies the source locator accordingly.
*/ */
public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor { public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
/**
* Encapsulate all the controls used within this class.
*/
private static class EditorControls {
public Composite buttonParentComposite;
public Button disassemblyButton;
public GridData disassemblyButtonGridData;
public Button locateFileButton;
public GridData locateFileButtonGridData;
public Button editLookupButton;
public GridData editLookupButtonGridData;
public Text fText;
public Text preferenceText;
public Button preferenceButton;
}
private static final String SOURCE_NOT_FOUND_PATH = "org.eclipse.cdt.debug.ui.CDebugPreferencePage"; //$NON-NLS-1$ private static final String SOURCE_NOT_FOUND_PATH = "org.eclipse.cdt.debug.ui.CDebugPreferencePage"; //$NON-NLS-1$
public final String foundMappingsContainerName = "Found Mappings"; //$NON-NLS-1$ public final String foundMappingsContainerName = "Found Mappings"; //$NON-NLS-1$
@ -81,22 +98,14 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
private IAdaptable context; private IAdaptable context;
private ITranslationUnit tunit; private ITranslationUnit tunit;
private Button disassemblyButton;
private Button locateFileButton;
private GridData locateFileButtonGridData;
private Button editLookupButton;
private GridData editLookupButtonGridData;
private boolean isDebugElement; private boolean isDebugElement;
private boolean isTranslationUnit; private boolean isTranslationUnit;
private Text fText;
private Text preferenceText; /**
private Button preferenceButton; * Encapsulate all the controls used within this class. This will be
* {@code null} until {@link #createPartControl(Composite)} is called.
private Composite buttonParentComposite; */
private EditorControls controls;
public CSourceNotFoundEditor() { public CSourceNotFoundEditor() {
super(); super();
@ -112,27 +121,34 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
parent.setLayoutData(data); parent.setLayoutData(data);
parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
fText = new Text(parent, SWT.READ_ONLY | SWT.WRAP); controls = new EditorControls();
controls.fText = new Text(parent, SWT.READ_ONLY | SWT.WRAP);
data = new GridData(GridData.FILL_HORIZONTAL); data = new GridData(GridData.FILL_HORIZONTAL);
data.grabExcessHorizontalSpace = true; data.grabExcessHorizontalSpace = true;
fText.setLayoutData(data); controls.fText.setLayoutData(data);
fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK)); controls.fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLACK));
fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); controls.fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
if (getEditorInput() != null) {
setInput(getEditorInput());
}
createButtons(parent); createButtons(parent);
Dialog.applyDialogFont(parent); Dialog.applyDialogFont(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICDebugHelpContextIds.SOURCE_NOT_FOUND); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICDebugHelpContextIds.SOURCE_NOT_FOUND);
/*
* Now that all the controls have been created in a non-data dependent
* way synchronize the controls content/visibility with the current
* input data.
*/
if (getEditorInput() != null) {
setInput(getEditorInput());
}
syncButtons();
} }
@Override @Override
public void setFocus() { public void setFocus() {
if (fText != null) { if (controls != null) {
fText.setFocus(); controls.fText.setFocus();
} }
} }
@ -160,25 +176,30 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
} }
} }
super.setInput(input); super.setInput(input);
if (fText != null) { if (controls != null) {
fText.setText(getText()); controls.fText.setText(getText());
} }
syncButtons(); syncButtons();
} }
private void syncButtons() { private void syncButtons() {
boolean visible = missingFile.length() > 0; if (controls != null) {
if (locateFileButton != null) { boolean missingFileNameKnown = missingFile.length() > 0;
locateFileButton.setVisible(visible);
locateFileButtonGridData.exclude = !visible; boolean disassemblyButtonVisible = isDebugElement;
} controls.disassemblyButton.setVisible(disassemblyButtonVisible);
if (editLookupButton != null) { controls.disassemblyButtonGridData.exclude = !disassemblyButtonVisible;
editLookupButton.setVisible(visible);
editLookupButtonGridData.exclude = !visible; boolean locateFileButtonVisible = missingFileNameKnown;
} controls.locateFileButton.setVisible(locateFileButtonVisible);
if (buttonParentComposite != null) { controls.locateFileButtonGridData.exclude = !locateFileButtonVisible;
buttonParentComposite.layout(true, true);
boolean editLookupButtonVisible = missingFileNameKnown && isDebugElement;
controls.editLookupButton.setVisible(editLookupButtonVisible);
controls.editLookupButtonGridData.exclude = !editLookupButtonVisible;
controls.buttonParentComposite.layout(true, true);
} }
} }
@ -210,65 +231,64 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
@Override @Override
protected void createButtons(Composite parent) { protected void createButtons(Composite parent) {
this.buttonParentComposite = parent; controls.buttonParentComposite = parent;
if (isDebugElement) { {
GridData data; controls.disassemblyButton = new Button(parent, SWT.PUSH);
disassemblyButton = new Button(parent, SWT.PUSH); controls.disassemblyButtonGridData = new GridData();
data = new GridData(); controls.disassemblyButtonGridData.grabExcessHorizontalSpace = false;
data.grabExcessHorizontalSpace = false; controls.disassemblyButtonGridData.grabExcessVerticalSpace = false;
data.grabExcessVerticalSpace = false; controls.disassemblyButton.setLayoutData(controls.disassemblyButtonGridData);
disassemblyButton.setLayoutData(data); controls.disassemblyButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_4);
disassemblyButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_4); controls.disassemblyButton.addSelectionListener(new SelectionAdapter() {
disassemblyButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent evt) { public void widgetSelected(SelectionEvent evt) {
viewDisassembly(); viewDisassembly();
} }
}); });
disassemblyButton.setData(UID_KEY, UID_DISASSEMBLY_BUTTON); controls.disassemblyButton.setData(UID_KEY, UID_DISASSEMBLY_BUTTON);
} }
{ {
locateFileButton = new Button(parent, SWT.PUSH); controls.locateFileButton = new Button(parent, SWT.PUSH);
locateFileButtonGridData = new GridData(); controls.locateFileButtonGridData = new GridData();
locateFileButtonGridData.grabExcessHorizontalSpace = false; controls.locateFileButtonGridData.grabExcessHorizontalSpace = false;
locateFileButtonGridData.grabExcessVerticalSpace = false; controls.locateFileButtonGridData.grabExcessVerticalSpace = false;
locateFileButton.setLayoutData(locateFileButtonGridData); controls.locateFileButton.setLayoutData(controls.locateFileButtonGridData);
locateFileButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_1); controls.locateFileButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_1);
locateFileButton.addSelectionListener(new SelectionAdapter() { controls.locateFileButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent evt) { public void widgetSelected(SelectionEvent evt) {
locateFile(); locateFile();
} }
}); });
locateFileButton.setData(UID_KEY, UID_LOCATE_FILE_BUTTON); controls.locateFileButton.setData(UID_KEY, UID_LOCATE_FILE_BUTTON);
} }
if (isDebugElement) { {
editLookupButton = new Button(parent, SWT.PUSH); controls.editLookupButton = new Button(parent, SWT.PUSH);
editLookupButtonGridData = new GridData(); controls.editLookupButtonGridData = new GridData();
editLookupButtonGridData.grabExcessHorizontalSpace = false; controls.editLookupButtonGridData.grabExcessHorizontalSpace = false;
editLookupButtonGridData.grabExcessVerticalSpace = false; controls.editLookupButtonGridData.grabExcessVerticalSpace = false;
editLookupButton.setLayoutData(editLookupButtonGridData); controls.editLookupButton.setLayoutData(controls.editLookupButtonGridData);
editLookupButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_5); controls.editLookupButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_5);
editLookupButton.addSelectionListener(new SelectionAdapter() { controls.editLookupButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent evt) { public void widgetSelected(SelectionEvent evt) {
editSourceLookupPath(); editSourceLookupPath();
} }
}); });
editLookupButton.setData(UID_KEY, UID_EDIT_LOOKUP_BUTTON); controls.editLookupButton.setData(UID_KEY, UID_EDIT_LOOKUP_BUTTON);
} }
{ {
Composite data = ControlFactory.createComposite(parent, 2); Composite data = ControlFactory.createComposite(parent, 2);
((GridLayout) data.getLayout()).marginWidth = 0; ((GridLayout) data.getLayout()).marginWidth = 0;
((GridLayout) data.getLayout()).marginHeight = 0; ((GridLayout) data.getLayout()).marginHeight = 0;
preferenceText = new Text(data, SWT.READ_ONLY | SWT.WRAP); controls.preferenceText = new Text(data, SWT.READ_ONLY | SWT.WRAP);
preferenceButton = new Button(data, SWT.PUSH); controls.preferenceButton = new Button(data, SWT.PUSH);
preferenceText.setText(SourceLookupUIMessages.CSourceNotFoundEditor_6); controls.preferenceText.setText(SourceLookupUIMessages.CSourceNotFoundEditor_6);
preferenceButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_7); controls.preferenceButton.setText(SourceLookupUIMessages.CSourceNotFoundEditor_7);
preferenceButton.addSelectionListener(new SelectionAdapter() { controls.preferenceButton.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(parent.getShell(), SOURCE_NOT_FOUND_PATH, null, null) PreferencesUtil.createPreferenceDialogOn(parent.getShell(), SOURCE_NOT_FOUND_PATH, null, null)
@ -276,8 +296,6 @@ public class CSourceNotFoundEditor extends CommonSourceNotFoundEditor {
} }
}); });
} }
syncButtons();
} }
protected void viewDisassembly() { protected void viewDisassembly() {