1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Discovery page: show page names instead of profile IDs where possible

Preferences: user can select naming rule for discovery profiles
This commit is contained in:
Oleg Krasilnikov 2007-04-05 10:55:46 +00:00
parent 6ca738c032
commit 32163b8508
5 changed files with 136 additions and 23 deletions

View file

@ -429,7 +429,7 @@
name="%Wizard.defaults"
parent="org.eclipse.cdt.managedbuilder.ui.preferences.PrefPage_NewCDTWizard"/>
<tab
class="org.eclipse.cdt.ui.newui.PropertyPageDefsTab"
class="org.eclipse.cdt.managedbuilder.ui.preferences.PropertyPageDefsTab"
name="%PropertyPage.defaults"
parent="org.eclipse.cdt.managedbuilder.ui.preferences.PrefPage_PropertyPage"/>
</extension>

View file

@ -8,23 +8,33 @@
* Contributors:
* Intel Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.newui;
package org.eclipse.cdt.managedbuilder.ui.preferences;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.swt.widgets.Group;
public class PropertyPageDefsTab extends AbstractCPropertyTab {
private static final int SPACING = 5; // for radio buttons layout
private Button show_tree;
private Button show_mul;
// private Button show_mul;
private Button show_mng;
private Button show_sav;
private Button show_tool;
private Button b_0;
private Button b_1;
private Button b_2;
private Button b_3;
public void createControls(Composite parent) {
super.createControls(parent);
@ -38,9 +48,9 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
show_tree.setText(UIMessages.getString("PropertyPageDefsTab.1")); //$NON-NLS-1$
show_tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
show_mul = new Button(usercomp, SWT.CHECK);
show_mul.setText(UIMessages.getString("PropertyPageDefsTab.2")); //$NON-NLS-1$
show_mul.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// show_mul = new Button(usercomp, SWT.CHECK);
// show_mul.setText(UIMessages.getString("PropertyPageDefsTab.2")); //$NON-NLS-1$
// show_mul.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
show_sav = new Button(usercomp, SWT.CHECK);
show_sav.setText(UIMessages.getString("PropertyPageDefsTab.3")); //$NON-NLS-1$
@ -50,28 +60,58 @@ public class PropertyPageDefsTab extends AbstractCPropertyTab {
show_tool.setText(UIMessages.getString("PropertyPageDefsTab.4")); //$NON-NLS-1$
show_tool.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Group discGrp = new Group(usercomp, SWT.NONE);
discGrp.setText(UIMessages.getString("PropertyPageDefsTab.5")); //$NON-NLS-1$
discGrp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
FillLayout fl = new FillLayout(SWT.VERTICAL);
fl.spacing = SPACING;
fl.marginHeight = SPACING;
fl.marginWidth = SPACING;
discGrp.setLayout(fl);
b_0 = new Button(discGrp, SWT.RADIO);
b_0.setText(UIMessages.getString("PropertyPageDefsTab.6")); //$NON-NLS-1$
b_1 = new Button(discGrp, SWT.RADIO);
b_1.setText(UIMessages.getString("PropertyPageDefsTab.7")); //$NON-NLS-1$
b_2 = new Button(discGrp, SWT.RADIO);
b_2.setText(UIMessages.getString("PropertyPageDefsTab.8")); //$NON-NLS-1$
b_3 = new Button(discGrp, SWT.RADIO);
b_3.setText(UIMessages.getString("PropertyPageDefsTab.9")); //$NON-NLS-1$
show_tree.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_DTREE));
show_mul.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_MULTI));
// show_mul.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_MULTI));
show_mng.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOMNG));
show_sav.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSAVE));
show_tool.setSelection(CDTPrefUtil.getBool(CDTPrefUtil.KEY_TOOLM));
show_mul.setVisible(false); // temporary
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_DISC_NAMES)) {
case CDTPrefUtil.DISC_NAMING_UNIQUE_OR_BOTH: b_0.setSelection(true); break;
case CDTPrefUtil.DISC_NAMING_UNIQUE_OR_IDS: b_1.setSelection(true); break;
case CDTPrefUtil.DISC_NAMING_ALWAYS_BOTH: b_2.setSelection(true); break;
case CDTPrefUtil.DISC_NAMING_ALWAYS_IDS: b_3.setSelection(true); break;
}
}
protected void performOK() {
CDTPrefUtil.setBool(CDTPrefUtil.KEY_DTREE, show_tree.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_MULTI, show_mul.getSelection());
// CDTPrefUtil.setBool(CDTPrefUtil.KEY_MULTI, show_mul.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOMNG, !show_mng.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_NOSAVE, !show_sav.getSelection());
CDTPrefUtil.setBool(CDTPrefUtil.KEY_TOOLM, show_tool.getSelection());
int x = 0;
if (b_1.getSelection()) x = 1;
else if (b_2.getSelection()) x = 2;
else if (b_3.getSelection()) x = 3;
CDTPrefUtil.setInt(CDTPrefUtil.KEY_DISC_NAMES, x);
}
protected void performDefaults() {
show_tree.setSelection(false);
show_mul.setSelection(false);
// show_mul.setSelection(false);
show_mng.setSelection(true);
show_mng.setSelection(true);
show_tool.setSelection(false);
b_0.setSelection(true);
}
protected void performApply(ICResourceDescription src, ICResourceDescription dst) { performOK(); }

View file

