From 06ad677dd9875e20549f82bc2abf3e2b4cd4b321 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Thu, 18 Nov 2010 14:55:17 -0800 Subject: [PATCH] Cleanup and comment the refresh code in GLE2. Change-Id: I95a922c463992600edfc8c25edfc688dc38f79bd --- .../editors/layout/gle2/GraphicalEditorPart.java | 46 ++++++++-------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index 433575401..73711aad6 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -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; -- 2.11.0