public void actionPerformed(final AnActionEvent e) {
   final PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
   final Project project = e.getData(CommonDataKeys.PROJECT);
   final Editor editor = e.getData(LangDataKeys.EDITOR);
   if (psiFile != null && project != null && editor != null) {
     ApplicationManager.getApplication()
         .runWriteAction(
             new Runnable() {
               public void run() {
                 CommandProcessor.getInstance()
                     .executeCommand(
                         project,
                         new Runnable() {
                           public void run() {
                             try {
                               intention.invoke(project, editor, psiFile);
                             } catch (IncorrectOperationException ex) {
                               LOGGER.error(ex);
                             }
                           }
                         },
                         e.getPresentation().getText(),
                         e.getActionManager().getId(SpellCheckerIntentionAction.this));
               }
             });
   }
 }
  @NotNull
  private static AnAction[] findActions(@NotNull AnActionEvent e) {
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
    Project project = e.getData(CommonDataKeys.PROJECT);
    Editor editor = e.getData(LangDataKeys.EDITOR);
    if (psiFile != null && project != null && editor != null) {
      List<HighlightInfo.IntentionActionDescriptor> quickFixes =
          ShowIntentionsPass.getAvailableActions(editor, psiFile, -1);
      Map<Anchor, List<AnAction>> children = new HashMap<Anchor, List<AnAction>>();
      ArrayList<AnAction> first = new ArrayList<AnAction>();
      children.put(Anchor.FIRST, first);
      ArrayList<AnAction> last = new ArrayList<AnAction>();
      children.put(Anchor.LAST, last);
      extractActions(quickFixes, children);
      if (first.size() > 0 && last.size() > 0) {
        first.add(new AnSeparator());
      }
      first.addAll(last);
      if (first.size() > 0) {
        return first.toArray(new AnAction[first.size()]);
      }
    }

    return AnAction.EMPTY_ARRAY;
  }
  public void update(AnActionEvent e) {
    super.update(e);

    final Project project = e.getData(DataKeys.PROJECT);
    final VirtualFile file = e.getData(DataKeys.VIRTUAL_FILE);

    boolean visible =
        project != null
            && file != null
            && !file.isDirectory()
            && file.getFileType() == CppSupportLoader.CPP_FILETYPE
            && !Communicator.isHeaderFile(file);
    boolean enabled = visible;

    if (!visible) {
      visible = ActionPlaces.MAIN_MENU.equals(e.getPlace());
    }

    e.getPresentation().setEnabled(enabled);
    e.getPresentation().setVisible(visible);

    if (visible) {
      final String s =
          "Do c&ompile for " + (file != null ? file.getName() : "selected c/c++ fileToCompile");
      e.getPresentation().setText(s);
      e.getPresentation().setDescription(s);
    }
  }
  // get gitRepository
  // check for existing git repo
  // check available repos and privateRepo access (net)
  // Show dialog (window)
  // create GitHub repo (net)
  // create local git repo (if not exist)
  // add GitHub as a remote host
  // make first commit
  // push everything (net)
  @Override
  public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);

    if (project == null || project.isDisposed() || !GithubUtil.testGitExecutable(project)) {
      return;
    }

    shareProjectOnGithub(project, file);
  }
  @Nullable
  public static I18nQuickFixHandler getHandler(final AnActionEvent e) {
    final Editor editor = getEditor(e);
    if (editor == null) return null;

    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    if (psiFile == null) return null;

    TextRange range = JavaI18nUtil.getSelectedRange(editor, psiFile);
    if (range == null) return null;

    final PsiLiteralExpression literalExpression = getEnclosingStringLiteral(psiFile, editor);
    PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (element == null) return null;
    if (I18nizeConcatenationQuickFix.getEnclosingLiteralConcatenation(element) != null) {
      return new I18nizeConcatenationQuickFix();
    } else if (literalExpression != null && literalExpression.getTextRange().contains(range)) {
      return new I18nizeQuickFix();
    }

    for (I18nizeHandlerProvider handlerProvider : I18nizeHandlerProvider.EP_NAME.getExtensions()) {
      I18nQuickFixHandler handler = handlerProvider.getHandler(psiFile, editor, range);
      if (handler != null) {
        return handler;
      }
    }

    return null;
  }
