Search in sources :

Example 1 with BookmarkItem

use of com.intellij.ide.bookmarks.BookmarkItem 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);
                }
            }
        }
    });
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) NonNls(org.jetbrains.annotations.NonNls) Comparing(com.intellij.openapi.util.Comparing) BookmarkItem(com.intellij.ide.bookmarks.BookmarkItem) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) JBList(com.intellij.ui.components.JBList) WindowManager(com.intellij.openapi.wm.WindowManager) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) KeyEvent(java.awt.event.KeyEvent) Editor(com.intellij.openapi.editor.Editor) BookmarkManager(com.intellij.ide.bookmarks.BookmarkManager) JBPopup(com.intellij.openapi.ui.popup.JBPopup) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) DimensionService(com.intellij.openapi.util.DimensionService) ItemWrapper(com.intellij.ui.popup.util.ItemWrapper) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) Bookmark(com.intellij.ide.bookmarks.Bookmark) BookmarksListener(com.intellij.ide.bookmarks.BookmarksListener) MasterDetailPopupBuilder(com.intellij.ui.popup.util.MasterDetailPopupBuilder) DetailViewImpl(com.intellij.ui.popup.util.DetailViewImpl) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) BookmarksListener(com.intellij.ide.bookmarks.BookmarksListener) MasterDetailPopupBuilder(com.intellij.ui.popup.util.MasterDetailPopupBuilder) Project(com.intellij.openapi.project.Project) Bookmark(com.intellij.ide.bookmarks.Bookmark) JBList(com.intellij.ui.components.JBList) BookmarkItem(com.intellij.ide.bookmarks.BookmarkItem)

Example 2 with BookmarkItem

use of com.intellij.ide.bookmarks.BookmarkItem in project intellij-community by JetBrains.

the class BookmarksAction method itemChosen.

@Override
public void itemChosen(ItemWrapper item, Project project, JBPopup popup, boolean withEnterOrDoubleClick) {
    if (item instanceof BookmarkItem && withEnterOrDoubleClick) {
        Bookmark bookmark = ((BookmarkItem) item).getBookmark();
        popup.cancel();
        bookmark.navigate(true);
    }
}
Also used : Bookmark(com.intellij.ide.bookmarks.Bookmark) BookmarkItem(com.intellij.ide.bookmarks.BookmarkItem)

Aggregations

Bookmark (com.intellij.ide.bookmarks.Bookmark)2 BookmarkItem (com.intellij.ide.bookmarks.BookmarkItem)2 BookmarkManager (com.intellij.ide.bookmarks.BookmarkManager)1 BookmarksListener (com.intellij.ide.bookmarks.BookmarksListener)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 DumbAware (com.intellij.openapi.project.DumbAware)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 Comparing (com.intellij.openapi.util.Comparing)1 DimensionService (com.intellij.openapi.util.DimensionService)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)1 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)1 WindowManager (com.intellij.openapi.wm.WindowManager)1 IdeBorderFactory (com.intellij.ui.IdeBorderFactory)1 JBList (com.intellij.ui.components.JBList)1 DetailViewImpl (com.intellij.ui.popup.util.DetailViewImpl)1