forked from Haehnchen/idea-php-symfony2-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide custom Twig file overlay to indicate "extends" and attached c…
…ontroller template types Haehnchen#1485
- Loading branch information
Showing
7 changed files
with
60 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
58 changes: 58 additions & 0 deletions
58
src/main/java/fr/adrienbrault/idea/symfony2plugin/twig/icon/TwigIconProvider.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,58 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.twig.icon; | ||
|
||
import com.intellij.ide.IconProvider; | ||
import com.intellij.openapi.project.DumbService; | ||
import com.intellij.openapi.util.Iconable; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.ui.LayeredIcon; | ||
import com.jetbrains.twig.TwigFile; | ||
import com.jetbrains.twig.elements.TwigExtendsTag; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; | ||
import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil; | ||
import icons.TwigIcons; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
|
||
/** | ||
* Based on Twig content add overlay to the default Twig file icon, indicating the possible template type | ||
* | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class TwigIconProvider extends IconProvider { | ||
public Icon getIcon(@NotNull PsiElement element, @Iconable.IconFlags int flags) { | ||
if (!(element instanceof TwigFile) || !Symfony2ProjectComponent.isEnabled(element.getProject()) || DumbService.getInstance(element.getProject()).isDumb()) { | ||
return null; | ||
} | ||
|
||
// attach controller icon overlay | ||
LayeredIcon icon = null; | ||
if (hasController((TwigFile) element)) { | ||
icon = new LayeredIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_CONTROLLER_FILE); | ||
icon.setIcon(Symfony2Icons.TWIG_CONTROLLER_FILE, 1, SwingConstants.NORTH_WEST); | ||
} | ||
|
||
// file provides extends tag, add another layer on top; but put the layer below the previous layer if provided | ||
TwigExtendsTag childOfType = PsiTreeUtil.findChildOfType(element, TwigExtendsTag.class); | ||
if (childOfType != null) { | ||
if (icon == null) { | ||
// we are alone so just place the icon | ||
icon = new LayeredIcon(TwigIcons.TwigFileIcon, Symfony2Icons.TWIG_EXTENDS_FILE); | ||
icon.setIcon(Symfony2Icons.TWIG_EXTENDS_FILE, 1, SwingConstants.NORTH_WEST); | ||
} else { | ||
// icon should be below first one | ||
icon = new LayeredIcon(icon, Symfony2Icons.TWIG_IMPLEMENTS_FILE); | ||
icon.setIcon(Symfony2Icons.TWIG_EXTENDS_FILE, 1, 0, Symfony2Icons.TWIG_CONTROLLER_FILE.getIconHeight() + 1); | ||
} | ||
} | ||
|
||
return icon; | ||
} | ||
|
||
private boolean hasController(@NotNull TwigFile twigFile) { | ||
return TwigUtil.findTwigFileController(twigFile).size() > 0 | ||
|| TwigUtil.getTwigFileMethodUsageOnIndex(twigFile).size() > 0; | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.