Exemple #6
0
  public final void update(final AnActionEvent e) {
    super.update(e);

    ActionPlace place = e.getData(MPSDataKeys.PLACE);

    if (e.getInputEvent() instanceof KeyEvent) {
      if (!getPlaces().contains(null)) {
        if (!getPlaces().contains(place)) {
          disable(e.getPresentation());
          return;
        }
      }
    }

    // TODO rewrite! do not start read action in EDT directly (to avoid UI freeze)
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                if (myDisableOnNoProject && e.getData(PlatformDataKeys.PROJECT) == null) {
                  disable(e.getPresentation());
                  return;
                }
                THashMap<String, Object> params = new THashMap<String, Object>();
                if (!collectActionData(e, params)) {
                  disable(e.getPresentation());
                  return;
                }
                doUpdate(e, params);
              }
            });
  }
 @Override
 public void update(AnActionEvent event) {
   final Presentation presentation = event.getPresentation();
   final Project project = event.getData(CommonDataKeys.PROJECT);
   presentation.setEnabled(project != null);
   presentation.setVisible(
       ActionPlaces.isMainMenuOrActionSearch(event.getPlace()) && !PlatformUtils.isCidr());
 }
 public void update(AnActionEvent e) {
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (project == null || project.isDefault()) {
     setVisibleEnabled(e, false, false);
     return;
   }
   setVisibleEnabled(e, true, true);
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;

    new ChooseRunConfigurationPopup(
            project, getAdKey(), getDefaultExecutor(), getAlternativeExecutor())
        .show();
  }
  @Override
  public void update(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    final Change[] changes = e.getData(getChangesKey());

    final Presentation presentation = e.getPresentation();
    presentation.setVisible(VcsDataKeys.CHANGES.getData(dataContext) != null);
    presentation.setEnabled(enabled(project, changes));
  }
    public void setSelected(AnActionEvent e, boolean state) {
      T change = ObjectUtils.tryCast(e.getData(VcsDataKeys.CURRENT_CHANGE), myClass);
      if (change == null) return;

      if (state) {
        myViewer.includeChange(change);
      } else {
        myViewer.excludeChange(change);
      }
    }
 @Override
 public void actionPerformed(final AnActionEvent e) {
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (project != null) {
     RunnerAndConfigurationSettings settings = chooseTempSettings(project);
     if (settings != null) {
       final RunManager runManager = RunManager.getInstance(project);
       runManager.makeStable(settings);
     }
   }
 }
