mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix bookmarks popup toolbar actions broken with introduction of FilteringListModel.
This commit is contained in:
@@ -87,7 +87,7 @@ public class BookmarkManager implements PersistentStateComponent<Element> {
|
||||
public void addTextBookmark(VirtualFile file, int lineIndex, String description) {
|
||||
Bookmark b = new Bookmark(myProject, file, lineIndex, description);
|
||||
myBus.syncPublisher(BookmarksListener.TOPIC).bookmarkAdded(b);
|
||||
myBookmarks.add(b);
|
||||
myBookmarks.add(0, b);
|
||||
}
|
||||
|
||||
public static String getAutoDescription(final Editor editor, final int lineIndex) {
|
||||
@@ -108,7 +108,7 @@ public class BookmarkManager implements PersistentStateComponent<Element> {
|
||||
if (findFileBookmark(file) != null) return;
|
||||
|
||||
Bookmark b = new Bookmark(myProject, file, description);
|
||||
myBookmarks.add(b);
|
||||
myBookmarks.add(0, b);
|
||||
myBus.syncPublisher(BookmarksListener.TOPIC).bookmarkAdded(b);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.speedSearch.FilteringListModel;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -257,7 +258,7 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
|
||||
for (Bookmark bookmark : BookmarkManager.getInstance(project).getValidBookmarks()) {
|
||||
model.insertElementAt(new BookmarkItem(bookmark), 0);
|
||||
model.addElement(new BookmarkItem(bookmark));
|
||||
}
|
||||
|
||||
if (bookmarkAtPlace == null) {
|
||||
@@ -601,11 +602,6 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
|
||||
b.setDescription(description);
|
||||
|
||||
DefaultListModel model = (DefaultListModel)myList.getModel();
|
||||
String fake = "Fake Element to make list re-count its size";
|
||||
model.addElement(fake);
|
||||
model.removeElement(fake);
|
||||
|
||||
myPopup.setUiVisible(true);
|
||||
myPopup.setSize(myPopup.getContent().getPreferredSize());
|
||||
}
|
||||
@@ -642,6 +638,12 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean notFiltered(JList list) {
|
||||
if (!(list.getModel() instanceof FilteringListModel)) return true;
|
||||
final FilteringListModel model = (FilteringListModel)list.getModel();
|
||||
return model.getOriginalModel().getSize() == model.getSize();
|
||||
}
|
||||
|
||||
private static class MoveBookmarkUpAction extends AnAction {
|
||||
private final Project myProject;
|
||||
private final JList myList;
|
||||
@@ -655,7 +657,7 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(getSelectedBookmarks(myList).size() == 1 && myList.getSelectedIndex() > 0);
|
||||
e.getPresentation().setEnabled(notFiltered(myList) && getSelectedBookmarks(myList).size() == 1 && myList.getSelectedIndex() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -679,7 +681,7 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
int modelSize = myList.getModel().getSize();
|
||||
if (modelSize == 0) {
|
||||
if (modelSize == 0 || !notFiltered(myList)) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.ui.speedSearch.FilteringListModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
@@ -120,7 +121,7 @@ public class ListUtil {
|
||||
}
|
||||
|
||||
public static int moveSelectedItemsUp(JList list) {
|
||||
DefaultListModel model = (DefaultListModel)list.getModel();
|
||||
DefaultListModel model = getModel(list);
|
||||
int[] indices = list.getSelectedIndices();
|
||||
if (!canMoveSelectedItemsUp(list)) return 0;
|
||||
for(int i = 0; i < indices.length; i++){
|
||||
@@ -144,7 +145,7 @@ public class ListUtil {
|
||||
}
|
||||
|
||||
public static int moveSelectedItemsDown(JList list) {
|
||||
DefaultListModel model = (DefaultListModel)list.getModel();
|
||||
DefaultListModel model = getModel(list);
|
||||
int[] indices = list.getSelectedIndices();
|
||||
if (!canMoveSelectedItemsDown(list)) return 0;
|
||||
for(int i = indices.length - 1; i >= 0 ; i--){
|
||||
@@ -162,6 +163,14 @@ public class ListUtil {
|
||||
return indices.length;
|
||||
}
|
||||
|
||||
private static DefaultListModel getModel(JList list) {
|
||||
final ListModel model = list.getModel();
|
||||
if (model instanceof FilteringListModel) {
|
||||
return (DefaultListModel)((FilteringListModel)model).getOriginalModel();
|
||||
}
|
||||
return (DefaultListModel)model;
|
||||
}
|
||||
|
||||
public static boolean canMoveSelectedItemsDown(JList list) {
|
||||
ListModel model = list.getModel();
|
||||
int[] indices = list.getSelectedIndices();
|
||||
@@ -256,6 +265,7 @@ public class ListUtil {
|
||||
private static ListModelExtension getExtensions(ListModel model) {
|
||||
if (model instanceof DefaultListModel) return DEFAULT_MODEL;
|
||||
if (model instanceof SortedListModel) return SORTED_MODEL;
|
||||
if (model instanceof FilteringListModel) return FILTERED_MODEL;
|
||||
|
||||
if (model == null) LOG.assertTrue(false);
|
||||
else LOG.assertTrue(false, "Unknown model class: " + model.getClass().getName());
|
||||
@@ -286,4 +296,14 @@ public class ListUtil {
|
||||
model.remove(index);
|
||||
}
|
||||
};
|
||||
|
||||
private static final ListModelExtension FILTERED_MODEL = new ListModelExtension<FilteringListModel>() {
|
||||
public Object get(FilteringListModel model, int index) {
|
||||
return model.getElementAt(index);
|
||||
}
|
||||
|
||||
public void remove(FilteringListModel model, int index) {
|
||||
model.remove(index);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.util.List;
|
||||
* @author max
|
||||
*/
|
||||
public class FilteringListModel<T> extends AbstractListModel {
|
||||
private final JList myList;
|
||||
private final ListModel myOriginalModel;
|
||||
private final List<T> myData = new ArrayList<T>();
|
||||
private Condition<T> myCondition = null;
|
||||
@@ -52,7 +51,6 @@ public class FilteringListModel<T> extends AbstractListModel {
|
||||
};
|
||||
|
||||
protected FilteringListModel(JList list) {
|
||||
myList = list;
|
||||
myOriginalModel = list.getModel();
|
||||
myOriginalModel.addListDataListener(myListDataListener);
|
||||
|
||||
@@ -111,4 +109,12 @@ public class FilteringListModel<T> extends AbstractListModel {
|
||||
public boolean contains(T value) {
|
||||
return myData.contains(value);
|
||||
}
|
||||
|
||||
public ListModel getOriginalModel() {
|
||||
return myOriginalModel;
|
||||
}
|
||||
|
||||
public void remove(int index) {
|
||||
((DefaultListModel)myOriginalModel).removeElement(myData.get(index));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user