mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 15:25:49 +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;
|
package org.eclipse.cdt.launchbar.core.internal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
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_CONFIG_DESC = "activeConfigDesc";
|
||||||
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
|
||||||
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
|
||||||
|
private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
|
||||||
|
|
||||||
public LaunchBarManager() throws CoreException {
|
public LaunchBarManager() throws CoreException {
|
||||||
// Load up the active from the preferences before loading the descriptors
|
// Load up the active from the preferences before loading the descriptors
|
||||||
IEclipsePreferences store = getPreferenceStore();
|
IEclipsePreferences store = getPreferenceStore();
|
||||||
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null);
|
||||||
|
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, Collections.EMPTY_LIST.toString());
|
||||||
IExtensionPoint point = getExtensionPoint();
|
IExtensionPoint point = getExtensionPoint();
|
||||||
IExtension[] extensions = point.getExtensions();
|
IExtension[] extensions = point.getExtensions();
|
||||||
// first pass - target, descriptors and object providers
|
// first pass - target, descriptors and object providers
|
||||||
|
@ -145,6 +146,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
launchConfigurationAdded(configuration);
|
launchConfigurationAdded(configuration);
|
||||||
}
|
}
|
||||||
launchManager.addLaunchConfigurationListener(this);
|
launchManager.addLaunchConfigurationListener(this);
|
||||||
|
reorderDescriptors(configDescIds);
|
||||||
// Now that all the descriptors are loaded, set the one
|
// Now that all the descriptors are loaded, set the one
|
||||||
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescId);
|
||||||
if (configDesc == null) {
|
if (configDesc == null) {
|
||||||
|
@ -153,6 +155,20 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
setActiveLaunchDescriptor(configDesc);
|
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) {
|
protected static void sortMapByValue(LinkedHashMap<ILaunchDescriptorType, Integer> map) {
|
||||||
List<Map.Entry<ILaunchDescriptorType, Integer>> entries =
|
List<Map.Entry<ILaunchDescriptorType, Integer>> entries =
|
||||||
new ArrayList<Map.Entry<ILaunchDescriptorType, Integer>>(map.entrySet());
|
new ArrayList<Map.Entry<ILaunchDescriptorType, Integer>>(map.entrySet());
|
||||||
|
@ -324,13 +340,15 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchDescriptor[] getLaunchDescriptors() {
|
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()]);
|
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
|
||||||
Arrays.sort(descs, new Comparator<ILaunchDescriptor>() {
|
// reverse
|
||||||
@Override
|
for (int i = 0; i < descs.length / 2; i++) {
|
||||||
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
|
ILaunchDescriptor ld = descs[i];
|
||||||
return o1.getName().compareTo(o2.getName());
|
int j = descs.length - 1 - i;
|
||||||
}
|
descs[i] = descs[j];
|
||||||
});
|
descs[j] = ld;
|
||||||
|
}
|
||||||
return descs;
|
return descs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,6 +380,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
// store in persistent storage
|
// store in persistent storage
|
||||||
setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc));
|
||||||
Activator.trace("new active config is stored " + configDesc);
|
Activator.trace("new active config is stored " + configDesc);
|
||||||
|
setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, descriptors.keySet().toString());
|
||||||
|
|
||||||
// Send notifications
|
// Send notifications
|
||||||
updateLaunchDescriptor(activeLaunchDesc);
|
updateLaunchDescriptor(activeLaunchDesc);
|
||||||
|
|
|
@ -85,6 +85,8 @@ public abstract class CSelector extends Composite {
|
||||||
private final int itemH = 30;
|
private final int itemH = 30;
|
||||||
private int scrollBucket;
|
private int scrollBucket;
|
||||||
private final int maxScrollBucket = 7;
|
private final int maxScrollBucket = 7;
|
||||||
|
private int separatorIndex = -1;
|
||||||
|
|
||||||
|
|
||||||
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
|
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,6 +173,7 @@ public abstract class CSelector extends Composite {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public CSelector(Composite parent, int style) {
|
public CSelector(Composite parent, int style) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
|
|
||||||
|
@ -366,12 +369,17 @@ public abstract class CSelector extends Composite {
|
||||||
for (Control child : listComp.getChildren())
|
for (Control child : listComp.getChildren())
|
||||||
child.dispose();
|
child.dispose();
|
||||||
|
|
||||||
Arrays.sort(elements, sorter);
|
if (sorter != null)
|
||||||
|
Arrays.sort(elements, sorter);
|
||||||
|
|
||||||
listItems = new ListItem[elements.length];
|
listItems = new ListItem[elements.length];
|
||||||
|
|
||||||
int heightHint = 0;
|
int heightHint = 0;
|
||||||
for (int i = 0; i < elements.length; ++i) {
|
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);
|
listItems[i] = new ListItem(listComp, SWT.NONE, elements[i], i);
|
||||||
if (i < maxScrollBucket) { // this is how many visible by default
|
if (i < maxScrollBucket) { // this is how many visible by default
|
||||||
listItems[i].lazyInit();
|
listItems[i].lazyInit();
|
||||||
|
@ -816,4 +824,11 @@ public abstract class CSelector extends Composite {
|
||||||
// nothing to do here
|
// 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;
|
package org.eclipse.cdt.launchbar.ui.internal.controls;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
|
||||||
|
@ -64,6 +65,7 @@ public class ConfigSelector extends CSelector {
|
||||||
private DefaultDescriptorLabelProvider defaultProvider;
|
private DefaultDescriptorLabelProvider defaultProvider;
|
||||||
|
|
||||||
private static final String[] noConfigs = new String[] { "No Launch Configurations" };
|
private static final String[] noConfigs = new String[] { "No Launch Configurations" };
|
||||||
|
private static final int SEPARATOR_INDEX = 3;
|
||||||
|
|
||||||
public ConfigSelector(Composite parent, int style) {
|
public ConfigSelector(Composite parent, int style) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
|
@ -82,8 +84,22 @@ public class ConfigSelector extends CSelector {
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
try {
|
try {
|
||||||
ILaunchDescriptor[] descs = getManager().getLaunchDescriptors();
|
ILaunchDescriptor[] descs = getManager().getLaunchDescriptors();
|
||||||
if (descs.length > 0)
|
if (descs.length > 0) {
|
||||||
return descs;
|
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) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e.getStatus());
|
Activator.log(e.getStatus());
|
||||||
}
|
}
|
||||||
|
@ -117,15 +133,9 @@ public class ConfigSelector extends CSelector {
|
||||||
return defaultProvider.getText(element);
|
return defaultProvider.getText(element);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// no sorter on view, data is sorted by provider
|
||||||
setSorter(new Comparator<Object>() {
|
setSorter(null);
|
||||||
@Override
|
setSeparatorIndex(SEPARATOR_INDEX);
|
||||||
public int compare(Object o1, Object o2) {
|
|
||||||
String text1 = getLabelProvider().getText(o1);
|
|
||||||
String text2 = getLabelProvider().getText(o2);
|
|
||||||
return text1.compareTo(text2);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue