OSDN Git Service

Cleanup and comment the refresh code in GLE2.
authorRaphael Moll <ralf@android.com>
Thu, 18 Nov 2010 22:55:17 +0000 (14:55 -0800)
committerRaphael Moll <ralf@android.com>
Thu, 18 Nov 2010 22:56:02 +0000 (14:56 -0800)
Change-Id: I95a922c463992600edfc8c25edfc688dc38f79bd

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java

index 4335754..73711aa 100755 (executable)
@@ -184,7 +184,6 @@ public class GraphicalEditorPart extends EditorPart
     private ProjectCallback mProjectCallback;
     private ILayoutLog mLogger;
 
-    private boolean mNeedsXmlReload = false;
     private boolean mNeedsRecompute = false;
 
     private TargetListener mTargetListener;
@@ -874,7 +873,7 @@ public class GraphicalEditorPart extends EditorPart
      * Responds to a page change that made the Graphical editor page the activated page.
      */
     public void activated() {
-        if (mNeedsRecompute || mNeedsXmlReload) {
+        if (mNeedsRecompute) {
             recomputeLayout();
         }
     }
@@ -965,41 +964,28 @@ public class GraphicalEditorPart extends EditorPart
      * Callback for XML model changed. Only update/recompute the layout if the editor is visible
      */
     public void onXmlModelChanged() {
+        // To optimize the rendering when the user is editing in the XML pane, we don't
+        // refresh the editor if it's not the active part.
+        //
+        // This behavior is acceptable when the editor is the single "full screen" part
+        // (as in this case active means visible.)
+        // Unfortunately this breaks in 2 cases:
+        // - when performing a drag'n'drop from one editor to another, the target is not
+        //   properly refreshed before it becomes active.
+        // - when duplicating the editor window and placing both editors side by side (xml in one
+        //   and canvas in the other one), the canvas may not be refreshed when the XML is edited.
+        //
+        // TODO find a way to really query whether the pane is visible, not just active.
+
         if (mLayoutEditor.isGraphicalEditorActive()) {
-            doXmlReload(true /* force */);
             recomputeLayout();
         } else {
-            mNeedsXmlReload = true;
-        }
-    }
-
-    /**
-     * Actually performs the XML reload
-     * @see #onXmlModelChanged()
-     */
-    private void doXmlReload(boolean force) {
-        if (force || mNeedsXmlReload) {
-
-            // TODO : update the mLayoutCanvas, preserving the current selection if possible.
-
-//            GraphicalViewer viewer = getGraphicalViewer();
-//
-//            // try to preserve the selection before changing the content
-//            SelectionManager selMan = viewer.getSelectionManager();
-//            ISelection selection = selMan.getSelection();
-//
-//            try {
-//                viewer.setContents(getModel());
-//            } finally {
-//                selMan.setSelection(selection);
-//            }
-
-            mNeedsXmlReload = false;
+            // Remember we want to recompute as soon as the editor becomes active.
+            mNeedsRecompute = true;
         }
     }
 
     public void recomputeLayout() {
-        doXmlReload(false /* force */);
         try {
             if (!ensureFileValid()) {
                 return;