Search in sources :

Example 1 with ArrangementMatchingRulesControl

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl in project intellij-community by JetBrains.

the class RemoveArrangementRuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null) {
        return;
    }
    control.hideEditor();
    final TIntArrayList rowsToRemove = control.getSelectedModelRows();
    if (rowsToRemove.isEmpty()) {
        return;
    }
    final ArrangementMatchingRulesModel model = control.getModel();
    control.runOperationIgnoreSelectionChange(() -> {
        for (int i = 0; i < rowsToRemove.size(); i++) {
            int row = rowsToRemove.get(i);
            model.removeRow(row);
        }
    });
}
Also used : ArrangementMatchingRulesModel(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel) ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl) TIntArrayList(gnu.trove.TIntArrayList)

Example 2 with ArrangementMatchingRulesControl

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl in project intellij-community by JetBrains.

the class AbstractMoveArrangementRuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null) {
        return;
    }
    final int editing = control.getEditingRow() - 1;
    control.runOperationIgnoreSelectionChange(() -> {
        control.hideEditor();
        final List<int[]> mappings = new ArrayList<>();
        fillMappings(control, mappings);
        if (mappings.isEmpty()) {
            return;
        }
        int newRowToEdit = editing;
        ArrangementMatchingRulesModel model = control.getModel();
        Object value;
        int from;
        int to;
        for (int[] pair : mappings) {
            from = pair[0];
            to = pair[1];
            if (from != to) {
                value = model.getElementAt(from);
                model.removeRow(from);
                model.insert(to, value);
                if (newRowToEdit == from) {
                    newRowToEdit = to;
                }
            }
        }
        ListSelectionModel selectionModel = control.getSelectionModel();
        for (int[] pair : mappings) {
            selectionModel.addSelectionInterval(pair[1], pair[1]);
        }
        int visibleRow = -1;
        if (newRowToEdit >= 0) {
            control.showEditor(newRowToEdit);
            visibleRow = newRowToEdit;
        } else if (!mappings.isEmpty()) {
            visibleRow = mappings.get(0)[1];
        }
        if (visibleRow != -1) {
            scrollRowToVisible(control, visibleRow);
        }
    });
    control.repaintRows(0, control.getModel().getSize() - 1, true);
}
Also used : ArrangementMatchingRulesModel(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel) ArrayList(java.util.ArrayList) ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)

Example 3 with ArrangementMatchingRulesControl

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl in project intellij-community by JetBrains.

the class AbstractMoveArrangementRuleAction method update.

@Override
public void update(AnActionEvent e) {
    ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null) {
        e.getPresentation().setEnabled(false);
        return;
    }
    final List<int[]> mappings = new ArrayList<>();
    fillMappings(control, mappings);
    for (int[] mapping : mappings) {
        if (mapping[0] != mapping[1]) {
            e.getPresentation().setEnabled(true);
            return;
        }
    }
    e.getPresentation().setEnabled(false);
}
Also used : ArrayList(java.util.ArrayList) ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)

Example 4 with ArrangementMatchingRulesControl

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl in project intellij-community by JetBrains.

the class AddArrangementRuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null) {
        return;
    }
    control.hideEditor();
    TIntArrayList rows = control.getSelectedModelRows();
    ArrangementMatchingRulesModel model = control.getModel();
    int rowToEdit;
    if (rows.size() == 1) {
        rowToEdit = rows.get(0) + 1;
        model.insertRow(rowToEdit, new Object[] { createNewRule(control) });
    } else {
        rowToEdit = model.getSize();
        model.add(createNewRule(control));
    }
    showEditor(control, rowToEdit);
    control.getSelectionModel().setSelectionInterval(rowToEdit, rowToEdit);
    scrollRowToVisible(control, rowToEdit);
}
Also used : ArrangementMatchingRulesModel(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel) ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl) TIntArrayList(gnu.trove.TIntArrayList)

Example 5 with ArrangementMatchingRulesControl

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl in project intellij-community by JetBrains.

the class AddArrangementSectionRuleAction method update.

@Override
public void update(AnActionEvent e) {
    final ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null || !(control instanceof ArrangementSectionRulesControl)) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setEnabledAndVisible(((ArrangementSectionRulesControl) control).getSectionRuleManager() != null);
}
Also used : ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl) ArrangementSectionRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRulesControl)

Aggregations

ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)9 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)3 TIntArrayList (gnu.trove.TIntArrayList)3 ArrayList (java.util.ArrayList)2 ArrangementSectionRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementSectionRulesControl)1