diff: IDEA-143772 make refresh synchronous
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Tue, 18 Aug 2015 13:29:58 +0000 (16:29 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 19 Aug 2015 10:57:52 +0000 (13:57 +0300)
* we will scan these files later, so we should wait till the end of refresh to process up-to-date data.
* we should pass valid ModalityState, as DirDiff dialog can be modal and refresh operations are performed with NON_MODAL by default.

platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java
platform/platform-impl/src/com/intellij/ide/diff/VirtualFileDiffElement.java

index de0a00d7ca7b9ffbd8022879d3fcee3026402a16..04a5d3a51ca12f3620767e86e7a21d6020405c48 100644 (file)
@@ -25,6 +25,8 @@ import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.diff.impl.dir.actions.popup.WarnOnDeletion;
+import com.intellij.openapi.progress.EmptyProgressIndicator;
+import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.MessageDialogBuilder;
@@ -215,30 +217,46 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode
     myTable.getEmptyText().setText(StatusText.DEFAULT_EMPTY_TEXT);
     final JBLoadingPanel loadingPanel = getLoadingPanel();
     loadingPanel.startLoading();
+
+    final ModalityState modalityState = ModalityState.current();
+
     ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
       public void run() {
-        try {
-          if (myDisposed) return;
-          myUpdater = new Updater(loadingPanel, 100);
-          myUpdater.start();
-          myTree = new DTree(null, "", true);
-          mySrc.refresh(userForcedRefresh);
-          myTrg.refresh(userForcedRefresh);
-          scan(mySrc, myTree, true);
-          scan(myTrg, myTree, false);
-        }
-        catch (final IOException e) {
-          LOG.warn(e);
-          reportException(VcsBundle.message("refresh.failed.message", StringUtil.decapitalize(e.getLocalizedMessage())));
-        }
-        finally {
-          if (myTree != null) {
-            myTree.setSource(mySrc);
-            myTree.setTarget(myTrg);
-            myTree.update(mySettings);
-            applySettings();
+        EmptyProgressIndicator indicator = new EmptyProgressIndicator() {
+          @NotNull
+          @Override
+          public ModalityState getModalityState() {
+            return modalityState;
           }
-        }
+        };
+        ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
+          @Override
+          public void run() {
+            try {
+              if (myDisposed) return;
+              myUpdater = new Updater(loadingPanel, 100);
+              myUpdater.start();
+              text.set("Loading...");
+              myTree = new DTree(null, "", true);
+              mySrc.refresh(userForcedRefresh);
+              myTrg.refresh(userForcedRefresh);
+              scan(mySrc, myTree, true);
+              scan(myTrg, myTree, false);
+            }
+            catch (final IOException e) {
+              LOG.warn(e);
+              reportException(VcsBundle.message("refresh.failed.message", StringUtil.decapitalize(e.getLocalizedMessage())));
+            }
+            finally {
+              if (myTree != null) {
+                myTree.setSource(mySrc);
+                myTree.setTarget(myTrg);
+                myTree.update(mySettings);
+                applySettings();
+              }
+            }
+          }
+        }, indicator);
       }
     });
   }
index 8d6585f2b59beba353d22158a37efaf4885ba113..075d66a517751c03d42c283f061710939aa5bbc2 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.DataProvider;
 import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.application.Result;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.diff.DiffRequest;
@@ -29,10 +30,12 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.fileEditor.*;
 import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
 import com.intellij.openapi.fileTypes.FileTypeManager;
+import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectManager;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.*;
+import com.intellij.openapi.vfs.newvfs.RefreshQueue;
 import com.intellij.util.PlatformIcons;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -298,7 +301,10 @@ public class VirtualFileDiffElement extends DiffElement<VirtualFile> {
         }.execute();
       }
 
-      VfsUtil.markDirtyAndRefresh(true, true, true, virtualFile);
+      ModalityState modalityState = ProgressManager.getInstance().getProgressIndicator().getModalityState();
+
+      VfsUtil.markDirty(true, true, virtualFile);
+      RefreshQueue.getInstance().refresh(false, true, null, modalityState, virtualFile);
     }
   }
 }