From d83c4e8189bd3eb013380541226184a5efea1795 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 19 Aug 2013 21:47:04 +0400 Subject: [PATCH] Github: update action quietly --- .../github/GithubOpenInBrowserAction.java | 35 +++++++++++-------- .../GithubWebBrowserUrlProvider.java | 5 ++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java index 5729c98b598b..a531db6853c1 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubOpenInBrowserAction.java @@ -97,14 +97,14 @@ public class GithubOpenInBrowserAction extends DumbAwareAction { return; } - String urlToOpen = getGithubUrl(project, virtualFile, editor); + String urlToOpen = getGithubUrl(project, virtualFile, editor, false); if (urlToOpen != null) { BrowserUtil.launchBrowser(urlToOpen); } } @Nullable - public static String getGithubUrl(@NotNull Project project, @NotNull VirtualFile virtualFile, @Nullable Editor editor) { + public static String getGithubUrl(@NotNull Project project, @NotNull VirtualFile virtualFile, @Nullable Editor editor, boolean quiet) { GitRepositoryManager manager = GitUtil.getRepositoryManager(project); final GitRepository repository = manager.getRepositoryForFile(virtualFile); @@ -113,25 +113,24 @@ public class GithubOpenInBrowserAction extends DumbAwareAction { for (GitRepository repo : manager.getRepositories()) { details.append(repo.getPresentableUrl()).append("; "); } - GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, "Can't find git repository", details.toString()); + showError(project, "Can't find git repository", details.toString(), quiet); return null; } final String githubRemoteUrl = GithubUtil.findGithubRemoteUrl(repository); if (githubRemoteUrl == null) { - GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, "Can't find github remote"); + showError(project, "Can't find github remote", null, quiet); return null; } final String rootPath = repository.getRoot().getPath(); final String path = virtualFile.getPath(); if (!path.startsWith(rootPath)) { - GithubNotifications - .showError(project, CANNOT_OPEN_IN_BROWSER, "File is not under repository root", "Root: " + rootPath + ", file: " + path); + showError(project, "File is not under repository root", "Root: " + rootPath + ", file: " + path, quiet); return null; } - String branch = getBranchNameOnRemote(project, repository); + String branch = getBranchNameOnRemote(project, repository, quiet); if (branch == null) { return null; } @@ -139,7 +138,7 @@ public class GithubOpenInBrowserAction extends DumbAwareAction { String relativePath = path.substring(rootPath.length()); String urlToOpen = makeUrlToOpen(editor, relativePath, branch, githubRemoteUrl); if (urlToOpen == null) { - GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, "Can't create properly url", githubRemoteUrl); + showError(project, "Can't create properly url", githubRemoteUrl, quiet); return null; } @@ -174,23 +173,31 @@ public class GithubOpenInBrowserAction extends DumbAwareAction { } @Nullable - public static String getBranchNameOnRemote(@NotNull Project project, @NotNull GitRepository repository) { + public static String getBranchNameOnRemote(@NotNull Project project, @NotNull GitRepository repository, boolean quiet) { GitLocalBranch currentBranch = repository.getCurrentBranch(); if (currentBranch == null) { - GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, - "Can't open the file on GitHub when repository is on detached HEAD. Please checkout a branch."); + showError(project, "Can't open the file on GitHub when repository is on detached HEAD. Please checkout a branch.", null, quiet); return null; } GitRemoteBranch tracked = currentBranch.findTrackedBranch(repository); if (tracked == null) { - GithubNotifications - .showError(project, CANNOT_OPEN_IN_BROWSER, "Can't open the file on GitHub when current branch doesn't have a tracked branch.", - "Current branch: " + currentBranch + ", tracked info: " + repository.getBranchTrackInfos()); + showError(project, "Can't open the file on GitHub when current branch doesn't have a tracked branch.", + "Current branch: " + currentBranch + ", tracked info: " + repository.getBranchTrackInfos(), quiet); return null; } return tracked.getNameForRemoteOperations(); } + private static void showError(@NotNull Project project, @NotNull String message, @Nullable String details, boolean quiet) { + if (!quiet) { + if (details == null) { + GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, message); + } + else { + GithubNotifications.showError(project, CANNOT_OPEN_IN_BROWSER, message, details); + } + } + } } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubWebBrowserUrlProvider.java b/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubWebBrowserUrlProvider.java index 3ae08d0563fd..bd3b42e3a3ea 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubWebBrowserUrlProvider.java +++ b/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubWebBrowserUrlProvider.java @@ -32,7 +32,10 @@ public class GithubWebBrowserUrlProvider extends WebBrowserUrlProvider { @Nullable @Override public Url getUrl(@NotNull PsiElement element, @NotNull PsiFile psiFile, @NotNull VirtualFile virtualFile) throws BrowserException { - String url = GithubOpenInBrowserAction.getGithubUrl(element.getProject(), virtualFile, null); + String url = GithubOpenInBrowserAction.getGithubUrl(element.getProject(), virtualFile, null, true); + if (url == null) { + return null; + } return new UrlImpl(url, "https", null, null, null); }