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

Java EditorHelper类代码示例

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

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



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

示例1: createFromTemplate

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void createFromTemplate(@NotNull Project project,
                                      @NotNull PsiDirectory taskDirectory,
                                      @NotNull String name,
                                      @Nullable IdeView view,
                                      boolean open) {
  FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(name);
  if (template == null) {
    LOG.info("Template " + name + " wasn't found");
    return;
  }
  try {
    final PsiElement file = FileTemplateUtil.createFromTemplate(template, name, null, taskDirectory);
    if (view != null && open) {
      EditorHelper.openInEditor(file, false);
      view.selectElement(file);
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:StudyUtils.java


示例2: configure

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root)
{
    try
    {
        //Create mule folders.
        final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/domain");
        final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
        final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory);
        createMuleDeployPropertiesFile(project, projectId, appDirectory);
        createPomFile(project, projectId, muleVersion, root);
        // execute when current dialog is closed (e.g. Project Structure)
        MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile)));

    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:20,代码来源:MuleDomainMavenProjectBuilderHelper.java


示例3: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
  final boolean isDirectory = element instanceof PsiDirectory;
  if (!isDirectory) {
    EditorHelper.openInEditor(element);
  }
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      myBuilder.selectElement(element, PsiUtilCore.getVirtualFile(element));
      if (!isDirectory) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            if (myMoveFocus) {
              ToolWindowManager.getInstance(myProject).activateEditorComponent();
            }
          }
        });
      }
    }
  }, ModalityState.NON_MODAL);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CommanderPanel.java


