Search in sources :

Example 1 with BookmarkManager

use of com.intellij.ide.bookmarks.BookmarkManager 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 2 with BookmarkManager

use of com.intellij.ide.bookmarks.BookmarkManager 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)2 BookmarkManager (com.intellij.ide.bookmarks.BookmarkManager)2 Project (com.intellij.openapi.project.Project)2 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1