Search in sources :

Example 21 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class GrExtractInterfaceHandler method doRefactoring.

private void doRefactoring() throws IncorrectOperationException {
    LocalHistoryAction a = LocalHistory.getInstance().startAction(getCommandName());
    final PsiClass anInterface;
    try {
        anInterface = extractInterface(myTargetDir, myClass, myInterfaceName, mySelectedMembers, myJavaDocPolicy);
    } finally {
        a.finish();
    }
    if (anInterface != null) {
        final SmartPsiElementPointer<PsiClass> classPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(myClass);
        final SmartPsiElementPointer<PsiClass> interfacePointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(anInterface);
        final Runnable turnRefsToSuperRunnable = () -> ExtractClassUtil.askAndTurnRefsToSuper(myProject, classPointer, interfacePointer);
        SwingUtilities.invokeLater(turnRefsToSuperRunnable);
    }
}
Also used : LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Example 22 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class ElementCreator method executeCommand.

@Nullable
private Exception executeCommand(String commandName, ThrowableRunnable<Exception> invokeCreate) {
    final Exception[] exception = new Exception[1];
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
        LocalHistoryAction action = LocalHistory.getInstance().startAction(commandName);
        try {
            if (startInWriteAction()) {
                WriteAction.run(invokeCreate);
            } else {
                invokeCreate.run();
            }
        } catch (Exception ex) {
            exception[0] = ex;
        } finally {
            action.finish();
        }
    }, commandName, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION);
    return exception[0];
}
Also used : LocalHistoryAction(com.intellij.history.LocalHistoryAction) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class CreateDirectoryOrPackageHandler method doCreateElement.

private void doCreateElement(final String subDirName, final boolean createFile) {
    Runnable command = () -> {
        final Runnable run = () -> {
            String dirPath = myDirectory.getVirtualFile().getPresentableUrl();
            String actionName = IdeBundle.message("progress.creating.directory", dirPath, File.separator, subDirName);
            LocalHistoryAction action = LocalHistory.getInstance().startAction(actionName);
            try {
                if (createFile) {
                    CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(subDirName, myDirectory);
                    myCreatedElement = mkdirs.directory.createFile(mkdirs.newName);
                } else {
                    createDirectories(subDirName);
                }
            } catch (final IncorrectOperationException ex) {
                ApplicationManager.getApplication().invokeLater(() -> showErrorDialog(CreateElementActionBase.filterMessage(ex.getMessage())));
            } finally {
                action.finish();
            }
        };
        ApplicationManager.getApplication().runWriteAction(run);
    };
    CommandProcessor.getInstance().executeCommand(myProject, command, createFile ? IdeBundle.message("command.create.file") : myIsDirectory ? IdeBundle.message("command.create.directory") : IdeBundle.message("command.create.package"), null);
}
Also used : LocalHistoryAction(com.intellij.history.LocalHistoryAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 24 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij by bazelbuild.

the class NewBlazeRuleDialog method doOKAction.

@Override
protected void doOKAction() {
    TargetName targetName = newRuleUI.getRuleName();
    Kind ruleKind = newRuleUI.getSelectedRuleKind();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    WorkspacePath workspacePath = workspaceRoot.workspacePathFor(new File(buildFile.getParent().getPath()));
    Label newRule = Label.create(workspacePath, targetName);
    BuildFileModifier buildFileModifier = BuildFileModifier.getInstance();
    String commandName = String.format("Add %s %s rule '%s'", buildSystemName, ruleKind, newRule);
    boolean success = new WriteCommandAction<Boolean>(project, commandName) {

        @Override
        protected void run(@NotNull Result<Boolean> result) throws Throwable {
            LocalHistory localHistory = LocalHistory.getInstance();
            LocalHistoryAction action = localHistory.startAction(commandName);
            try {
                result.setResult(buildFileModifier.addRule(project, newRule, ruleKind));
            } finally {
                action.finish();
            }
        }
    }.execute().getResultObject();
    if (success) {
        super.doOKAction();
    } else {
        super.setErrorText(String.format("Could not create new rule, see %s Console for details", buildSystemName));
    }
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Label(com.google.idea.blaze.base.model.primitives.Label) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Kind(com.google.idea.blaze.base.model.primitives.Kind) LocalHistoryAction(com.intellij.history.LocalHistoryAction) BuildFileModifier(com.google.idea.blaze.base.buildmodifier.BuildFileModifier) LocalHistory(com.intellij.history.LocalHistory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

LocalHistoryAction (com.intellij.history.LocalHistoryAction)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Result (com.intellij.openapi.application.Result)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)7 NotNull (org.jetbrains.annotations.NotNull)7 UsageInfo (com.intellij.usageView.UsageInfo)4 Revision (com.intellij.history.core.revisions.Revision)3 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)2 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)2 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)2 BuildFileModifier (com.google.idea.blaze.base.buildmodifier.BuildFileModifier)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 LocalHistory (com.intellij.history.LocalHistory)2 Module (com.intellij.openapi.module.Module)2