Search in sources :

Example 1 with VariableDescription

use of com.perl5.lang.mason2.idea.configuration.VariableDescription in project Perl5-IDEA by Camelcade.

the class AbstractMasonSettingsConfigurable method createGlobalsComponent.

public void createGlobalsComponent(FormBuilder builder) {
    globalsModel = new ListTableModel<>(new myVariableNameColumnInfo(), new myVariableTypeColumnInfo());
    globalsTable = new JBTable(globalsModel);
    builder.addLabeledComponent(new JLabel("Components global variables (allow_globals option):"), ToolbarDecorator.createDecorator(globalsTable).setAddAction(anActionButton -> {
        final TableCellEditor cellEditor = globalsTable.getCellEditor();
        if (cellEditor != null) {
            cellEditor.stopCellEditing();
        }
        final TableModel model = globalsTable.getModel();
        int indexToEdit = -1;
        for (VariableDescription variableDescription : globalsModel.getItems()) {
            if (StringUtil.isEmpty(variableDescription.variableName)) {
                indexToEdit = globalsModel.indexOf(variableDescription);
                break;
            }
        }
        if (indexToEdit == -1) {
            globalsModel.addRow(new VariableDescription());
            indexToEdit = model.getRowCount() - 1;
        }
        TableUtil.editCellAt(globalsTable, indexToEdit, 0);
    }).disableDownAction().disableUpAction().setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel());
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) PerlLexer(com.perl5.lang.perl.lexer.PerlLexer) StringUtil(com.intellij.openapi.util.text.StringUtil) PerlConfigurationUtil(com.perl5.lang.perl.util.PerlConfigurationUtil) Configurable(com.intellij.openapi.options.Configurable) ColumnInfo(com.intellij.util.ui.ColumnInfo) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) Nls(org.jetbrains.annotations.Nls) 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) Pattern(java.util.regex.Pattern) FormBuilder(com.intellij.util.ui.FormBuilder) PerlBaseLexer(com.perl5.lang.perl.lexer.PerlBaseLexer) javax.swing(javax.swing) TableModel(javax.swing.table.TableModel) VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) TableCellEditor(javax.swing.table.TableCellEditor) JBTable(com.intellij.ui.table.JBTable) ListTableModel(com.intellij.util.ui.ListTableModel) TableModel(javax.swing.table.TableModel)

Example 2 with VariableDescription

use of com.perl5.lang.mason2.idea.configuration.VariableDescription in project Perl5-IDEA by Camelcade.

the class HTMLMasonSettingsConfigurable method apply.

@Override
public void apply() {
    boolean forceReparse = isStructureModified();
    Set<String> extDiff = getDiff(mySettings.substitutedExtensions, substitutedExtensionsModel.getItems());
    mySettings.substitutedExtensions.clear();
    mySettings.substitutedExtensions.addAll(substitutedExtensionsModel.getItems());
    mySettings.autoHandlerName = autohandlerName.getText();
    mySettings.defaultHandlerName = defaulthandlerName.getText();
    mySettings.globalVariables.clear();
    for (VariableDescription variableDescription : new ArrayList<>(globalsModel.getItems())) {
        if (StringUtil.isNotEmpty(variableDescription.variableName)) {
            mySettings.globalVariables.add(variableDescription);
        } else {
            globalsModel.removeRow(globalsModel.indexOf(variableDescription));
        }
    }
    mySettings.customTags.clear();
    mySettings.customTags.addAll(customTagsModel.getItems());
    mySettings.settingsUpdated();
    if (!extDiff.isEmpty() || forceReparse) {
        // fixme move this logic to the settings
        WriteAction.run(() -> FileTypeManagerEx.getInstanceEx().fireFileTypesChanged());
    }
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) ArrayList(java.util.ArrayList)

Example 3 with VariableDescription

use of com.perl5.lang.mason2.idea.configuration.VariableDescription in project Perl5-IDEA by Camelcade.

the class HTMLMasonArgsDefVariablesResolveTest method doTestResolve.

@Override
public void doTestResolve() {
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    settings.globalVariables.add(new VariableDescription("$product", "Foo::Bar"));
    settings.settingsUpdated();
    super.doTestResolve();
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription) HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)

Example 4 with VariableDescription

use of com.perl5.lang.mason2.idea.configuration.VariableDescription 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)

Example 5 with VariableDescription

use of com.perl5.lang.mason2.idea.configuration.VariableDescription in project Perl5-IDEA by Camelcade.

the class MasonCoreUtil method fillVariablesList.

public static void fillVariablesList(PsiElement parent, List<PerlVariableDeclarationElement> targetList, List<VariableDescription> sourceList) {
    for (VariableDescription variableDescription : sourceList) {
        String variableType = variableDescription.variableType;
        if (StringUtil.isEmpty(variableType)) {
            variableType = null;
        }
        targetList.add(PerlImplicitVariableDeclaration.createGlobal(parent, variableDescription.variableName, variableType));
    }
}
Also used : VariableDescription(com.perl5.lang.mason2.idea.configuration.VariableDescription)

Aggregations

VariableDescription (com.perl5.lang.mason2.idea.configuration.VariableDescription)5 Configurable (com.intellij.openapi.options.Configurable)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 TableUtil (com.intellij.ui.TableUtil)1 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)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 HTMLMasonSettings (com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings)1 PerlBaseLexer (com.perl5.lang.perl.lexer.PerlBaseLexer)1 PerlLexer (com.perl5.lang.perl.lexer.PerlLexer)1 PerlConfigurationUtil (com.perl5.lang.perl.util.PerlConfigurationUtil)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 javax.swing (javax.swing)1 TableCellEditor (javax.swing.table.TableCellEditor)1