Skip to content

Commit

Permalink
issue-tracker-idea-plugin-12 Action > Add action to Open the IssueUrl…
Browse files Browse the repository at this point in the history
… in browser

- Added the action to open the browser. The action will honor Enable/Disable.
  • Loading branch information
thsaravana committed Oct 22, 2016
1 parent 7a61143 commit f19e792
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Plugin/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
description="Reloads the issues from the task repository"
icon="AllIcons.Actions.Refresh"
id="IssueTracker.RefreshIssueList" text="Refresh"/>
<action class="com.madrapps.issuetracker.actions.OpenIssueInBrowserAction"
description="Opens the issue in the respective repository in the browser"
icon="AllIcons.General.Web"
id="IssueTracker.OpenIssueInBrowser"
text="Open Issue in Browser"/>
</actions>
</idea-plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.madrapps.issuetracker.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.Task;
import com.madrapps.issuetracker.listissues.IListIssuesContract;
import com.madrapps.issuetracker.listissues.ListIssuesPresenter;

import org.jetbrains.annotations.Nullable;

/**
* This will open the IssueUrl of the issue on the Browser
* <p>
* Created by Henry on 10/22/2016.
*/
public class OpenIssueInBrowserAction extends AnAction {

public static final String ACTION_ID = "IssueTracker.OpenIssueInBrowser";

@Override
public void update(AnActionEvent e) {
final Presentation presentation = e.getPresentation();
final Task selectedIssue = getSelectedIssue(e);
presentation.setEnabled(selectedIssue != null);
}

@Override
public void actionPerformed(AnActionEvent e) {
final Task selectedIssue = getSelectedIssue(e);
if (selectedIssue != null) {
ListIssuesPresenter.getInstance().openUrl(selectedIssue);
}
}

/**
* Get the issue currently selected, or null if nothing is selected
*
* @param e the actionEvent to get the Project
* @return selected issue or null
*/
@Nullable
private Task getSelectedIssue(AnActionEvent e) {
final Project project = e.getProject();
if (project != null) {
final IListIssuesContract.IView view = ListIssuesPresenter.getInstance().setView(project);
return view.getSelectedIssue();
}
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.madrapps.issuetracker.listissues.IListIssuesContract.IPresenter;
import com.madrapps.issuetracker.listissues.ListIssuesPresenter;

/**
Expand All @@ -18,7 +19,7 @@ public class RefreshIssueListAction extends AnAction {
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project != null) {
final ListIssuesPresenter presenter = ListIssuesPresenter.getInstance();
final IPresenter presenter = ListIssuesPresenter.getInstance();
presenter.setView(project);
presenter.pullIssues(project, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ interface IView {
void showLoadingScreen(boolean shouldShow);

void showEmptyIssueListScreen();

void openInBrowser(@NotNull String issueUrl);

@Nullable
Task getSelectedIssue();
}

/**
Expand All @@ -55,8 +60,12 @@ interface IPresenter {

void loadInitialIssues(@NotNull Project project);

void setView(@NotNull Project project);
@NotNull
IView setView(@NotNull Project project);

@NotNull
IView setView(@NotNull IView view);

void setView(@NotNull IView view);
void openUrl(@NotNull Task selectedIssue);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.madrapps.issuetracker.listissues;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.ActionToolbar;
Expand All @@ -19,6 +20,7 @@
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import com.madrapps.issuetracker.actions.OpenIssueInBrowserAction;
import com.madrapps.issuetracker.actions.RefreshIssueListAction;

import org.commonmark.node.Node;
Expand Down Expand Up @@ -232,6 +234,17 @@ public void showEmptyIssueListScreen() {
mIssueSummaryTextPane.setText("");
}

@Override
public void openInBrowser(@NotNull String issueUrl) {
BrowserUtil.browse(issueUrl);
}

@Nullable
@Override
public Task getSelectedIssue() {
return mIssuesTable.getSelectedObject();
}

/**
* Get a neat readable format of the date if it's not null, or an empty string
*
Expand All @@ -249,9 +262,12 @@ private static String getValueOfDate(@Nullable Date date) {

private void initializeActions() {
final AnAction refreshAction = ActionManager.getInstance().getAction(RefreshIssueListAction.ACTION_ID);
final AnAction openIssueInBrowserAction = ActionManager.getInstance().getAction(OpenIssueInBrowserAction.ACTION_ID);


final DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(refreshAction);
actionGroup.add(openIssueInBrowserAction);

final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, actionGroup, false);
actionToolbar.setTargetComponent(mToolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void onSuccess() {
}

@Override
public void setView(@NotNull Project project) {
@NotNull
public IListIssuesContract.IView setView(@NotNull Project project) {
if (mView == null) {
final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(IssuesToolWindow.TOOL_WINDOW_ID);
final Content content = toolWindow.getContentManager().getContent(0);
Expand All @@ -126,11 +127,22 @@ public void setView(@NotNull Project project) {
}
}
}
return mView;
}

@Override
public void setView(@NotNull IListIssuesContract.IView view) {
@NotNull
public IListIssuesContract.IView setView(@NotNull IListIssuesContract.IView view) {
mView = view;
return mView;
}

@Override
public void openUrl(@NotNull Task selectedIssue) {
final String issueUrl = selectedIssue.getIssueUrl();
if (issueUrl != null) {
mView.openInBrowser(issueUrl);
}
}

public static ListIssuesPresenter getInstance() {
Expand Down

0 comments on commit f19e792

Please sign in to comment.