Delete action listener, capturing what's deleted

Hi,

I'm trying to change xml when file is deleted (I did it for Java files by using JavaSafeDeleteProcessor, but as expected it doesn't work with with directories or non-java files. I need to change xml when directory/css/js files are removed too (because i have information about them in my xml file). I made ApplicationComponent that add my ActionListener. With my ActionListener i can "capture" $Delete action when it's called with afterActionPerformed method but i don't know how to catch what file is deleted by it (i need to have directory or file name somehow).

I will appreciate any help or ideas how to access it.

public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event)
0

Hi John,

you may of cause watch VFS when files are deleted (`com.intellij.openapi.vfs.VirtualFileListener#fileDeleted`) but it looks incorrect to me. How is the xml and the deleted files connected together? How do you need to update the xml?

Anna

0
Avatar
Permanently deleted user

Thanks for reply

With one of the actions i generate directory with some js and css files in it and put them into my xml file:

<Directory name="xc">
<Resources>
<File description="" file="name.js" type="JS"/>
<File description="" file="name.css" type="CSS"/>
</Resources>
</Directory>

(I need it to use in other software later). If user remove directory i want to delete it in xml file. I managed to get what's deleted (all those directories are created in parent directory) by getting project and it's files before delete action and compare it to what's left there after delete action (and it works).

event.getProject().getBaseDir().findChild("parentdirectoryname").getChildren()

but the problem is i'm getting fatal error:

cannot share data context between Swing events; initial event count = 13272; current event count 

and I don't know how to remove it.

0

so files you remove are referenced in the xml? I would expect that safe delete would find them then, no?

You try to separate delete action into two parts and that could lead to e.g. undo problems (and thus it's asserted that you don't try to reuse old context). Let's try to find the solution to perform all modifications inside safe delete action.

0
Avatar
Permanently deleted user

Unfortunately I think safe delete isn't triggered when you remove directory (I don't even get option to safe delete with usage search when deleting directory, it even says that it could be not able to fully undo this operation). 

0

You may provide your own delegate to process directories?

0

请先登录再写评论。