in idea-plugin/src/main/java/com/jetbrains/ide/streamdeck/util/ActionExecutor.java [141:260]
public static void performActionFocusedProject(@NotNull AnAction action, boolean allowCallInBackground) {
System.out.println("ActionExecutor.performActionFocusedProject(allowCallInBackground = " + allowCallInBackground + ")");
Result result = getResult(allowCallInBackground);
if (result == null) return;
var focusOwner = result.focusOwner;// FocusManager.getCurrentManager().getFocusOwner();
var ideFocusManager = result.ideFocusManager;
System.out.println("FocusManager.getCurrentManager() = " + FocusManager.getCurrentManager());
System.out.println("focusManager = " + ideFocusManager);
System.out.println("keyboard focusOwner = " + FocusManager.getCurrentManager().getFocusOwner());
System.out.println("ideFocusManager focusOwner = " + ideFocusManager.getFocusOwner());
// if(focusOwner == null) {
// IdeFrame ideFrame = ideFocusManager.getLastFocusedFrame();
// if(ideFrame != null) {
// focusOwner = ideFrame.getComponent();
// }
// }
// Keymap shortcuts (i.e. not local shortcuts) should work only in:
// - main frame
// - floating focusedWindow
// - when there's an editor in contexts
// boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow);
DataContext context = getDataContext(focusOwner);
// if(fileEditor instanceof TextEditor && fileEditor.isValid() && dataManager != null) {
// context = dataManager.getDataContext(fileEditor.getComponent());
// }
DataContext wrappedContext = Utils.createAsyncDataContext(context);
Project project = CommonDataKeys.PROJECT.getData(wrappedContext);
System.out.println("project=" + project);
if (project != null && project.isDisposed()) return;
// CurrentEditorProvider currentEditorProvider = ApplicationManager.getApplication().getService(CurrentEditorProvider.class);
// FileEditor fileEditor = null;
// try {
// // Works for 2023.3 which has deprecated old API for `new FocusBasedCurrentEditorProvider().getCurrentEditor()`
// Method currentEditor = CurrentEditorProvider.class.getDeclaredMethod("getCurrentEditor", Project.class);
// fileEditor = (FileEditor) currentEditor.invoke(currentEditorProvider, project);
// } catch (Exception ex) {
// ex.printStackTrace();
// fileEditor = new FocusBasedCurrentEditorProvider().getCurrentEditor();
// }
//
// System.out.println("fileEditor=" + fileEditor);
//
// if (fileEditor != null) {
//// ActionToolbar actionToolbar = ActionToolbar.findToolbarBy(fileEditor.getComponent());
//// try {
//// System.out.println(actionToolbar.getActions());
//// } catch (Exception e) {
//// e.printStackTrace();
//// }
// }
// boolean dumb = project != null && DumbService.getInstance(project).isDumb();
// Note: some action may produce exceptions if executed from the wrong focused component, eg:
// GET http://localhost:63344/api/action/Vcs.ShowTabbedFileHistory requires a vcs file
// TODO: Enable enable check?
AnActionEvent event = AnActionEvent.createEvent(wrappedContext,
action.getTemplatePresentation().clone(),
ActionPlaces.MAIN_TOOLBAR,
ActionUiKind.TOOLBAR,
null
// dataId -> {
// // System.out.println("Request dataId =" + dataId);
// Project project = ProjectUtil.tryGuessFocusedProject();
// // System.out.println("Request project =" + project);
//
// if (CommonDataKeys.PROJECT.is(dataId)) return project;
// return null;
// }
);
event.setInjectedContext(action.isInInjectedContext());
System.out.println("event=" + event);
// Executed in EDT, so catch it
try {
System.out.println("ActionUtil.lastUpdateAndCheckDumb(action, event, false)=" + ActionUtil.lastUpdateAndCheckDumb(action, event, false));
System.out.println("performActionDumbAwareWithCallbacks action =" + action);
ActionUtil.performActionDumbAwareWithCallbacks(action, event);
if (ActionUtil.lastUpdateAndCheckDumb(action, event, false)) {
Window window;
if (focusOwner != null) {
window = SwingUtilities.getWindowAncestor(focusOwner);
} else {
window = null;
}
// System.out.println("performActionDumbAwareWithCallbacks action =" + action);
// ActionUtil.performActionDumbAwareWithCallbacks(action, event);
// action.actionPerformed(event);
// ActionUtil.performDumbAwareWithCallbacks(action, event, () ->
// ActionUtil.doPerformActionOrShowPopup(action, event, popup -> {
// if (window != null) {
// popup.showInCenterOf(window);
// }
// else {
// popup.showInFocusCenter();
// }
// }));
}
// action.actionPerformed(event);
} catch (Exception e) {
e.printStackTrace();
// throw new RuntimeException(e);
}
}