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);
}
}
}
});
}
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));
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations