Is it possible to get the current directory in CreateFromTemplateActionReplacer?

Answered

Hi,

I'm using the createFromTemplateActionReplacer extension, but I need to get the current dir to modify the displayed template names based on that. Is it possible?

Here's my code

I also tried the extension "defaultTemplatePropertiesProvider" but it executes after the template selection, not when the popup is displayed

Thank you

0
5 comments

Hi,

Try overriding the AnAction.update() method to get the folder with e.getData(CommonDataKeys.VIRTUAL_FILE) and update event’s presentation based on your requirements.

0

Thank you very much Karol

I made it work using the update method

https://cln.sh/HJqDWLFh

e.getData(CommonDataKeys.VIRTUAL_FILE) gave me null so I used e.getData(DataKey.create<Any>("selectedItems")) instead

Here's the code in case someone finds it helpful

Thank you

 

0

Hi,

I checked the VIRTUAL_FILE data before posting my answer, and it was available (not null). It’s unclear why it doesn’t work in your context.

Anyway, the “selectedItems” data key also looks good, but I suggest using the constant: com.intellij.openapi.actionSystem.PlatformCoreDataKeys#SELECTED_ITEMS.

0

Thank you for your support, I appreciate it

I recorded a short video to show when it's not reliable

https://cln.sh/p46XK7H3

It's a bit strange as it only works the first time, then it will send a null

I did another test with mouse right click instead of cmd + n and it was reliable

So it's only unreliable when using cmd + n (as far as I noticed)

Maybe this could help solve the issue

Thank you

0

Hi,

I checked the VIRTUAL_FILE only once. That’s why I thought it was working fine. To be honest, I don’t know the reason why it is available only for the first time, and I suggest sticking to the SELECTED_ITEMS key if it works.

1

Please sign in to leave a comment.