1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

View: Do not show the "Choose terminal:" combo box if there is only one

possible selection
This commit is contained in:
Uwe Stieber 2015-05-06 17:10:43 +02:00
parent 98c485b819
commit 5ef6efe70a

View file

@ -69,6 +69,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
// The dialog settings storage // The dialog settings storage
private IDialogSettings dialogSettings; private IDialogSettings dialogSettings;
// In case of a single available terminal launcher delegate, the label of that delegate
private String singleDelegateLabel = null;
/** /**
* The control managing the terminal setting panels. * The control managing the terminal setting panels.
*/ */
@ -277,53 +280,60 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
setDialogTitle(Messages.LaunchTerminalSettingsDialog_title); setDialogTitle(Messages.LaunchTerminalSettingsDialog_title);
final List<String> items = getTerminals();
Composite panel = new Composite(parent, SWT.NONE); Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false); GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0; layout.marginWidth = 0; layout.marginHeight = 0; layout.marginWidth = 0;
panel.setLayout(layout); panel.setLayout(layout);
panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
Label label = new Label(panel, SWT.HORIZONTAL); if (items.size() != 1) {
label.setText(Messages.LaunchTerminalSettingsDialog_combo_label); Label label = new Label(panel, SWT.HORIZONTAL);
label.setText(Messages.LaunchTerminalSettingsDialog_combo_label);
terminals = new Combo(panel, SWT.READ_ONLY); terminals = new Combo(panel, SWT.READ_ONLY);
terminals.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); terminals.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
terminals.addSelectionListener(new SelectionAdapter() { terminals.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
// Get the old panel // Get the old panel
IConfigurationPanel oldPanel = settings.getActiveConfigurationPanel(); IConfigurationPanel oldPanel = settings.getActiveConfigurationPanel();
// Extract the current settings in an special properties container // Extract the current settings in an special properties container
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
if (oldPanel != null) oldPanel.extractData(data); if (oldPanel != null) oldPanel.extractData(data);
// Clean out settings which are never passed between the panels // Clean out settings which are never passed between the panels
data.remove(ITerminalsConnectorConstants.PROP_IP_PORT); data.remove(ITerminalsConnectorConstants.PROP_IP_PORT);
data.remove(ITerminalsConnectorConstants.PROP_TIMEOUT); data.remove(ITerminalsConnectorConstants.PROP_TIMEOUT);
data.remove(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID); data.remove(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
data.remove(ITerminalsConnectorConstants.PROP_ENCODING); data.remove(ITerminalsConnectorConstants.PROP_ENCODING);
// Switch to the new panel // Switch to the new panel
settings.showConfigurationPanel(terminals.getText()); settings.showConfigurationPanel(terminals.getText());
// Get the new panel // Get the new panel
IConfigurationPanel newPanel = settings.getActiveConfigurationPanel(); IConfigurationPanel newPanel = settings.getActiveConfigurationPanel();
// Re-setup the relevant data // Re-setup the relevant data
if (newPanel != null) newPanel.setupData(data); if (newPanel != null) newPanel.setupData(data);
// resize the dialog if needed to show the complete panel // resize the dialog if needed to show the complete panel
getShell().pack(); getShell().pack();
// validate the settings dialog // validate the settings dialog
validate(); validate();
} }
}); });
// fill the combo with content // fill the combo with content
fillCombo(terminals); fillCombo(terminals, items);
} else {
Assert.isTrue(items.size() == 1);
singleDelegateLabel = items.get(0);
}
// Create the settings panel control // Create the settings panel control
settings = new SettingsPanelControl(); settings = new SettingsPanelControl();
// Create, initialize and add the first visible panel. All // Create, initialize and add the first visible panel. All
// other panels are created on demand only. // other panels are created on demand only.
String terminalLabel = terminals.getItem(0); String terminalLabel = terminals != null ? terminals.getItem(0) : singleDelegateLabel;
if (terminalLabel != null) { if (terminalLabel != null) {
// Get the corresponding delegate // Get the corresponding delegate
ILauncherDelegate delegate = label2delegate.get(terminalLabel); ILauncherDelegate delegate = label2delegate.get(terminalLabel);
@ -339,16 +349,20 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
} }
// Setup the panel control // Setup the panel control
settings.setupPanel(panel, terminals.getItems()); settings.setupPanel(panel, terminals != null ? terminals.getItems() : new String[] { singleDelegateLabel });
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
layoutData.horizontalSpan = 2; layoutData.horizontalSpan = 2;
settings.getPanel().setLayoutData(layoutData); settings.getPanel().setLayoutData(layoutData);
// Preselect the first terminal launcher // Preselect the first terminal launcher
terminals.select(0); if (terminals != null) {
settings.showConfigurationPanel(terminals.getText()); terminals.select(0);
settings.showConfigurationPanel(terminals.getText());
terminals.setEnabled(terminals.getItemCount() > 1); terminals.setEnabled(terminals.getItemCount() > 1);
} else {
settings.showConfigurationPanel(singleDelegateLabel);
}
restoreWidgetValues(); restoreWidgetValues();
@ -361,19 +375,31 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
} }
/** /**
* Fill the given combo with content. The content are the terminal * Fill the given combo with the given list of terminal launcher delegate labels.
* launcher delegate labels.
* *
* @param combo The combo. Must not be <code>null</code>. * @param combo The combo. Must not be <code>null</code>.
* @param items The list of terminal launcher delegates. Must not be <code>null</code>.
*/ */
protected void fillCombo(Combo combo) { protected void fillCombo(Combo combo, List<String> items) {
Assert.isNotNull(combo); Assert.isNotNull(combo);
Assert.isNotNull(items);
if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) { if (UIPlugin.getTraceHandler().isSlotEnabled(0, ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER)) {
UIPlugin.getTraceHandler().trace("Filling combo after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$ UIPlugin.getTraceHandler().trace("Filling combo after " + (System.currentTimeMillis() - start) + " ms.", //$NON-NLS-1$ //$NON-NLS-2$
ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this); ITraceIds.TRACE_LAUNCH_TERMINAL_COMMAND_HANDLER, LaunchTerminalSettingsDialog.this);
} }
Collections.sort(items);
combo.setItems(items.toArray(new String[items.size()]));
}
/**
* Returns the list of terminal launcher delegate labels. The method queries the
* terminal launcher delegates and initialize the <code>label2delegate</code> map.
*
* @return The list of terminal launcher delegate labels or an empty list.
*/
protected List<String> getTerminals() {
List<String> items = new ArrayList<String>(); List<String> items = new ArrayList<String>();
if(selection==null || selection.isEmpty()){ if(selection==null || selection.isEmpty()){
@ -417,8 +443,8 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
items.add(label); items.add(label);
} }
} }
Collections.sort(items);
combo.setItems(items.toArray(new String[items.size()])); return items;
} }
/** /**
@ -474,7 +500,7 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
IDialogSettings settings = getDialogSettings(); IDialogSettings settings = getDialogSettings();
if (settings != null) { if (settings != null) {
String terminalLabel = settings.get("terminalLabel"); //$NON-NLS-1$ String terminalLabel = settings.get("terminalLabel"); //$NON-NLS-1$
int index = terminalLabel != null ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) : -1; int index = terminalLabel != null && terminals != null ? Arrays.asList(terminals.getItems()).indexOf(terminalLabel) : -1;
if (index != -1) { if (index != -1) {
terminals.select(index); terminals.select(index);
this.settings.showConfigurationPanel(terminals.getText()); this.settings.showConfigurationPanel(terminals.getText());
@ -502,7 +528,9 @@ public class LaunchTerminalSettingsDialog extends TrayDialog {
data = new HashMap<String, Object>(); data = new HashMap<String, Object>();
// Store the id of the selected delegate // Store the id of the selected delegate
data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, label2delegate.get(terminals.getText()).getId()); String terminalLabel = terminals != null ? terminals.getText() : singleDelegateLabel;
String delegateId = terminalLabel != null ? label2delegate.get(terminalLabel).getId() : null;
if (delegateId != null) data.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegateId);
// Store the selection // Store the selection
data.put(ITerminalsConnectorConstants.PROP_SELECTION, selection); data.put(ITerminalsConnectorConstants.PROP_SELECTION, selection);