Exemple #13
0
  public void actionPerformed(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    Icon i = getQuestionIcon();

    //Prompt the user for their choice of dimension filters (only one-at-a-time atm)
    String dimension = showInputDialog(project, "What dimesion would you like to filter by?", "Dimension name",i);
    String value = showInputDialog(project, "What choice would you like to make in dimension " + dimension + "?", "Chocie", i);

    //Grab the file and store it's current state before making any modifications
    //TODO: this will have to account for if a partial selection has already been made on the file
    VirtualFile f = event.getData(DataKeys.VIRTUAL_FILE);
    String name = f.getName();


    //Perform the modification to the file, store it's new state, and display to the user
    Choice c = new Choice(dimension, value);

    //TODO: rather than passing in names, pass in some representation of the original file and the modified file
    FileVariation fv = new FileVariation(name, name, c);
    variedFiles.add(fv);
  }
 public void actionPerformed(final AnActionEvent e) {
   LogModel model = myConsole.myProjectModel;
   for (Notification notification : model.getNotifications()) {
     notification.expire();
     model.removeNotification(notification);
   }
   model.setStatusMessage(null, 0);
   final Editor editor = e.getData(CommonDataKeys.EDITOR);
   if (editor != null) {
     editor.getDocument().deleteString(0, editor.getDocument().getTextLength());
   }
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) return;

    Runnable searchEverywhere = mySearchEverywhereRunnable;
    mySearchEverywhereRunnable = null;
    hideHints();

    if (searchEverywhere != null) {
      searchEverywhere.run();
      return;
    }

    final RelativePoint popupPosition =
        JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.usages");

    UsageTarget[] usageTargets = e.getData(UsageView.USAGE_TARGETS_KEY);
    final Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (usageTargets == null) {
      chooseAmbiguousTargetAndPerform(
          project,
          editor,
          new PsiElementProcessor<PsiElement>() {
            @Override
            public boolean execute(@NotNull final PsiElement element) {
              startFindUsages(element, popupPosition, editor, USAGES_PAGE_SIZE);
              return false;
            }
          });
    } else {
      PsiElement element = ((PsiElementUsageTarget) usageTargets[0]).getElement();
      if (element != null) {
        startFindUsages(element, popupPosition, editor, USAGES_PAGE_SIZE);
      }
    }
  }
  public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    final Change[] changes = e.getData(getChangesKey());

    if (!enabled(project, changes)) {
      return;
    }

    final Change change = changes[0];

    final CalculateAndShow worker =
        new CalculateAndShow(project, change, e.getPresentation().getText());
    ProgressManager.getInstance().run(worker);
  }
 @Override
 public void update(final AnActionEvent e) {
   final Presentation presentation = e.getPresentation();
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (project == null) {
     disable(presentation);
     return;
   }
   RunnerAndConfigurationSettings settings = chooseTempSettings(project);
   if (settings == null) {
     disable(presentation);
   } else {
     presentation.setText(
         ExecutionBundle.message(
             "save.temporary.run.configuration.action.name", settings.getName()));
     presentation.setDescription(presentation.getText());
     presentation.setVisible(true);
     presentation.setEnabled(true);
   }
 }
  @Override
  public void update(AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getData(CommonDataKeys.PROJECT);

    presentation.setEnabled(true);
    if (project == null || project.isDisposed()) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    if (null == getDefaultExecutor()) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    presentation.setEnabled(true);
    presentation.setVisible(true);
  }
 @Override
 public void update(AnActionEvent e) {
   Presentation presentation = e.getPresentation();
   Project project = e.getData(CommonDataKeys.PROJECT);
   if (ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) {
     presentation.setDescription(
         ExecutionBundle.message("choose.run.configuration.action.description"));
   }
   try {
     if (project == null || project.isDisposed() || !project.isInitialized()) {
       updatePresentation(null, null, null, presentation);
       presentation.setEnabled(false);
     } else {
       updatePresentation(
           ExecutionTargetManager.getActiveTarget(project),
           RunManagerEx.getInstanceEx(project).getSelectedConfiguration(),
           project,
           presentation);
       presentation.setEnabled(true);
     }
   } catch (IndexNotReadyException e1) {
     presentation.setEnabled(false);
   }
 }
 public void actionPerformed(AnActionEvent anActionEvent) {
   invoke(
       anActionEvent.getData(DataKeys.PROJECT),
       anActionEvent.getData(DataKeys.VIRTUAL_FILE),
       null);
 }
    public boolean isSelected(AnActionEvent e) {
      T change = ObjectUtils.tryCast(e.getData(VcsDataKeys.CURRENT_CHANGE), myClass);
      if (change == null) return false;

      return myViewer.isIncluded(change);
    }
 @Override
 public final void update(AnActionEvent e) {
   SearchSession search = e.getData(SearchSession.KEY);
   e.getPresentation().setEnabled(search != null && search.hasMatches());
 }
 @NotNull
 public static Notification get(@NotNull AnActionEvent e) {
   //noinspection ConstantConditions
   return e.getData(KEY);
 }
 public void actionPerformed(AnActionEvent e) {
   Change change = e.getData(VcsDataKeys.CURRENT_CHANGE);
   askAndMove(myProject, Collections.singletonList(change), null);
 }
 @Override
 protected boolean isEnabled(AnActionEvent e) {
   Change change = e.getData(VcsDataKeys.CURRENT_CHANGE);
   if (change == null) return false;
   return super.isEnabled(e);
 }
  @Override
  public void actionPerformed(AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);

    LOG.assertTrue(project != null);

    final FileChooserDescriptor descriptor =
        new FileChooserDescriptor(false, true, false, false, false, false) {
          @Override
          public Icon getIcon(VirtualFile file) {
            if (file.isDirectory()) {
              if (file.findChild(
                      InspectionApplication.DESCRIPTIONS
                          + "."
                          + StdFileTypes.XML.getDefaultExtension())
                  != null) {
                return AllIcons.Nodes.InspectionResults;
              }
            }
            return super.getIcon(file);
          }
        };
    descriptor.setTitle("Select Path");
    descriptor.setDescription("Select directory which contains exported inspections results");
    final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
    if (virtualFile == null || !virtualFile.isDirectory()) return;

    final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<>();
    final String[] profileName = new String[1];
    final Runnable process =
        () -> {
          final VirtualFile[] files = virtualFile.getChildren();
          try {
            for (final VirtualFile inspectionFile : files) {
              if (inspectionFile.isDirectory()) continue;
              final String shortName = inspectionFile.getNameWithoutExtension();
              final String extension = inspectionFile.getExtension();
              if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
                profileName[0] =
                    ApplicationManager.getApplication()
                        .runReadAction(
                            (Computable<String>)
                                () ->
                                    OfflineViewParseUtil.parseProfileName(
                                        LoadTextUtil.loadText(inspectionFile).toString()));
              } else if (XML_EXTENSION.equals(extension)) {
                resMap.put(
                    shortName,
                    ApplicationManager.getApplication()
                        .runReadAction(
                            new Computable<Map<String, Set<OfflineProblemDescriptor>>>() {
                              @Override
                              public Map<String, Set<OfflineProblemDescriptor>> compute() {
                                return OfflineViewParseUtil.parse(
                                    LoadTextUtil.loadText(inspectionFile).toString());
                              }
                            }));
              }
            }
          } catch (final Exception e) { // all parse exceptions
            SwingUtilities.invokeLater(
                () ->
                    Messages.showInfoMessage(
                        e.getMessage(),
                        InspectionsBundle.message("offline.view.parse.exception.title")));
            throw new ProcessCanceledException(); // cancel process
          }
        };
    ProgressManager.getInstance()
        .runProcessWithProgressAsynchronously(
            project,
            InspectionsBundle.message("parsing.inspections.dump.progress.title"),
            process,
            () ->
                SwingUtilities.invokeLater(
                    () -> {
                      final String name = profileName[0];
                      showOfflineView(
                          project,
                          name,
                          resMap,
                          InspectionsBundle.message("offline.view.title")
                              + " ("
                              + (name != null
                                  ? name
                                  : InspectionsBundle.message("offline.view.editor.settings.title"))
                              + ")");
                    }),
            null,
            new PerformAnalysisInBackgroundOption(project));
  }
 @Override
 public void update(AnActionEvent e) {
   Editor editor = e.getData(CommonDataKeys.EDITOR);
   e.getPresentation().setEnabled(editor != null && editor.getDocument().getTextLength() > 0);
 }
