summaryrefslogtreecommitdiff
path: root/platform/platform-api/src/com/intellij/openapi/fileEditor/FileEditorManager.java
blob: b9589574059d5f6f3afb06c3f81c9458b7c6929c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 * Copyright 2000-2009 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;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.List;

public abstract class FileEditorManager {

  public static final Key<Boolean> USE_CURRENT_WINDOW = Key.create("OpenFile.searchForOpen");

  public static FileEditorManager getInstance(@NotNull Project project) {
    return project.getComponent(FileEditorManager.class);
  }

  /**
   * @param file file to open. Parameter cannot be null. File should be valid.
   *
   * @return array of opened editors
   */
  @NotNull
  public abstract FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor);


  /**
   * Opens a file
   *
   *
   * @param file file to open
   * @param focusEditor <code>true</code> if need to focus
   * @return array of opened editors
   */
  @NotNull
  public FileEditor[] openFile(@NotNull VirtualFile file, boolean focusEditor, boolean searchForOpen) {
    throw new UnsupportedOperationException("Not implemented");
  }

  /**
   * Closes all editors opened for the file.
   *
   * @param file file to be closed. Cannot be null.
   */
  public abstract void closeFile(@NotNull VirtualFile file);

  /**
   * Works as {@link #openFile(VirtualFile, boolean)} but forces opening of text editor.
   * This method ignores {@link FileEditorPolicy#HIDE_DEFAULT_EDITOR} policy.
   *
   * @return opened text editor. The method returns <code>null</code> in case if text editor wasn't opened.
   */
  @Nullable
  public abstract Editor openTextEditor(@NotNull OpenFileDescriptor descriptor, boolean focusEditor);

  /**
   * @return currently selected text editor. The method returns <code>null</code> in case
   * there is no selected editor at all or selected editor is not a text one.
   */
  @Nullable
  public abstract Editor getSelectedTextEditor();

  /**
   * @return <code>true</code> if <code>file</code> is opened, <code>false</code> otherwise
   */
  public abstract boolean isFileOpen(@NotNull VirtualFile file);

  /**
   * @return all opened files. Order of files in the array corresponds to the order of editor tabs.
   */
  @NotNull
  public abstract VirtualFile[] getOpenFiles();

  /**
   * @return files currently selected. The method returns empty array if there are no selected files.
   * If more than one file is selected (split), the file with most recent focused editor is returned first.
   */
  @NotNull
  public abstract VirtualFile[] getSelectedFiles();

  /**
   * @return editors currently selected. The method returns empty array if no editors are open.
   */
  @NotNull
  public abstract FileEditor[] getSelectedEditors();

  /**
   * @param file cannot be null
   *
   * @return editor which is currently selected in the currently selected file.
   * The method returns <code>null</code> if <code>file</code> is not opened.
   */
  @Nullable
  public abstract FileEditor getSelectedEditor(@NotNull VirtualFile file);

  /**
   * @param file cannot be null
   *
   * @return current editors for the specified <code>file</code>
   */
  @NotNull
  public abstract FileEditor[] getEditors(@NotNull VirtualFile file);

  /**
   * @param file cannot be null
   *
   * @return all editors for the specified <code>file</code>
   */
  @NotNull
  public abstract FileEditor[] getAllEditors(@NotNull VirtualFile file);

  /**
   * @return all open editors
   */
  @NotNull
  public abstract FileEditor[] getAllEditors();

  /**
   * @deprecated use addTopComponent
   */
  public abstract void showEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComponent);
  /**
   * @deprecated use removeTopComponent
   */
  public abstract void removeEditorAnnotation(@NotNull FileEditor editor, @NotNull JComponent annotationComponent);

  public abstract void addTopComponent(@NotNull final FileEditor editor, @NotNull final JComponent component);
  public abstract void removeTopComponent(@NotNull final FileEditor editor, @NotNull final JComponent component);
  public abstract void addBottomComponent(@NotNull final FileEditor editor, @NotNull final JComponent component);
  public abstract void removeBottomComponent(@NotNull final FileEditor editor, @NotNull final JComponent component);


  /**
   * Adds specified <code>listener</code>
   * @param listener listener to be added
   * @deprecated Use MessageBus instead: see {@link FileEditorManagerListener#FILE_EDITOR_MANAGER}
   */
  public abstract void addFileEditorManagerListener(@NotNull FileEditorManagerListener listener);

  /**
   * @deprecated Use {@link FileEditorManagerListener#FILE_EDITOR_MANAGER} instead
   */
  public abstract void addFileEditorManagerListener(@NotNull FileEditorManagerListener listener, @NotNull Disposable parentDisposable);

  /**
   * Removes specified <code>listener</code>
   *
   * @param listener listener to be removed
   * @deprecated Use {@link FileEditorManagerListener#FILE_EDITOR_MANAGER} instead
   */
  public abstract void removeFileEditorManagerListener(@NotNull FileEditorManagerListener listener);

  @NotNull
  public abstract List<FileEditor> openEditor(@NotNull OpenFileDescriptor descriptor, boolean focusEditor);

  /**
   * Returns the project with which the file editor manager is associated.
   *
   * @return the project instance.
   * @since 5.0.1
   */
  @NotNull
  public abstract Project getProject();

  public abstract void registerExtraEditorDataProvider(@NotNull EditorDataProvider provider, Disposable parentDisposable);

  /**
   * Selects a specified file editor tab for the specified editor.
   * @param file a file to switch the file editor tab for. The function does nothing if the file is not currently open in the editor.
   * @param fileEditorProviderId the ID of the file editor to open; matches the return value of
   * {@link com.intellij.openapi.fileEditor.FileEditorProvider#getEditorTypeId()}
   */
  public abstract void setSelectedEditor(@NotNull VirtualFile file, String fileEditorProviderId);
}