Skip to content

Commit 648af46

Browse files
committed
Re-enabled "Create GraphQL Endpoint file" action based on whether Endpoint Language has been configured (#164)
1 parent 4ba8dba commit 648af46

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

resources/META-INF/plugin.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,9 @@
333333
<add-to-group group-id="NewGroup" />
334334
</action>
335335

336-
<!-- TODO JKM: Needs integration with references service
337336
<action id="com.intellij.lang.jsgraphql.endpoint.ide.actions.JSGraphQLEndpointNewFileAction" class="com.intellij.lang.jsgraphql.endpoint.ide.actions.JSGraphQLEndpointNewFileAction">
338337
<add-to-group group-id="NewGroup"/>
339338
</action>
340-
-->
341339

342340
<action class="com.intellij.lang.jsgraphql.v1.ide.actions.JSGraphQLExecuteEditorAction" id="com.intellij.lang.jsgraphql.v1.ide.actions.JSGraphQLExecuteEditorAction">
343341
<keyboard-shortcut first-keystroke="control ENTER" keymap="$default"/>

src/main/com/intellij/lang/jsgraphql/endpoint/ide/actions/JSGraphQLEndpointNewFileAction.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2015-present, Jim Kynde Meyer
33
* All rights reserved.
44
*
@@ -10,11 +10,13 @@
1010
import com.intellij.ide.actions.CreateFileFromTemplateAction;
1111
import com.intellij.ide.actions.CreateFileFromTemplateDialog;
1212
import com.intellij.lang.jsgraphql.icons.JSGraphQLIcons;
13+
import com.intellij.lang.jsgraphql.ide.project.graphqlconfig.GraphQLConfigManager;
14+
import com.intellij.lang.jsgraphql.ide.project.graphqlconfig.model.GraphQLConfigData;
15+
import com.intellij.openapi.actionSystem.CommonDataKeys;
1316
import com.intellij.openapi.actionSystem.DataContext;
14-
import com.intellij.openapi.actionSystem.LangDataKeys;
15-
import com.intellij.openapi.module.Module;
1617
import com.intellij.openapi.project.DumbAware;
1718
import com.intellij.openapi.project.Project;
19+
import com.intellij.openapi.vfs.VirtualFile;
1820
import com.intellij.psi.PsiDirectory;
1921

2022
public class JSGraphQLEndpointNewFileAction extends CreateFileFromTemplateAction implements DumbAware {
@@ -28,8 +30,22 @@ protected boolean isAvailable(DataContext dataContext) {
2830
if (!super.isAvailable(dataContext)) {
2931
return false;
3032
}
31-
final Module module = LangDataKeys.MODULE.getData(dataContext);
32-
return module != null;
33+
34+
final Project myProject = CommonDataKeys.PROJECT.getData(dataContext);
35+
if (myProject != null) {
36+
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
37+
if (virtualFile != null) {
38+
final GraphQLConfigManager configManager = GraphQLConfigManager.getService(myProject);
39+
final VirtualFile configFile = configManager.getClosestConfigFile(virtualFile);
40+
if (configFile != null) {
41+
final GraphQLConfigData configData = configManager.getConfigurationsByPath().get(configFile.getParent());
42+
if (configData != null && configData.extensions != null) {
43+
return configData.extensions.get(GraphQLConfigManager.ENDPOINT_LANGUAGE_EXTENSION) != null;
44+
}
45+
}
46+
}
47+
}
48+
return false;
3349
}
3450

3551
@Override

0 commit comments

Comments
 (0)