-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from parrt/dont-rely-on-current-file
Dont rely on current file
- Loading branch information
Showing
9 changed files
with
146 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/java/org/antlr/intellij/plugin/actions/MyActionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.antlr.intellij.plugin.actions; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
|
||
public class MyActionUtils { | ||
public static void selectedFileIsGrammar(AnActionEvent e) { | ||
VirtualFile vfile = getGrammarFileFromEvent(e); | ||
if ( vfile==null ) return; | ||
e.getPresentation().setEnabled(true); // enable action if we're looking at grammar file | ||
e.getPresentation().setVisible(true); | ||
} | ||
|
||
public static VirtualFile getGrammarFileFromEvent(AnActionEvent e) { | ||
VirtualFile[] files = LangDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext()); | ||
if ( files==null || files.length==0 ) return null; | ||
VirtualFile vfile = files[0]; | ||
if ( vfile!=null && vfile.getName().endsWith(".g4") ) { | ||
return vfile; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.