mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
LaunchBar - config selector keep first 3 elements sorted by usage
* added interface for CSelector to show one separator bar at given index * change ConfigSelector provider to do special sorting and set separtor index to 3, so first 3 elements are sorted by usage, then all descriptors alphabetically (including first 3) * persist descriptor order Change-Id: Ib61d43abcb0da52f10d4b1e1ac7c0dc4f0d7958f Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30905 Tested-by: Hudson CI
This commit is contained in:
parent
b877d85865
commit
c819ee49f4
3 changed files with 63 additions and 19 deletions
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.launchbar.core.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
@ -65,11 +64,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
|
||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||
private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
|
||||
|
||||
public LaunchBarManager() throws CoreException {
|
||||
// Load up the active from the preferences before loading the descriptors
|
||||
IEclipsePreferences store = getPreferenceStore();
|
||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, Collections.EMPTY_LIST.toString());
|
||||
IExtensionPoint point = getExtensionPoint();
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
// first pass - target, descriptors and object providers
|
||||
|
@ -145,6 +146,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
launchConfigurationAdded(configuration);
|
||||
}
|
||||
launchManager.addLaunchConfigurationListener(this);
|
||||
reorderDescriptors(configDescIds);
|
||||
// Now that all the descriptors are loaded, set the one
|
||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||
if (configDesc == null) {
|
||||
|
@ -153,6 +155,20 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
setActiveLaunchDescriptor(configDesc);
|
||||
}
|
||||
|
||||
private void reorderDescriptors(String configDescIds) {
|
||||
configDescIds = configDescIds.replaceAll("[\\]\\[]", "");
|
||||
String[] split = configDescIds.split(",");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String string = split[i];
|
||||
String id = string.trim();
|
||||
ILaunchDescriptor desc = descriptors.get(id);
|
||||
if (desc != null) {
|
||||
descriptors.remove(id);
|
||||
descriptors.put(id, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void sortMapByValue(LinkedHashMap<ILaunchDescriptorType, Integer> map) {
|
||||
List<Map.Entry<ILaunchDescriptorType, Integer>> entries =
|
||||
new ArrayList<Map.Entry<ILaunchDescriptorType, Integer>>(map.entrySet());
|
||||
|
@ -324,13 +340,15 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
|
||||
@Override
|
||||
public ILaunchDescriptor[] getLaunchDescriptors() {
|
||||
// return descriptor in usage order (most used first). UI can sort them later as it wishes
|
||||
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
|
||||
Arrays.sort(descs, new Comparator<ILaunchDescriptor>() {
|
||||
@Override
|
||||
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
// reverse
|
||||
for (int i = 0; i < descs.length / 2; i++) {
|
||||
ILaunchDescriptor ld = descs[i];
|
||||
int j = descs.length - 1 - i;
|
||||
descs[i] = descs[j];
|
||||
descs[j] = ld;
|
||||
}
|
||||
return descs;
|
||||
}
|
||||
|
||||
|
@ -362,6 +380,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
|||
// store in persistent storage
|
||||
setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||
Activator.trace("new active config is stored " + configDesc);
|
||||
setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, descriptors.keySet().toString());
|
||||
|
||||
// Send notifications
|
||||
updateLaunchDescriptor(activeLaunchDesc);
|
||||
|
|
|
@ -85,6 +85,8 @@ public abstract class CSelector extends Composite {
|
|||
private final int itemH = 30;
|
||||
private int scrollBucket;
|
||||
private final int maxScrollBucket = 7;
|
||||
private int separatorIndex = -1;
|
||||
|
||||
|
||||
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
|
||||
@Override
|
||||
|
@ -171,6 +173,7 @@ public abstract class CSelector extends Composite {
|
|||
|
||||
};
|
||||
|
||||
|
||||
public CSelector(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
|
||||
|
@ -366,12 +369,17 @@ public abstract class CSelector extends Composite {
|
|||
for (Control child : listComp.getChildren())
|
||||
child.dispose();
|
||||
|
||||
Arrays.sort(elements, sorter);
|
||||
if (sorter != null)
|
||||
Arrays.sort(elements, sorter);
|
||||
|
||||
listItems = new ListItem[elements.length];
|
||||
|
||||
int heightHint = 0;
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
if (i == separatorIndex) {
|
||||
Label label = new Label(listComp, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.BORDER);
|
||||
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
|
||||
}
|
||||
listItems[i] = new ListItem(listComp, SWT.NONE, elements[i], i);
|
||||
if (i < maxScrollBucket) { // this is how many visible by default
|
||||
listItems[i].lazyInit();
|
||||
|
@ -816,4 +824,11 @@ public abstract class CSelector extends Composite {
|
|||
// nothing to do here
|
||||
}
|
||||
|
||||
public int getSeparatorIndex() {
|
||||
return separatorIndex;
|
||||
}
|
||||
|
||||
public void setSeparatorIndex(int separatorIndex) {
|
||||
this.separatorIndex = separatorIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.launchbar.ui.internal.controls;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||
|
@ -64,6 +65,7 @@ public class ConfigSelector extends CSelector {
|
|||
private DefaultDescriptorLabelProvider defaultProvider;
|
||||
|
||||
private static final String[] noConfigs = new String[] { "No Launch Configurations" };
|
||||
private static final int SEPARATOR_INDEX = 3;
|
||||
|
||||
public ConfigSelector(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
|
@ -82,8 +84,22 @@ public class ConfigSelector extends CSelector {
|
|||
public Object[] getElements(Object inputElement) {
|
||||
try {
|
||||
ILaunchDescriptor[] descs = getManager().getLaunchDescriptors();
|
||||
if (descs.length > 0)
|
||||
return descs;
|
||||
if (descs.length > 0) {
|
||||
if (descs.length > SEPARATOR_INDEX + 1) {
|
||||
ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length];
|
||||
System.arraycopy(descs, 0, descsCopy, 0, SEPARATOR_INDEX); // copy first 3 elements
|
||||
System.arraycopy(descs, 0, descsCopy, SEPARATOR_INDEX, descs.length); // copy all into rest
|
||||
// sort rest
|
||||
Arrays.sort(descsCopy, SEPARATOR_INDEX, descsCopy.length, new Comparator<ILaunchDescriptor>() {
|
||||
@Override
|
||||
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
return descsCopy;
|
||||
} else
|
||||
return descs;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
|
@ -117,15 +133,9 @@ public class ConfigSelector extends CSelector {
|
|||
return defaultProvider.getText(element);
|
||||
}
|
||||
});
|
||||
|
||||
setSorter(new Comparator<Object>() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
String text1 = getLabelProvider().getText(o1);
|
||||
String text2 = getLabelProvider().getText(o2);
|
||||
return text1.compareTo(text2);
|
||||
}
|
||||
});
|
||||
// no sorter on view, data is sorted by provider
|
||||
setSorter(null);
|
||||
setSeparatorIndex(SEPARATOR_INDEX);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue