package jetbrains.mps.editor.runtime.impl.cellActions;
/*Generated by MPS */
import jetbrains.mps.editor.runtime.cells.AbstractCellAction;
import jetbrains.mps.nodeEditor.selectionRestoring.RestorableSelection;
import jetbrains.mps.openapi.editor.EditorContext;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.nodeEditor.selectionRestoring.CellIdLocator;
import jetbrains.mps.nodeEditor.selectionRestoring.CellSelector;
import jetbrains.mps.openapi.editor.cells.EditorCell_Label;
import jetbrains.mps.nodeEditor.selectionRestoring.LabelCellSelector;
import jetbrains.mps.nodeEditor.selectionRestoring.WholeCellSelector;
import jetbrains.mps.nodeEditor.selectionRestoring.RestorableSelectionByCell;
import jetbrains.mps.openapi.editor.selection.Selection;
import jetbrains.mps.nodeEditor.selection.EditorCellLabelSelection;
import jetbrains.mps.openapi.editor.selection.SingularSelection;
public abstract class AbstractCommentAction extends AbstractCellAction {
protected RestorableSelection createRestorableSelection(EditorContext editorContext) {
EditorCell selectedCell = editorContext.getSelectedCell();
String cellId = check_j6szs9_a0b0a(selectedCell);
SNode selectedNode = check_j6szs9_a0c0a(selectedCell);
if (cellId == null || selectedNode == null) {
return null;
}
CellIdLocator locator = new CellIdLocator(cellId, selectedNode);
CellSelector selector;
if (selectedCell instanceof EditorCell_Label) {
EditorCell_Label label = ((EditorCell_Label) selectedCell);
selector = new LabelCellSelector(label.getCaretPosition(), label.getSelectionStart(), label.getSelectionEnd());
} else {
selector = new WholeCellSelector();
}
return new RestorableSelectionByCell(locator, selector);
}
public void execute(EditorContext editorContext) {
RestorableSelection restorableSelection = createRestorableSelection(editorContext);
executeInternal(editorContext);
editorContext.flushEvents();
check_j6szs9_a3a1(restorableSelection, editorContext);
}
protected boolean isNonTrivialSingleSelection(EditorContext editorContext) {
Selection selection = editorContext.getSelectionManager().getSelection();
return (selection instanceof EditorCellLabelSelection ? ((EditorCellLabelSelection) selection).hasNonTrivialSelection() : selection instanceof SingularSelection);
}
protected abstract void executeInternal(EditorContext editorContext);
private static String check_j6szs9_a0b0a(EditorCell checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getCellId();
}
return null;
}
private static SNode check_j6szs9_a0c0a(EditorCell checkedDotOperand) {
if (null != checkedDotOperand) {
return checkedDotOperand.getSNode();
}
return null;
}
private static boolean check_j6szs9_a3a1(RestorableSelection checkedDotOperand, EditorContext editorContext) {
if (null != checkedDotOperand) {
return checkedDotOperand.restore(editorContext);
}
return false;
}
}