Search in sources :

Example 1 with TemplateToolkitSettings

use of com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings in project Perl5-IDEA by Camelcade.

the class TemplateToolkitEditorNotificationsProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() == TemplateToolkitFileType.INSTANCE) {
        TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(myProject);
        if (!settings.isVirtualFileUnderRoot(file)) {
            EditorNotificationPanel panel = new EditorNotificationPanel();
            panel.setText(PerlBundle.message("tt2.error.file.not.in.root"));
            panel.createActionLabel("Configure", () -> Perl5SettingsConfigurable.open(myProject));
            return panel;
        }
    }
    return null;
}
Also used : TemplateToolkitSettings(com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TemplateToolkitSettings

use of com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings in project Perl5-IDEA by Camelcade.

the class TemplateToolkitEditorTest method testAutocloseTagCustom.

public void testAutocloseTagCustom() {
    saveSettings();
    TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(getProject());
    settings.START_TAG = "%SOME%=";
    settings.END_TAG = "/ENDTAG$";
    testSmartKey("%SOME%<caret>", '=', "%SOME%=  /ENDTAG$");
    restoreSettings();
}
Also used : TemplateToolkitSettings(com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings)

Example 3 with TemplateToolkitSettings

use of com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings in project Perl5-IDEA by Camelcade.

the class TemplateToolkitTypedHandler method processChar.

protected Result processChar(char c, Project project, Editor editor, PsiFile file, FileType fileType) {
    FileViewProvider viewProvider = file.getViewProvider();
    if (!(viewProvider instanceof TemplateToolkitFileViewProvider)) {
        return null;
    }
    TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(project);
    String openTag = settings.START_TAG;
    if (StringUtil.isEmpty(openTag) || c != openTag.charAt(openTag.length() - 1)) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    if (offset == 0) {
        return null;
    }
    PsiElement element = viewProvider.findElementAt(offset - 1, TemplateToolkitLanguage.INSTANCE);
    if (element == null) {
        return null;
    }
    IElementType tokenType = element.getNode().getElementType();
    if (tokenType != TT2_HTML) {
        return null;
    }
    String openTagPrefix = openTag.substring(0, openTag.length() - 1);
    if (openTagPrefix.length() == 0) {
        return null;
    }
    int startOffset = offset - openTagPrefix.length();
    if (startOffset < 0) {
        return null;
    }
    if (StringUtil.equals(file.getText().subSequence(startOffset, offset), openTagPrefix)) {
        EditorModificationUtil.insertStringAtCaret(editor, c + "  " + settings.END_TAG, false, true, 2);
        return Result.STOP;
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) TemplateToolkitSettings(com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings) TemplateToolkitFileViewProvider(com.perl5.lang.tt2.TemplateToolkitFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) TemplateToolkitFileViewProvider(com.perl5.lang.tt2.TemplateToolkitFileViewProvider) PsiElement(com.intellij.psi.PsiElement)

Example 4 with TemplateToolkitSettings

use of com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings in project Perl5-IDEA by Camelcade.

the class TemplateToolkitTestSettings method tearDown.

public void tearDown() {
    TemplateToolkitSettings templateToolkitSettings = TemplateToolkitSettings.getInstance(myProject);
    templateToolkitSettings.START_TAG = myOpenTagBackup;
    templateToolkitSettings.END_TAG = myCloseTagBackup;
    templateToolkitSettings.OUTLINE_TAG = myOutlineTagBackup;
    templateToolkitSettings.ENABLE_ANYCASE = myEnableAnyCase;
}
Also used : TemplateToolkitSettings(com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings)

Example 5 with TemplateToolkitSettings

use of com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings in project Perl5-IDEA by Camelcade.

the class TemplateToolkitTestSettings method setUp.

public void setUp() {
    TemplateToolkitSettings templateToolkitSettings = TemplateToolkitSettings.getInstance(myProject);
    myOpenTagBackup = templateToolkitSettings.START_TAG;
    myCloseTagBackup = templateToolkitSettings.END_TAG;
    myOutlineTagBackup = templateToolkitSettings.OUTLINE_TAG;
    myEnableAnyCase = templateToolkitSettings.ENABLE_ANYCASE;
    templateToolkitSettings.START_TAG = TemplateToolkitSettings.DEFAULT_START_TAG;
    templateToolkitSettings.END_TAG = TemplateToolkitSettings.DEFAULT_END_TAG;
    templateToolkitSettings.OUTLINE_TAG = TemplateToolkitSettings.DEFAULT_OUTLINE_TAG;
    templateToolkitSettings.ENABLE_ANYCASE = false;
}
Also used : TemplateToolkitSettings(com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings)

Aggregations

TemplateToolkitSettings (com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings)5 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiElement (com.intellij.psi.PsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)1 TemplateToolkitFileViewProvider (com.perl5.lang.tt2.TemplateToolkitFileViewProvider)1 Nullable (org.jetbrains.annotations.Nullable)1