public void actionPerformed(AnActionEvent event) {
    PluginConfig config = PluginConfig.getInstance(event.getProject());
    if (!config.JNIPath.isEmpty()) {
      JNI_PATH = config.JNIPath;
    }
    if (!config.GeneratedHeaderName.isEmpty()) {
      HEADER_NAME = config.GeneratedHeaderName;
    }
    if (!config.Prefix4Variable.isEmpty()) {
      PREFIX_CL = config.Prefix4Variable;
    }

    boolean isOK = false;
    String exceptionMessage = null;
    try {
      String projectPath = event.getProject().getBasePath();
      File clHeader = new File(projectPath + JNI_PATH + HEADER_NAME);
      if (!clHeader.exists()) {
        clHeader.createNewFile();
      }
      clHeaderWriter = new BufferedWriter(new FileWriter(clHeader));

      writeHeader();

      File jniDir = new File(projectPath + JNI_PATH);
      readDir(jniDir);

      writeFooter();
      clHeaderWriter.flush();

      isOK = true;
    } catch (Exception e) {
      e.printStackTrace();
      exceptionMessage = e.getMessage();
    } finally {
      if (clHeaderWriter != null) {
        try {
          clHeaderWriter.close();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
      }
      if (isOK) {
        Notifications.Bus.notify(
            new Notification(
                "OpenCLCLGenerator",
                "Success!",
                "Finish to generate OpenCL's CL files header.",
                NotificationType.INFORMATION));
      } else {
        Notifications.Bus.notify(
            new Notification(
                "OpenCLCLGenerator",
                "Failure!",
                "Fail to generate OpenCL's CL files header.\nError:" + exceptionMessage,
                NotificationType.INFORMATION));
      }
    }
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   if (e.getProject() == null) return;
   RESOLVEPluginController controller = RESOLVEPluginController.getInstance(e.getProject());
   controller.getVerifierWindow().show(null); // open the verifier window
   VerificationConditionSelectorPanel vcselector =
       controller.getVerifierPanel().getVcSelectorPanel();
   if (vcselector == null) return;
   vcselector.vcTabs.get(Integer.parseInt(vcNum));
   VerifierPanel verifierPanel = controller.getVerifierPanel();
   if (verifierPanel.getVcSelectorPanel() == null) return;
   VerificationConditionSelectorPanel selector = verifierPanel.getVcSelectorPanel();
   ConditionCollapsiblePanel details = selector.vcTabs.get(Integer.parseInt(vcNum));
   details.setExpanded(true);
 }
  @Override
  public void update(AnActionEvent e) {
    super.update(e);
    Presentation presentation = e.getPresentation();
    Project project = e.getProject();
    if (project == null) {
      presentation.setEnabled(false);
      presentation.setVisible(false);
      return;
    }

    VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (vFiles == null || vFiles.length != 1 || vFiles[0] == null) { // only 1 file for now
      presentation.setEnabled(false);
      presentation.setVisible(true);
      return;
    }

    GitRepositoryManager manager = GitUtil.getRepositoryManager(project);

    GitRepository repository = manager.getRepositoryForFile(vFiles[0]);
    if (repository == null || repository.isFresh() || noBranchesToCompare(repository)) {
      presentation.setEnabled(false);
      presentation.setVisible(true);
      return;
    }

    presentation.setEnabled(true);
    presentation.setVisible(true);
  }
  @NotNull
  @Override
  protected JBPopup createPopup(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) project = ProjectManager.getInstance().getDefaultProject();

    Ref<JBPopup> popup = new Ref<JBPopup>();
    ChangesBrowser cb = new MyChangesBrowser(project, getChanges(), getCurrentSelection(), popup);

    popup.set(
        JBPopupFactory.getInstance()
            .createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent())
            .setResizable(true)
            .setModalContext(false)
            .setFocusable(true)
            .setRequestFocus(true)
            .setCancelOnWindowDeactivation(true)
            .setCancelOnOtherWindowOpen(true)
            .setMovable(true)
            .setCancelKeyEnabled(true)
            .setCancelOnClickOutside(true)
            .setDimensionServiceKey(project, "Diff.GoToChangePopup", false)
            .createPopup());

    return popup.get();
  }
  @Override
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();

    Project project = e.getProject();
    if (project == null) {
      presentation.setEnabled(false);
      return;
    }

    final DataContext dataContext = e.getDataContext();
    Editor editor = getEditor(dataContext, project, true);
    if (editor == null) {
      presentation.setEnabled(false);
      return;
    }

    final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
      presentation.setEnabled(false);
      return;
    }

    update(presentation, project, editor, file, dataContext, e.getPlace());
  }
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    assert project != null;

    final PsiAnnotation annotation =
        KotlinSignatureUtil.findKotlinSignatureAnnotation(annotationOwner);
    assert annotation != null;

    if (annotation.getContainingFile() != annotationOwner.getContainingFile()) {
      // external annotation
      new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
          ExternalAnnotationsManager.getInstance(project)
              .deannotate(annotationOwner, KOTLIN_SIGNATURE.asString());
          ExternalAnnotationsManager.getInstance(project)
              .deannotate(annotationOwner, OLD_KOTLIN_SIGNATURE.asString());
        }
      }.execute();
    } else {
      new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
          annotation.delete();
        }
      }.execute();
    }

    KotlinSignatureUtil.refreshMarkers(project);
  }
