mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Restore state: change editor, undo, redo, external psi update
This commit is contained in:
@@ -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;
|
||||
|
||||
+3
-4
@@ -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
|
||||
|
||||
+34
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user