Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Fix/browse without current file #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .run/Run Plugin.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Plugin" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runIde" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.1'
Expand All @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/gitextensions/commands/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/gitextensions/commands/Browse.java
Original file line number Diff line number Diff line change
@@ -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;
}
}