Esempio n. 7
0
 @Override
 public void actionPerformed(AnActionEvent e) {
   Project project = e.getProject();
   if (project != null) {
     setZoom(project, Math.max(MIN_ZOOM, getZoom(project) - ZOOM_STEP));
   }
 }
  @Override
  public void update(final AnActionEvent event) {
    if (event.getProject() == null
        || event.getData(EditorGutter.KEY) != null
        || Boolean.TRUE.equals(event.getData(CommonDataKeys.EDITOR_VIRTUAL_SPACE))) {
      event.getPresentation().setEnabled(false);
      return;
    }

    for (GotoDeclarationHandler handler :
        Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
      try {
        String text = handler.getActionText(event.getDataContext());
        if (text != null) {
          Presentation presentation = event.getPresentation();
          presentation.setText(text);
          break;
        }
      } catch (AbstractMethodError e) {
        LOG.error(handler.toString(), e);
      }
    }

    super.update(event);
  }
 @Nullable
 private AnAction getAction(AnActionEvent e) {
   Project project = e.getProject();
   ProjectType projectType = ProjectTypeService.getProjectType(project);
   AnAction action = myActions.get(projectType);
   if (action == null) action = myActions.get(null);
   return action;
 }
 @Override
 public final void update(final AnActionEvent e) {
   final Presentation presentation = e.getPresentation();
   final Project project = e.getProject();
   if (project == null) return;
   presentation.setEnabled(isEnabled());
   presentation.setText(getCurrentScopeType());
 }
 @Override
 public void beforeActionPerformedUpdate(@NotNull AnActionEvent e) {
   Project project = e.getProject();
   if (project != null) {
     getEditor(e.getDataContext(), project, false); // ensure documents are committed
   }
   super.beforeActionPerformedUpdate(e);
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   Project project = e.getProject();
   if (project != null) {
     Editor editor = getEditor(e.getDataContext(), project, false);
     actionPerformedImpl(project, editor);
   }
 }
  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    assert project != null;

    Navigatable navigatable = e.getRequiredData(CommonDataKeys.NAVIGATABLE);
    openEditor(project, navigatable);
  }
 @Override
 public void setSelected(AnActionEvent e, boolean watch) {
   myWatchesReturnValues = watch;
   DebuggerSettings.getInstance().WATCH_RETURN_VALUES = watch;
   DebugProcessImpl process = getCurrentDebugProcess(e.getProject());
   if (process != null) {
     process.setWatchMethodReturnValuesEnabled(watch);
   }
 }
  @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 actionPerformed(AnActionEvent e) {
    final BaseRefactorHandler handler = initHandler(e.getProject(), e.getDataContext());

    boolean processChooser = handler.processChooser();

    if (processChooser) {
      final Editor editor = getEditor(e);

      CommandProcessor.getInstance()
          .executeCommand(
              e.getProject(),
              new Runnable() {
                @Override
                public void run() {
                  ApplicationManager.getApplication().runWriteAction(handler);
                }
              },
              getClass().getName() + "-Commandname",
              DocCommandGroupId.noneGroupId(editor.getDocument()));
    }
  }
