com.intellij.history.LocalHistory Java Examples
The following examples show how to use
com.intellij.history.LocalHistory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FavoritesTreeViewPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void deleteElement(@Nonnull DataContext dataContext) { List<PsiElement> allElements = Arrays.asList(getElementsToDelete()); List<PsiElement> validElements = new ArrayList<>(); for (PsiElement psiElement : allElements) { if (psiElement != null && psiElement.isValid()) validElements.add(psiElement); } final PsiElement[] elements = PsiUtilCore.toPsiElementArray(validElements); LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #2
Source File: UndoableGroup.java From consulo with Apache License 2.0 | 6 votes |
private void undoOrRedo(boolean isUndo) { LocalHistoryAction action; if (myProject != null && isGlobal()) { String actionName = CommonBundle.message(isUndo ? "local.vcs.action.name.undo.command" : "local.vcs.action.name.redo.command", myCommandName); action = LocalHistory.getInstance().startAction(actionName); } else { action = LocalHistoryAction.NULL; } try { doUndoOrRedo(isUndo); } finally { action.finish(); } }
Example #3
Source File: ElementCreator.java From consulo with Apache License 2.0 | 6 votes |
@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 { invokeCreate.run(); } catch (Exception ex) { exception[0] = ex; } finally { action.finish(); } }, commandName, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION); return exception[0]; }
Example #4
Source File: ActionsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testActionInsideCommand() throws Exception { // This is very important test. Mostly all actions are performed // inside surrounding command. Therefore we have to correctly // handle such situation. final VirtualFile f = createFile("f.txt"); setContent(f, "file"); setDocumentTextFor(f, "doc1"); CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { LocalHistoryAction a = LocalHistory.getInstance().startAction("action"); setDocumentTextFor(f, "doc2"); a.finish(); } }, "command", null); List<Revision> rr = getRevisionsFor(f); assertEquals(5, rr.size()); assertContent("doc2", rr.get(0).findEntry()); assertEquals("command", rr.get(1).getChangeSetName()); assertContent("doc1", rr.get(1).findEntry()); assertContent("file", rr.get(2).findEntry()); assertContent("", rr.get(3).findEntry()); }
Example #5
Source File: ActionsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testSavingDocumentBeforeAndAfterAction() throws Exception { VirtualFile f = createFile("f.txt", "file1"); setContent(f, "file2"); setDocumentTextFor(f, "doc1"); LocalHistoryAction a = LocalHistory.getInstance().startAction("name"); setDocumentTextFor(f, "doc2"); a.finish(); List<Revision> rr = getRevisionsFor(f); assertEquals(5, rr.size()); assertContent("doc2", rr.get(0).findEntry()); assertEquals("name", rr.get(1).getChangeSetName()); assertContent("doc1", rr.get(1).findEntry()); assertContent("file2", rr.get(2).findEntry()); assertContent("file1", rr.get(3).findEntry()); }
Example #6
Source File: PatchApplier.java From consulo with Apache License 2.0 | 6 votes |
@CalledInAwt public void run() { myRemainingPatches.addAll(myPatches); final ApplyPatchStatus patchStatus = nonWriteActionPreCheck(); final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(myProject, "Before patch"); final TriggerAdditionOrDeletion trigger = new TriggerAdditionOrDeletion(myProject); final ApplyPatchStatus applyStatus = getApplyPatchStatus(trigger); myStatus = ApplyPatchStatus.SUCCESS.equals(patchStatus) ? applyStatus : ApplyPatchStatus.and(patchStatus, applyStatus); // listeners finished, all 'legal' file additions/deletions with VCS are done trigger.processIt(); LocalHistory.getInstance().putSystemLabel(myProject, "After patch"); // insert a label to be visible in local history dialog if (myStatus == ApplyPatchStatus.FAILURE) { suggestRollback(myProject, Collections.singletonList(PatchApplier.this), beforeLabel); } else if (myStatus == ApplyPatchStatus.ABORT) { rollbackUnderProgress(myProject, myProject.getBaseDir(), beforeLabel); } if(myShowNotification || !ApplyPatchStatus.SUCCESS.equals(myStatus)) { showApplyStatus(myProject, myStatus); } refreshFiles(trigger.getAffected()); }
Example #7
Source File: BasicsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testDoNotRegisterSameUnsavedDocumentContentTwice() throws Exception { VirtualFile f = myRoot.createChildData(null, "f.txt"); setContent(f, "1"); setDocumentTextFor(f, "2"); LocalHistory.getInstance().putSystemLabel(myProject, "label"); LocalHistory.getInstance().putUserLabel(myProject, "label"); List<Revision> rr = getRevisionsFor(f); assertEquals(6, rr.size()); // 3 changes + 2 labels assertEquals("2", new String(rr.get(0).findEntry().getContent().getBytes())); assertEquals("2", new String(rr.get(1).findEntry().getContent().getBytes())); assertEquals("2", new String(rr.get(2).findEntry().getContent().getBytes())); assertEquals("1", new String(rr.get(3).findEntry().getContent().getBytes())); assertEquals("", new String(rr.get(4).findEntry().getContent().getBytes())); }
Example #8
Source File: BasicsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testPuttingLabelWithUnsavedDocuments() throws Exception { VirtualFile f = myRoot.createChildData(null, "f.txt"); setContent(f, "1"); setDocumentTextFor(f, "2"); LocalHistory.getInstance().putSystemLabel(myProject, "label"); setDocumentTextFor(f, "3"); LocalHistory.getInstance().putUserLabel(myProject, "label"); setDocumentTextFor(f, "4"); LocalHistory.getInstance().putUserLabel(myProject, "label"); List<Revision> rr = getRevisionsFor(f); assertEquals(9, rr.size()); // 5 changes + 3 labels assertEquals("4", new String(rr.get(0).findEntry().getContent().getBytes())); assertEquals("4", new String(rr.get(1).findEntry().getContent().getBytes())); assertEquals("3", new String(rr.get(2).findEntry().getContent().getBytes())); assertEquals("3", new String(rr.get(3).findEntry().getContent().getBytes())); assertEquals("2", new String(rr.get(4).findEntry().getContent().getBytes())); assertEquals("2", new String(rr.get(5).findEntry().getContent().getBytes())); assertEquals("1", new String(rr.get(6).findEntry().getContent().getBytes())); assertEquals("", new String(rr.get(7).findEntry().getContent().getBytes())); }
Example #9
Source File: BasicsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testPuttingSystemLabel() throws IOException { VirtualFile f = myRoot.createChildData(null, "file.txt"); assertEquals(2, getRevisionsFor(f).size()); assertEquals(2, getRevisionsFor(myRoot).size()); LocalHistory.getInstance().putSystemLabel(myProject, "label"); List<Revision> rr = getRevisionsFor(f); assertEquals(3, rr.size()); assertEquals("label", rr.get(1).getLabel()); rr = getRevisionsFor(myRoot); assertEquals(3, rr.size()); assertEquals("label", rr.get(1).getLabel()); }
Example #10
Source File: BasicsTest.java From consulo with Apache License 2.0 | 6 votes |
public void testPuttingUserLabel() throws Exception { VirtualFile f = myRoot.createChildData(null, "f.txt"); LocalHistory.getInstance().putUserLabel(myProject, "global"); assertEquals(3, getRevisionsFor(f).size()); assertEquals(3, getRevisionsFor(myRoot).size()); LocalHistory.getInstance().putUserLabel(myProject, "file"); List<Revision> rr = getRevisionsFor(f); assertEquals(4, rr.size()); assertEquals("file", rr.get(1).getLabel()); assertEquals(-1, rr.get(1).getLabelColor()); assertEquals("global", rr.get(2).getLabel()); assertEquals(-1, rr.get(2).getLabelColor()); }
Example #11
Source File: UndoChangeRevertingVisitor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void visit(MoveChange c) throws StopVisitingException { if (shouldRevert(c)) { VirtualFile f = myGateway.findVirtualFile(c.getPath()); if (f != null) { try { VirtualFile parent = myGateway.findOrCreateFileSafely(c.getOldParent(), true); VirtualFile existing = parent.findChild(f.getName()); if (existing != null) existing.delete(LocalHistory.VFS_EVENT_REQUESTOR); f.move(LocalHistory.VFS_EVENT_REQUESTOR, parent); } catch (IOException e) { throw new RuntimeIOException(e); } } } checkShouldStop(c); }
Example #12
Source File: UndoChangeRevertingVisitor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void visit(CreateEntryChange c) throws StopVisitingException { if (shouldRevert(c)) { VirtualFile f = myGateway.findVirtualFile(c.getPath()); if (f != null) { unregisterDelayedApplies(f); try { f.delete(LocalHistory.VFS_EVENT_REQUESTOR); } catch (IOException e) { throw new RuntimeIOException(e); } } } checkShouldStop(c); }
Example #13
Source File: FlutterApp.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Perform a hot restart of the the app. */ public CompletableFuture<DaemonApi.RestartResult> performRestartApp(@NotNull String reason) { if (myAppId == null) { FlutterUtils.warn(LOG, "cannot restart Flutter app because app id is not set"); final CompletableFuture<DaemonApi.RestartResult> result = new CompletableFuture<>(); result.completeExceptionally(new IllegalStateException("cannot restart Flutter app because app id is not set")); return result; } restartCount++; userReloadCount = 0; LocalHistory.getInstance().putSystemLabel(getProject(), "Flutter hot restart"); maxFileTimestamp = System.currentTimeMillis(); changeState(State.RESTARTING); final CompletableFuture<DaemonApi.RestartResult> future = myDaemonApi.restartApp(myAppId, true, false, reason); future.thenAccept(result -> changeState(State.STARTED)); future.thenRun(this::notifyAppRestarted); return future; }
Example #14
Source File: FlutterApp.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Perform a hot restart of the the app. */ public CompletableFuture<DaemonApi.RestartResult> performRestartApp(@NotNull String reason) { if (myAppId == null) { FlutterUtils.warn(LOG, "cannot restart Flutter app because app id is not set"); final CompletableFuture<DaemonApi.RestartResult> result = new CompletableFuture<>(); result.completeExceptionally(new IllegalStateException("cannot restart Flutter app because app id is not set")); return result; } restartCount++; userReloadCount = 0; LocalHistory.getInstance().putSystemLabel(getProject(), "Flutter hot restart"); maxFileTimestamp = System.currentTimeMillis(); changeState(State.RESTARTING); final CompletableFuture<DaemonApi.RestartResult> future = myDaemonApi.restartApp(myAppId, true, false, reason); future.thenAccept(result -> changeState(State.STARTED)); future.thenRun(this::notifyAppRestarted); return future; }
Example #15
Source File: ScopeTreeViewPanel.java From consulo with Apache License 2.0 | 6 votes |
@Override public void deleteElement(@Nonnull DataContext dataContext) { List<PsiElement> allElements = Arrays.asList(getSelectedPsiElements()); ArrayList<PsiElement> validElements = new ArrayList<PsiElement>(); for (PsiElement psiElement : allElements) { if (psiElement != null && psiElement.isValid()) validElements.add(psiElement); } final PsiElement[] elements = PsiUtilBase.toPsiElementArray(validElements); LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #16
Source File: ExtractInterfaceHandler.java From intellij-haxe with Apache License 2.0 | 6 votes |
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 = new Runnable() { @Override public void run() { ExtractClassUtil.askAndTurnRefsToSuper(myProject, classPointer, interfacePointer); } }; SwingUtilities.invokeLater(turnRefsToSuperRunnable); } }
Example #17
Source File: LvcsHelper.java From consulo with Apache License 2.0 | 6 votes |
public static void addLabel(final TestFrameworkRunningModel model) { String label; int color; if (model.getRoot().isDefect()) { color = RED.getRGB(); label = ExecutionBundle.message("junit.runing.info.tests.failed.label"); } else { color = GREEN.getRGB(); label = ExecutionBundle.message("junit.runing.info.tests.passed.label"); } final TestConsoleProperties consoleProperties = model.getProperties(); String name = label + " " + consoleProperties.getConfiguration().getName(); Project project = consoleProperties.getProject(); if (project.isDisposed()) return; LocalHistory.getInstance().putSystemLabel(project, name, color); }
Example #18
Source File: ProjectViewImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void deleteElement(@Nonnull DataContext dataContext) { List<PsiElement> allElements = Arrays.asList(getElementsToDelete()); List<PsiElement> validElements = new ArrayList<>(); for (PsiElement psiElement : allElements) { if (psiElement != null && psiElement.isValid()) validElements.add(psiElement); } final PsiElement[] elements = PsiUtilCore.toPsiElementArray(validElements); LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #19
Source File: PlatformTestCase.java From consulo with Apache License 2.0 | 6 votes |
public static void cleanupApplicationCaches(Project project) { if (project != null && !project.isDisposed()) { UndoManagerImpl globalInstance = (UndoManagerImpl)UndoManager.getGlobalInstance(); if (globalInstance != null) { globalInstance.dropHistoryInTests(); } ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests(); ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest(); } LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance(); if (localFileSystem != null) { localFileSystem.cleanupForNextTest(); } LocalHistory.getInstance().cleanupForNextTest(); }
Example #20
Source File: PackageViewPane.java From consulo with Apache License 2.0 | 6 votes |
@Override public void deleteElement(@Nonnull DataContext dataContext) { List<PsiDirectory> allElements = Arrays.asList(getSelectedDirectories()); List<PsiElement> validElements = new ArrayList<PsiElement>(); for (PsiElement psiElement : allElements) { if (psiElement != null && psiElement.isValid()) validElements.add(psiElement); } final PsiElement[] elements = PsiUtilCore.toPsiElementArray(validElements); LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #21
Source File: UndoChangeRevertingVisitor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void visit(RenameChange c) throws StopVisitingException { if (shouldRevert(c)) { VirtualFile f = myGateway.findVirtualFile(c.getPath()); if (f != null) { VirtualFile existing = f.getParent().findChild(c.getOldName()); try { if (existing != null && !Comparing.equal(existing, f)) { existing.delete(LocalHistory.VFS_EVENT_REQUESTOR); } f.rename(LocalHistory.VFS_EVENT_REQUESTOR, c.getOldName()); } catch (IOException e) { throw new RuntimeIOException(e); } } } checkShouldStop(c); }
Example #22
Source File: TypeHierarchyBrowserBase.java From consulo with Apache License 2.0 | 5 votes |
@Override public final void deleteElement(@Nonnull final DataContext dataContext) { final PsiElement aClass = getSelectedElement(); if (!canBeDeleted(aClass)) return; LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting.class", getQualifiedName(aClass))); try { final PsiElement[] elements = {aClass}; DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #23
Source File: VcsBackgroundTaskWithLocalHistory.java From consulo with Apache License 2.0 | 5 votes |
@Override public void run(@Nonnull ProgressIndicator indicator) { LocalHistoryAction action = LocalHistoryAction.NULL; if (myActionName != null) { action = LocalHistory.getInstance().startAction(myActionName); } try { super.run(indicator); } finally { action.finish(); } }
Example #24
Source File: CommanderPanel.java From consulo with Apache License 2.0 | 5 votes |
@Override public void deleteElement(@Nonnull final DataContext dataContext) { LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { final PsiElement[] elements = getSelectedElements(); DeleteHandler.deletePsiElement(elements, myProject); } finally { a.finish(); } }
Example #25
Source File: CommitHelper.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doBeforeRefresh() { final ChangeListManagerImpl clManager = (ChangeListManagerImpl)ChangeListManager.getInstance(myProject); clManager.showLocalChangesInvalidated(); myAction = ApplicationManager.getApplication().runReadAction(new Computable<LocalHistoryAction>() { @Override public LocalHistoryAction compute() { return LocalHistory.getInstance().startAction(myActionName); } }); }
Example #26
Source File: RollbackWorker.java From consulo with Apache License 2.0 | 5 votes |
private void doRefresh(final Project project, final List<Change> changesToRefresh) { final LocalHistoryAction action = LocalHistory.getInstance().startAction(myOperationName); final Runnable forAwtThread = new Runnable() { public void run() { action.finish(); LocalHistory.getInstance().putSystemLabel(myProject, (myLocalHistoryActionName == null) ? myOperationName : myLocalHistoryActionName, -1); final VcsDirtyScopeManager manager = project.getComponent(VcsDirtyScopeManager.class); VcsGuess vcsGuess = new VcsGuess(myProject); for (Change change : changesToRefresh) { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); if ((!change.isIsReplaced()) && beforeRevision != null && Comparing.equal(beforeRevision, afterRevision)) { manager.fileDirty(beforeRevision.getFile()); } else { markDirty(manager, vcsGuess, beforeRevision); markDirty(manager, vcsGuess, afterRevision); } } myAfterRefresh.run(); } }; RefreshVFsSynchronously.updateChangesForRollback(changesToRefresh); WaitForProgressToShow.runOrInvokeLaterAboveProgress(forAwtThread, null, project); }
Example #27
Source File: DeleteHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void deleteElement(@Nonnull DataContext dataContext) { PsiElement[] elements = getPsiElements(dataContext); if (elements == null) return; Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) return; LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting")); try { deletePsiElement(elements, project); } finally { a.finish(); } }
Example #28
Source File: FlutterApp.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Perform a hot reload of the app. */ public CompletableFuture<DaemonApi.RestartResult> performHotReload(boolean pauseAfterRestart, @NotNull String reason) { if (myAppId == null) { FlutterUtils.warn(LOG, "cannot reload Flutter app because app id is not set"); if (getState() == State.RELOADING) { changeState(State.STARTED); } final CompletableFuture<DaemonApi.RestartResult> result = new CompletableFuture<>(); result.completeExceptionally(new IllegalStateException("cannot reload Flutter app because app id is not set")); return result; } reloadCount++; userReloadCount++; LocalHistory.getInstance().putSystemLabel(getProject(), "hot reload #" + userReloadCount); maxFileTimestamp = System.currentTimeMillis(); changeState(State.RELOADING); final CompletableFuture<DaemonApi.RestartResult> future = myDaemonApi.restartApp(myAppId, false, pauseAfterRestart, reason); future.thenAccept(result -> changeState(State.STARTED)); future.thenRun(this::notifyAppReloaded); return future; }
Example #29
Source File: CreateDirectoryOrPackageHandler.java From consulo with Apache License 2.0 | 5 votes |
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); }
Example #30
Source File: FlutterApp.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Perform a hot reload of the app. */ public CompletableFuture<DaemonApi.RestartResult> performHotReload(boolean pauseAfterRestart, @NotNull String reason) { if (myAppId == null) { FlutterUtils.warn(LOG, "cannot reload Flutter app because app id is not set"); if (getState() == State.RELOADING) { changeState(State.STARTED); } final CompletableFuture<DaemonApi.RestartResult> result = new CompletableFuture<>(); result.completeExceptionally(new IllegalStateException("cannot reload Flutter app because app id is not set")); return result; } reloadCount++; userReloadCount++; LocalHistory.getInstance().putSystemLabel(getProject(), "hot reload #" + userReloadCount); maxFileTimestamp = System.currentTimeMillis(); changeState(State.RELOADING); final CompletableFuture<DaemonApi.RestartResult> future = myDaemonApi.restartApp(myAppId, false, pauseAfterRestart, reason); future.thenAccept(result -> changeState(State.STARTED)); future.thenRun(this::notifyAppReloaded); return future; }