Beispiel #1
0
int EBuffer::BlockSort(int Reverse) {
    int rq;
    ELine *oldL;

    if (CheckBlock() == 0) return 0;
    if (RCount == 0) return 0;

    SortMinRow = BB.Row;
    SortMaxRow = BE.Row;
    if (BlockMode != bmStream || BE.Col == 0)
        SortMaxRow--;

    if (SortMinRow >= SortMaxRow)
        return 1;

    SortBuffer = this;
    SortReverse = Reverse;
    switch (BlockMode) {
    case bmLine:
    case bmStream:
        SortMinCol = -1;
        SortMaxCol = -1;
        break;

    case bmColumn:
        SortMinCol = BB.Col;
        SortMaxCol = BE.Col;
        break;
    }

    SortRows = (int *)malloc((SortMaxRow - SortMinRow + 1) * sizeof(int));
    if (SortRows == 0) {
        free(SortRows);
        return 0;
    }
    for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++)
        SortRows[rq] = rq + SortMinRow;

    qsort(SortRows, SortMaxRow - SortMinRow + 1, sizeof(int), SortProc);

    // now change the order of lines according to new order in Rows array.

    for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++) {
        oldL = RLine(SortRows[rq]);
        if (InsLine(1 + rq + SortMaxRow, 0) == 0)
            return 0;
        if (InsChars(1 + rq + SortMaxRow, 0, oldL->Count, oldL->Chars) == 0)
            return 0;
    }

    for (rq = 0; rq <= SortMaxRow - SortMinRow; rq++)
        if (DelLine(SortMinRow) == 0)
            return 0;

    free(SortRows);
    return 1;
}
Beispiel #2
0
int EBuffer::LineAdd() {
    if (InsLine(VToR(CP.Row), 1) && MoveDown()) return 1;
    return 0;
}
Beispiel #3
0
int EBuffer::LineInsert() {
    if (InsLine(VToR(CP.Row), 0)) return 1;
    return 0;
}
Beispiel #4
0
int EBuffer::LineDuplicate() {
    int Y = VToR(CP.Row);
    if (InsLine(Y, 1) == 0) return 0;
    if (InsChars(Y + 1, 0, RLine(Y)->Count, RLine(Y)->Chars) == 0) return 0;
    return 1;
}
Beispiel #5
0
int EBuffer::BlockPaste(int clipboard) {
    EPoint B, E;
    int L, BL;

    if (SystemClipboard)
        GetPMClip(clipboard);

    if (SSBuffer == 0) return 0;
    if (SSBuffer->RCount == 0) return 0;
    AutoExtend = 0;
    BFI(SSBuffer, BFI_TabSize) = BFI(this, BFI_TabSize);
    BFI(SSBuffer, BFI_ExpandTabs) = BFI(this, BFI_ExpandTabs);
    BFI(SSBuffer, BFI_Undo) = 0;
    BlockUnmark();
    B.Row = VToR(CP.Row);
    B.Col = CP.Col;
    BL = B.Row;
    switch(BlockMode) {
    case bmLine:
        B.Col = 0;
        for (L = 0; L < SSBuffer->RCount; L++) {
            if (InsLine(BL, 0) == 0) return 0;
            if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0;
            BL++;
        }
        E.Row = BL;
        E.Col = 0;
        SetBB(B);
        SetBE(E);
        break;

    case bmColumn:
        for (L = 0; L < SSBuffer->RCount; L++) {
            if (AssertLine(BL) == 0) return 0;
            if (InsLineText(BL, B.Col, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0;
            if (TrimLine(BL) == 0) return 0;
            BL++;
        }
        if (AssertLine(BL) == 0) return 0;
        E.Row = BL;
        E.Col = B.Col + SSBuffer->LineLen(0);
        SetBB(B);
        SetBE(E);
        break;

    case bmStream:
        if (SSBuffer->RCount > 1)
            if (SplitLine(B.Row, B.Col) == 0) return 0;
        if (InsLineText(B.Row, B.Col, SSBuffer->LineLen(0), 0, SSBuffer->RLine(0)) == 0) return 0;
        E = B;
        E.Col += SSBuffer->LineLen(0);
        BL++;
        if (SSBuffer->RCount > 1) {
            for (L = 1; L < SSBuffer->RCount - 1; L++) {
                if (InsLine(BL, 0) == 0) return 0;
                if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0;
                BL++;
            }
            L = SSBuffer->RCount - 1;
            if (InsLineText(BL, 0, SSBuffer->LineLen(L), 0, SSBuffer->RLine(L)) == 0) return 0;
            E.Col = SSBuffer->LineLen(L);
            E.Row = BL;
        }
        SetBB(B);
        SetBE(E);
        break;
    }
    return 1;
}