diff --git a/.run/Run Plugin.run.xml b/.run/Run Plugin.run.xml new file mode 100644 index 0000000..ce1940e --- /dev/null +++ b/.run/Run Plugin.run.xml @@ -0,0 +1,24 @@ + + + + + + + true + true + false + false + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0ef5f25..b676da7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ + + plugins { id 'java' id 'org.jetbrains.intellij' version '0.4.1' @@ -8,8 +10,12 @@ version '0.4.4' sourceCompatibility = 1.8 +repositories { + mavenCentral() +} + dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile group: 'junit', name: 'junit', version: '4.13.2' } intellij { diff --git a/src/main/java/gitextensions/commands/BaseAction.java b/src/main/java/gitextensions/commands/BaseAction.java index dc3bcc8..c533d24 100644 --- a/src/main/java/gitextensions/commands/BaseAction.java +++ b/src/main/java/gitextensions/commands/BaseAction.java @@ -3,8 +3,10 @@ import com.google.common.base.Strings; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataConstants; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; import gitextensions.GitExtensionsService; @@ -29,8 +31,7 @@ public BaseAction(@NotNull String command) { @Override public void actionPerformed(@NotNull AnActionEvent e) { try { - VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE); - String fileName = getFileName(file); + String fileName = getFileNameFromEvent(e); if (fileName != null) { GitExtensionsService service = ApplicationManager.getApplication().getService(GitExtensionsService.class); @@ -57,6 +58,12 @@ public void actionPerformed(@NotNull AnActionEvent e) { } } + @Nullable + protected String getFileNameFromEvent(@NotNull AnActionEvent e) { + VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE); + return getFileName(file); + } + protected String getFileName(@Nullable VirtualFile file) { return file != null ? file.getCanonicalPath() : null; } diff --git a/src/main/java/gitextensions/commands/Browse.java b/src/main/java/gitextensions/commands/Browse.java index fbf41dd..67216d0 100644 --- a/src/main/java/gitextensions/commands/Browse.java +++ b/src/main/java/gitextensions/commands/Browse.java @@ -1,7 +1,26 @@ package gitextensions.commands; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + public class Browse extends BaseAction { public Browse() { super(Commands.BROWSE); } + + @Nullable + @Override + protected String getFileNameFromEvent(@NotNull AnActionEvent e) { + String result = super.getFileNameFromEvent(e); + if (result == null) { + Project project = e.getData(PlatformDataKeys.PROJECT); + if (project != null) { + result = project.getBasePath(); + } + } + return result; + } }