コード例 #1
0
  @Nullable
  public Object getData(String dataId) {

    if (CommonDataKeys.PROJECT.is(dataId)) {
      return editor != null ? editor.getProject() : null;
    } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
      return editor != null ? editor.getFile() : null;
    } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
      return editor != null ? new VirtualFile[] {editor.getFile()} : new VirtualFile[] {};
    } else if (CommonDataKeys.PSI_FILE.is(dataId)) {
      return getData(CommonDataKeys.PSI_ELEMENT.getName());
    } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
      VirtualFile file = editor != null ? editor.getFile() : null;
      return file != null && file.isValid()
          ? PsiManager.getInstance(editor.getProject()).findFile(file)
          : null;
    } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
      return editor != null
          ? new PsiElement[] {(PsiElement) getData(CommonDataKeys.PSI_ELEMENT.getName())}
          : new PsiElement[] {};
    } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) {
      return this;
    } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) {
      return copyPasteSupport.getCutProvider();
    } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
      return deleteProvider;
    } else if (ImageComponentDecorator.DATA_KEY.is(dataId)) {
      return editor != null ? editor : this;
    }

    return null;
  }
コード例 #2
0
 @Override
 public void update(AnActionEvent e) {
   final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
   final boolean isPng = isPngFile(file);
   e.getPresentation().setEnabled(isPng);
   e.getPresentation().setVisible(isPng);
 }
コード例 #3
0
    public BookmarkInContextInfo invoke() {
      myBookmarkAtPlace = null;
      myFile = null;
      myLine = -1;

      BookmarkManager bookmarkManager = BookmarkManager.getInstance(myProject);
      if (ToolWindowManager.getInstance(myProject).isEditorComponentActive()) {
        Editor editor = CommonDataKeys.EDITOR.getData(myDataContext);
        if (editor != null) {
          Document document = editor.getDocument();
          myLine = editor.getCaretModel().getLogicalPosition().line;
          myFile = FileDocumentManager.getInstance().getFile(document);
          myBookmarkAtPlace = bookmarkManager.findEditorBookmark(document, myLine);
        }
      }

      if (myFile == null) {
        myFile = CommonDataKeys.VIRTUAL_FILE.getData(myDataContext);
        myLine = -1;

        if (myBookmarkAtPlace == null && myFile != null) {
          myBookmarkAtPlace = bookmarkManager.findFileBookmark(myFile);
        }
      }
      return this;
    }
 @Override
 public void update(AnActionEvent e) {
   final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
   final boolean enabled = isAcceptableFile(file);
   e.getPresentation().setEnabled(enabled);
   if (ActionPlaces.isPopupPlace(e.getPlace())) {
     e.getPresentation().setVisible(enabled);
   }
 }
コード例 #5
0
  /** @return selected editor or <code>null</code> */
  @Nullable
  private static VirtualFile getFile(final DataContext context) {
    Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
      return null;
    }

    return CommonDataKeys.VIRTUAL_FILE.getData(context);
  }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());

    final GenerateSchemaFromInstanceDocumentDialog dialog =
        new GenerateSchemaFromInstanceDocumentDialog(project, file);
    dialog.setOkAction(() -> doAction(project, dialog));

    dialog.show();
  }
 public void update(AnActionEvent e) {
   Module module = LangDataKeys.MODULE.getData(e.getDataContext());
   if (module == null) {
     e.getPresentation().setEnabledAndVisible(false);
   } else {
     VirtualFile selectedFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
     e.getPresentation()
         .setEnabledAndVisible(
             PluginUtil.isModuleRoot(selectedFile, module)
                     && AzureModuleType.AZURE_MODULE.equals(
                         module.getOptionValue(Module.ELEMENT_TYPE))
                 || PluginUtil.isRoleFolder(selectedFile, module) /* ||
                   ModuleTypeId.JAVA_MODULE.equals(module.getOptionValue(Module.ELEMENT_TYPE))*/);
   }
 }
コード例 #8
0
 @NotNull
 private DataContext getContext() {
   Editor editor = getEditor();
   DataContext parent = DataManager.getInstance().getDataContext((Component) myStatusBar);
   return SimpleDataContext.getSimpleContext(
       CommonDataKeys.VIRTUAL_FILE.getName(),
       getSelectedFile(),
       SimpleDataContext.getSimpleContext(
           CommonDataKeys.PROJECT.getName(),
           getProject(),
           SimpleDataContext.getSimpleContext(
               PlatformDataKeys.CONTEXT_COMPONENT.getName(),
               editor == null ? null : editor.getComponent(),
               parent)));
 }
