1111import com .intellij .openapi .fileEditor .*;
1212import com .intellij .openapi .project .Project ;
1313import com .intellij .openapi .util .Key ;
14+ import com .intellij .openapi .util .SystemInfo ;
1415import com .intellij .openapi .util .UserDataHolder ;
1516import com .intellij .openapi .util .UserDataHolderBase ;
1617import com .intellij .openapi .vfs .ReadonlyStatusHandler ;
3031import org .jetbrains .annotations .Nullable ;
3132
3233import javax .swing .*;
34+ import javax .swing .plaf .FontUIResource ;
35+ import javax .swing .text .StyleContext ;
3336import java .awt .*;
3437import java .beans .PropertyChangeListener ;
3538import java .beans .PropertyChangeSupport ;
@@ -108,8 +111,11 @@ public CsvColumnInfoMap<PsiElement> getColumnInfoMap() {
108111 }
109112
110113 public boolean hasErrors () {
114+ if (!isValid ()) {
115+ return true ;
116+ }
111117 CsvColumnInfoMap columnInfoMap = getColumnInfoMap ();
112- return ! isValid () || (columnInfoMap != null && columnInfoMap .hasErrors ());
118+ return (columnInfoMap != null && columnInfoMap .hasErrors ());
113119 }
114120
115121 protected Object [][] storeStateChange (Object [][] data ) {
@@ -129,7 +135,8 @@ public void saveChanges(final String content) {
129135 return ;
130136 }
131137 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 ())) {
133140 return ;
134141 }
135142 ApplicationManager .getApplication ().runWriteAction (() ->
@@ -206,6 +213,9 @@ public boolean isModified() {
206213
207214 @ Override
208215 public boolean isValid () {
216+ if (file == null || !file .isValid ()) {
217+ return false ;
218+ }
209219 CsvFile csvFile = this .getCsvFile ();
210220 return csvFile != null && csvFile .isValid ();
211221 }
@@ -277,7 +287,7 @@ public int compareTo(@NotNull FileEditorLocation o) {
277287
278288 @ Nullable
279289 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 ;
281291 }
282292
283293 @ Nullable
@@ -292,6 +302,9 @@ public Project getProject() {
292302
293303 @ Nullable
294304 public final CsvFile getCsvFile () {
305+ if (project == null || project .isDisposed ()) {
306+ return null ;
307+ }
295308 if (this .psiFile == null || !this .psiFile .isValid ()) {
296309 this .document = FileDocumentManager .getInstance ().getDocument (this .file );
297310 PsiDocumentManager documentManager = PsiDocumentManager .getInstance (project );
@@ -310,7 +323,15 @@ public final int getRowCount() {
310323 }
311324
312325 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 );
314335 }
315336
316337 protected int getStringWidth (String text ) {
0 commit comments