mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
save recently changed keys on top
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.intellij.openapi.util.registry;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationInfo;
|
||||
@@ -27,6 +28,7 @@ import com.intellij.openapi.application.impl.LaterInvocator;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.ShadowAction;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
@@ -54,6 +56,7 @@ import java.util.List;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class RegistryUi implements Disposable {
|
||||
private static final String RECENT_PROPERTIES_KEY = "RegistryRecentKeys";
|
||||
|
||||
private final JBTable myTable;
|
||||
private final JTextArea myDescriptionLabel;
|
||||
@@ -217,10 +220,21 @@ public class RegistryUi implements Disposable {
|
||||
|
||||
private MyTableModel() {
|
||||
myAll = Registry.getAll();
|
||||
final List<String> recent = getRecent();
|
||||
|
||||
Collections.sort(myAll, new Comparator<RegistryValue>() {
|
||||
@Override
|
||||
public int compare(@NotNull RegistryValue o1, @NotNull RegistryValue o2) {
|
||||
return o1.getKey().compareTo(o2.getKey());
|
||||
final String key1 = o1.getKey();
|
||||
final String key2 = o2.getKey();
|
||||
final int i1 = recent.indexOf(key1);
|
||||
final int i2 = recent.indexOf(key2);
|
||||
final boolean c1 = i1 != -1;
|
||||
final boolean c2 = i2 != -1;
|
||||
if (c1 && !c2) return -1;
|
||||
if (!c1 && c2) return 1;
|
||||
if (c1 && c2) return i1 - i2;
|
||||
return key1.compareToIgnoreCase(key2);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -264,6 +278,19 @@ public class RegistryUi implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getRecent() {
|
||||
String value = PropertiesComponent.getInstance().getValue(RECENT_PROPERTIES_KEY);
|
||||
return StringUtil.isEmpty(value) ? new ArrayList<String>(0) : StringUtil.split(value, "=");
|
||||
}
|
||||
|
||||
private static void keyChanged(String key) {
|
||||
final List<String> recent = getRecent();
|
||||
recent.remove(key);
|
||||
recent.add(0, key);
|
||||
final String newValue = StringUtil.join(recent, "=");
|
||||
PropertiesComponent.getInstance().setValue(RECENT_PROPERTIES_KEY, newValue);
|
||||
}
|
||||
|
||||
public boolean show() {
|
||||
DialogWrapper dialog = new DialogWrapper(true) {
|
||||
{
|
||||
@@ -468,6 +495,7 @@ public class RegistryUi implements Disposable {
|
||||
} else {
|
||||
myValue.setValue(myField.getText().trim());
|
||||
}
|
||||
keyChanged(myValue.getKey());
|
||||
}
|
||||
revaliateActions();
|
||||
return super.stopCellEditing();
|
||||
|
||||
Reference in New Issue
Block a user