mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-163208: make ToggleBookmark,ToggleLineBreakpoint actions to be instances of Toggleable
to achieve 'toggle'-behaviour in touchbar
This commit is contained in:
+25
-7
@@ -15,17 +15,16 @@
|
||||
*/
|
||||
package com.intellij.ide.bookmarks.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.bookmarks.BookmarkManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ToggleBookmarkAction extends BookmarksAction implements DumbAware {
|
||||
public class ToggleBookmarkAction extends BookmarksAction implements DumbAware, Toggleable {
|
||||
public ToggleBookmarkAction() {
|
||||
getTemplatePresentation().setText(IdeBundle.message("action.bookmark.toggle"));
|
||||
}
|
||||
@@ -40,6 +39,14 @@ public class ToggleBookmarkAction extends BookmarksAction implements DumbAware {
|
||||
CommonDataKeys.VIRTUAL_FILE.getData(dataContext) != null));
|
||||
|
||||
event.getPresentation().setText(IdeBundle.message("action.bookmark.toggle"));
|
||||
|
||||
if (ActionPlaces.TOUCHBAR_GENERAL.equals(event.getPlace())) {
|
||||
event.getPresentation().setIcon(AllIcons.Actions.Checked);
|
||||
}
|
||||
|
||||
final BookmarkInContextInfo info = getBookmarkInfo(event);
|
||||
final boolean selected = info != null && info.getBookmarkAtPlace() != null;
|
||||
event.getPresentation().putClientProperty(SELECTED_PROPERTY, selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,14 +54,25 @@ public class ToggleBookmarkAction extends BookmarksAction implements DumbAware {
|
||||
Project project = e.getProject();
|
||||
if (project == null) return;
|
||||
|
||||
BookmarkInContextInfo info = new BookmarkInContextInfo(e.getDataContext(), project).invoke();
|
||||
if (info.getFile() == null) return;
|
||||
final BookmarkInContextInfo info = getBookmarkInfo(e);
|
||||
if (info == null) return;
|
||||
|
||||
if (info.getBookmarkAtPlace() != null) {
|
||||
final boolean selected = info.getBookmarkAtPlace() != null;
|
||||
e.getPresentation().putClientProperty(SELECTED_PROPERTY, selected);
|
||||
|
||||
if (selected) {
|
||||
BookmarkManager.getInstance(project).removeBookmark(info.getBookmarkAtPlace());
|
||||
}
|
||||
else {
|
||||
BookmarkManager.getInstance(project).addTextBookmark(info.getFile(), info.getLine(), "");
|
||||
}
|
||||
}
|
||||
|
||||
private BookmarkInContextInfo getBookmarkInfo(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) return null;
|
||||
|
||||
final BookmarkInContextInfo info = new BookmarkInContextInfo(e.getDataContext(), project).invoke();
|
||||
return info.getFile() == null ? null : info;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class TBItemAnActionButton extends TBItemButton {
|
||||
|
||||
setAction(this::_performAction, true, modality);
|
||||
|
||||
if (action instanceof ToggleAction) {
|
||||
if (action instanceof Toggleable) {
|
||||
myFlags |= NSTLibrary.BUTTON_FLAG_TOGGLE;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class TBItemAnActionButton extends TBItemButton {
|
||||
}
|
||||
|
||||
boolean isSelected = false;
|
||||
if (myAnAction instanceof ToggleAction) {
|
||||
if (myAnAction instanceof Toggleable) {
|
||||
final Object selectedProp = presentation.getClientProperty(Toggleable.SELECTED_PROPERTY);
|
||||
isSelected = selectedProp != null && selectedProp == Boolean.TRUE;
|
||||
}
|
||||
|
||||
+44
-2
@@ -15,14 +15,26 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.impl.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Toggleable;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpointManager;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
|
||||
import com.intellij.xdebugger.impl.DebuggerSupport;
|
||||
import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ToggleLineBreakpointAction extends XDebuggerActionBase implements DumbAware {
|
||||
public class ToggleLineBreakpointAction extends XDebuggerActionBase implements DumbAware, Toggleable {
|
||||
public ToggleLineBreakpointAction() {
|
||||
super(true);
|
||||
}
|
||||
@@ -31,4 +43,34 @@ public class ToggleLineBreakpointAction extends XDebuggerActionBase implements D
|
||||
protected DebuggerActionHandler getHandler(@NotNull final DebuggerSupport debuggerSupport) {
|
||||
return debuggerSupport.getToggleLineBreakpointHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent event) {
|
||||
super.update(event);
|
||||
|
||||
if (ActionPlaces.TOUCHBAR_GENERAL.equals(event.getPlace()))
|
||||
event.getPresentation().setIcon(AllIcons.Debugger.Db_set_breakpoint);
|
||||
|
||||
final boolean selected = hasLineBreakpoint(event);
|
||||
event.getPresentation().putClientProperty(SELECTED_PROPERTY, selected);
|
||||
}
|
||||
|
||||
private static boolean hasLineBreakpoint(@NotNull AnActionEvent e) {
|
||||
final Project proj = e.getProject();
|
||||
if (proj == null)
|
||||
return false;
|
||||
|
||||
final XLineBreakpointType<?>[] breakpointTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
|
||||
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(proj).getBreakpointManager();
|
||||
for (XSourcePosition position : XDebuggerUtilImpl.getAllCaretsPositions(proj, e.getDataContext())) {
|
||||
for (XLineBreakpointType<?> breakpointType : breakpointTypes) {
|
||||
final VirtualFile file = position.getFile();
|
||||
final int line = position.getLine();
|
||||
if (breakpointManager.findBreakpointAtLine(breakpointType, file, line) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user