use of com.intellij.ui.popup.util.MasterDetailPopupBuilder in project intellij-community by JetBrains.
the class BookmarksAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null)
return;
if (myPopup != null && myPopup.isVisible()) {
myPopup.cancel();
return;
}
final JBList list = new JBList(buildModel(project));
EditBookmarkDescriptionAction editDescriptionAction = new EditBookmarkDescriptionAction(project, list);
DefaultActionGroup actions = new DefaultActionGroup();
actions.add(editDescriptionAction);
actions.add(new DeleteBookmarkAction(project, list));
actions.add(new ToggleSortBookmarksAction());
actions.add(new MoveBookmarkUpAction(project, list));
actions.add(new MoveBookmarkDownAction(project, list));
myPopup = new MasterDetailPopupBuilder(project).setList(list).setDelegate(this).setDetailView(new MyDetailView(project)).setDimensionServiceKey(DIMENSION_SERVICE_KEY).setAddDetailViewToEast(true).setActionsGroup(actions).setPopupTuner(builder -> builder.setCloseOnEnter(false).setCancelOnClickOutside(false)).setDoneRunnable(() -> myPopup.cancel()).createMasterDetailPopup();
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
@SuppressWarnings("deprecation") Object[] values = list.getSelectedValues();
for (Object item : values) {
if (item instanceof BookmarkItem) {
itemChosen((BookmarkItem) item, project, myPopup, true);
}
}
}
}.registerCustomShortcutSet(CommonShortcuts.getEditSource(), list);
editDescriptionAction.setPopup(myPopup);
final Point location = DimensionService.getInstance().getLocation(DIMENSION_SERVICE_KEY, project);
if (location != null) {
myPopup.showInScreenCoordinates(WindowManager.getInstance().getFrame(project), location);
} else {
myPopup.showCenteredInCurrentWindow(project);
}
list.getEmptyText().setText("No Bookmarks");
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
project.getMessageBus().connect(myPopup).subscribe(BookmarksListener.TOPIC, new BookmarksListener() {
@Override
public void bookmarkAdded(@NotNull Bookmark b) {
}
@Override
public void bookmarkRemoved(@NotNull Bookmark b) {
}
@Override
public void bookmarkChanged(@NotNull Bookmark b) {
}
@Override
public void bookmarksOrderChanged() {
doUpdate();
}
private void doUpdate() {
TreeSet selectedValues = new TreeSet(Arrays.asList(list.getSelectedValues()));
DefaultListModel listModel = buildModel(project);
list.setModel(listModel);
ListSelectionModel selectionModel = list.getSelectionModel();
for (int i = 0; i < listModel.getSize(); i++) {
if (selectedValues.contains(listModel.get(i))) {
selectionModel.addSelectionInterval(i, i);
}
}
}
});
}
Aggregations