Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Commit

Permalink
v 1.0.2
Browse files Browse the repository at this point in the history
notifications support

dumb bugfixes
  • Loading branch information
bsideup committed Oct 27, 2013
1 parent a7390f9 commit 72a6905
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
4 changes: 2 additions & 2 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>ru.trylogic.idea.gitlab.integration</id>
<name>GitLab integration</name>
<version>1.0.1</version>
<version>1.0.2</version>
<vendor email="bsideup@gmail.com" url="https://github.com/bsideup">Sergei BSiDeUp Egorov</vendor>

<description><![CDATA[
Expand All @@ -10,7 +10,7 @@
]]></description>

<change-notes><![CDATA[
Bug fix for IDEA 13 EAP. Tested on 132.719.
Bug fix for IDEA 13 EAP. Tested on 132.719. Error notifications support.
]]>
</change-notes>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ru.trylogic.idea.gitlab.integration.actions;

import com.intellij.ide.BrowserUtil;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.DumbAwareAction;
Expand All @@ -14,6 +17,7 @@
import git4idea.GitLocalBranch;
import git4idea.GitRemoteBranch;
import git4idea.GitUtil;
import git4idea.Notificator;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
Expand All @@ -22,10 +26,17 @@
import org.jetbrains.annotations.Nullable;
import ru.trylogic.idea.gitlab.integration.utils.GitlabUrlUtil;

import java.util.ArrayList;
import java.util.List;

public class GitLabOpenInBrowserAction extends DumbAwareAction {

public static final Logger LOG = Logger.getInstance("gitlab");

public static final String CANNOT_OPEN_IN_BROWSER = "Cannot open in browser";

private static final String GITLAB_NOTIFICATION_GROUP = "gitlab";

protected GitLabOpenInBrowserAction() {
super("Open on GitLab", "Open corresponding link in browser", GitlabIcons.Gitlab_icon);
}
Expand All @@ -35,16 +46,17 @@ static void setVisibleEnabled(AnActionEvent e, boolean visible, boolean enabled)
e.getPresentation().setEnabled(enabled);
}

static void showError(Project project, String cannotOpenInBrowser) {
showError(project, cannotOpenInBrowser, null);
static void showError(Project project, String title, String message) {
showError(project, title, message, null);
}

static void showError(Project project, String cannotOpenInBrowser, String s) {
showError(project, cannotOpenInBrowser, s, null);
}

static void showError(Project project, String cannotOpenInBrowser, String s, String s1) {
System.out.println(cannotOpenInBrowser + ";" + s + ";" + s1);
static void showError(Project project, String title, String message, String debugInfo) {
LOG.warn(title + "; " + message);
if (debugInfo != null) {
LOG.warn(debugInfo);
}
Notification notification = new Notification(GITLAB_NOTIFICATION_GROUP, title, message, NotificationType.ERROR);
Notificator.getInstance(project).notify(notification);
}

@Nullable
Expand Down Expand Up @@ -143,27 +155,32 @@ public void actionPerformed(final AnActionEvent e) {
return;
}

if (repository.getRemotes().size() == 0) {
showError(project, CANNOT_OPEN_IN_BROWSER, "Can't find gitlab remote");
return;
}

final String rootPath = repository.getRoot().getPath();
final String path = virtualFile.getPath();
DefaultActionGroup remotesActionGroup = new DefaultActionGroup();
remotesActionGroup.add(new RemoteSelectedAction(project, repository, editor, repository.getRemotes().iterator().next(), rootPath, path));

List<AnAction> remoteSelectedActions = new ArrayList<AnAction>();

DataContext dataContext = e.getDataContext();
final ListPopup popup =
JBPopupFactory.getInstance().createActionGroupPopup(
"Select remote",
remotesActionGroup,
dataContext,
JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
true);
for (GitRemote remote : repository.getRemotes()) {
remoteSelectedActions.add(new RemoteSelectedAction(project, repository, editor, remote, rootPath, path));
}

popup.showInBestPositionFor(dataContext);
if (remoteSelectedActions.size() > 1) {
DefaultActionGroup remotesActionGroup = new DefaultActionGroup();
remotesActionGroup.addAll(remoteSelectedActions);
DataContext dataContext = e.getDataContext();
final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
"Select remote",
remotesActionGroup,
dataContext,
JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
true);

popup.showInBestPositionFor(dataContext);
} else if (remoteSelectedActions.size() == 1) {
remoteSelectedActions.get(0).actionPerformed(null);
} else {
showError(project, CANNOT_OPEN_IN_BROWSER, "Can't find gitlab remote");
}
}


Expand Down Expand Up @@ -202,7 +219,7 @@ public void update(AnActionEvent e) {
}

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
public void actionPerformed(@Nullable AnActionEvent unused) {
if (!path.startsWith(rootPath)) {
GitLabOpenInBrowserAction.showError(project, GitLabOpenInBrowserAction.CANNOT_OPEN_IN_BROWSER,
"File is not under repository root", "Root: " + rootPath + ", file: " + path);
Expand All @@ -213,7 +230,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
if (branch == null) {
return;
}

String remoteUrl = remote.getFirstUrl();

if (remoteUrl == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public static String findRemoteUrl(@NotNull GitRepository repository) {
public static String makeRepoUrlFromRemoteUrl(@NotNull String remoteUrl) {
String cleanedFromDotGit = StringUtil.trimEnd(remoteUrl, ".git");

System.out.println(cleanedFromDotGit);

if (remoteUrl.startsWith("http://")) {
return cleanedFromDotGit;
} else if (remoteUrl.startsWith("git@")) {
Expand Down

0 comments on commit 72a6905

Please sign in to comment.