From e07ef58e4ea42daa7efa3045bff8928445050d04 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 22 Dec 2017 11:34:46 +0100 Subject: [PATCH] =?UTF-8?q?ProjectView=20=E2=80=94=20do=20not=20write=20de?= =?UTF-8?q?faults=20(pane=20id)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AbstractProjectViewPane.java | 17 ++++++++---- .../ide/projectView/impl/ProjectViewImpl.java | 27 ++++++++++++------- .../ide/projectView/impl/ProjectViewPane.java | 23 ++++------------ 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java index 1eae077ebf37..090ae33f3b2e 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.ide.projectView.impl; @@ -130,9 +132,14 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl } public abstract String getTitle(); + public abstract Icon getIcon(); - @NotNull public abstract String getId(); - @Nullable public final String getSubId(){ + + @NotNull + public abstract String getId(); + + @Nullable + public final String getSubId() { return mySubId; } @@ -443,7 +450,7 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl return myTreeBuilder; } - public void readExternal(Element element) throws InvalidDataException { + public void readExternal(@NotNull Element element) { List subPanes = element.getChildren(ELEMENT_SUBPANE); for (Element subPane : subPanes) { String subId = subPane.getAttributeValue(ATTRIBUTE_SUBID); @@ -454,7 +461,7 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl } } - public void writeExternal(Element element) throws WriteExternalException { + public void writeExternal(Element element) { saveExpandedPaths(); for (String subId : myReadTreeState.keySet()) { TreeState treeState = myReadTreeState.get(subId); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index d48f60d29129..a35f1e33f8c3 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -176,7 +176,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo private final MyPanel myDataProvider; private final SplitterProportionsData splitterProportions = new SplitterProportionsDataImpl(); private final MessageBusConnection myConnection; - private final Map myUninitializedPaneState = new HashMap<>(); + private final Map myUninitializedPaneState = new THashMap<>(); private final Map mySelectInTargets = new LinkedHashMap<>(); private ContentManager myContentManager; @@ -1364,7 +1364,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo return; } for (Attribute attribute : node.getAttributes()) { - options.put(attribute.getName(), Boolean.TRUE.toString().equals(attribute.getValue()) ? Boolean.TRUE : Boolean.FALSE); + options.put(attribute.getName(), Boolean.parseBoolean(attribute.getValue())); } } @@ -1378,7 +1378,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo final String key = entry.getKey(); //SCR48267 if (key != null) { - e.setAttribute(key, Boolean.toString(entry.getValue().booleanValue())); + e.setAttribute(key, Boolean.toString(entry.getValue())); } } @@ -1395,6 +1395,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo mySavedPaneId = ProjectViewPane.ID; mySavedPaneSubId = null; } + readOption(navigatorElement.getChild(ELEMENT_FLATTEN_PACKAGES), myFlattenPackages); readOption(navigatorElement.getChild(ELEMENT_SHOW_MEMBERS), myShowMembers); readOption(navigatorElement.getChild(ELEMENT_SHOW_MODULES), myShowModules); @@ -1427,13 +1428,16 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo for (Element paneElement : paneElements) { String paneId = paneElement.getAttributeValue(ATTRIBUTE_ID); + if (StringUtil.isEmptyOrSpaces(paneId)) { + continue; + } + final AbstractProjectViewPane pane = myId2Pane.get(paneId); if (pane != null) { try { pane.readExternal(paneElement); } - catch (InvalidDataException e) { - // ignore + catch (InvalidDataException ignore) { } } else { @@ -1446,14 +1450,18 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo public Element getState() { Element parentNode = new Element("projectView"); Element navigatorElement = new Element(ELEMENT_NAVIGATOR); + AbstractProjectViewPane currentPane = getCurrentProjectViewPane(); if (currentPane != null) { - navigatorElement.setAttribute(ATTRIBUTE_CURRENT_VIEW, currentPane.getId()); String subId = currentPane.getSubId(); - if (subId != null) { - navigatorElement.setAttribute(ATTRIBUTE_CURRENT_SUBVIEW, subId); + if (subId != null || !currentPane.getId().equals(ProjectViewPane.ID)) { + navigatorElement.setAttribute(ATTRIBUTE_CURRENT_VIEW, currentPane.getId()); + if (subId != null) { + navigatorElement.setAttribute(ATTRIBUTE_CURRENT_SUBVIEW, subId); + } } } + writeOption(navigatorElement, myFlattenPackages, ELEMENT_FLATTEN_PACKAGES); writeOption(navigatorElement, myShowMembers, ELEMENT_SHOW_MEMBERS); writeOption(navigatorElement, myShowModules, ELEMENT_SHOW_MODULES); @@ -1473,8 +1481,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo try { splitterProportions.writeExternal(navigatorElement); } - catch (WriteExternalException e) { - // ignore + catch (WriteExternalException ignored) { } if (!JDOMUtil.isEmpty(navigatorElement)) { diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewPane.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewPane.java index e34681415f14..5f1f1e0be40e 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewPane.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewPane.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.projectView.impl; @@ -37,9 +25,7 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.registry.Registry; import com.intellij.psi.PsiDirectory; import org.jdom.Element; @@ -119,8 +105,9 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane { } @Override - public void readExternal(Element element) throws InvalidDataException { + public void readExternal(@NotNull Element element) { super.readExternal(element); + String showExcludedOption = JDOMExternalizerUtil.readField(element, SHOW_EXCLUDED_FILES_OPTION); myShowExcludedFiles = showExcludedOption == null || Boolean.parseBoolean(showExcludedOption); String useFileNestingRules = JDOMExternalizerUtil.readField(element, USE_FILE_NESTING_RULES); @@ -128,7 +115,7 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane { } @Override - public void writeExternal(Element element) throws WriteExternalException { + public void writeExternal(Element element) { super.writeExternal(element); if (!myShowExcludedFiles) { JDOMExternalizerUtil.writeField(element, SHOW_EXCLUDED_FILES_OPTION, String.valueOf(false)); @@ -233,7 +220,7 @@ public class ProjectViewPane extends AbstractProjectViewPSIPane { } @Override - public void update(AnActionEvent e) { + public void update(@NotNull AnActionEvent e) { super.update(e); final Presentation presentation = e.getPresentation(); final ProjectView projectView = ProjectView.getInstance(myProject);