private ProjectCallback mProjectCallback;
private ILayoutLog mLogger;
- private boolean mNeedsXmlReload = false;
private boolean mNeedsRecompute = false;
private TargetListener mTargetListener;
* Responds to a page change that made the Graphical editor page the activated page.
*/
public void activated() {
- if (mNeedsRecompute || mNeedsXmlReload) {
+ if (mNeedsRecompute) {
recomputeLayout();
}
}
* 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;