Beispiel #1
0
YSelection YSelection::clip( const YInterval& bound ) const
{

    // dbg() << "YSelection::clip " << bound << endl << "*** INPUT ***" << endl << *this << "*** END INPUT ***" << endl;

    YBound limitFrom( bound.fromPos(), !bound.from().opened() );
    YBound limitTo( bound.toPos(), !bound.to().opened() );

    YSelection tmp( mName );
    tmp.setMap( mMap );
    YBound lastBound = mMap[ mMap.size() - 1 ].to();
    YBound firstBound = mMap[ 0 ].from();
    if ( lastBound > limitTo )
        tmp.delInterval( YInterval( limitTo, lastBound ) );
    if ( !tmp.isEmpty() && firstBound < limitFrom )
        tmp.delInterval( YInterval( firstBound, limitFrom ) );

    // dbg() << "*** TMP ****" << endl << tmp << "*** END TMP ***" << endl;

    YSelection ret( mName );

    unsigned int startX = bound.fromPos().x();
    unsigned int endX = bound.toPos().x();
    unsigned int fX, tX, fY, tY;
    for ( int i = 0; i < tmp.mMap.size(); ++i ) {
        fX = tmp.mMap[ i ].fromPos().x();
        fY = tmp.mMap[ i ].fromPos().y();
        tX = tmp.mMap[ i ].toPos().x();
        tY = tmp.mMap[ i ].toPos().y();
        if ( !( fY == tY && ( fX > endX || tX < startX ) ) ) {
            if ( fX <= endX ) {
                fX = qMax( fX, startX );
            } else {
                ++fY;
                fX = startX;
            }
            if ( tX >= startX ) {
                tX = qMin( tX, endX );
            } else if ( fY < tY ) {
                --tY;
                tX = endX;
            } else {
                continue;
            }
            ret.addInterval( YInterval( YCursor( fX, fY ), YCursor( tX, tY ) ) );
        }
    }

    // dbg() << "#### result #####" << endl << ret << "#### end result ####" << endl;

    return ret;
}
Beispiel #2
0
void NYView::guiScroll(int dx, int dy)
{
    Q_UNUSED(dx); //TODO

    if(dy >= getLinesVisible()) {
        guiPaintEvent(YSelection(YInterval(YCursor(0, 0), YCursor(getColumnsVisible() - 1, getLinesVisible() - 1))));
    } else {
        scrollok(editor, true);
        wscrl(editor, dy);
        scrollok(editor, false);
        int top = 0;
        int n = qAbs(dy);

        if(dy > 0) {
            /* redraw the new bottom */
            top += getLinesVisible() - n;
        }

        guiPaintEvent(YSelection(YInterval(YCursor(0, top), YCursor(getColumnsVisible() - 1, top + n - 1))));
    }
}
Beispiel #3
0
bool YSwapFile::recover()
{
    mRecovering = true;
    QFile f( mFilename );
    if ( f.open( QIODevice::ReadOnly ) ) {
        QTextStream stream( &f );
        while ( !stream.atEnd() ) {
            QString line = stream.readLine();
            QRegExp rx("([0-9]) ([0-9]*) ([0-9]*) ([01]) ([0-9]*) ([0-9]*) ([01])");
			bool error = !stream.atEnd();
            if ( !error && rx.exactMatch( line ) ) {
				YBufferOperation::OperationType type = (YBufferOperation::OperationType)rx.cap(1).toInt();
				YBound from = YBound(YCursor(rx.cap(2).toInt(),rx.cap(3).toInt()), rx.cap(4) == "0");
				YBound to = YBound(YCursor(rx.cap(5).toInt(),rx.cap(6).toInt()), rx.cap(7) == "0");
				YRawData data;
				line = stream.readLine();
				while ( !error && line.length() > 0 ) {
					if ( stream.atEnd() ) {
						error = true;
					} else {
						data << line.mid(1);
						line = stream.readLine();
					}
				}
				if ( !error ) {
					replay(type, YInterval(from, to), data);
				}
			} else {
				error = true;
			}
			if ( error ) {
                dbg() << "Error reading swap file" << endl;
            }
        }
        f.close();
    } else {
        YSession::self()->guiPopupMessage(_( "The swap file could not be opened, there will be no recovering for this file, you might want to check permissions of files." ));
        mRecovering = false;
        return false;
    }

    mRecovering = false;
    return true;
}
Beispiel #4
0
const YInterval operator- ( const YInterval& l, const YCursor r )
{
    return YInterval( qMax(l.from() - r, YBound(YCursor(0, 0))), qMax(l.to() - r, YBound(YCursor(0, 0), true)) );
}
Beispiel #5
0
YInterval YInterval::intersection( const YInterval& i ) const
{
	return YInterval(i.from() < from() ? from() : i.from(), i.to() < to() ? i.to() : to());
}