use of com.intellij.openapi.util.AsyncResult in project intellij-community by JetBrains.
the class EditorPlaybackCall method waitDaemonForFinish.
public static AsyncResult<String> waitDaemonForFinish(final PlaybackContext context) {
final AsyncResult<String> result = new AsyncResult<>();
final Disposable connection = Disposer.newDisposable();
result.doWhenProcessed(() -> Disposer.dispose(connection));
WindowSystemPlaybackCall.findProject().doWhenDone(new Consumer<Project>() {
@Override
public void consume(Project project) {
final MessageBusConnection bus = project.getMessageBus().connect(connection);
bus.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
@Override
public void daemonFinished() {
context.flushAwtAndRunInEdt(result.createSetDoneRunnable());
}
@Override
public void daemonCancelEventOccurred(@NotNull String reason) {
result.setDone();
}
});
}
}).doWhenRejected(() -> result.setRejected("Cannot find project"));
return result;
}
use of com.intellij.openapi.util.AsyncResult in project intellij-community by JetBrains.
the class WindowSystemPlaybackCall method contextMenu.
public static AsyncResult<String> contextMenu(final PlaybackContext context, final String path) {
final AsyncResult<String> result = new AsyncResult<>();
final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
fm.doWhenFocusSettlesDown(() -> {
Component owner = fm.getFocusOwner();
if (owner == null) {
result.setRejected("No component focused");
return;
}
ActionManager am = ActionManager.getInstance();
AnAction showPopupMenu = am.getAction("ShowPopupMenu");
if (showPopupMenu == null) {
result.setRejected("Cannot find action: ShowPopupMenu");
return;
}
am.tryToExecute(showPopupMenu, new MouseEvent(owner, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, true), null, null, false).doWhenDone(() -> SwingUtilities.invokeLater(() -> {
MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
if (selectedPath.length == 0) {
result.setRejected("Failed to find active popup menu");
return;
}
selectNext(context, path.split("\\|"), 0, selectedPath[0].getSubElements(), result);
})).doWhenRejected(() -> result.setRejected("Cannot invoke popup menu from the ShowPopupMenu action, action call rejected"));
});
return result;
}
use of com.intellij.openapi.util.AsyncResult in project intellij-community by JetBrains.
the class EditorTabbedContainer method close.
@Override
public void close() {
TabInfo selected = myTabs.getTargetInfo();
if (selected == null)
return;
final VirtualFile file = (VirtualFile) selected.getObject();
final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);
AsyncResult<EditorWindow> window = mgr.getActiveWindow();
window.doWhenDone((Consumer<EditorWindow>) wnd -> {
if (wnd != null) {
if (wnd.findFileComposite(file) != null) {
mgr.closeFile(file, wnd);
}
}
});
}
use of com.intellij.openapi.util.AsyncResult in project intellij-community by JetBrains.
the class TodoTreeBuilder method createUpdater.
@Override
protected final AbstractTreeUpdater createUpdater() {
return new AbstractTreeUpdater(this) {
@Override
protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
if (!myDirtyFileSet.isEmpty()) {
// suppress redundant cache validations
final AsyncResult callback = new AsyncResult();
DumbService.getInstance(myProject).runWhenSmart(() -> {
try {
validateCache();
getTodoTreeStructure().validateCache();
} finally {
callback.setDone();
}
});
return callback;
}
return ActionCallback.DONE;
}
};
}
use of com.intellij.openapi.util.AsyncResult in project android by JetBrains.
the class AndroidExtractAsIncludeAction method doRefactorForPsiRange.
@Override
protected void doRefactorForPsiRange(@NotNull final Project project, @NotNull final PsiFile file, @NotNull final PsiElement from, @NotNull final PsiElement to) {
final PsiDirectory dir = file.getContainingDirectory();
if (dir == null) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(from);
assert facet != null;
final XmlTag parentTag = PsiTreeUtil.getParentOfType(from, XmlTag.class);
assert parentTag != null;
final List<XmlTag> tagsInRange = collectAllTags(from, to);
assert tagsInRange.size() > 0 : "there is no tag inside the range";
final String fileName = myTestConfig != null ? myTestConfig.myLayoutFileName : null;
final String dirName = dir.getName();
final FolderConfiguration config = dirName.length() > 0 ? FolderConfiguration.getConfig(dirName.split(SdkConstants.RES_QUALIFIER_SEP)) : null;
final String title = "Extract Android Layout";
AsyncResult<DataContext> dataContextAsyncResult = DataManager.getInstance().getDataContextFromFocus();
dataContextAsyncResult.doWhenDone((Consumer<DataContext>) dataContext -> CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
final XmlFile newFile = CreateResourceFileAction.createFileResource(facet, ResourceFolderType.LAYOUT, fileName, "temp_root", config, true, title, null, dataContext);
if (newFile != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
doRefactor(facet, file, newFile, from, to, parentTag, tagsInRange.size() > 1);
}
});
}
}
}, title, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION));
}
Aggregations