Search in sources :

Example 11 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.

the class KeyEditAction method run.

public void run(NatTable natTable, KeyEvent event) {
    Character character = null;
    if (LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character) || event.character == ' ') {
        character = Character.valueOf(event.character);
    }
    if (character != null) {
        int[] selectedRowIndexs = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows();
        if (selectedRowIndexs.length == 0) {
            return;
        }
        Arrays.sort(selectedRowIndexs);
        int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
        ViewportLayer viewportLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        // 先记录下可见区域的范围
        int originRowPosition = viewportLayer.getOriginRowPosition();
        // 总行数
        int rowCount = viewportLayer.getRowCount();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            rowIndex = rowIndex * 2;
        }
        if (rowIndex < originRowPosition || rowIndex > originRowPosition + rowCount || HsMultiActiveCellEditor.getTargetEditor() == null) {
            HsMultiActiveCellEditor.commit(true);
            PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
            if (!editor.isHorizontalLayout()) {
                natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
            } else {
                if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                    p.columnPosition = editor.getTgtColumnIndex();
                }
                natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
            }
            HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
            StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
            if (cellEditor != null && cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
                cellEditor.insertCanonicalValue(character);
            }
        }
    } else if ((event.character == SWT.CR) && event.stateMask == SWT.NONE) {
        HsMultiActiveCellEditor.commit(true);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
        } else {
            if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                p.columnPosition = editor.getTgtColumnIndex();
            }
            natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Aggregations

StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)11 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)9 IEditorPart (org.eclipse.ui.IEditorPart)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)4 ArrayList (java.util.ArrayList)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)2 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)2 StyledText (org.eclipse.swt.custom.StyledText)2 Point (org.eclipse.swt.graphics.Point)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 SegmentViewer (net.heartsome.cat.ts.ui.innertag.SegmentViewer)1 UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)1 EditableManager (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager)1 SourceEditMode (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode)1