Search in sources :

Example 96 with Application

use of com.intellij.openapi.application.Application in project android by JetBrains.

the class GradleSpecificInitializer method checkInstallPath.

/**
   * Gradle has an issue when the studio path contains ! (http://b.android.com/184588)
   */
private static void checkInstallPath() {
    if (PathManager.getHomePath().contains("!")) {
        final Application app = ApplicationManager.getApplication();
        app.getMessageBus().connect(app).subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() {

            @Override
            public void appStarting(Project project) {
                app.invokeLater(() -> {
                    String message = String.format("%1$s must not be installed in a path containing '!' or Gradle sync will fail!", ApplicationNamesInfo.getInstance().getProductName());
                    Notification notification = getNotificationGroup().createNotification(message, NotificationType.ERROR);
                    notification.setImportant(true);
                    Notifications.Bus.notify(notification);
                });
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) AppLifecycleListener(com.intellij.ide.AppLifecycleListener) Application(com.intellij.openapi.application.Application)

Example 97 with Application

use of com.intellij.openapi.application.Application in project android-selector-intellij-plugin by importre.

the class AndroidSelectorDialog method doOKAction.

@Override
protected void doOKAction() {
    String f = filenameText.getText();
    final String filename = (f.endsWith(".xml") ? f : f + ".xml").trim();
    final String color = getColorName(colorCombo);
    final String pressed = getColorName(pressedCombo);
    final String pressedV21 = getColorName(pressedV21Combo);
    if (!valid(filename, color, pressed, pressedV21)) {
        String title = "Invalidation";
        String msg = "color, pressed, pressedV21 must start with `@color/`";
        showMessageDialog(title, msg);
        return;
    }
    if (exists(filename)) {
        String title = "Cannot create files";
        String msg = String.format(Locale.US, "`%s` already exists", filename);
        showMessageDialog(title, msg);
        return;
    }
    Application app = ApplicationManager.getApplication();
    app.runWriteAction(new Runnable() {

        @Override
        public void run() {
            try {
                createDrawable(filename, color, pressed);
                createDrawableV21(filename, color, pressedV21);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    super.doOKAction();
}
Also used : Application(com.intellij.openapi.application.Application)

Example 98 with Application

use of com.intellij.openapi.application.Application in project ideavim by JetBrains.

the class KeyHandler method handleKeyMapping.

private boolean handleKeyMapping(@NotNull final Editor editor, @NotNull final KeyStroke key, @NotNull final DataContext context) {
    final CommandState commandState = CommandState.getInstance(editor);
    commandState.stopMappingTimer();
    final List<KeyStroke> mappingKeys = commandState.getMappingKeys();
    final List<KeyStroke> fromKeys = new ArrayList<KeyStroke>(mappingKeys);
    fromKeys.add(key);
    final MappingMode mappingMode = commandState.getMappingMode();
    if (MappingMode.NVO.contains(mappingMode) && (state != State.NEW_COMMAND || currentArg != Argument.Type.NONE)) {
        return false;
    }
    final KeyMapping mapping = VimPlugin.getKey().getKeyMapping(mappingMode);
    final MappingInfo currentMappingInfo = mapping.get(fromKeys);
    final MappingInfo prevMappingInfo = mapping.get(mappingKeys);
    final MappingInfo mappingInfo = currentMappingInfo != null ? currentMappingInfo : prevMappingInfo;
    final Application application = ApplicationManager.getApplication();
    if (mapping.isPrefix(fromKeys)) {
        mappingKeys.add(key);
        if (!application.isUnitTestMode() && Options.getInstance().isSet(Options.TIMEOUT)) {
            commandState.startMappingTimer(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    mappingKeys.clear();
                    for (KeyStroke keyStroke : fromKeys) {
                        handleKey(editor, keyStroke, new EditorDataContext(editor), false);
                    }
                }
            });
        }
        return true;
    } else if (mappingInfo != null) {
        mappingKeys.clear();
        final Runnable handleMappedKeys = new Runnable() {

            @Override
            public void run() {
                if (editor.isDisposed()) {
                    return;
                }
                final List<KeyStroke> toKeys = mappingInfo.getToKeys();
                final VimExtensionHandler extensionHandler = mappingInfo.getExtensionHandler();
                final EditorDataContext currentContext = new EditorDataContext(editor);
                if (toKeys != null) {
                    final boolean fromIsPrefix = isPrefix(mappingInfo.getFromKeys(), toKeys);
                    boolean first = true;
                    for (KeyStroke keyStroke : toKeys) {
                        final boolean recursive = mappingInfo.isRecursive() && !(first && fromIsPrefix);
                        handleKey(editor, keyStroke, currentContext, recursive);
                        first = false;
                    }
                } else if (extensionHandler != null) {
                    RunnableHelper.runWriteCommand(editor.getProject(), new Runnable() {

                        @Override
                        public void run() {
                            extensionHandler.execute(editor, context);
                        }
                    }, "Vim " + extensionHandler.getClass().getSimpleName(), null);
                }
                if (prevMappingInfo != null) {
                    handleKey(editor, key, currentContext);
                }
            }
        };
        if (application.isUnitTestMode()) {
            handleMappedKeys.run();
        } else {
            application.invokeLater(handleMappedKeys);
        }
        return true;
    } else {
        final List<KeyStroke> unhandledKeys = new ArrayList<KeyStroke>(mappingKeys);
        mappingKeys.clear();
        for (KeyStroke keyStroke : unhandledKeys) {
            handleKey(editor, keyStroke, context, false);
        }
        return false;
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) VimExtensionHandler(com.maddyhome.idea.vim.extension.VimExtensionHandler) ArrayList(java.util.ArrayList) MappingMode(com.maddyhome.idea.vim.command.MappingMode) ActionListener(java.awt.event.ActionListener) CommandState(com.maddyhome.idea.vim.command.CommandState) ArrayList(java.util.ArrayList) List(java.util.List) Application(com.intellij.openapi.application.Application)

Example 99 with Application

use of com.intellij.openapi.application.Application in project ideavim by JetBrains.

the class UiHelper method runAfterGotFocus.

/**
   * Run code after getting focus on request.
   *
   * @see #requestFocus
   */
public static void runAfterGotFocus(@NotNull final Runnable runnable) {
    final Application application = ApplicationManager.getApplication();
    // XXX: One more invokeLater than in requestFocus()
    application.invokeLater(new Runnable() {

        @Override
        public void run() {
            application.invokeLater(new Runnable() {

                @Override
                public void run() {
                    application.invokeLater(runnable);
                }
            });
        }
    });
}
Also used : Application(com.intellij.openapi.application.Application)

Example 100 with Application

use of com.intellij.openapi.application.Application in project android by JetBrains.

the class SimulatedSyncErrors method simulateRegisteredSyncError.

public static void simulateRegisteredSyncError() {
    Application application = ApplicationManager.getApplication();
    ExternalSystemException error = application.getUserData(SIMULATED_ERROR_KEY);
    if (error != null) {
        verifyIsTestMode();
        application.putUserData(SIMULATED_ERROR_KEY, null);
        throw error;
    }
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) Application(com.intellij.openapi.application.Application)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3