IDEA-96242 github: "Open On Github" from VCS history panel

This commit is contained in:
Aleksey Pivovarov
2016-04-18 14:08:43 +03:00
parent af40ac7d84
commit 6597584aec
2 changed files with 57 additions and 0 deletions
+3
View File
@@ -51,6 +51,9 @@
<add-to-group group-id="Git.LogContextMenu" />
<add-to-group group-id="Vcs.Log.ContextMenu" />
</action>
<action id="Github.Open.History.Commit.In.Browser" class="org.jetbrains.plugins.github.GithubShowCommitInBrowserFromHistoryAction">
<add-to-group group-id="VcsHistoryActionsGroup"/>
</action>
<action id="Github.Create.Gist" class="org.jetbrains.plugins.github.GithubCreateGistAction">
<add-to-group group-id="EditorPopupMenu"/>
<add-to-group group-id="ProjectViewPopupMenu"/>
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.github;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import git4idea.GitFileRevision;
import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.github.util.GithubUtil;
public class GithubShowCommitInBrowserFromHistoryAction extends GithubShowCommitInBrowserAction {
@Override
public void update(@NotNull AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
if (project == null || filePath == null || fileRevision == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
boolean isOnGithub = repository != null && GithubUtil.isRepositoryOnGitHub(repository);
e.getPresentation().setEnabledAndVisible(isOnGithub && fileRevision instanceof GitFileRevision);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
VcsFileRevision fileRevision = e.getRequiredData(VcsDataKeys.VCS_FILE_REVISION);
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
openInBrowser(project, repository, ((GitRevisionNumber)fileRevision.getRevisionNumber()).getRev());
}
}