use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class EncodingPanel method getContext.
@NotNull
private DataContext getContext() {
Editor editor = getEditor();
DataContext parent = DataManager.getInstance().getDataContext((Component) myStatusBar);
return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE.getName(), getSelectedFile(), SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent)));
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class FocusTrackback method restoreFocus.
public void restoreFocus() {
if (isHeadlessOrWrongOS() || myConsumed || isScheduledForRestore())
return;
Project project = null;
DataManager dataManager = DataManager.getInstance();
if (dataManager != null) {
DataContext context = myParentWindow == null ? dataManager.getDataContext() : dataManager.getDataContext(myParentWindow);
if (context != null) {
project = CommonDataKeys.PROJECT.getData(context);
}
}
myScheduledForRestore = true;
final List<FocusTrackback> stack = getCleanStackForRoot();
final int index = stack.indexOf(this);
for (int i = index - 1; i >= 0; i--) {
if (stack.get(i).isScheduledForRestore()) {
dispose();
return;
}
}
if (project != null && !project.isDisposed()) {
final IdeFocusManager focusManager = IdeFocusManager.getInstance(project);
cleanParentWindow();
final Project finalProject = project;
focusManager.requestFocus(new MyFocusCommand(), myForcedRestore).doWhenProcessed(() -> dispose()).doWhenRejected(() -> focusManager.revalidateFocus(new ExpirableRunnable.ForProject(finalProject) {
@Override
public void run() {
if (UIUtil.isMeaninglessFocusOwner(focusManager.getFocusOwner())) {
focusManager.requestDefaultFocus(false);
}
}
}));
} else {
// no ide focus manager, so no way -- do just later
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
_restoreFocus();
dispose();
});
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class JarRootsRefreshTest method checkMove.
private void checkMove(File jar, VirtualFile vFile, PsiFile file) {
VirtualFile jarRoot;
File libDir = new File(jar.getParent(), "lib");
assertTrue(libDir.mkdir());
VirtualFile vLibDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libDir);
assertNotNull(vLibDir);
jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile);
assertNotNull(jarRoot);
assertTrue(jarRoot.isValid());
PsiDirectory directory = getPsiManager().findDirectory(vLibDir);
DataContext psiDataContext = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory);
new MoveHandler().invoke(myProject, new PsiElement[] { file }, psiDataContext);
assertFalse(jarRoot.isValid());
jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile);
assertNotNull(jarRoot);
assertTrue(jarRoot.isValid());
rename(directory, "lib2");
assertFalse(jarRoot.isValid());
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method type.
public static void type(char c, @NotNull Editor editor, Project project) {
if (c == '\n') {
executeAction(IdeActions.ACTION_EDITOR_ENTER, editor, project);
} else {
EditorActionManager actionManager = EditorActionManager.getInstance();
final DataContext dataContext = DataManager.getInstance().getDataContext();
TypedAction action = actionManager.getTypedAction();
action.actionPerformed(editor, c, dataContext);
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class XEvaluateInConsoleFromEditorActionHandler method perform.
@Override
protected void perform(@NotNull XDebugSession session, DataContext dataContext) {
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null || !(editor instanceof EditorEx)) {
return;
}
int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
Promise<Pair<TextRange, String>> rangeAndText = null;
if (selectionStart != selectionEnd) {
TextRange textRange = new TextRange(selectionStart, selectionEnd);
rangeAndText = Promise.resolve(Pair.create(textRange, editor.getDocument().getText(textRange)));
} else {
XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
if (evaluator != null) {
Promise<ExpressionInfo> expressionInfoPromise = evaluator.getExpressionInfoAtOffsetAsync(session.getProject(), editor.getDocument(), selectionStart, true);
rangeAndText = expressionInfoPromise.then(expressionInfo -> {
if (expressionInfo == null) {
return null;
}
return Pair.create(expressionInfo.getTextRange(), XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument()));
});
} else {
return;
}
}
rangeAndText.done(textRangeStringPair -> {
ApplicationManager.getApplication().invokeLater(() -> {
TextRange range = textRangeStringPair.getFirst();
String text = textRangeStringPair.getSecond();
if (text == null)
return;
ConsoleExecuteAction action = getConsoleExecuteAction(session);
if (action != null) {
action.execute(range, text, (EditorEx) editor);
}
});
});
}
Aggregations