Restore state: change editor, undo, redo, external psi update

This commit is contained in:
Alexander Lobas
2012-04-04 14:46:20 +04:00
parent bf2efd03e6
commit 354751f0c5
3 changed files with 40 additions and 6 deletions
@@ -55,6 +55,7 @@ public class ProfileAction {
@Override
public void run() {
myProfileList.addVersion();
myVersion = myProfileList.getVersion();
}
});
@@ -78,6 +79,8 @@ public class ProfileAction {
editProfiles();
}
else {
myProfileList.addVersion();
myVersion = myProfileList.getVersion();
updateActions(item);
}
return item != EDIT_PROFILE;
@@ -81,7 +81,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
myPSIChangeListener = new ExternalPSIChangeListener(this, myXmlFile, 100, new Runnable() {
@Override
public void run() {
System.out.println("=== Full update ===");
reparseFile();
}
});
@@ -92,14 +91,13 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
public void run() {
myActionPanel.update();
if (myRootComponent == null) {
myPSIChangeListener.start();
myPSIChangeListener.activate();
myPSIChangeListener.addRequest();
}
else if (myProfileLastVersion != myProfileAction.getVersion()) {
myPSIChangeListener.addRequest(new Runnable() {
@Override
public void run() {
System.out.println("=== Light update ===");
updateRenderer(true);
}
});
@@ -403,11 +401,12 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
@Override
public void activate() {
myProfileAction.externalUpdate();
myPSIChangeListener.activate();
}
@Override
public void deactivate() {
// TODO: Auto-generated method stub
myPSIChangeListener.deactivate();
}
@Override
@@ -15,11 +15,16 @@
*/
package com.intellij.android.designer.designSurface;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.psi.*;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiTreeChangeAdapter;
import com.intellij.psi.PsiTreeChangeEvent;
import com.intellij.util.Alarm;
import com.intellij.util.containers.ComparatorUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -33,6 +38,7 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter {
private final int myDelayMillis;
private final Runnable myRunnable;
private volatile boolean myRunState;
private String myContent;
public ExternalPSIChangeListener(JComponent component, PsiFile file, int delayMillis, Runnable runnable) {
myComponent = component;
@@ -56,6 +62,32 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter {
}
}
public void activate() {
if (!myRunState) {
start();
if (!ComparatorUtil.equalsNullable(myContent, getContent())) {
addRequest();
}
myContent = null;
}
}
public void deactivate() {
if (myRunState) {
stop();
myContent = getContent();
}
}
private String getContent() {
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return myFile.getText();
}
});
}
private void updatePsi(PsiTreeChangeEvent event) {
if (myRunState && myFile == event.getFile()) {
addRequest();