mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEADEV-41389: enable "go to bookmark" when all windows are closed
IDEADEV-41390: remove "bookmark this place"
This commit is contained in:
@@ -77,10 +77,7 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
public void update(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
e.getPresentation().setEnabled(project != null &&
|
||||
(ToolWindowManager.getInstance(project).isEditorComponentActive() &&
|
||||
PlatformDataKeys.EDITOR.getData(dataContext) != null ||
|
||||
PlatformDataKeys.VIRTUAL_FILE.getData(dataContext) != null));
|
||||
e.getPresentation().setEnabled(project != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,14 +87,7 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
if (project == null) return;
|
||||
|
||||
|
||||
BookmarkInContextInfo bookmarkInContextInfo = new BookmarkInContextInfo(dataContext, project).invoke();
|
||||
VirtualFile file = bookmarkInContextInfo.getFile();
|
||||
Bookmark bookmarkAtPlace = bookmarkInContextInfo.getBookmarkAtPlace();
|
||||
int line = bookmarkInContextInfo.getLine();
|
||||
|
||||
if (file == null) return;
|
||||
|
||||
final DefaultListModel model = buildModel(project, bookmarkAtPlace, file, line);
|
||||
final DefaultListModel model = buildModel(project);
|
||||
|
||||
|
||||
final JLabel pathLabel = new JLabel(" ");
|
||||
@@ -268,17 +258,13 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
popup.showCenteredInCurrentWindow(project);
|
||||
}
|
||||
|
||||
private static DefaultListModel buildModel(Project project, Bookmark bookmarkAtPlace, VirtualFile file, int line) {
|
||||
private static DefaultListModel buildModel(Project project) {
|
||||
final DefaultListModel model = new DefaultListModel();
|
||||
|
||||
for (Bookmark bookmark : BookmarkManager.getInstance(project).getValidBookmarks()) {
|
||||
model.addElement(new BookmarkItem(bookmark));
|
||||
}
|
||||
|
||||
if (bookmarkAtPlace == null) {
|
||||
model.addElement(new SetBookmarkItem(file, line));
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -296,82 +282,6 @@ public class BookmarksAction extends AnAction implements DumbAware {
|
||||
void updatePreviewPanel(PreviewPanel panel);
|
||||
}
|
||||
|
||||
protected static class SetBookmarkItem implements ItemWrapper {
|
||||
private final VirtualFile myFile;
|
||||
private final int myLine;
|
||||
|
||||
public SetBookmarkItem(VirtualFile file, int line) {
|
||||
myFile = file;
|
||||
myLine = line;
|
||||
}
|
||||
|
||||
public void setupRenderer(ColoredListCellRenderer renderer, Project project, boolean selected) {
|
||||
renderer.append(speedSearchText());
|
||||
}
|
||||
|
||||
public void updateMnemonicLabel(JLabel label) {
|
||||
label.setText("");
|
||||
}
|
||||
|
||||
public String speedSearchText() {
|
||||
return "Bookmark this place";
|
||||
}
|
||||
|
||||
public void execute(Project project) {
|
||||
BookmarkManager.getInstance(project).addTextBookmark(myFile, myLine, "");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String footerText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updatePreviewPanel(PreviewPanel panel) {
|
||||
panel.cleanup();
|
||||
|
||||
JLabel label = new JLabel("Choose this option to bookmark current place");
|
||||
label.setHorizontalAlignment(JLabel.CENTER);
|
||||
panel.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class RemoveBookmarkItem implements ItemWrapper {
|
||||
private final Bookmark myBookmark;
|
||||
|
||||
public RemoveBookmarkItem(Bookmark bookmark) {
|
||||
myBookmark = bookmark;
|
||||
}
|
||||
|
||||
public void setupRenderer(ColoredListCellRenderer renderer, Project project, boolean selected) {
|
||||
renderer.append(speedSearchText());
|
||||
}
|
||||
|
||||
public void updateMnemonicLabel(JLabel label) {
|
||||
label.setText("");
|
||||
}
|
||||
|
||||
public String speedSearchText() {
|
||||
return "Remove Bookmark";
|
||||
}
|
||||
|
||||
public void execute(Project project) {
|
||||
BookmarkManager.getInstance(project).removeBookmark(myBookmark);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String footerText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updatePreviewPanel(PreviewPanel panel) {
|
||||
panel.cleanup();
|
||||
|
||||
JLabel label = new JLabel("Choose this option to remove bookmark at current place");
|
||||
label.setHorizontalAlignment(JLabel.CENTER);
|
||||
panel.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
private static class BookmarkItem implements ItemWrapper {
|
||||
private final Bookmark myBookmark;
|
||||
|
||||
|
||||
+10
-3
@@ -17,11 +17,13 @@
|
||||
package com.intellij.ide.bookmarks.actions;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.bookmarks.BookmarkManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
|
||||
public class ToggleBookmarkAction extends BookmarksAction implements DumbAware {
|
||||
public ToggleBookmarkAction() {
|
||||
@@ -35,15 +37,20 @@ public class ToggleBookmarkAction extends BookmarksAction implements DumbAware {
|
||||
BookmarkInContextInfo info = new BookmarkInContextInfo(dataContext, project).invoke();
|
||||
|
||||
if (info.getBookmarkAtPlace() != null) {
|
||||
new RemoveBookmarkItem(info.getBookmarkAtPlace()).execute(project);
|
||||
BookmarkManager.getInstance(project).removeBookmark(info.getBookmarkAtPlace());
|
||||
}
|
||||
else {
|
||||
new SetBookmarkItem(info.getFile(), info.getLine()).execute(project);
|
||||
BookmarkManager.getInstance(project).addTextBookmark(info.getFile(), info.getLine(), "");
|
||||
}
|
||||
}
|
||||
|
||||
public void update(AnActionEvent event) {
|
||||
super.update(event);
|
||||
DataContext dataContext = event.getDataContext();
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
event.getPresentation().setEnabled(project != null &&
|
||||
(ToolWindowManager.getInstance(project).isEditorComponentActive() &&
|
||||
PlatformDataKeys.EDITOR.getData(dataContext) != null ||
|
||||
PlatformDataKeys.VIRTUAL_FILE.getData(dataContext) != null));
|
||||
|
||||
event.getPresentation().setText(IdeBundle.message("action.toggle.bookmark"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user