@ -35,6 +35,7 @@ import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.newui.CDTListComparator;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
import org.eclipse.core.resources.IProject;
@ -267,20 +268,18 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
Collections.sort(profilesList, CDTListComparator.getInstance());
visibleProfilesList = new ArrayList(profilesList.size());
realPages = new AbstractDiscoveryPage[profilesList.size()];
String[] labels = new String[profilesList.size()];
String[] profiles = new String[profilesList.size()];
Iterator it = profilesList.iterator();
int counter = 0;
int pos = 0;
String savedId = buildInfo.getSelectedProfileId();
while (it.hasNext()) {
String profileId = (String)it.next();
System.out.println(profileId);
if (!cbi.isProfileSupported(iContext, profileId))
continue;
visibleProfilesList.add(profileId);
String profileName = getProfileName(profileId);
profileComboBox.add(profileName);
labels[counter] = profiles[counter] = getProfileName(profileId);
if (profileId.equals(savedId))
pos = counter;
buildInfo.setSelectedProfileId(profileId); // needs to create page
@ -290,6 +289,9 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
AbstractDiscoveryPage pg = p.getPage();
if (pg != null) {
realPages[counter] = pg;
String s = p.name;
if (s != null && s.length() > 0)
labels[counter] = s;
pg.setContainer(wrapper);
pg.createControl(profileComp);
profileComp.layout(true);
@ -299,11 +301,70 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
}
counter ++;
}
buildInfo.setSelectedProfileId(savedId);
if (profileComboBox.getItemCount() > 0)
profileComboBox.select(pos);
enableAllControls();
handleDiscoveryProfileChanged();
profileComboBox.setItems(normalize(labels, profiles, counter));
buildInfo.setSelectedProfileId(savedId);
if (profileComboBox.getItemCount() > 0)
profileComboBox.select(pos);
enableAllControls();
handleDiscoveryProfileChanged();
}
private String[] normalize(String[] labels, String[] ids, int counter) {
int mode = CDTPrefUtil.getInt(CDTPrefUtil.KEY_DISC_NAMES);
String[] tmp = new String[counter];
// Always show either Name + ID, or ID only
// These cases do not require checking for doubles.
if (mode == CDTPrefUtil.DISC_NAMING_ALWAYS_BOTH ||
mode == CDTPrefUtil.DISC_NAMING_ALWAYS_IDS){
for (int i=0; i<counter; i++)
tmp[i] = (mode == CDTPrefUtil.DISC_NAMING_ALWAYS_IDS) ?
ids[i] :
combine(labels[i], ids[i]);
return tmp;
}
// For not-unique names only, either display ID or name + ID
boolean doubles = false;
outer:
// quick check for at least one double
for (int i=0; i<counter; i++) {
for (int j=0; j<counter; j++) {
// sic! i < j, to avoid repeated comparison
if (i < j && labels[i].equals(labels[j])) {
doubles = true;
break outer;
}
}
}
if (!doubles) { // all names are unique.
for (int i=0; i<counter; i++)
tmp[i] = labels[i];
} else {
for (int i=0; i<counter; i++) {
doubles = false;
for (int j=0; j<counter; j++) {
if (i != j && labels[i].equals(labels[j])) {
doubles = true;
break;
}
}
if (doubles) {
if (mode == CDTPrefUtil.DISC_NAMING_UNIQUE_OR_IDS)
tmp[i] = ids[i];
else // replace with Name + Id
tmp[i] = combine(labels[i], ids[i]);
} else { // this name is unique - no changes !
tmp[i] = labels[i];
}
}
}
return tmp;
}
private String combine(String s1, String s2) {
if (s1.equals(s2)) return s1;
else return s1 + " (" + s2 + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
private void handleDiscoveryProfileChanged() {

View file

@ -29,7 +29,14 @@ public class CDTPrefUtil {
public static final String KEY_TOOLM = "properties.toolchain.modification.enable"; //$NON-NLS-1$
// string keys
public static final String KEY_PREFTC = "wizard.preferred.toolchains"; //$NON-NLS-1$
// integer keys
public static final String KEY_DISC_NAMES = "properties.discovery.naming"; //$NON-NLS-1$
public static final int DISC_NAMING_UNIQUE_OR_BOTH = 0;
public static final int DISC_NAMING_UNIQUE_OR_IDS = 1;
public static final int DISC_NAMING_ALWAYS_BOTH = 2;
public static final int DISC_NAMING_ALWAYS_IDS = 3;
public static final int DISC_NAMING_DEFAULT = DISC_NAMING_UNIQUE_OR_BOTH;
public static final String NULL = "NULL"; //$NON-NLS-1$
private static final IPreferenceStore pref = CUIPlugin.getDefault().getPreferenceStore();
private static final String DELIMITER = " "; //$NON-NLS-1$

View file

@ -341,6 +341,11 @@ PropertyPageDefsTab.1=Display <Data hierarchy> tab
PropertyPageDefsTab.2=Enable multiple configurations setting
PropertyPageDefsTab.3=Save property dialog size and position
PropertyPageDefsTab.4=Display <Toolchain modification> tab
PropertyPageDefsTab.5=Discovery profiles naming rule
PropertyPageDefsTab.6=Show disc. page names if they're unique. Else names + profile IDs.
PropertyPageDefsTab.7=Show disc. page names if they're unique. Else show profile IDs.
PropertyPageDefsTab.8=Always show names + profile IDs
PropertyPageDefsTab.9=Always show profile IDs only
ProjectConvert.convertersList=Converters List
ScannerConfigOptionsDialog.title=Discovery Options