select files from project

Hi,
In my plugin project, from executeWriteAction(Editor editor, DataContext dataContext) , iam calling following  filechooser code.

ApplicationManager.getApplication().invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                 files[0] =    FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), createSnippetData.getProject(), createSnippetData.getProject().getBaseDir());
                            }
                        }, ModalityState.current());




The dialog comes up, but no files are shown.


Can anyone please help. How can i list the files from project.

5 comments
Comment actions Permalink

The reason why the files are not shown is described here: https://devnet.jetbrains.com/message/5547698#5547698

invokeLater() does not help because you are using ModalityState.current(). This means that the invocation is processed while the dialog is displayed, and while the write action is still being held.

As I said in the linked thread, you can list the files from project if you call executeWriteAction() after you have selected the files from FileChooser, and not before that.

0
Comment actions Permalink

Hi,
I have gone through this link. For my plugin the flow is such that it has to go through executeWriteAction(), is there any work around for this.

0
Comment actions Permalink

Sorry, but I don't believe you that it has to be that way. We've run into this situation a number of times during IntelliJ IDEA development, and it's always possible to restructure the code in such a way that the file chooser is invoked outside of write action.

If I had access to the code of your plugin, I could show you exactly how this can be done in your situation.

0
Comment actions Permalink

Hi,
I refactored the code, Now my flow is like this

EditorActionHandler----open dialog---open file chooser--EditorWriteActionHandler.

Now iam getting the files in the popup, but iam getting this error

Assertion failed: Write access is allowed inside write-action only, The new file has the expected contents. Whta do i need to do.


Thanks

0
Comment actions Permalink

Getting this error from where?


0

Please sign in to leave a comment.