-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decorate tabs for BUILD files with package name
Since BUILD files all have the same name it's hard to distinguish them, so we can use EditorTabTitleProvider to write full label in the editor tab title
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
base/src/com/google/idea/blaze/base/editor/BazelEditorTabTitleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.google.idea.blaze.base.editor; | ||
|
||
import com.google.idea.blaze.base.lang.buildfile.psi.BuildFile; | ||
import com.google.idea.blaze.base.settings.Blaze; | ||
import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BazelEditorTabTitleProvider implements EditorTabTitleProvider { | ||
private static boolean requiresDecoration(Project project, String fileName) { | ||
return Blaze.getBuildSystemProvider(project).possibleBuildFileNames().contains(fileName); | ||
} | ||
@Override | ||
public @Nullable String getEditorTabTitle(@NotNull Project project, | ||
@NotNull VirtualFile virtualFile) { | ||
var fileName = virtualFile.getName(); | ||
if (!requiresDecoration(project, fileName)) { | ||
return null; | ||
} | ||
|
||
return BuildFile.getBuildFileString(project, virtualFile.getPath()); | ||
} | ||
|
||
@Override | ||
public @Nullable String getEditorTabTooltipText(@NotNull Project project, | ||
@NotNull VirtualFile virtualFile) { | ||
return EditorTabTitleProvider.super.getEditorTabTooltipText(project, virtualFile); | ||
} | ||
} |