Search in sources :

Example 1 with Bookmark

use of com.intellij.ide.bookmarks.Bookmark 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 Bookmark

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

the class BookmarksAction method handleMnemonic.

@Override
public void handleMnemonic(KeyEvent e, Project project, JBPopup popup) {
    char mnemonic = e.getKeyChar();
    final Bookmark bookmark = BookmarkManager.getInstance(project).findBookmarkForMnemonic(mnemonic);
    if (bookmark != null) {
        popup.cancel();
        IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> bookmark.navigate(true));
    }
}
Also used : Bookmark(com.intellij.ide.bookmarks.Bookmark)

Example 3 with Bookmark

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

the class EditBookmarkDescriptionAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Bookmark bookmark = BookmarksAction.getSelectedBookmarks(myList).get(0);
    myPopup.setUiVisible(false);
    BookmarkManager.getInstance(myProject).editDescription(bookmark);
    myPopup.setUiVisible(true);
    final JComponent content = myPopup.getContent();
    if (content != null) {
        myPopup.setSize(content.getPreferredSize());
    }
}
Also used : Bookmark(com.intellij.ide.bookmarks.Bookmark)

Example 4 with Bookmark

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

the class ToggleBookmarkWithMnemonicAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    super.actionPerformed(e);
    final Project project = e.getProject();
    if (project == null)
        return;
    final BookmarkInContextInfo info = new BookmarkInContextInfo(e.getDataContext(), project).invoke();
    final Bookmark bookmark = info.getBookmarkAtPlace();
    final BookmarkManager bookmarks = BookmarkManager.getInstance(project);
    if (bookmark != null) {
        final JBPopup[] popup = new JBPopup[1];
        MnemonicChooser mc = new MnemonicChooser() {

            @Override
            protected void onMnemonicChosen(char c) {
                popup[0].cancel();
                bookmarks.setMnemonic(bookmark, c);
            }

            @Override
            protected void onCancelled() {
                popup[0].cancel();
                bookmarks.removeBookmark(bookmark);
            }

            @Override
            protected boolean isOccupied(char c) {
                return bookmarks.findBookmarkForMnemonic(c) != null;
            }
        };
        popup[0] = JBPopupFactory.getInstance().createComponentPopupBuilder(mc, mc).setTitle("Bookmark Mnemonic").setFocusable(true).setRequestFocus(true).setMovable(false).setCancelKeyEnabled(false).setAdText(bookmarks.hasBookmarksWithMnemonics() ? (UIUtil.isUnderDarcula() ? "Brown" : "Yellow") + " cells are in use" : null).setResizable(false).createPopup();
        popup[0].showInBestPositionFor(e.getDataContext());
    }
}
Also used : Project(com.intellij.openapi.project.Project) Bookmark(com.intellij.ide.bookmarks.Bookmark) JBPopup(com.intellij.openapi.ui.popup.JBPopup) BookmarkManager(com.intellij.ide.bookmarks.BookmarkManager)

Example 5 with Bookmark

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

the class ToggleNumberedBookmarkActionBase method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null)
        return;
    BookmarksAction.BookmarkInContextInfo info = new BookmarksAction.BookmarkInContextInfo(e.getDataContext(), project).invoke();
    if (info.getFile() == null)
        return;
    Bookmark oldBookmark = info.getBookmarkAtPlace();
    BookmarkManager manager = BookmarkManager.getInstance(project);
    if (oldBookmark != null) {
        manager.removeBookmark(oldBookmark);
    }
    char mnemonic = (char) ('0' + myNumber);
    if (oldBookmark == null || oldBookmark.getMnemonic() != mnemonic) {
        Bookmark bookmark = manager.addTextBookmark(info.getFile(), info.getLine(), "");
        manager.setMnemonic(bookmark, mnemonic);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Bookmark(com.intellij.ide.bookmarks.Bookmark) BookmarkManager(com.intellij.ide.bookmarks.BookmarkManager)

Aggregations

Bookmark (com.intellij.ide.bookmarks.Bookmark)8 BookmarkManager (com.intellij.ide.bookmarks.BookmarkManager)3 Project (com.intellij.openapi.project.Project)3 BookmarkItem (com.intellij.ide.bookmarks.BookmarkItem)2 JBPopup (com.intellij.openapi.ui.popup.JBPopup)2 Nullable (org.jetbrains.annotations.Nullable)2 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 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 LayeredIcon (com.intellij.ui.LayeredIcon)1