IDEA-120343 Gradle: custom title for gradle files in editors

This commit is contained in:
Vladislav.Soroka
2014-02-05 18:11:08 +04:00
parent bd2fcae8c9
commit 61e3b94bd0
2 changed files with 44 additions and 0 deletions
+1
View File
@@ -63,6 +63,7 @@
key="gradle.name" bundle="i18n.GradleBundle"/>
<library.presentationProvider implementation="org.jetbrains.plugins.gradle.config.GradleLibraryPresentationProvider" order="last"/>
<java.elementFinder implementation="org.jetbrains.plugins.gradle.config.GradleClassFinder"/>
<editorTabTitleProvider implementation="org.jetbrains.plugins.gradle.util.GradleEditorTabTitleProvider"/>
<projectOpenProcessor implementation="org.jetbrains.plugins.gradle.service.project.wizard.GradleProjectOpenProcessor"/>
<configurationType implementation="org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType"/>
@@ -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;
}
}