Esempio n. 17
0
  public static boolean isInsideProjectSources(AnActionEvent event) {
    ProjectFileIndex projectFileIndex =
        ProjectRootManager.getInstance(event.getProject()).getFileIndex();
    final IdeView view = event.getData(DataKeys.IDE_VIEW);

    for (PsiDirectory dir : view.getDirectories()) {
      if (projectFileIndex.isInSourceContent(dir.getVirtualFile())
          && JavaDirectoryService.getInstance().getPackage(dir) != null) {
        return true;
      }
    }
    return false;
  }
 public static void updateAction(AnActionEvent e) {
   Presentation presentation = e.getPresentation();
   presentation.setEnabled(false);
   Project project = e.getProject();
   if (project != null) {
     FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors();
     for (FileEditor editor : editors) {
       if (editor instanceof StudyEditor) {
         presentation.setEnabled(true);
       }
     }
   }
 }
 @Override
 public void update(@NotNull final AnActionEvent e) {
   super.update(e);
   final Presentation presentation = e.getPresentation();
   DebugProcessImpl process = getCurrentDebugProcess(e.getProject());
   if (process == null || process.canGetMethodReturnValue()) {
     presentation.setEnabled(true);
     presentation.setText(myText);
   } else {
     presentation.setEnabled(false);
     presentation.setText(myTextUnavailable);
   }
 }
 @Override
 protected boolean isEnabled(@NotNull AnActionEvent event) {
   final Collection<Change> changes =
       ChangeListManager.getInstance(event.getProject()).getAllChanges();
   if (changes.size() > 1000) {
     return true;
   }
   for (Change change : changes) {
     if (change.getFileStatus() == FileStatus.MERGED_WITH_CONFLICTS) {
       return true;
     }
   }
   return false;
 }
Esempio n. 21
0
    @Override
    public void actionPerformed(AnActionEvent e) {
      final DataContext dataContext = e.getDataContext();
      Project project = e.getProject();
      FavoritesTreeNodeDescriptor[] roots =
          FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
      String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);

      String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
      if (newName != null) {
        new SendToFavoritesAction(newName)
            .doSend(FavoritesManager.getInstance(project), roots, listName);
      }
    }