示例4: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
  if (element != null) {
    selectPsiElement(element, false);
    boolean requestFocus = true;
    final boolean isDirectory = element instanceof PsiDirectory;
    if (!isDirectory) {
      Editor editor = EditorHelper.openInEditor(element);
      if (editor != null) {
        ToolWindowManager.getInstance(myProject).activateEditorComponent();
        requestFocus = false;
      }
    }
    if (requestFocus) {
      selectPsiElement(element, true);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FavoritesTreeViewPanel.java


示例5: startLiveTemplate

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void startLiveTemplate(PsiFile file) {
  Project project = file.getProject();
  final Editor editor = EditorHelper.openInEditor(file);
  if (editor == null) return;

  final TemplateImpl template = new TemplateImpl("", file.getText(), "");
  template.setInline(true);
  int count = template.getSegmentsCount();
  if (count == 0) return;

  Set<String> variables = new HashSet<String>();
  for (int i = 0; i < count; i++) {
    variables.add(template.getSegmentName(i));
  }
  variables.removeAll(TemplateImpl.INTERNAL_VARS_SET);
  for (String variable : variables) {
    template.addVariable(variable, null, "\"" + variable + "\"", true);
  }
  WriteCommandAction.runWriteCommandAction(project, new Runnable() {
    @Override
    public void run() {
      editor.getDocument().setText(template.getTemplateText());
    }
  });
  TemplateManager.getInstance(project).startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateFromTemplateActionBase.java


示例6: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(PsiElement element) {
  selectPsiElement(element, false);
  boolean requestFocus = true;
  if (element != null) {
    final boolean isDirectory = element instanceof PsiDirectory;
    if (!isDirectory) {
      FileEditor editor = EditorHelper.openInEditor(element, false);
      if (editor != null) {
        ToolWindowManager.getInstance(myProject).activateEditorComponent();
        requestFocus = false;
      }
    }
  }

  if (requestFocus) {
    selectPsiElement(element, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ProjectViewImpl.java


示例7: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
  if (element != null) {
    final PackageSet packageSet = getCurrentScope().getValue();
    final PsiFile psiFile = element.getContainingFile();
    if (packageSet == null) return;
    final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() :
                                    (element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : null);
    if (virtualFile != null) {
      final ProjectView projectView = ProjectView.getInstance(myProject);
      final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, CURRENT_SCOPE_NAME, myDependencyValidationManager);
      if (packageSet instanceof PackageSetBase && !((PackageSetBase)packageSet).contains(virtualFile, myProject, holder) ||
          psiFile != null && !packageSet.contains(psiFile, holder)) {
        projectView.changeView(ProjectViewPane.ID);
      }
      projectView.select(element, virtualFile, false);
    }
    Editor editor = EditorHelper.openInEditor(element);
    if (editor != null) {
      ToolWindowManager.getInstance(myProject).activateEditorComponent();
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ScopeTreeViewPanel.java


示例8: createFromTemplateAndOpen

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private static void createFromTemplateAndOpen(@NotNull final PsiDirectory taskDirectory,
                                              @Nullable final FileTemplate template,
                                              @Nullable IdeView view) {
  if (template == null) {
    return;
  }
  try {
    final PsiElement file = FileTemplateUtil.createFromTemplate(template, template.getName(), null, taskDirectory);
    if (view != null) {
      EditorHelper.openInEditor(file, false);
      view.selectElement(file);
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:CCCreateTask.java


示例9: startLiveTemplate

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void startLiveTemplate(@Nonnull PsiFile file, @Nonnull Map<String, String> defaultValues) {
  Editor editor = EditorHelper.openInEditor(file);
  if (editor == null) return;

  TemplateImpl template = new TemplateImpl("", file.getText(), "");
  template.setInline(true);
  int count = template.getSegmentsCount();
  if (count == 0) return;

  Set<String> variables = new HashSet<>();
  for (int i = 0; i < count; i++) {
    variables.add(template.getSegmentName(i));
  }
  variables.removeAll(TemplateImpl.INTERNAL_VARS_SET);
  for (String variable : variables) {
    String defaultValue = defaultValues.getOrDefault(variable, variable);
    template.addVariable(variable, null, '"' + defaultValue + '"', true);
  }

  Project project = file.getProject();
  WriteCommandAction.runWriteCommandAction(project, () -> editor.getDocument().setText(template.getTemplateText()));

  editor.getCaretModel().moveToOffset(0);  // ensures caret at the start of the template
  TemplateManager.getInstance(project).startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:CreateFromTemplateActionBase.java


示例10: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
  if (element != null) {
    final PackageSet packageSet = getCurrentScope().getValue();
    final PsiFile psiFile = element.getContainingFile();
    if (packageSet == null) return;
    final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() :
                                    (element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : null);
    if (virtualFile != null) {
      final ProjectView projectView = ProjectView.getInstance(myProject);
      final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, CURRENT_SCOPE_NAME, myDependencyValidationManager);
      if (packageSet instanceof PackageSetBase && !((PackageSetBase)packageSet).contains(virtualFile, holder) ||
          psiFile != null && !packageSet.contains(psiFile, holder)) {
        projectView.changeView(ProjectViewPane.ID);
      }
      projectView.select(element, virtualFile, false);
    }
    Editor editor = EditorHelper.openInEditor(element);
    if (editor != null) {
      ToolWindowManager.getInstance(myProject).activateEditorComponent();
    }
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:ScopeTreeViewPanel.java


示例11: configure

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root, @Nullable MavenId parentId)
{
    try
    {
        //Create mule folders.
        final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/app");
        final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
        createLog4J(project, projectId, resources);
        final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory);
        createMuleDeployPropertiesFile(project, projectId, appDirectory);
        createMuleAppPropertiesFiles(project, appDirectory);
        VfsUtil.createDirectories(root.getPath() + "/src/main/api");
        //MUnit support
        VfsUtil.createDirectories(root.getPath() + "/src/test/munit");
        final VirtualFile testResources = VfsUtil.createDirectories(root.getPath() + "/src/test/resources");
        createLog4JTest(project, projectId, testResources);

        if (parentId == null)
            createPomFile(project, projectId, muleVersion, root);
        else
            createModulePomFile(project, projectId, root, parentId);

        // execute when current dialog is closed (e.g. Project Structure)
        MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile)));

    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:32,代码来源:MuleMavenProjectBuilderHelper.java


示例12: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(PsiElement element) {
  PsiFileSystemItem psiFile;
  if (element instanceof PsiFileSystemItem) {
    psiFile = (PsiFileSystemItem)element;
  }
  else {
    psiFile = element.getContainingFile();
    if (psiFile == null) {
      return;
    }
  }

  VirtualFile virtualFile = psiFile.getVirtualFile();
  if (virtualFile == null) {
    return;
  }

  selectFile(virtualFile, false);

  boolean requestFocus = true;

  if (psiFile instanceof PsiFile) {
    Editor editor = EditorHelper.openInEditor(element);
    if (editor != null) {
      ToolWindowManager.getInstance(myProject).activateEditorComponent();
      requestFocus = false;
    }
  }

  if (requestFocus) {
    selectFile(virtualFile, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:MvcProjectViewPane.java


示例13: selectElement

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void selectElement(PsiElement element) {
  PsiFileSystemItem psiFile;

  if (!(element instanceof PsiFileSystemItem)) {
    psiFile = element.getContainingFile();
  }
  else {
    psiFile = (PsiFileSystemItem)element;
  }

  if (psiFile == null) return;

  VirtualFile virtualFile = psiFile.getVirtualFile();
  if (virtualFile == null) return;

  selectFile(virtualFile, false);

  boolean requestFocus = true;

  if (psiFile instanceof PsiFile) {
    Editor editor = EditorHelper.openInEditor(element);
    if (editor != null) {
      ToolWindowManager.getInstance(myProject).activateEditorComponent();
      requestFocus = false;
    }
  }

  if (requestFocus) {
    selectFile(virtualFile, true);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:32,代码来源:MvcProjectViewPane.java


示例14: doRefactoring

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private void doRefactoring(UsageInfo[] usages) throws IncorrectOperationException {
  myTypeParameterReplacements = buildTypeParameterReplacements();
  List<PsiClass> inheritors = new ArrayList<PsiClass>();

  CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);

  // Process usages
  for (final UsageInfo usage : usages) {
    if (usage instanceof MethodCallUsageInfo) {
      processMethodCall((MethodCallUsageInfo)usage);
    }
    else if (usage instanceof ParameterUsageInfo) {
      processParameterUsage((ParameterUsageInfo)usage);
    }
    else if (usage instanceof ImplementingClassUsageInfo) {
      inheritors.add(((ImplementingClassUsageInfo)usage).getPsiClass());
    }
  }

  prepareTypeParameterReplacement();
  myTargetParameter.delete();
  ChangeContextUtil.encodeContextInfo(myMethod, true);
  if (!myTargetClass.isInterface()) {
    PsiMethod method = addMethodToClass(myTargetClass);
    fixVisibility(method, usages);
    EditorHelper.openInEditor(method);
  }
  else {
    final PsiMethod interfaceMethod = addMethodToClass(myTargetClass);
    final PsiModifierList modifierList = interfaceMethod.getModifierList();
    modifierList.setModifierProperty(PsiModifier.PRIVATE, false);
    modifierList.setModifierProperty(PsiModifier.PUBLIC, false);
    modifierList.setModifierProperty(PsiModifier.PROTECTED, false);
    RefactoringUtil.makeMethodAbstract(myTargetClass, interfaceMethod);

    EditorHelper.openInEditor(interfaceMethod);

    for (final PsiClass psiClass : inheritors) {
      final PsiMethod newMethod = addMethodToClass(psiClass);
      PsiUtil.setModifierProperty(newMethod, myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
                                                                                                                                    : PsiModifier.PUBLIC, true);
    }
  }
  myMethod.delete();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:46,代码来源:ConvertToInstanceMethodProcessor.java


示例15: performRefactoring

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
protected void performRefactoring(@NotNull UsageInfo[] usages) {
  if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myTargetClass)) return;

  PsiMethod patternMethod = createMethodToAdd();
  final List<PsiReference> docRefs = new ArrayList<PsiReference>();
  for (UsageInfo usage : usages) {
    if (usage instanceof InheritorUsageInfo) {
      final PsiClass inheritor = ((InheritorUsageInfo)usage).getInheritor();
      addMethodToClass(inheritor, patternMethod, true);
    }
    else if (usage instanceof MethodCallUsageInfo && !((MethodCallUsageInfo)usage).isInternal()) {
      final PsiElement expression = ((MethodCallUsageInfo)usage).getMethodCallExpression();
      if (expression instanceof PsiMethodCallExpression) {
        correctMethodCall((PsiMethodCallExpression)expression, false);
      } else if (expression instanceof PsiMethodReferenceExpression) {
        PsiExpression newQualifier = JavaPsiFacade.getInstance(myProject).getElementFactory().createExpressionFromText(myTargetVariable.getType().getCanonicalText(), null);
        ((PsiMethodReferenceExpression)expression).setQualifierExpression(newQualifier);
      }
    }
    else if (usage instanceof JavadocUsageInfo) {
      docRefs.add(usage.getElement().getReference());
    }
  }

  try {
    if (myTargetClass.isInterface()) patternMethod.getBody().delete();

    final PsiMethod method = addMethodToClass(myTargetClass, patternMethod, false);
    myMethod.delete();
    for (PsiReference reference : docRefs) {
      reference.bindToElement(method);
    }
    VisibilityUtil.fixVisibility(UsageViewUtil.toElements(usages), method, myNewVisibility);

    if (myOpenInEditor) {
      EditorHelper.openInEditor(method);
    }
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:MoveInstanceMethodProcessor.java


示例16: copyClassesImpl

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel, 
                                    final boolean openInEditor) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            Collection<PsiFile> files = doCopyClasses(classes, map, copyClassName, target, project);
            if (files != null) {
              if (openInEditor) {
                for (PsiFile file : files) {
                  CopyHandler.updateSelectionInActiveProjectView(file, project, selectInActivePanel);
                }
                EditorHelper.openFilesInEditor(files.toArray(new PsiFile[files.size()]));
              }

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:CopyClassesHandler.java


示例17: actionPerformed

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);

  if (view == null || project == null) {
    return;
  }
  final PsiDirectory taskDir = DirectoryChooserUtil.getOrChooseDirectory(view);
  if (taskDir == null) return;
  PsiDirectory lessonDir = taskDir.getParent();
  if (lessonDir == null) {
    return;
  }
  final CCProjectService service = CCProjectService.getInstance(project);
  final Course course = service.getCourse();
  final Lesson lesson = course.getLesson(lessonDir.getName());
  final Task task = lesson.getTask(taskDir.getName());

  final int index = task.getTaskFiles().size() + 1;
  String generatedName = "file" + index;
  CreateTaskFileDialog dialog = new CreateTaskFileDialog(project, generatedName, course);
  dialog.show();
  if (dialog.getExitCode() != OK_EXIT_CODE) {
    return;
  }
  final String taskFileName = dialog.getFileName();
  if (taskFileName == null) return;
  FileType type = dialog.getFileType();
  if (type == null) {
    return;
  }
  final CCLanguageManager CCLanguageManager = CCUtils.getStudyLanguageManager(course);
  if (CCLanguageManager == null) {
    return;
  }
  final String extension = type.getDefaultExtension();
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final FileTemplate taskTemplate = CCLanguageManager.getTaskFileTemplateForExtension(project, extension);
      final String answerFileName = taskFileName + ".answer." + extension;
      try {
        if (taskTemplate == null) {
          VirtualFile file = taskDir.getVirtualFile().createChildData(this, answerFileName);
          ProjectView.getInstance(project).select(file, file, false);
          FileEditorManager.getInstance(project).openFile(file, true);
        }
        else {
          final PsiElement taskFile = FileTemplateUtil.createFromTemplate(taskTemplate, answerFileName, null, taskDir);
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              EditorHelper.openInEditor(taskFile, false);
              view.selectElement(taskFile);
            }
          });
        }
        task.addTaskFile(taskFileName + "." + extension, index);
      }
      catch (Exception ignored) {
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:66,代码来源:CCCreateTaskFile.java


示例18: copyClassesImpl

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel, 
                                    final boolean openInEditor) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project);
            if (newElement != null) {
              CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel);
              if (openInEditor) EditorHelper.openInEditor(newElement);

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:53,代码来源:CopyClassesHandler.java


示例19: copyImpl

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
/**
 * @param files
 * @param newName can be not null only if elements.length == 1
 * @param targetDirectory
 * @param openInEditor
 */
private static void copyImpl(@Nonnull final VirtualFile[] files,
                             @Nullable final String newName,
                             @Nonnull final PsiDirectory targetDirectory,
                             final boolean doClone,
                             final boolean openInEditor) {
  if (doClone && files.length != 1) {
    throw new IllegalArgumentException("invalid number of elements to clone:" + files.length);
  }

  if (newName != null && files.length != 1) {
    throw new IllegalArgumentException("no new name should be set; number of elements is: " + files.length);
  }

  final Project project = targetDirectory.getProject();
  if (!CommonRefactoringUtil.checkReadOnlyStatus(project, Collections.singleton(targetDirectory), false)) {
    return;
  }

  String title = RefactoringBundle.message(doClone ? "copy,handler.clone.files.directories" : "copy.handler.copy.files.directories");
  try {
    PsiFile firstFile = null;
    final int[] choice = files.length > 1 || files[0].isDirectory() ? new int[]{-1} : null;
    PsiManager manager = PsiManager.getInstance(project);
    for (VirtualFile file : files) {
      PsiElement psiElement = file.isDirectory() ? manager.findDirectory(file) : manager.findFile(file);
      if (psiElement == null) {
        LOG.info("invalid file: " + file.getExtension());
        continue;
      }
      PsiFile f = copyToDirectory((PsiFileSystemItem)psiElement, newName, targetDirectory, choice, title);
      if (firstFile == null) {
        firstFile = f;
      }
    }

    if (firstFile != null && openInEditor) {
      CopyHandler.updateSelectionInActiveProjectView(firstFile, project, doClone);
      if (!(firstFile instanceof PsiBinaryFile)) {
        EditorHelper.openInEditor(firstFile);
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    }
  }
  catch (final IncorrectOperationException | IOException ex) {
    Messages.showErrorDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"));
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:54,代码来源:CopyFilesOrDirectoriesHandler.java


示例20: copyClassesImpl

import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private static void copyClassesImpl(final String copyClassName,
                                    final Project project,
                                    final Map<PsiFile, PsiClass[]> classes,
                                    final HashMap<PsiFile, String> map,
                                    final Object targetDirectory,
                                    final PsiDirectory defaultTargetDirectory,
                                    final String commandName,
                                    final boolean selectInActivePanel) {
  final boolean[] result = new boolean[] {false};
  Runnable command = new Runnable() {
    public void run() {
      final Runnable action = new Runnable() {
        public void run() {
          try {
            PsiDirectory target;
            if (targetDirectory instanceof PsiDirectory) {
              target = (PsiDirectory)targetDirectory;
            } else {
              target = ((MoveDestination)targetDirectory).getTargetDirectory(defaultTargetDirectory);
            }
            PsiElement newElement = doCopyClasses(classes, map, copyClassName, target, project);
            if (newElement != null) {
              CopyHandler.updateSelectionInActiveProjectView(newElement, project, selectInActivePanel);
              EditorHelper.openInEditor(newElement);

              result[0] = true;
            }
          }
          catch (final IncorrectOperationException ex) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
              public void run() {
                Messages.showMessageDialog(project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
              }
            });
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  };
  CommandProcessor processor = CommandProcessor.getInstance();
  processor.executeCommand(project, command, commandName, null);

  if (result[0]) {
    ToolWindowManager.getInstance(project).invokeLater(new Runnable() {
      public void run() {
        ToolWindowManager.getInstance(project).activateEditorComponent();
      }
    });
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:52,代码来源:CopyClassesHandler.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Container类代码示例发布时间:2022-05-22
下一篇:
Java QuitEvent类代码示例发布时间: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