Is it possible to get the current directory in CreateFromTemplateActionReplacer?
已回答
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

请先登录再写评论。
Hi,
Try overriding the
AnAction.update()method to get the folder withe.getData(CommonDataKeys.VIRTUAL_FILE)and update event’s presentation based on your requirements.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
Hi,
I checked the
VIRTUAL_FILEdata 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.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
Hi,
I checked the
VIRTUAL_FILEonly 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 theSELECTED_ITEMSkey if it works.