コード例 #9
0
  public static void setDirectoryName(@NotNull FindModel model, @NotNull DataContext dataContext) {
    PsiElement psiElement = null;
    Project project = CommonDataKeys.PROJECT.getData(dataContext);

    if (project != null && !DumbServiceImpl.getInstance(project).isDumb()) {
      try {
        psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
      } catch (IndexNotReadyException ignore) {
      }
    }

    String directoryName = null;

    if (psiElement instanceof PsiDirectory) {
      directoryName = ((PsiDirectory) psiElement).getVirtualFile().getPresentableUrl();
    }

    if (directoryName == null && psiElement instanceof PsiDirectoryContainer) {
      final PsiDirectory[] directories = ((PsiDirectoryContainer) psiElement).getDirectories();
      directoryName =
          directories.length == 1 ? directories[0].getVirtualFile().getPresentableUrl() : null;
    }

    Module module = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    if (module != null) {
      model.setModuleName(module.getName());
    }

    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (model.getModuleName() == null || editor == null) {
      model.setDirectoryName(directoryName);
      model.setProjectScope(
          directoryName == null && module == null && !model.isCustomScope() || editor != null);
      if (directoryName != null) {
        model.setCustomScope(false); // to select "Directory: " radio button
      }

      // for convenience set directory name to directory of current file, note that we doesn't
      // change default projectScope
      if (directoryName == null) {
        VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
        if (virtualFile != null && !virtualFile.isDirectory())
          virtualFile = virtualFile.getParent();
        if (virtualFile != null) model.setDirectoryName(virtualFile.getPresentableUrl());
      }
    }
  }
 @Override
 public boolean isAvailableOnDataContext(DataContext dataContext) {
   final Project project = CommonDataKeys.PROJECT.getData(dataContext);
   if (project == null) {
     return false;
   }
   final ResourceBundle bundle = ResourceBundleUtil.getResourceBundleFromDataContext(dataContext);
   if (bundle == null) {
     return false;
   }
   final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
   if (fileEditor == null || !(fileEditor instanceof ResourceBundleEditor)) {
     return false;
   }
   final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
   return !(virtualFile == null || !(virtualFile instanceof ResourceBundleAsVirtualFile));
 }
コード例 #11
0
  @Override
  public void actionPerformed(AnActionEvent e) {
    final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (!isPngFile(pngFile)) {
      return;
    }

    FileSaverDescriptor descriptor =
        new FileSaverDescriptor(
            AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog =
        FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);
    VirtualFileWrapper fileWrapper =
        saveFileDialog.save(
            pngFile.getParent(), pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG));
    if (fileWrapper == null) {
      return;
    }

    final File patchFile = fileWrapper.getFile();
    new Task.Modal(null, "Creating 9-Patch File", false) {
      private IOException myException;

      @Override
      public void run(@NotNull ProgressIndicator indicator) {
        indicator.setIndeterminate(true);
        try {
          BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile));
          BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1);
          ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile);
          LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile);
        } catch (IOException e) {
          myException = e;
        }
      }

      @Override
      public void onSuccess() {
        if (myException != null) {
          Messages.showErrorDialog(
              AndroidBundle.message("android.9patch.creator.error", myException.getMessage()),
              AndroidBundle.message("android.9patch.creator.error.title"));
        }
      }
    }.queue();
  }
コード例 #12
0
  @Nullable
  private static VirtualFile findPomXml(@NotNull DataContext dataContext) {
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    if (file == null) return null;

    if (file.isDirectory()) {
      file = file.findChild("pom.xml");
      if (file == null) return null;
    }

    MavenProjectsManager manager = MavenActionUtil.getProjectsManager(dataContext);
    if (manager == null) return null;
    MavenProject mavenProject = manager.findProject(file);
    if (mavenProject == null) return null;

    return file;
  }
コード例 #13
0
 @Override
 public String expand(final DataContext dataContext) {
   final Project project = CommonDataKeys.PROJECT.getData(dataContext);
   if (project == null) {
     return null;
   }
   VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
   if (file == null) {
     return null;
   }
   final VirtualFile sourceRoot =
       ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(file);
   if (sourceRoot == null) {
     return null;
   }
   return getPath(sourceRoot);
 }
コード例 #14
0
 @Nullable
 private static VirtualFile getSelectedFile(DataContext context) {
   return CommonDataKeys.VIRTUAL_FILE.getData(context);
 }
コード例 #15
0
 @Override
 public String expand(DataContext dataContext) {
   VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
   if (file == null) return null;
   return getPath(file);
 }