Correct time to use VirtualFile.refresh(true, xx)?

I'm trying to implement a dialog very similar to the "Updating modified
files" dialog which shows up when IDEA detects some files changed. Here,
the "synchronize on frame activation" is far too slow (with 9000 files
in the project tree), and it doesn't show progress or anything, so we
turn it off. I'm writing a plugin which interfaces with some tools we
use, to only refresh files which we know were changed.

However, I'm having a problem. The dialog often doesn't show up, and the
IDE simply locks and says "Synchronizing files..." in the status bar.

The code looks like this:

() {
           public VirtualFile compute() {
             return getVFile(file);
           }
         });
         app.invokeAndWait(new Runnable() {
           public void run() {
             prog.setIndeterminate(false);
             prog.setText(file);
             prog.setFraction(((double) iHack + 1) / modifiedTotal);
             if (vfile != null) {
               ApplicationManager.getApplication().runWriteAction(new 
Runnable() {
                 public void run() {
                   vfile.refresh(true, false);
                 }
               });
             }
           }
         }, ModalityState.defaultModalityState());
         System.out.println("invoked");
       }
     }
]]>


Am I doing something wrong? Does anyone have tips? Thanks!

2 comments

I'm having better luck with calling refresh(false). The window doesn't
go crazy repainting or hanging like it did before. However, each
refresh() call takes 500-1000ms, AND, once the process is done, I see
the real "Updating Modified Files" dialog, which takes another long
time. What's the point of refresh() if it doesn't update modified files?

Keith Lea wrote:

I'm trying to implement a dialog very similar to the "Updating modified
files" dialog which shows up when IDEA detects some files changed. Here,
the "synchronize on frame activation" is far too slow (with 9000 files
in the project tree), and it doesn't show progress or anything, so we
turn it off. I'm writing a plugin which interfaces with some tools we
use, to only refresh files which we know were changed.

However, I'm having a problem. The dialog often doesn't show up, and the
IDE simply locks and says "Synchronizing files..." in the status bar.

The code looks like this:

         ApplicationManager.getApplication().invokeLater(new Runnable() {
>             public void run() {
>               Application app = ApplicationManager.getApplication();
>               boolean result = 
> app.runProcessWithProgressSynchronously(new Runnable() {
>                 public void run() {
>                   updateFiles(modifiedTotal);
>                 }
>               }, "Updating modified files", true, project);
>             }
>           });
>         }
> 
> ....
> 
>     private void updateFiles(final int modifiedTotal) {
>       final ProgressIndicator prog = 
> ProgressManager.getInstance().getProgressIndicator();
>       prog.setText2("Updating modified files from Mach");
>       prog.setIndeterminate(true);
>       Application app = ApplicationManager.getApplication();
>       for (int i = 0; i < modifiedTotal; i++) {
>         final String file = modifiedFiles.remove();
>         final int iHack = i;
>         final VirtualFile vfile = app.runReadAction(new 
> Computable() {
>           public VirtualFile compute() {
>             return getVFile(file);
>           }
>         });
>         app.invokeAndWait(new Runnable() {
>           public void run() {
>             prog.setIndeterminate(false);
>             prog.setText(file);
>             prog.setFraction(((double) iHack + 1) / modifiedTotal);
>             if (vfile != null) {
>               ApplicationManager.getApplication().runWriteAction(new 
> Runnable() {
>                 public void run() {
>                   vfile.refresh(true, false);
>                 }
>               });
>             }
>           }
>         }, ModalityState.defaultModalityState());
>         System.out.println("invoked");
>       }
>     }
> ]]>


Am I doing something wrong? Does anyone have tips? Thanks!

0

refresh only updates VFS structure, subsequent updates are from PSI.

0

Please sign in to leave a comment.