Search in sources :

Example 6 with AsyncResult

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;
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Consumer(com.intellij.util.Consumer) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 7 with AsyncResult

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;
}
Also used : ActionManager(com.intellij.openapi.actionSystem.ActionManager) MouseEvent(java.awt.event.MouseEvent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) AsyncResult(com.intellij.openapi.util.AsyncResult) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 8 with AsyncResult

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);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ShowFilePathAction(com.intellij.ide.actions.ShowFilePathAction) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) DragSession(com.intellij.ui.docking.DragSession) VirtualFile(com.intellij.openapi.vfs.VirtualFile) UniqueVFilePathBuilder(com.intellij.openapi.fileEditor.UniqueVFilePathBuilder) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) com.intellij.ui.tabs(com.intellij.ui.tabs) InplaceButton(com.intellij.ui.InplaceButton) Border(javax.swing.border.Border) JBUI(com.intellij.util.ui.JBUI) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) MouseAdapter(java.awt.event.MouseAdapter) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) AsyncResult(com.intellij.openapi.util.AsyncResult) Extensions(com.intellij.openapi.extensions.Extensions) ColorUtil(com.intellij.ui.ColorUtil) UISettingsListener(com.intellij.ide.ui.UISettingsListener) ActionCallback(com.intellij.openapi.util.ActionCallback) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) DockContainer(com.intellij.ui.docking.DockContainer) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) com.intellij.openapi.wm(com.intellij.openapi.wm) GeneralSettings(com.intellij.ide.GeneralSettings) Registry(com.intellij.openapi.util.registry.Registry) NotNull(org.jetbrains.annotations.NotNull) DockableContent(com.intellij.ui.docking.DockableContent) Consumer(com.intellij.util.Consumer) InputEvent(java.awt.event.InputEvent) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) DataFlavor(java.awt.datatransfer.DataFlavor) Transferable(java.awt.datatransfer.Transferable) NonNls(org.jetbrains.annotations.NonNls) FileDropHandler(com.intellij.openapi.fileEditor.impl.text.FileDropHandler) IdeEventQueue(com.intellij.ide.IdeEventQueue) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) CloseAction(com.intellij.ide.actions.CloseAction) IdeDocumentHistory(com.intellij.openapi.fileEditor.ex.IdeDocumentHistory) UISettings(com.intellij.ide.ui.UISettings) Disposable(com.intellij.openapi.Disposable) SystemInfo(com.intellij.openapi.util.SystemInfo) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ShadowAction(com.intellij.openapi.ui.ShadowAction) DockManager(com.intellij.ui.docking.DockManager) JBTabsImpl(com.intellij.ui.tabs.impl.JBTabsImpl) Queryable(com.intellij.openapi.ui.Queryable) TimedDeadzone(com.intellij.util.ui.TimedDeadzone) FocusEvent(java.awt.event.FocusEvent) CustomActionsSchema(com.intellij.ide.ui.customization.CustomActionsSchema) BitUtil(com.intellij.util.BitUtil) VfsUtil(com.intellij.openapi.vfs.VfsUtil) JBEditorTabs(com.intellij.ui.tabs.impl.JBEditorTabs) javax.swing(javax.swing) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)

Example 9 with AsyncResult

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;
        }
    };
}
Also used : AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 10 with AsyncResult

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));
}
Also used : Include(org.jetbrains.android.dom.layout.Include) DataContext(com.intellij.openapi.actionSystem.DataContext) SdkConstants(com.android.SdkConstants) XmlFile(com.intellij.psi.xml.XmlFile) ResourceFolderType(com.android.resources.ResourceFolderType) Document(com.intellij.openapi.editor.Document) HashSet(com.intellij.util.containers.HashSet) NonNls(org.jetbrains.annotations.NonNls) ResourceType(com.android.resources.ResourceType) DomElement(com.intellij.util.xml.DomElement) CreateResourceFileAction(org.jetbrains.android.actions.CreateResourceFileAction) ArrayList(java.util.ArrayList) IncludeReference(com.android.tools.idea.rendering.IncludeReference) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Project(com.intellij.openapi.project.Project) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) UndoConfirmationPolicy(com.intellij.openapi.command.UndoConfirmationPolicy) DataManager(com.intellij.ide.DataManager) AsyncResult(com.intellij.openapi.util.AsyncResult) XmlTag(com.intellij.psi.xml.XmlTag) ResourceHelper(com.android.tools.idea.res.ResourceHelper) LayoutViewElement(org.jetbrains.android.dom.layout.LayoutViewElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Set(java.util.Set) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) TextRange(com.intellij.openapi.util.TextRange) AndroidCommonUtils(org.jetbrains.android.util.AndroidCommonUtils) TestOnly(org.jetbrains.annotations.TestOnly) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Nullable(org.jetbrains.annotations.Nullable) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) DomManager(com.intellij.util.xml.DomManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) DataContext(com.intellij.openapi.actionSystem.DataContext) XmlFile(com.intellij.psi.xml.XmlFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

AsyncResult (com.intellij.openapi.util.AsyncResult)17 Consumer (com.intellij.util.Consumer)8 Project (com.intellij.openapi.project.Project)6 ActionCallback (com.intellij.openapi.util.ActionCallback)5 MouseEvent (java.awt.event.MouseEvent)4 Disposable (com.intellij.openapi.Disposable)3 NotNull (org.jetbrains.annotations.NotNull)3 DocumentInfo (com.intellij.flex.uiDesigner.DocumentFactoryManager.DocumentInfo)2 DataManager (com.intellij.ide.DataManager)2 UISettings (com.intellij.ide.ui.UISettings)2 CustomActionsSchema (com.intellij.ide.ui.customization.CustomActionsSchema)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)2