Search in sources :

Example 1 with HTMLMasonCustomTag

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag in project Perl5-IDEA by Camelcade.

the class HTMLMasonBaseLexer method processCustomSimpleOpenTag.

protected IElementType processCustomSimpleOpenTag() {
    CharSequence tokenText = yytext();
    CharSequence tokenKey = tokenText.subSequence(0, tokenText.length() - 1);
    assert myCustomTagsMap != null;
    HTMLMasonCustomTag customTag = myCustomTagsMap.get(tokenKey.toString());
    if (customTag != null) {
        HTMLMasonCustomTagRole tagRole = customTag.getRole();
        if (tagRole == HTMLMasonCustomTagRole.ARGS) {
            return processArgsOpenTag(ARGS_WITH_CUSTOM_CLOSER);
        } else if (tagRole == HTMLMasonCustomTagRole.PERL) {
            return processPerlOpenTag(PERL_WITH_CUSTOM_CLOSER);
        }
    }
    return processOpenTagFallback();
}
Also used : HTMLMasonCustomTag(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag) HTMLMasonCustomTagRole(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTagRole)

Example 2 with HTMLMasonCustomTag

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag in project Perl5-IDEA by Camelcade.

the class HTMLMasonBaseLexer method processCustomCloseTag.

protected IElementType processCustomCloseTag() {
    CharSequence tokenText = yytext();
    CharSequence tokenKey = tokenText.subSequence(0, tokenText.length() - 1);
    assert myCustomTagsMap != null;
    HTMLMasonCustomTag customTag = myCustomTagsMap.get(tokenKey.toString());
    if (customTag != null) {
        HTMLMasonCustomTagRole tagRole = customTag.getRole();
        if (tagRole == HTMLMasonCustomTagRole.METHOD) {
            return processMethodCloseTag();
        } else if (tagRole == HTMLMasonCustomTagRole.DEF) {
            return processDefCloseTag();
        }
    }
    return processCloseTagFallback();
}
Also used : HTMLMasonCustomTag(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag) HTMLMasonCustomTagRole(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTagRole)

Example 3 with HTMLMasonCustomTag

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag in project Perl5-IDEA by Camelcade.

the class HTMLMasonParserTest method addCustomTag.

private void addCustomTag(String text, HTMLMasonCustomTagRole role) {
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    settings.customTags.add(new HTMLMasonCustomTag(text, role));
    settings.settingsUpdated();
}
Also used : HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) HTMLMasonCustomTag(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag)

Example 4 with HTMLMasonCustomTag

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag in project Perl5-IDEA by Camelcade.

the class HTMLMasonSettingsConfigurable method createCustomTagsComponent.

