IDEA-184729 Remember Preview state for SvgEditor and reuse it when opening new ones

This commit is contained in:
Konstantin Bulenkov
2018-01-09 22:18:29 +01:00
parent 9992d81eb1
commit 51a907fc00
2 changed files with 22 additions and 15 deletions
@@ -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;
}
@@ -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";
}
}