Esempio n. 22
0
  @Override
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
      return;
    }
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) {
      return;
    }
    final Document document = editor.getDocument();
    if (document == null) {
      return;
    }
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    if (virtualFile == null) {
      return;
    }

    VirtualFile parent = virtualFile.getParent();
    if (parent == null) {
      return;
    }

    VirtualFile buckFile = parent.findChild(BuckFileUtil.getBuildFileName());
    while (buckFile == null && parent != null) {
      parent = parent.getParent();
      buckFile = parent.findChild(BuckFileUtil.getBuildFileName());
    }

    final VirtualFile file = buckFile;
    if (file != null) {
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  // This is for better cursor position.
                  OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
                  Navigatable n = descriptor.setUseCurrentWindow(false);
                  if (!n.canNavigate()) {
                    return;
                  }
                  n.navigate(true);
                }
              },
              ModalityState.NON_MODAL);
    }
  }
 @Override
 public void update(@NotNull AnActionEvent e) {
   Presentation presentation = e.getPresentation();
   Project project = e.getProject();
   presentation.setEnabledAndVisible(project != null && CCUtils.isCourseCreator(project));
   if (project != null) {
     final Course course = StudyTaskManager.getInstance(project).getCourse();
     if (course != null) {
       final int id = course.getId();
       if (id > 0) {
         presentation.setText("Update Course on Stepik");
       }
     }
   }
 }
 @Nullable
 private static AnswerPlaceholder getAnswerPlaceholder(AnActionEvent e) {
   final Project project = e.getProject();
   if (project == null) {
     return null;
   }
   StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
   final StudyState studyState = new StudyState(studyEditor);
   if (studyEditor == null || !studyState.isValid()) {
     return null;
   }
   final Editor editor = studyState.getEditor();
   final TaskFile taskFile = studyState.getTaskFile();
   return taskFile.getAnswerPlaceholder(editor.getCaretModel().getOffset());
 }
  @Override
  public void actionPerformed(@NotNull AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
      return;
    }

    final Set<VirtualFile> conflictedFiles =
        new TreeSet<VirtualFile>(
            new Comparator<VirtualFile>() {
              @Override
              public int compare(@NotNull VirtualFile f1, @NotNull VirtualFile f2) {
                return f1.getPresentableUrl().compareTo(f2.getPresentableUrl());
              }
            });
    for (Change change : ChangeListManager.getInstance(project).getAllChanges()) {
      if (change.getFileStatus() != FileStatus.MERGED_WITH_CONFLICTS) {
        continue;
      }
      final ContentRevision before = change.getBeforeRevision();
      final ContentRevision after = change.getAfterRevision();
      if (before != null) {
        final VirtualFile file = before.getFile().getVirtualFile();
        if (file != null) {
          conflictedFiles.add(file);
        }
      }
      if (after != null) {
        final VirtualFile file = after.getFile().getVirtualFile();
        if (file != null) {
          conflictedFiles.add(file);
        }
      }
    }

    AbstractVcsHelper.getInstance(project)
        .showMergeDialog(
            new ArrayList<VirtualFile>(conflictedFiles),
            GitVcs.getInstance(project).getMergeProvider());
    for (VirtualFile conflictedFile : conflictedFiles) {
      final GitRepository repo =
          GitRepositoryManager.getInstance(project).getRepositoryForFile(conflictedFile);
      if (repo != null) {
        repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
      }
    }
  }
  @Override
  public void update(AnActionEvent e) {
    Presentation presentation = e.getPresentation();

    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace())
        || ActionPlaces.COMMANDER_POPUP.equals(e.getPlace())) {
      presentation.setText(IdeBundle.message("action.delete.ellipsis"));
    } else {
      presentation.setText(IdeBundle.message("action.delete"));
    }

    if (e.getProject() == null) {
      presentation.setEnabled(false);
      return;
    }

    DataContext dataContext = e.getDataContext();
    DeleteProvider provider = getDeleteProvider(dataContext);
    if (e.getInputEvent() instanceof KeyEvent) {
      KeyEvent keyEvent = (KeyEvent) e.getInputEvent();
      Object component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
      if (component instanceof JTextComponent) provider = null; // Do not override text deletion
      if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        // Do not override text deletion in speed search
        if (component instanceof JComponent) {
          SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent) component);
          if (searchSupply != null) provider = null;
        }

        String activeSpeedSearchFilter =
            SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext);
        if (!StringUtil.isEmpty(activeSpeedSearchFilter)) {
          provider = null;
        }
      }
    }
    if (provider instanceof TitledHandler) {
      presentation.setText(((TitledHandler) provider).getActionTitle());
    }
    boolean canDelete = provider != null && provider.canDeleteElement(dataContext);
    if (ActionPlaces.isPopupPlace(e.getPlace())) {
      presentation.setVisible(canDelete);
    } else {
      presentation.setEnabled(canDelete);
    }
  }
  public void actionPerformed(AnActionEvent e) {
    String url = "https://floobits.com/";
    FloobitsPlugin floobitsPlugin = FloobitsPlugin.getInstance(e.getProject());
    if (floobitsPlugin == null) {
      return;
    }
    FlooContext context = floobitsPlugin.context;
    FlooUrl floourl = DotFloo.read(context.project.getBasePath());
    if (floourl != null) {
      url = floourl.toString();
    }
    String inputValue = JOptionPane.showInputDialog("Workspace URL", url);
    if (inputValue == null) {
      return;
    }

    FloobitsApplication.self.joinWorkspace(context, inputValue);
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   Project project = e.getProject();
   if (project == null) {
     return;
   }
   for (StudyActionListener listener : Extensions.getExtensions(StudyActionListener.EP_NAME)) {
     listener.beforeCheck(e);
   }
   final AnswerPlaceholder answerPlaceholder = getAnswerPlaceholder(e);
   if (answerPlaceholder == null) {
     return;
   }
   StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
   final StudyState studyState = new StudyState(studyEditor);
   if (answerPlaceholder.getTaskFile().getTask().hasSubtasks()) {
     StudySubtaskUtils.refreshPlaceholder(studyState.getEditor(), answerPlaceholder);
     return;
   }
   Document patternDocument =
       StudyUtils.getPatternDocument(
           answerPlaceholder.getTaskFile(), studyState.getVirtualFile().getName());
   if (patternDocument == null) {
     return;
   }
   AnswerPlaceholder.MyInitialState initialState = answerPlaceholder.getInitialState();
   int startOffset = initialState.getOffset();
   final String text =
       patternDocument.getText(new TextRange(startOffset, startOffset + initialState.getLength()));
   CommandProcessor.getInstance()
       .executeCommand(
           project,
           () ->
               ApplicationManager.getApplication()
                   .runWriteAction(
                       () -> {
                         Document document = studyState.getEditor().getDocument();
                         int offset = answerPlaceholder.getOffset();
                         document.deleteString(offset, offset + answerPlaceholder.getRealLength());
                         document.insertString(offset, text);
                       }),
           NAME,
           null);
 }
  private boolean isActive(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
      return false;
    }

    TestFrameworkRunningModel model = getModel();
    if (model == null || model.getRoot() == null) {
      return false;
    }
    Filter filter = getFailuresFilter();
    for (AbstractTestProxy test : model.getRoot().getAllTests()) {
      //noinspection unchecked
      if (filter.shouldAccept(test)) {
        return true;
      }
    }
    return false;
  }
 @Override
 public void update(@NotNull AnActionEvent event) {
   final Project project = event.getProject();
   final Presentation presentation = event.getPresentation();
   if (project == null) {
     return;
   }
   presentation.setEnabledAndVisible(false);
   if (!CCUtils.isCourseCreator(project)) {
     return;
   }
   final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
   if (view == null) {
     return;
   }
   final PsiDirectory[] directories = view.getDirectories();
   if (directories.length == 0) {
     return;
   }
   presentation.setEnabledAndVisible(true);
 }