Search in sources :

Example 1 with ArrangementMatchingRulesModel

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel 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 ArrangementMatchingRulesModel

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel 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 ArrangementMatchingRulesModel

use of com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel 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)

Aggregations

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