Kaydet (Commit) 2c945010 authored tarafından Matúš Kukan's avatar Matúš Kukan

datastreams: implement moving the import range down until the limit is reached

Change-Id: Iaaed4399a980697c37683d838fcb1f99208233e8
üst ac435437
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
namespace datastreams { class CallerThread; } namespace datastreams { class CallerThread; }
namespace { class DataStreamsDlg; }
class ScDocShell; class ScDocShell;
class ScDocument; class ScDocument;
class ScRange; class ScRange;
...@@ -24,26 +25,31 @@ class Window; ...@@ -24,26 +25,31 @@ class Window;
class DataStreams : boost::noncopyable class DataStreams : boost::noncopyable
{ {
friend DataStreamsDlg;
enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP };
ScDocShell *mpScDocShell; ScDocShell *mpScDocShell;
ScDocument *mpScDocument; ScDocument *mpScDocument;
bool mbMove; MoveEnum meMove;
bool mbRunning; bool mbRunning;
bool mbIsUndoEnabled; bool mbIsUndoEnabled;
boost::scoped_ptr<ScRange> mpRange; boost::scoped_ptr<ScRange> mpRange;
boost::scoped_ptr<ScRange> mpStartRange;
boost::scoped_ptr<ScRange> mpEndRange; boost::scoped_ptr<ScRange> mpEndRange;
boost::scoped_ptr<SvStream> mpStream; boost::scoped_ptr<SvStream> mpStream;
rtl::Reference<datastreams::CallerThread> mxThread; rtl::Reference<datastreams::CallerThread> mxThread;
public: public:
DataStreams(ScDocShell *pScDocShell); DataStreams(ScDocShell *pScDocShell);
virtual ~DataStreams(); ~DataStreams();
bool ImportData(); bool ImportData();
void Move();
void ShowDialog(Window *pParent); void ShowDialog(Window *pParent);
private:
void MoveData();
void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange,
sal_Int32 nLimit, MoveEnum eMove);
void Start(); void Start();
void Stop(); void Stop();
void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange);
void SetMove(sal_Int32 nLimit);
}; };
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <asciiopt.hxx> #include <asciiopt.hxx>
#include <docsh.hxx> #include <docsh.hxx>
#include <impex.hxx> #include <impex.hxx>
#include <viewdata.hxx>
#include <dbfunc.hxx>
namespace datastreams { namespace datastreams {
...@@ -54,7 +56,7 @@ private: ...@@ -54,7 +56,7 @@ private:
DataStreams::DataStreams(ScDocShell *pScDocShell): DataStreams::DataStreams(ScDocShell *pScDocShell):
mpScDocShell(pScDocShell) mpScDocShell(pScDocShell)
, mpScDocument(mpScDocShell->GetDocument()) , mpScDocument(mpScDocShell->GetDocument())
, mbMove(false) , meMove(NO_MOVE)
{ {
mxThread = new datastreams::CallerThread( this ); mxThread = new datastreams::CallerThread( this );
mxThread->launch(); mxThread->launch();
...@@ -81,23 +83,21 @@ void DataStreams::Stop() ...@@ -81,23 +83,21 @@ void DataStreams::Stop()
{ {
mbRunning = false; mbRunning = false;
mpScDocument->EnableUndo(mbIsUndoEnabled); mpScDocument->EnableUndo(mbIsUndoEnabled);
mbMove = false;
} }
void DataStreams::Set(const OUString& rUrl, bool bIsScript, const OUString& rRange) void DataStreams::Set(const OUString& rUrl, bool bIsScript,
const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove)
{ {
mpRange.reset ( new ScRange() ); mpRange.reset ( new ScRange() );
mpRange->Parse(rRange, mpScDocument); mpRange->Parse(rRange, mpScDocument);
mpStartRange.reset( new ScRange(*mpRange.get()) );
if (bIsScript) if (bIsScript)
mpStream.reset( new SvScriptStream(rUrl) ); mpStream.reset( new SvScriptStream(rUrl) );
else else
mpStream.reset( new SvFileStream(rUrl, STREAM_READ) ); mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
}
void DataStreams::SetMove(sal_Int32 nLimit)
{
mpEndRange.reset( NULL ); mpEndRange.reset( NULL );
mbMove = true; meMove = eMove;
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
nLimit = nHeight * (nLimit / nHeight); nLimit = nHeight * (nLimit / nHeight);
if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW) if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW)
...@@ -107,15 +107,26 @@ void DataStreams::SetMove(sal_Int32 nLimit) ...@@ -107,15 +107,26 @@ void DataStreams::SetMove(sal_Int32 nLimit)
} }
} }
void DataStreams::Move() void DataStreams::MoveData()
{ {
if (!mbMove) switch (meMove)
return;
if (mpEndRange.get())
{ {
mpScDocument->DeleteRow(*mpEndRange); case RANGE_DOWN:
if (mpRange->aStart == mpEndRange->aStart)
meMove = MOVE_UP;
break;
case MOVE_UP:
mpScDocument->DeleteRow(*mpStartRange);
mpScDocument->InsertRow(*mpEndRange);
break;
case MOVE_DOWN:
if (mpEndRange.get())
mpScDocument->DeleteRow(*mpEndRange);
mpScDocument->InsertRow(*mpRange);
break;
case NO_MOVE:
break;
} }
mpScDocument->InsertRow(*mpRange);
} }
bool DataStreams::ImportData() bool DataStreams::ImportData()
...@@ -127,8 +138,6 @@ bool DataStreams::ImportData() ...@@ -127,8 +138,6 @@ bool DataStreams::ImportData()
return mbRunning; return mbRunning;
} }
SolarMutexGuard aGuard;
Move();
SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
OStringBuffer aBuf; OStringBuffer aBuf;
OString sTmp; OString sTmp;
...@@ -138,17 +147,25 @@ bool DataStreams::ImportData() ...@@ -138,17 +147,25 @@ bool DataStreams::ImportData()
aBuf.append(sTmp); aBuf.append(sTmp);
aBuf.append('\n'); aBuf.append('\n');
} }
SolarMutexGuard aGuard;
MoveData();
SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ); SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
ScImportExport aImport(mpScDocument, *mpRange); ScImportExport aImport(mpScDocument, *mpRange);
aImport.SetSeparator(','); aImport.SetSeparator(',');
aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING); aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
// ImportStream calls PostPaint for relevant area, // ImportStream calls PostPaint for relevant area,
// we need to call it explicitly only when moving rows. // we need to call it explicitly only when moving rows.
if (!mbMove) if (meMove == NO_MOVE)
return mbRunning; return mbRunning;
if (meMove == RANGE_DOWN)
{
mpRange->Move(0, mpRange->aEnd.Row() - mpRange->aStart.Row() + 1, 0);
mpScDocShell->GetViewData()->GetView()->AlignToCursor(
mpRange->aStart.Col(), mpRange->aStart.Row(), SC_FOLLOW_JUMP);
}
SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW; SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW;
mpScDocShell->PostPaint( ScRange( mpRange->aStart, ScAddress( mpRange->aEnd.Col(), mpScDocShell->PostPaint( ScRange( mpStartRange->aStart, ScAddress( mpRange->aEnd.Col(),
aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID ); aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID );
return mbRunning; return mbRunning;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment