11
11
import com .intellij .openapi .fileEditor .*;
12
12
import com .intellij .openapi .project .Project ;
13
13
import com .intellij .openapi .util .Key ;
14
+ import com .intellij .openapi .util .SystemInfo ;
14
15
import com .intellij .openapi .util .UserDataHolder ;
15
16
import com .intellij .openapi .util .UserDataHolderBase ;
16
17
import com .intellij .openapi .vfs .ReadonlyStatusHandler ;
30
31
import org .jetbrains .annotations .Nullable ;
31
32
32
33
import javax .swing .*;
34
+ import javax .swing .plaf .FontUIResource ;
35
+ import javax .swing .text .StyleContext ;
33
36
import java .awt .*;
34
37
import java .beans .PropertyChangeListener ;
35
38
import java .beans .PropertyChangeSupport ;
@@ -108,8 +111,11 @@ public CsvColumnInfoMap<PsiElement> getColumnInfoMap() {
108
111
}
109
112
110
113
public boolean hasErrors () {
114
+ if (!isValid ()) {
115
+ return true ;
116
+ }
111
117
CsvColumnInfoMap columnInfoMap = getColumnInfoMap ();
112
- return ! isValid () || (columnInfoMap != null && columnInfoMap .hasErrors ());
118
+ return (columnInfoMap != null && columnInfoMap .hasErrors ());
113
119
}
114
120
115
121
protected Object [][] storeStateChange (Object [][] data ) {
@@ -129,7 +135,8 @@ public void saveChanges(final String content) {
129
135
return ;
130
136
}
131
137
ApplicationManager .getApplication ().invokeLater (() -> {
132
- if (!this .document .isWritable () && ReadonlyStatusHandler .getInstance (this .project ).ensureFilesWritable (this .file ).hasReadonlyFiles ()) {
138
+ if (project == null || project .isDisposed () ||
139
+ (!this .document .isWritable () && ReadonlyStatusHandler .getInstance (this .project ).ensureFilesWritable (this .file ).hasReadonlyFiles ())) {
133
140
return ;
134
141
}
135
142
ApplicationManager .getApplication ().runWriteAction (() ->
@@ -206,6 +213,9 @@ public boolean isModified() {
206
213
207
214
@ Override
208
215
public boolean isValid () {
216
+ if (file == null || !file .isValid ()) {
217
+ return false ;
218
+ }
209
219
CsvFile csvFile = this .getCsvFile ();
210
220
return csvFile != null && csvFile .isValid ();
211
221
}
@@ -277,7 +287,7 @@ public int compareTo(@NotNull FileEditorLocation o) {
277
287
278
288
@ Nullable
279
289
public StructureViewBuilder getStructureViewBuilder () {
280
- return file != null && file . isValid () ? StructureViewBuilder .PROVIDER .getStructureViewBuilder (file .getFileType (), file , this .project ) : null ;
290
+ return isValid () ? StructureViewBuilder .PROVIDER .getStructureViewBuilder (file .getFileType (), file , this .project ) : null ;
281
291
}
282
292
283
293
@ Nullable
@@ -292,6 +302,9 @@ public Project getProject() {
292
302
293
303
@ Nullable
294
304
public final CsvFile getCsvFile () {
305
+ if (project == null || project .isDisposed ()) {
306
+ return null ;
307
+ }
295
308
if (this .psiFile == null || !this .psiFile .isValid ()) {
296
309
this .document = FileDocumentManager .getInstance ().getDocument (this .file );
297
310
PsiDocumentManager documentManager = PsiDocumentManager .getInstance (project );
@@ -310,7 +323,15 @@ public final int getRowCount() {
310
323
}
311
324
312
325
public Font getFont () {
313
- return EditorColorsManager .getInstance ().getGlobalScheme ().getFont (EditorFontType .PLAIN );
326
+ // the one-liner to be used requires 172.2465.6 - compatibility
327
+ // return UIUtil.getFontWithFallback(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN));
328
+
329
+ Font font = EditorColorsManager .getInstance ().getGlobalScheme ().getFont (EditorFontType .PLAIN );
330
+ String familyName = font .getFamily ();
331
+ int style = font .getStyle ();
332
+ int size = font .getSize ();
333
+ Font fontWithFallback = SystemInfo .isMac ? new Font (familyName , style , size ) : (new StyleContext ()).getFont (familyName , style , size );
334
+ return fontWithFallback instanceof FontUIResource ? (FontUIResource )fontWithFallback : new FontUIResource (fontWithFallback );
314
335
}
315
336
316
337
protected int getStringWidth (String text ) {
0 commit comments