CR-IC-3471

This commit is contained in:
Vladimir Krivosheev
2013-12-02 13:49:12 +01:00
parent 73b245e482
commit b213f1036b
9 changed files with 46 additions and 58 deletions
@@ -15,7 +15,10 @@
*/
package org.intellij.images.editor.impl;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorPolicy;
import com.intellij.openapi.fileEditor.FileEditorProvider;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
@@ -58,7 +61,7 @@ final class ImageFileEditorProvider implements FileEditorProvider, DumbAware {
@Override
@NotNull
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
return new NullFileEditorState();
return FileEditorState.INSTANCE;
}
@Override
@@ -43,6 +43,7 @@ public class ImageFileEditorState implements TransferableFileEditorState, Serial
this.zoomFactor = zoomFactor;
}
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return otherState instanceof ImageFileEditorState;
}
@@ -63,6 +63,7 @@ public interface FileEditorProvider {
/**
* Deserialize state from the specified <code>sourceElement</code>
* Use {@link FileEditorState#INSTANCE} as default implementation
*/
@NotNull
FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file);
@@ -1,23 +0,0 @@
/*
* Copyright 2000-2013 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.
*/
package com.intellij.openapi.fileEditor;
public final class NullFileEditorState implements FileEditorState {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return false;
}
}
@@ -78,12 +78,7 @@ public class Mock {
@Override
@NotNull
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState fileEditorState, FileEditorStateLevel fileEditorStateLevel) {
return false;
}
};
return FileEditorState.INSTANCE;
}
@Override
@@ -316,10 +311,10 @@ public class Mock {
@Override
@NotNull
public Pair<FileEditor[],FileEditorProvider[]> openFileWithProviders(@NotNull VirtualFile file,
boolean focusEditor,
boolean searchForSplitter) {
return Pair.create (new FileEditor[0], new FileEditorProvider [0]);
public Pair<FileEditor[], FileEditorProvider[]> openFileWithProviders(@NotNull VirtualFile file,
boolean focusEditor,
boolean searchForSplitter) {
return Pair.create(new FileEditor[0], new FileEditorProvider[0]);
}
@Override
@@ -387,11 +382,11 @@ public class Mock {
}
@Override
public void removeEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComoponent) {
public void removeEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComponent) {
}
@Override
public void showEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComoponent) {
public void showEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComponent) {
}
@Override
@@ -108,8 +108,8 @@ public class Disposer {
ourTree.executeAll(disposable, true, ourDisposeAction, processUnregistered);
}
public static void disposeChildAndReplace(@NotNull Disposable toDipose, @NotNull Disposable toReplace) {
ourTree.executeChildAndReplace(toDipose, toReplace, true, ourDisposeAction);
public static void disposeChildAndReplace(@NotNull Disposable toDispose, @NotNull Disposable toReplace) {
ourTree.executeChildAndReplace(toDispose, toReplace, true, ourDisposeAction);
}
@NotNull
@@ -50,6 +50,7 @@ final class MyEditorState implements FileEditorState{
return (int)(myDocumentModificationStamp ^ (myDocumentModificationStamp >>> 32));
}
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return otherState instanceof MyEditorState;
}
@@ -18,13 +18,13 @@ package com.intellij.util.xml.ui;
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -46,7 +46,7 @@ import java.beans.PropertyChangeSupport;
* @author Sergey.Vasiliev
*/
abstract public class PerspectiveFileEditor extends UserDataHolderBase implements DocumentsEditor, Committable {
private final Wrapper myWrapprer = new Wrapper();
private final Wrapper myWrapper = new Wrapper();
private boolean myInitialised = false;
private final PropertyChangeSupport myPropertyChangeSupport = new PropertyChangeSupport(this);
@@ -55,22 +55,18 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
private final UndoHelper myUndoHelper;
private boolean myInvalidated;
private static final FileEditorState FILE_EDITOR_STATE = new FileEditorState() {
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return true;
}
};
protected PerspectiveFileEditor(final Project project, final VirtualFile file) {
myProject = project;
myUndoHelper = new UndoHelper(project, this);
myFile = file;
FileEditorManager.getInstance(myProject).addFileEditorManagerListener(new FileEditorManagerAdapter() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
if (!isValid()) return;
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myUndoHelper.isShowing() && !getComponent().isShowing()) {
deselectNotify();
@@ -183,6 +179,7 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
return PsiManager.getInstance(myProject).findFile(myFile);
}
@Override
public final Document[] getDocuments() {
return myUndoHelper.getDocuments();
}
@@ -195,20 +192,24 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
return myFile;
}
@Override
public void dispose() {
if (myInvalidated) return;
myInvalidated = true;
myUndoHelper.stopListeningDocuments();
}
@Override
public final boolean isModified() {
return FileDocumentManager.getInstance().isFileModified(getVirtualFile());
}
@Override
public boolean isValid() {
return getVirtualFile().isValid();
}
@Override
public void selectNotify() {
if (!checkIsValid() || myInvalidated) return;
ensureInitialized();
@@ -222,50 +223,60 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
protected final synchronized void ensureInitialized() {
if (!isInitialised()) {
myWrapprer.setContent(createCustomComponent());
myWrapper.setContent(createCustomComponent());
myInitialised = true;
}
}
@Override
public void deselectNotify() {
if (!checkIsValid() || myInvalidated) return;
setShowing(false);
commit();
}
@Override
public BackgroundEditorHighlighter getBackgroundHighlighter() {
return null;
}
@Override
public FileEditorLocation getCurrentLocation() {
return new FileEditorLocation() {
@Override
@NotNull
public FileEditor getEditor() {
return PerspectiveFileEditor.this;
}
public int compareTo(final FileEditorLocation fileEditorLocation) {
@Override
public int compareTo(@NotNull final FileEditorLocation fileEditorLocation) {
return 0;
}
};
}
@Override
public StructureViewBuilder getStructureViewBuilder() {
return null;
}
@Override
@NotNull
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
return FILE_EDITOR_STATE;
return FileEditorState.INSTANCE;
}
@Override
public void setState(@NotNull FileEditorState state) {
}
@Override
public void addPropertyChangeListener(@NotNull PropertyChangeListener listener) {
myPropertyChangeSupport.addPropertyChangeListener(listener);
}
@Override
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
myPropertyChangeSupport.removePropertyChangeListener(listener);
}
@@ -278,6 +289,7 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
return !myInvalidated;
}
@Override
@NotNull
public JComponent getComponent() {
return getWrapper();
@@ -287,7 +299,7 @@ abstract public class PerspectiveFileEditor extends UserDataHolderBase implement
protected abstract JComponent createCustomComponent();
public Wrapper getWrapper() {
return myWrapprer;
return myWrapper;
}
protected final synchronized boolean isInitialised() {
@@ -15,7 +15,10 @@
*/
package com.intellij.util.xml.ui;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorPolicy;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.fileEditor.WeighedFileEditorProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
@@ -39,12 +42,7 @@ public abstract class PerspectiveFileEditorProvider extends WeighedFileEditorPro
@Override
@NotNull
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return true;
}
};
return FileEditorState.INSTANCE;
}
@Override