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);
}
}
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];
}
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);
}
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));
}
}
Aggregations