protected void createCustomTagsComponent(FormBuilder builder) {
    myTagNameColumnInfo myTagNameColumnInfo = new myTagNameColumnInfo();
    customTagsModel = new ListTableModel<>(myTagNameColumnInfo, new myTagRoleColumInfo());
    myTagNameColumnInfo.setCustomTagsModel(customTagsModel);
    customTagsTable = new JBTable(customTagsModel);
    final TableColumn secondColumn = customTagsTable.getColumnModel().getColumn(1);
    ComboBoxTableRenderer<HTMLMasonCustomTagRole> roleComboBoxTableRenderer = new ComboBoxTableRenderer<HTMLMasonCustomTagRole>(HTMLMasonCustomTagRole.values()) {

        @Override
        protected String getTextFor(@NotNull HTMLMasonCustomTagRole value) {
            return value.getTitle();
        }

        @Override
        public boolean isCellEditable(EventObject event) {
            if (event instanceof MouseEvent) {
                return ((MouseEvent) event).getClickCount() >= 1;
            }
            return true;
        }
    };
    secondColumn.setCellRenderer(roleComboBoxTableRenderer);
    secondColumn.setCellEditor(roleComboBoxTableRenderer);
    builder.addLabeledComponent(new JLabel("Custom tags that mimics built-in HTML::Mason tags:"), ToolbarDecorator.createDecorator(customTagsTable).setAddAction(anActionButton -> {
        final TableCellEditor cellEditor = customTagsTable.getCellEditor();
        if (cellEditor != null) {
            cellEditor.stopCellEditing();
        }
        final TableModel model = customTagsTable.getModel();
        int indexToEdit = -1;
        for (HTMLMasonCustomTag entry : customTagsModel.getItems()) {
            if (StringUtil.isEmpty(entry.getText())) {
                indexToEdit = customTagsModel.indexOf(entry);
                break;
            }
        }
        if (indexToEdit == -1) {
            customTagsModel.addRow(new HTMLMasonCustomTag("customTag" + customTagsModel.getItems().size(), HTMLMasonCustomTagRole.PERL));
            indexToEdit = model.getRowCount() - 1;
        }
        TableUtil.editCellAt(customTagsTable, indexToEdit, 0);
    }).disableDownAction().disableUpAction().setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) WriteAction(com.intellij.openapi.application.WriteAction) PerlLexer(com.perl5.lang.perl.lexer.PerlLexer) HTMLMasonSyntaxElements(com.perl5.lang.htmlmason.HTMLMasonSyntaxElements) ColumnInfo(com.intellij.util.ui.ColumnInfo) THashSet(gnu.trove.THashSet) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) ArrayList(java.util.ArrayList) EventObject(java.util.EventObject) TableCellEditor(javax.swing.table.TableCellEditor) JBUI(com.intellij.util.ui.JBUI) TableUtil(com.intellij.ui.TableUtil) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) ListTableModel(com.intellij.util.ui.ListTableModel) TableModel(javax.swing.table.TableModel) JBList(com.intellij.ui.components.JBList) VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) StringUtil(com.intellij.openapi.util.text.StringUtil) TableColumn(javax.swing.table.TableColumn) PerlConfigurationUtil(com.perl5.lang.perl.util.PerlConfigurationUtil) Set(java.util.Set) ComboBoxTableRenderer(com.intellij.openapi.ui.ComboBoxTableRenderer) CollectionListModel(com.intellij.ui.CollectionListModel) FileTypeManagerEx(com.intellij.openapi.fileTypes.ex.FileTypeManagerEx) MouseEvent(java.awt.event.MouseEvent) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull) FormBuilder(com.intellij.util.ui.FormBuilder) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) NotNull(org.jetbrains.annotations.NotNull) EventObject(java.util.EventObject) ComboBoxTableRenderer(com.intellij.openapi.ui.ComboBoxTableRenderer) TableCellEditor(javax.swing.table.TableCellEditor) ListTableModel(com.intellij.util.ui.ListTableModel) TableModel(javax.swing.table.TableModel)

Example 5 with HTMLMasonCustomTag

use of com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag in project Perl5-IDEA by Camelcade.

the class HTMLMasonSettingsConfigurable method reset.

@Override
public void reset() {
    substitutedExtensionsModel.removeAll();
    substitutedExtensionsModel.add(mySettings.substitutedExtensions);
    autohandlerName.setText(mySettings.autoHandlerName);
    defaulthandlerName.setText(mySettings.defaultHandlerName);
    customTagsModel.setItems(new ArrayList<>());
    for (HTMLMasonCustomTag htmlMasonCustomTag : mySettings.customTags) {
        customTagsModel.addRow(htmlMasonCustomTag.clone());
    }
    globalsModel.setItems(new ArrayList<>());
    for (VariableDescription variableDescription : mySettings.globalVariables) {
        globalsModel.addRow(variableDescription.clone());
    }
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription)

Aggregations

HTMLMasonCustomTag (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTag)5 HTMLMasonCustomTagRole (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonCustomTagRole)2 VariableDescription (com.perl5.lang.mason2.idea.configuration.VariableDescription)2 WriteAction (com.intellij.openapi.application.WriteAction)1 FileTypeManagerEx (com.intellij.openapi.fileTypes.ex.FileTypeManagerEx)1 Project (com.intellij.openapi.project.Project)1 ComboBoxTableRenderer (com.intellij.openapi.ui.ComboBoxTableRenderer)1 Messages (com.intellij.openapi.ui.Messages)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 CollectionListModel (com.intellij.ui.CollectionListModel)1 TableUtil (com.intellij.ui.TableUtil)1 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)1 JBList (com.intellij.ui.components.JBList)1 JBTable (com.intellij.ui.table.JBTable)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 FormBuilder (com.intellij.util.ui.FormBuilder)1 JBUI (com.intellij.util.ui.JBUI)1 ListTableModel (com.intellij.util.ui.ListTableModel)1 HTMLMasonSyntaxElements (com.perl5.lang.htmlmason.HTMLMasonSyntaxElements)1