public void update()

in plugin/src/com/microsoft/alm/plugin/idea/common/actions/OpenFileInBrowserAction.java [49:111]


    public void update(@NotNull final AnActionEvent anActionEvent) {
        final Presentation presentation = anActionEvent.getPresentation();
        final Project project = anActionEvent.getProject();
        if (project == null || project.isDisposed()) {
            presentation.setEnabledAndVisible(false);
            return;
        }

        final VirtualFile[] vFiles = anActionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (vFiles == null || vFiles.length == 0 || vFiles[0] == null) {
            // quick exit if no valid file selected
            presentation.setEnabledAndVisible(false);
            return;
        } else if (vFiles.length > 1) {
            // only supporting one file for now, so disable the action
            presentation.setEnabled(false);

            // however we do want to leave a breadcrumb if any of the files selected individually are valid
            final GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
            for (VirtualFile vFile : vFiles) {
                final GitRepository repository = manager.getRepositoryForFileQuick(vFile);
                if (repository != null && TfGitHelper.isTfGitRepository(repository)) {
                    // show the action if any of the files are TF
                    presentation.setVisible(true);
                    return;
                }
            }

            // no valid selection, hide the action.
            presentation.setVisible(false);
            return;
        }

        final VirtualFile vFile = vFiles[0];

        final GitRepositoryManager manager = GitUtil.getRepositoryManager(project);

        try {
            final GitRepository repository = manager.getRepositoryForFileQuick(vFile);

            if (repository == null || !TfGitHelper.isTfGitRepository(repository)) {
                presentation.setEnabledAndVisible(false);
                return;
            }
        } catch (InvalidVirtualFileAccessException e) {
            logger.warn("Exception caught while trying to find file's repo", e);
            return;
        }

        final ChangeListManager changeListManager = ChangeListManager.getInstance(project);

        // ignored via .gitignore
        if (changeListManager.isIgnoredFile(vFile)) {
            presentation.setEnabledAndVisible(false);
            return;
        }

        // OK show the action
        presentation.setVisible(true);

        // Now check if should be enabled
        presentation.setEnabled(isEnabled(changeListManager, project, vFile));
    }