From 61e3b94bd0e27fec6df6396d6abd97ddebbc4d21 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 5 Feb 2014 18:09:33 +0400 Subject: [PATCH] IDEA-120343 Gradle: custom title for gradle files in editors --- plugins/gradle/src/META-INF/plugin.xml | 1 + .../util/GradleEditorTabTitleProvider.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleEditorTabTitleProvider.java diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 5b349a5b580a..287091125f4d 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -63,6 +63,7 @@ key="gradle.name" bundle="i18n.GradleBundle"/> + diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleEditorTabTitleProvider.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleEditorTabTitleProvider.java new file mode 100644 index 000000000000..635d43749382 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/util/GradleEditorTabTitleProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.plugins.gradle.util; + +import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootManager; +import com.intellij.openapi.vfs.VirtualFile; + +/** + * @author Vladislav.Soroka + * @since 2/5/14 + */ +public class GradleEditorTabTitleProvider implements EditorTabTitleProvider { + public String getEditorTabTitle(Project project, VirtualFile file) { + if (GradleConstants.EXTENSION.equals(file.getExtension()) && GradleConstants.DEFAULT_SCRIPT_NAME.equals(file.getName())) { + for (Module module : ModuleManager.getInstance(project).getModules()) { + if (module.isDisposed()) return null; + + final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); + for (VirtualFile virtualFile : moduleRootManager.getContentRoots()) { + if (virtualFile == file.getParent()) return module.getName(); + } + } + } + return null; + } +}