From 151a60c6ffa540f37dc6b2471cd892a3b4df852f Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Wed, 14 Dec 2011 15:45:15 +0400 Subject: [PATCH] pattern list component: api updated - user friendly "remove" which updates selection --- .../intellij/ui/OptionalChooserComponent.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java b/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java index 520574581923..dbf4464ea373 100644 --- a/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java +++ b/platform/platform-api/src/com/intellij/ui/OptionalChooserComponent.java @@ -73,6 +73,34 @@ public abstract class OptionalChooserComponent implements CheckBoxListListene return myList.getSelectedIndex(); } + public void setSelectedIndex(final int index) { + myList.setSelectedIndex(index); + } + + public boolean removeAt(final int index) { + getCurrentModel().remove(index); + refresh(); + + if (index < getCurrentModel().size()) { + setSelectedIndex(index); + return true; + } + else if (index > 0) { + setSelectedIndex(index - 1); + return true; + } + return false; + } + + public boolean removeSelected() { + final int selectedIndex = getSelectedIndex(); + // selected index + if (selectedIndex != -1) { + return removeAt(selectedIndex); + } + return false; + } + public boolean isModified() { return !myWorkingList.equals(myInitialList); }