From 51a907fc00bdf99832c564172bcd088beb313841 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 9 Jan 2018 22:16:38 +0100 Subject: [PATCH] IDEA-184729 Remember Preview state for SvgEditor and reuse it when opening new ones --- .../editor/impl/ImageFileEditorProvider.java | 2 +- .../fileEditor/TextEditorWithPreview.java | 35 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/images/src/org/intellij/images/editor/impl/ImageFileEditorProvider.java b/images/src/org/intellij/images/editor/impl/ImageFileEditorProvider.java index c36fa48e2c0f..b53f67202986 100644 --- a/images/src/org/intellij/images/editor/impl/ImageFileEditorProvider.java +++ b/images/src/org/intellij/images/editor/impl/ImageFileEditorProvider.java @@ -48,7 +48,7 @@ final class ImageFileEditorProvider implements FileEditorProvider, DumbAware { public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) { ImageFileEditorImpl viewer = new ImageFileEditorImpl(project, file); if ("svg".equalsIgnoreCase(file.getExtension())) { - return new TextEditorWithPreview((TextEditor)TextEditorProvider.getInstance().createEditor(project, file), viewer); + return new TextEditorWithPreview((TextEditor)TextEditorProvider.getInstance().createEditor(project, file), viewer, "SvgEditor"); } return viewer; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/TextEditorWithPreview.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/TextEditorWithPreview.java index 3b47012a999d..8d6ee21eea8a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/TextEditorWithPreview.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/TextEditorWithPreview.java @@ -1,23 +1,12 @@ /* - * 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-2018 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.openapi.fileEditor; import com.intellij.codeHighlighting.BackgroundEditorHighlighter; import com.intellij.icons.AllIcons; import com.intellij.ide.structureView.StructureViewBuilder; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.ex.EditorGutterComponentEx; @@ -120,7 +109,10 @@ public class TextEditorWithPreview extends UserDataHolderBase implements FileEdi final JPanel result = new JPanel(new BorderLayout()); result.add(myToolbarWrapper, BorderLayout.NORTH); result.add(splitter, BorderLayout.CENTER); - if (myLayout == null) myLayout = Layout.SHOW_EDITOR_AND_PREVIEW; + if (myLayout == null) { + String lastUsed = PropertiesComponent.getInstance().getValue(getLayoutPropertyName()); + myLayout = Layout.fromName(lastUsed, Layout.SHOW_EDITOR_AND_PREVIEW); + } adjustEditorsVisibility(); myComponent = result; @@ -409,6 +401,15 @@ public class TextEditorWithPreview extends UserDataHolderBase implements FileEdi myIcon = icon; } + public static Layout fromName(String name, Layout defaultValue) { + for (Layout layout : Layout.values()) { + if (layout.myName.equals(name)) { + return layout; + } + } + return defaultValue; + } + public String getName() { return myName; } @@ -435,8 +436,14 @@ public class TextEditorWithPreview extends UserDataHolderBase implements FileEdi public void setSelected(AnActionEvent e, boolean state) { if (state) { myLayout = myActionLayout; + PropertiesComponent.getInstance().setValue(getLayoutPropertyName(), myLayout.myName, Layout.SHOW_EDITOR_AND_PREVIEW.myName); adjustEditorsVisibility(); } } } + + @NotNull + private String getLayoutPropertyName() { + return myName + "Layout"; + } }