Intention actions in text files: can we?

Hi,

Is there a way to have intentions available in plain text files?
I can only make them work in java classes.

Alain

7 comments

Well
public boolean isAvailable(Project project, Editor editor, PsiFile file) {

file.getVirtualFile() and you have file
with Editor you can determine position

Then next code

public class PropertiesShowIntentionAction extends AnAction {
// -


FIELDS -



private AnAction wrappedAction;

// -


CONSTRUCTORS -



public PropertiesShowIntentionAction() {
this.wrappedAction = ActionManager.getInstance().getAction("ShowIntentionActions");
}

// -


OTHER METHODS -



public void actionPerformed(AnActionEvent e) {
ActionManager.getInstance().getAction("ShowIntentionActions").actionPerformed(e);
}

public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
DataContext datacontext = e.getDataContext();
Project project = (Project) datacontext.getData("project");
if (project != null) {
Editor editor = (Editor) datacontext.getData("editor");
if (editor != null) {
PropertiesFileEditorItem propertiesFileEditor = (PropertiesFileEditorItem) editor.getUserData(
PropertiesFileEditor.PROPERTIES_FILE_EDITOR_KEY);
if (propertiesFileEditor != null) {
presentation.setEnabled(true);
return;
}
}
}
presentation.setEnabled(false);
}
}

and
]]>

And Intentions working in property files.

TIA,
Dmitry

0

Dmitry

>...

>
Thanks.

It looks a lot like the code I'm using, except that I'm implementing an
IntentionAction, and not extending AnAction.

Here is the simplest complete piece of code that's failing me (ie. the
bulb pops up in java files, but not in text files):

public class CreateWikiFileAction
implements IntentionAction
{
public String getText () { return
"CreateWikiFileAction.getText()"; }
public String getFamilyName () { return
"CreateWikiFileAction.getFamilyName"; }

public boolean isAvailable (Project i_project, Editor i_editor,
PsiFile i_psiFile) {
return true;
}


public void invoke (Project i_project, Editor i_editor, PsiFile
i_psiFile)
throws IncorrectOperationException {
}

public boolean startInWriteAction () { return true; }
}


and, in plugin.xml:
com.ravet.ideaplugins.miniWiki.IntentionsInstaller ]]>
, that calls:

public final class IntentionsInstaller
implements ProjectComponent
{

public IntentionsInstaller (final Project project) {
__myProject = project;
}

public final void projectOpened ()
{
IntentionManager mgr = IntentionManager.getInstance (__myProject);
mgr.addAction (new CreateWikiFileAction () );

}
public final void projectClosed () { }
public final String getComponentName () { return "MiniWiki pack"; }

public final void initComponent () { }
public final void disposeComponent () { }

private final Project __myProject;
}

No bulb showing here.
I'm in the dark.

Any idea.

Alain

0

Hi Alain

Actually focus in wrapping standard Intention action as descibed in previous post, not just implementing intention action and it wasn't here.
So you have second part Intention, now you must add support to show intention in your files and it may be achieved using code extending AnAction and adding action in plugin.xml.

I'm not sure that it only way to do it but it works fine for me.

TIA,
Dmitry

0

Dmitry,

Are we talking about the same thing?
- In your example, you link to an action.
- I want a bulb to appear spontaneously, based on the caret surroundings.

I already have a working action, that intercepts , and performs
a custom action in text files.

I don't see how to merge your code sample with my example.


Alain

0

Hi Alain,

We talking about same thing I'm think :)

Problem:
Intentions not available in text files.

Solution:
Add similiar action to invoke bulb in required files. PropertiesShowIntentionAction class demonstrates how it works in PE. It wraps standard action and added to Idea in plugin.xml by
]]>

TIA,
Dmitry

0

Alain,

the code Dmitry posted enables the manual triggering of the popup menu for
Intention Actions by pressing Alt-Enter. It does however not automatically
make the light bulb appear where an intention's isAvailable() returns true.

So yes, you can make intentions for non-java files, but you have to invoke
them manually by pressing Alt-Enter and selecting the appropriate one.
Automatically notifying the user of an intention's availability (the light bulb)
is currently impossible I think.

Sascha

Alain Ravet wrote:

Dmitry,

Are we talking about the same thing?
- In your example, you link to an action.
- I want a bulb to appear spontaneously, based on the caret surroundings.

I already have a working action, that intercepts , and performs
a custom action in text files.

I don't see how to merge your code sample with my example.


Alain

0

Hi,

Bulbs available too.
When show intention action enabled then isAvailable called and bulb displayed. Of ource if I rememember correctly :) I'll check one more time.

TIA,
Dmitry

0

Please sign in to leave a comment.