• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UndoManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.openapi.command.undo.UndoManager的典型用法代码示例。如果您正苦于以下问题:Java UndoManager类的具体用法?Java UndoManager怎么用?Java UndoManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UndoManager类属于com.intellij.openapi.command.undo包,在下文中一共展示了UndoManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: importClass

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public boolean importClass(PsiClass aClass) {
  final String className = aClass.getName();
  final String qName = aClass.getQualifiedName();
  if (qName == null) return false;
  //if (!myPseudoImports.containsKey(className)){
  myPseudoImports.put(className, qName);
  myManager.beforeChange(false); // to clear resolve caches!
  if (isPhysical()) {
    final Project project = myManager.getProject();
    final Document document = PsiDocumentManager.getInstance(project).getDocument(this);
    UndoManager.getInstance(project).undoableActionPerformed(new ImportClassUndoableAction(className, qName, document, myPseudoImports));
  }
  return true;
  //}
  //else{
  //  return false;
  //}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PsiCodeFragmentImpl.java


示例2: handleQualifiedNameChange

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public void handleQualifiedNameChange(@NotNull final PsiPackage psiPackage, @NotNull final String newQualifiedName) {
  ApplicationManager.getApplication().assertWriteAccessAllowed();
  final String oldQualifedName = psiPackage.getQualifiedName();
  final boolean anyChanged = changePackagePrefixes(psiPackage, oldQualifedName, newQualifiedName);
  if (anyChanged) {
    UndoManager.getInstance(psiPackage.getProject()).undoableActionPerformed(new GlobalUndoableAction() {
      @Override
      public void undo() {
        changePackagePrefixes(psiPackage, newQualifiedName, oldQualifedName);
      }

      @Override
      public void redo() {
        changePackagePrefixes(psiPackage, oldQualifedName, newQualifiedName);
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PsiPackageImplementationHelperImpl.java


示例3: testAutoImportWorks

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public void testAutoImportWorks() throws Throwable {
  @NonNls final String text = "class S { JFrame x; <caret> }";
  configureByText(StdFileTypes.JAVA, text);
  ((UndoManagerImpl)UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
  ((UndoManagerImpl)UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(getFile().getVirtualFile());
  assertFalse(DaemonListeners.canChangeFileSilently(getFile()));


  doHighlighting();
  assertFalse(DaemonListeners.canChangeFileSilently(getFile()));

  type(" ");
  assertTrue(DaemonListeners.canChangeFileSilently(getFile()));

  undo();

  assertFalse(DaemonListeners.canChangeFileSilently(getFile()));//CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ImportHelperTest.java


示例4: cleanupApplicationCaches

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
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();

    ((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest();
  }

  ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance();
  if (projectManager.isDefaultProjectInitialized()) {
    Project defaultProject = projectManager.getDefaultProject();
    ((PsiManagerImpl)PsiManager.getInstance(defaultProject)).cleanupForNextTest();
  }

  LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance();
  if (localFileSystem != null) {
    localFileSystem.cleanupForNextTest();
  }

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PlatformTestCase.java


示例5: createWorkingDocument

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public Document createWorkingDocument(final Project project) {
  //TODO[ik]: do we really need to create copy here?
  final Document workingDocument = myDocument; //DocumentUtil.createCopy(myDocument, project);
  //LOG.assertTrue(workingDocument != myDocument);
  workingDocument.setReadOnly(false);
  final DocumentReference ref = DocumentReferenceManager.getInstance().create(workingDocument);
  myTextBeforeMerge = myDocument.getText();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      setDocumentText(workingDocument, myOriginalText, DiffBundle.message("merge.init.merge.content.command.name"), project);
      if (project != null) {
        final UndoManager undoManager = UndoManager.getInstance(project);
        if (undoManager != null) { //idea.sh merge command
          undoManager.nonundoableActionPerformed(ref, false);
        }
      }
    }
  });
  return workingDocument;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:MergeVersion.java


示例6: update

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);

  // do not allow global undo in dialogs
  if (editor == null) {
    final Boolean isModalContext = PlatformDataKeys.IS_MODAL_CONTEXT.getData(dataContext);
    if (isModalContext != null && isModalContext) {
      presentation.setEnabled(false);
      return;
    }
  }

  UndoManager undoManager = getUndoManager(editor, dataContext);
  if (undoManager == null) {
    presentation.setEnabled(false);
    return;
  }
  presentation.setEnabled(isAvailable(editor, undoManager));

  Pair<String, String> pair = getActionNameAndDescription(editor, undoManager);

  presentation.setText(pair.first);
  presentation.setDescription(pair.second);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:UndoRedoAction.java


示例7: runExecuteAction

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public void runExecuteAction(@NotNull LanguageConsoleView consoleView) {
  if (!myUseProcessStdIn) {
    beforeExecution(consoleView);
  }

  String text = ((LanguageConsoleImpl)consoleView).prepareExecuteAction(myAddToHistory && !myUseProcessStdIn,
                                                                                   myPreserveMarkup, true);
  ((UndoManagerImpl)UndoManager.getInstance(consoleView.getProject())).invalidateActionsFor(DocumentReferenceManager.getInstance().create(
    consoleView.getCurrentEditor().getDocument()));

  if (myUseProcessStdIn) {
    consoleView.print(text, ConsoleViewContentType.USER_INPUT);
    consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
  }
  else {
    addToCommandHistoryAndExecute(consoleView, text);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ConsoleExecuteAction.java


示例8: doRename

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project,
                            @Nullable final RefactoringElementListener listener) throws IncorrectOperationException{
  final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
  final String fqn = element instanceof PsiFile ? ((PsiFile)element).getVirtualFile().getPath() : CopyReferenceAction.elementToFqn(element);
  if (fqn != null) {
    UndoableAction action = new BasicUndoableAction() {
      @Override
      public void undo() throws UnexpectedUndoException {
        if (listener instanceof UndoRefactoringElementListener) {
          ((UndoRefactoringElementListener)listener).undoElementMovedOrRenamed(element, fqn);
        }
      }

      @Override
      public void redo() throws UnexpectedUndoException {
      }
    };
    UndoManager.getInstance(project).undoableActionPerformed(action);
  }
  processor.renameElement(element, newName, usages, listener);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:RenameUtil.java


示例9: run

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public void run() {
  FORMATTING_CANCELLED_FLAG.set(true);
  VirtualFile file = myFile.get();
  Document document = myDocument.get();
  if (file == null || document == null || myDocumentModificationStampBefore < 0) {
    return;
  }
  FileEditor editor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
  if (editor == null) {
    return;
  }

  UndoManager manager = UndoManager.getInstance(myProject);
  while (manager.isUndoAvailable(editor) && document.getModificationStamp() != myDocumentModificationStampBefore) {
    manager.undo(editor);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FormattingProgressTask.java


示例10: renameElement

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public void renameElement(PsiElement element, final String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener)
  throws IncorrectOperationException {
  if (element instanceof PsiField) {
    new RenameJavaVariableProcessor().renameElement(element, newName, usages, listener);
  }
  else {
    if (element instanceof PsiNamedElement) {
      super.renameElement(element, newName, usages, listener);

      if (element instanceof PsiFile) {
        VirtualFile virtualFile = ((PsiFile)element).getVirtualFile();
        if (virtualFile != null && !LocalHistory.getInstance().isUnderControl(virtualFile)) {
          DocumentReference ref = DocumentReferenceManager.getInstance().create(virtualFile);
          UndoManager.getInstance(element.getProject()).nonundoableActionPerformed(ref, false);
        }
      }
    }
    else if (element instanceof XmlAttributeValue) {
      new RenameXmlAttributeProcessor().renameElement(element, newName, usages, listener);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AndroidResourceRenameResourceProcessor.java


示例11: execute

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public static void execute(final Project project, final UndoableAction action, String name, String groupId) {
  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    public void run() {

      try {
        action.redo();
      }
      catch (UnexpectedUndoException e) {
        throw new RuntimeException(e);
      }
      UndoManager.getInstance(project).undoableActionPerformed(action);

    }
  }, name, groupId);

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:UndoableCommand.java


示例12: markUnshelvedFilesNonUndoable

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@CalledInAwt
private static void markUnshelvedFilesNonUndoable(@NotNull final Project project,
                                                  @NotNull List<ShelvedChange> changes) {
  final UndoManagerImpl undoManager = (UndoManagerImpl)UndoManager.getInstance(project);
  if (undoManager != null && !changes.isEmpty()) {
    ContainerUtil.process(changes, new Processor<ShelvedChange>() {
      @Override
      public boolean process(ShelvedChange change) {
        final VirtualFile vfUnderProject = VfsUtil.findFileByIoFile(new File(project.getBasePath(), change.getAfterPath()), false);
        if (vfUnderProject != null) {
          final DocumentReference documentReference = DocumentReferenceManager.getInstance().create(vfUnderProject);
          undoManager.nonundoableActionPerformed(documentReference, false);
          undoManager.invalidateActionsFor(documentReference);
        }
        return true;
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GitShelveUtils.java


示例13: doFix

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
protected void doFix(final Project project, ProblemDescriptor descriptor) {
  addRemoveTestsScope(project, true);
  final VirtualFile vFile = descriptor.getPsiElement().getContainingFile().getVirtualFile();
  UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction(vFile) {
    @Override
    public void undo() throws UnexpectedUndoException {
      addRemoveTestsScope(project, false);
    }

    @Override
    public void redo() throws UnexpectedUndoException {
      addRemoveTestsScope(project, true);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:SuppressForTestsScopeFix.java


示例14: doMoveRename

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
private boolean doMoveRename(final VirtualFile file, final VirtualFile newParent, final String newName) throws IOException {
  if (!CvsUtil.fileIsUnderCvs(file)) return false;
  if (newParent == null) return false;
  final File newFile = new File(newParent.getPath(), newName);
  myComponent.getDeleteHandler().addDeletedRoot(file);
  if (!file.isDirectory()) {
    myComponent.getAddHandler().addFile(newFile);
    return false;
  }
  newFile.mkdir();
  copyDirectoryStructure(file, newFile);
  myComponent.getAddHandler().addFile(newFile);
  final DocumentReference ref = DocumentReferenceManager.getInstance().create(file);
  UndoManager.getInstance(myProject).nonundoableActionPerformed(ref, false);
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CvsFileOperationsHandler.java


示例15: invokeOnTheFlyImportOptimizer

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
                                                 @NotNull final PsiFile file,
                                                 @NotNull final Editor editor) {
  final long stamp = editor.getDocument().getModificationStamp();
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      if (file.getProject().isDisposed() || editor.isDisposed() || editor.getDocument().getModificationStamp() != stamp) return;
      //no need to optimize imports on the fly during undo/redo
      final UndoManager undoManager = UndoManager.getInstance(editor.getProject());
      if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) return;
      PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
      String beforeText = file.getText();
      final long oldStamp = editor.getDocument().getModificationStamp();
      DocumentUtil.writeInRunUndoTransparentAction(runnable);
      if (oldStamp != editor.getDocument().getModificationStamp()) {
        String afterText = file.getText();
        if (Comparing.strEqual(beforeText, afterText)) {
          String path = file.getViewProvider().getVirtualFile().getPath();
          LOG.error("Import optimizer  hasn't optimized any imports", new Attachment(path, afterText));
        }
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GroovyOptimizeImportsFix.java


示例16: handleQualifiedNameChange

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
@Override
public void handleQualifiedNameChange(final PsiPackage psiPackage, final String newQualifiedName) {
  ApplicationManager.getApplication().assertWriteAccessAllowed();
  final String oldQualifedName = psiPackage.getQualifiedName();
  final boolean anyChanged = changePackagePrefixes(psiPackage, oldQualifedName, newQualifiedName);
  if (anyChanged) {
    UndoManager.getInstance(psiPackage.getProject()).undoableActionPerformed(new GlobalUndoableAction() {
      @Override
      public void undo() {
        changePackagePrefixes(psiPackage, newQualifiedName, oldQualifedName);
      }

      @Override
      public void redo() {
        changePackagePrefixes(psiPackage, oldQualifedName, newQualifiedName);
      }
    });
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:PsiPackageImplementationHelperImpl.java


示例17: testAutoImportWorks

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public void testAutoImportWorks() throws Throwable {
  @NonNls final String text = "class S { JFrame x; <caret> }";
  configureByText(StdFileTypes.JAVA, text);
  ((UndoManagerImpl)UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
  ((UndoManagerImpl)UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(getFile().getVirtualFile());
  assertFalse(((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).canChangeFileSilently(getFile()));


  doHighlighting();
  assertFalse(((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).canChangeFileSilently(getFile()));

  type(" ");
  assertTrue(((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).canChangeFileSilently(getFile()));

  undo();

  assertFalse(((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).canChangeFileSilently(getFile()));//CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:ImportHelperTest.java


示例18: cleanupApplicationCaches

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
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();
  }

  LocalHistoryImpl.getInstanceImpl().cleanupForNextTest();

  PatchedWeakReference.clearAll();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:PlatformTestCase.java


示例19: createWorkingDocument

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public Document createWorkingDocument(final Project project) {
  //TODO[ik]: do we really need to create copy here?
  final Document workingDocument = myDocument; //DocumentUtil.createCopy(myDocument, project);
  //LOG.assertTrue(workingDocument != myDocument);
  workingDocument.setReadOnly(false);
  final DocumentReference ref = DocumentReferenceManager.getInstance().create(workingDocument);
  myTextBeforeMerge = myDocument.getText();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    public void run() {
      setDocumentText(workingDocument, myOriginalText, DiffBundle.message("merge.init.merge.content.command.name"), project);
      if (project != null) {
        final UndoManager undoManager = UndoManager.getInstance(project);
        if (undoManager != null) { //idea.sh merge command
          undoManager.nonundoableActionPerformed(ref, false);
        }
      }
    }
  });
  return workingDocument;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:MergeVersion.java


示例20: runExecuteAction

import com.intellij.openapi.command.undo.UndoManager; //导入依赖的package包/类
public void runExecuteAction(LanguageConsoleImpl languageConsole) {

    // Process input and add to history
    final Document document = languageConsole.getCurrentEditor().getDocument();
    final String text = document.getText();
    final TextRange range = new TextRange(0, document.getTextLength());

    languageConsole.getCurrentEditor().getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
    if (myAddCurrentToHistory) {
      languageConsole.addCurrentToHistory(range, false, myPreserveMarkup);
    }

    languageConsole.setInputText("");

    final UndoManager manager = languageConsole.getProject() == null ? UndoManager.getGlobalInstance() : UndoManager.getInstance(
      languageConsole.getProject());

    ((UndoManagerImpl)manager).invalidateActionsFor(DocumentReferenceManager.getInstance().create(document));

    myConsoleHistoryModel.addToHistory(text);
    // Send to interpreter / server

    processLine(text);
  }
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:ConsoleExecuteActionHandler.java



注:本文中的com.intellij.openapi.command.undo.UndoManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DefaultDeferredManager类代码示例发布时间:2022-05-22
下一篇:
Java XmlHighlighterColors类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap