Commit bf87b59f authored by Vladimir Krivosheev's avatar Vladimir Krivosheev
Browse files

extract ComboBoxModelEditor to reuse in editor color scheme editor

parent 26c1dc53
Showing with 12 additions and 12 deletions
+12 -12
......@@ -55,6 +55,7 @@ import com.intellij.ui.FilterComponent;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.Alarm;
import com.intellij.util.IJSwingUtilities;
import com.intellij.util.ui.ComboBoxModelEditor;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.ListItemEditor;
import com.intellij.util.ui.UIUtil;
......@@ -84,7 +85,9 @@ public class KeymapPanel extends JPanel implements SearchableConfigurable, Confi
}
};
private final KeymapListModelEditor<Keymap> myEditor = new KeymapListModelEditor<Keymap>(new ListItemEditor<Keymap>() {
// Name editor calls "setName" to apply new name. It is scheme name, not presentable name —
// but only bundled scheme name could be different from presentable and bundled scheme is not editable (could not be renamed). So, it is ok.
private final ComboBoxModelEditor<Keymap> myEditor = new ComboBoxModelEditor<Keymap>(new ListItemEditor<Keymap>() {
@NotNull
@Override
public String getName(@NotNull Keymap item) {
......
......@@ -13,30 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.keymap.impl.ui;
package com.intellij.util.ui;
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.impl.KeymapImpl;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.FixedComboBoxEditor;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.MutableCollectionComboBoxModel;
import com.intellij.util.ui.ListItemEditor;
import com.intellij.util.ui.ListModelEditorBase;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
public class KeymapListModelEditor<T extends Keymap> extends ListModelEditorBase<T> {
public final class ComboBoxModelEditor<T> extends ListModelEditorBase<T> {
private final ComboBox comboBox;
public KeymapListModelEditor(@NotNull final ListItemEditor<T> itemEditor) {
public ComboBoxModelEditor(@NotNull ListItemEditor<T> itemEditor) {
super(itemEditor);
comboBox = new ComboBox((ComboBoxModel)model);
comboBox.setEditor(new MyEditor());
comboBox.setEditor(new NameEditor());
comboBox.setRenderer(new MyListCellRenderer());
}
......@@ -51,17 +48,17 @@ public class KeymapListModelEditor<T extends Keymap> extends ListModelEditorBase
return comboBox;
}
private class MyEditor extends FixedComboBoxEditor {
private class NameEditor extends FixedComboBoxEditor {
private T item = null;
private boolean mutated;
public MyEditor() {
public NameEditor() {
getField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (item != null && item.canModify()) {
if (item != null && itemEditor.isEditable(item)) {
String newName = getField().getText();
if (newName.equals(item.getName())) {
if (newName.equals(itemEditor.getName(item))) {
return;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment