mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-119135 Save a state of the XDebuggerHistoryManager
This commit is contained in:
+75
-1
@@ -15,11 +15,21 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.impl;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.SerializationFilter;
|
||||
import com.intellij.util.xmlb.SkipDefaultsSerializationFilter;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.xdebugger.XExpression;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,12 +38,20 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class XDebuggerHistoryManager {
|
||||
@State(name = "debuggerHistoryManager", storages = @Storage(value = "debugger-history.xml"))
|
||||
public class XDebuggerHistoryManager implements PersistentStateComponent<Element> {
|
||||
public static final int MAX_RECENT_EXPRESSIONS = 10;
|
||||
private static final SerializationFilter SERIALIZATION_FILTER = new SkipDefaultsSerializationFilter();
|
||||
private static final String STATE_TAG = "root";
|
||||
private static final String ID_ATTRIBUTE = "id";
|
||||
private static final String EXPRESSIONS_TAG = "expressions";
|
||||
private static final String EXPRESSION_TAG = "expression";
|
||||
|
||||
private final Map<String, LinkedList<XExpression>> myRecentExpressions = new HashMap<>();
|
||||
|
||||
public static XDebuggerHistoryManager getInstance(@NotNull Project project) {
|
||||
@@ -59,4 +77,60 @@ public class XDebuggerHistoryManager {
|
||||
public List<XExpression> getRecentExpressions(@NonNls String id) {
|
||||
return ContainerUtil.notNullize(myRecentExpressions.get(id));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element state = new Element(STATE_TAG);
|
||||
for (String id : myRecentExpressions.keySet()) {
|
||||
LinkedList<XExpression> expressions = myRecentExpressions.get(id);
|
||||
List<ExpressionState> states = expressions.stream().map(ExpressionState::new).collect(Collectors.toList());
|
||||
Element entryElement = new Element(EXPRESSIONS_TAG);
|
||||
entryElement.setAttribute(ID_ATTRIBUTE, id);
|
||||
for (ExpressionState expressionState : states) {
|
||||
entryElement.addContent(XmlSerializer.serialize(expressionState, SERIALIZATION_FILTER));
|
||||
}
|
||||
state.addContent(entryElement);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
myRecentExpressions.clear();
|
||||
for (Element expression : state.getChildren(EXPRESSIONS_TAG)) {
|
||||
String id = expression.getAttributeValue(ID_ATTRIBUTE);
|
||||
LinkedList<XExpression> expressions = new LinkedList<>();
|
||||
for (Element expressionElement : expression.getChildren(EXPRESSION_TAG)) {
|
||||
expressions.add(XmlSerializer.deserialize(expressionElement, ExpressionState.class).toXExpression());
|
||||
}
|
||||
|
||||
myRecentExpressions.put(id, expressions);
|
||||
}
|
||||
}
|
||||
|
||||
@Tag(EXPRESSION_TAG)
|
||||
private static class ExpressionState {
|
||||
@Tag("expression-string") String myExpression;
|
||||
@Tag("language-id") String myLanguageId;
|
||||
@Tag("custom-info") String myCustomInfo;
|
||||
@Tag("evaluation-mode") EvaluationMode myEvaluationMode;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
ExpressionState() {
|
||||
}
|
||||
|
||||
ExpressionState(@NotNull XExpression expression) {
|
||||
myExpression = expression.getExpression();
|
||||
Language language = expression.getLanguage();
|
||||
myLanguageId = language == null ? null : language.getID();
|
||||
myCustomInfo = expression.getCustomInfo();
|
||||
myEvaluationMode = expression.getMode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
XExpression toXExpression() {
|
||||
return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguageId), myCustomInfo, myEvaluationMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user