Exemple #28
0
 @Nullable
 public static XDebuggerTree getTree(final AnActionEvent e) {
   return e.getData(XDEBUGGER_TREE_KEY);
 }
  @Override
  public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) {
      LOGGER.error("actionPerformed (genVCs): no project for " + e);
      return;
    }
    VirtualFile resolveFile = getRESOLVEFileFromEvent(e);
    LOGGER.info("prove actionPerformed " + (resolveFile == null ? "NONE" : resolveFile));
    if (resolveFile == null) return;
    String title = "RESOLVE Prove";
    boolean canBeCancelled = true;

    commitDoc(project, resolveFile);
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) return;

    RunRESOLVEOnLanguageFile gen = new RunRESOLVEOnLanguageFile(resolveFile, project, title);

    MyProverListener pl = new MyProverListener();
    VCOutputFile vco = generateVCs(resolveFile, editor, project);
    // give each action an instance of the prover listener and make Update() print the result as it
    // comes back produce
    if (vco == null) return;

    RESOLVEPluginController controller = RESOLVEPluginController.getInstance(project);
    VerifierPanel verifierPanel = controller.getVerifierPanel();
    verifierPanel.createVerifierView2(
        vco.getFinalVCs(), pl); // TODO: maybe make this take in a list of VCs

    addVCGutterIcons(vco, editor, project, pl);
    controller.getVerifierWindow().show(null);

    // runProver
    List<String> args = new ArrayList<>();
    args.add(resolveFile.getPath());
    args.add("-lib");
    args.add(RunRESOLVEOnLanguageFile.getContentRoot(project, resolveFile).getPath());
    args.add("-prove");
    RESOLVECompiler compiler = new RESOLVECompiler(args.toArray(new String[args.size()]));
    compiler.addProverListener(pl);

    // TODO: Instead of this being anon, make a separate static class and add an error listener to
    // 'compiler' that (make it accessible
    // right here though so the UI part below can stop and update remaining (unproved) vcs if the
    // compiler does indeed suffer some
    // catastrophic failure: npe, etc.
    Task.Backgroundable proverTask =
        new Task.Backgroundable(project, "Proving") {
          @Override
          public void run(@NotNull final ProgressIndicator progressIndicator) {
            compiler.processCommandLineTargets();
          }
        };
    ProgressManager.getInstance().run(proverTask);

    // TODO: Different status icons for different proof results.
    running = true;
    Task.Backgroundable task =
        new Task.Backgroundable(project, "Updating Presentation") {

          @Override
          public void run(@NotNull final ProgressIndicator progressIndicator) {
            Map<String, Boolean> processed = new HashMap<>();
            for (VC vc : vco.getFinalVCs()) {
              processed.put(vc.getName(), false);
            }
            while (pl.vcIsProved.size() != vco.getFinalVCs().size()) {
              // if (proverTask.getNotificationInfo().)//TODO: Put something here that breaks out of
              // this if the compiler crashes..
              for (VC vc : vco.getFinalVCs()) {
                if (pl.vcIsProved.containsKey(vc.getName()) && !processed.get(vc.getName())) {
                  processed.put(vc.getName(), true);
                  long dur = pl.vcMetrics.get(vc.getName()).getProofDuration();
                  ConditionCollapsiblePanel section =
                      verifierPanel.vcSelectorPanel.vcTabs.get(vc.getNumber());
                  section.changeToFinalState(
                      pl.vcIsProved.get(vc.getName())
                          ? ConditionCollapsiblePanel.State.PROVED
                          : ConditionCollapsiblePanel.State.NOT_PROVED,
                      dur);
                }
              }
            }
            running = false;
          }
        };
    ProgressManager.getInstance().run(task);
  }