Skip to content

Commit

Permalink
subclass platform editor tab title provider to respect settings (redh…
Browse files Browse the repository at this point in the history
…at-developer#652)

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Sep 5, 2023
1 parent df31833 commit 6b2b311
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
package com.redhat.devtools.intellij.kubernetes.editor

import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider
import com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.redhat.devtools.intellij.common.validation.KubernetesResourceInfo
import com.redhat.devtools.intellij.kubernetes.editor.util.isKubernetesResource

open class ResourceEditorTabTitleProvider : EditorTabTitleProvider {
open class ResourceEditorTabTitleProvider(
private val fallback: EditorTabTitleProvider = UniqueNameEditorTabTitleProvider()
) : EditorTabTitleProvider {

companion object {
const val TITLE_UNKNOWN_CLUSTERRESOURCE = "Unknown Cluster Resource"
Expand All @@ -34,14 +37,10 @@ open class ResourceEditorTabTitleProvider : EditorTabTitleProvider {
TITLE_UNKNOWN_CLUSTERRESOURCE
}
} else {
getTitleFor(file)
fallback.getEditorTabTitle(project, file)
}
}

private fun getTitleFor(file: VirtualFile): String {
return file.name
}

private fun getTitleFor(info: KubernetesResourceInfo): String {
val name = info.name ?: TITLE_UNKNOWN_NAME
val namespace = info.namespace
Expand Down
Empty file added src/main/resources/test.yml
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

package com.redhat.devtools.intellij.kubernetes.editor

import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.*
import com.redhat.devtools.intellij.common.validation.KubernetesResourceInfo
import com.redhat.devtools.intellij.kubernetes.editor.ResourceEditorTabTitleProvider.Companion.TITLE_UNKNOWN_NAME
import com.redhat.devtools.intellij.kubernetes.model.mocks.Mocks.kubernetesResourceInfo
Expand All @@ -28,7 +28,6 @@ class ResourceEditorTabTitleProviderTest {
private val namespace = "WildWest"
private val kind = "Cowboy"
private val apiGroup = "sillyLads/v1"
private val resourceInfo = kubernetesResourceInfo(name, namespace, kubernetesTypeInfo(kind, apiGroup))

@Test
fun `#getTitle should return 'resourcename@namespace' if file is temporary and contains kubernetes resource with namespace`() {
Expand Down Expand Up @@ -71,28 +70,28 @@ class ResourceEditorTabTitleProviderTest {
}

@Test
fun `#getTitle should return filename if file is NOT temporary`() {
fun `#getTitle should ask parent provider for title if file is NOT temporary`() {
// given
val fileName = "JollyJumper"
val isTemporary = false
val file: VirtualFile = mock {
on { getName() } doReturn fileName
}
val file: VirtualFile = mock()
val resourceInfo = kubernetesResourceInfo(
"<none>",
"<none>",
kubernetesTypeInfo("<none>", "<none>"))
val provider = createResourceEditorTabTitleProvider(isTemporary, resourceInfo)
val fallback: EditorTabTitleProvider = mock()
val provider = createResourceEditorTabTitleProvider(isTemporary, resourceInfo, fallback)
// when
val title = provider.getEditorTabTitle(mock(), file)
provider.getEditorTabTitle(mock(), file)
// then
assertThat(title).isEqualTo(fileName)
verify(fallback).getEditorTabTitle(any(), eq(file))
}

private fun createResourceEditorTabTitleProvider(
isTemporary: Boolean, info: KubernetesResourceInfo
isTemporary: Boolean,
info: KubernetesResourceInfo,
fallback: EditorTabTitleProvider = mock()
): ResourceEditorTabTitleProvider {
return object : ResourceEditorTabTitleProvider() {
return object : ResourceEditorTabTitleProvider(fallback) {

override fun getKubernetesResourceInfo(file: VirtualFile, project: Project): KubernetesResourceInfo {
return info
Expand Down

0 comments on commit 6b2b311

Please sign in to comment.