[Libreoffice-commits] core.git: Branch 'private/matus/sc-hacks' - sc/source

Matúš Kukan matus.kukan at gmail.com
Mon Nov 11 13:28:47 PST 2013


 sc/source/ui/inc/datastreams.hxx         |    7 ++--
 sc/source/ui/miscdlgs/datastreams.cxx    |   45 +++++++++++++++++++------------
 sc/source/ui/miscdlgs/datastreamsdlg.cxx |    2 -
 3 files changed, 34 insertions(+), 20 deletions(-)

New commits:
commit 0e5bdef60037160cb3cbed09e25f147420640069
Author: Matúš Kukan <matus.kukan at gmail.com>
Date:   Mon Nov 11 22:26:54 2013 +0100

    datastreams: implement moving the import range down until the limit is reached
    
    Change-Id: Iaaed4399a980697c37683d838fcb1f99208233e8

diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx
index fa04e41..ae807df 100644
--- a/sc/source/ui/inc/datastreams.hxx
+++ b/sc/source/ui/inc/datastreams.hxx
@@ -27,9 +27,10 @@ class DataStreams
     Dialog *mpDialog;
     ScDocShell *mpScDocShell;
     ScDocument *mpScDocument;
-    bool mbMove;
+    enum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP } meMove;
     bool mbRunning;
     boost::scoped_ptr<ScRange> mpRange;
+    boost::scoped_ptr<ScRange> mpStartRange;
     boost::scoped_ptr<ScRange> mpEndRange;
     boost::scoped_ptr<SvStream> mpStream;
     rtl::Reference<datastreams::CallerThread> mxThread;
@@ -38,12 +39,12 @@ public:
     DataStreams(ScDocShell *pScDocShell);
     virtual ~DataStreams();
     bool ImportData();
-    void Move();
+    void MoveData();
     void ShowDialog(Window *pParent);
     void Start();
     void Stop();
     void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange);
-    void SetMove(sal_Int32 nLimit);
+    void SetMove(sal_Int32 nLimit, bool bMoveRangeDown);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx
index 5ac0e05..61e211d 100644
--- a/sc/source/ui/miscdlgs/datastreams.cxx
+++ b/sc/source/ui/miscdlgs/datastreams.cxx
@@ -15,6 +15,8 @@
 #include <asciiopt.hxx>
 #include <docsh.hxx>
 #include <impex.hxx>
+#include <viewdata.hxx>
+#include <dbfunc.hxx>
 
 namespace datastreams {
 
@@ -55,7 +57,7 @@ DataStreams::DataStreams(ScDocShell *pScDocShell):
     mpDialog(NULL)
     , mpScDocShell(pScDocShell)
     , mpScDocument(mpScDocShell->GetDocument())
-    , mbMove(false)
+    , meMove(NO_MOVE)
 {
     mxThread = new datastreams::CallerThread( this );
     mxThread->launch();
@@ -79,41 +81,51 @@ void DataStreams::Stop()
 {
     mbRunning = false;
     mpScDocument->EnableUndo(true);
-    mbMove = false;
 }
 
 void DataStreams::Set(const OUString& rUrl, bool bIsScript, const OUString& rRange)
 {
     mpRange.reset ( new ScRange() );
     mpRange->Parse(rRange, mpScDocument);
+    mpStartRange.reset( new ScRange(*mpRange.get()) );
     if (bIsScript)
         mpStream.reset( new SvScriptStream(rUrl) );
     else
         mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
 }
 
-void DataStreams::SetMove(sal_Int32 nLimit)
+void DataStreams::SetMove(sal_Int32 nLimit, bool bMoveRangeDown)
 {
     mpEndRange.reset( NULL );
-    mbMove = true;
+    meMove = bMoveRangeDown ? RANGE_DOWN : MOVE_DOWN;
     sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
     nLimit = nHeight * (nLimit / nHeight);
     if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW)
     {
-        mpEndRange.reset( new ScRange(*(mpRange.get())) );
+        mpEndRange.reset( new ScRange(*mpRange.get()) );
         mpEndRange->Move(0, nLimit - nHeight, 0);
     }
 }
 
-void DataStreams::Move()
+void DataStreams::MoveData()
 {
-    if (!mbMove)
-        return;
-    if (mpEndRange.get())
+    if (meMove == MOVE_DOWN)
     {
-        mpScDocument->DeleteRow(*(mpEndRange.get()));
+        if (mpEndRange.get())
+            mpScDocument->DeleteRow(*mpEndRange.get());
+        mpScDocument->InsertRow(*mpRange.get());
+    }
+    else if (meMove == RANGE_DOWN)
+    {
+        mpRange->Move(0, mpRange->aEnd.Row() - mpRange->aStart.Row() + 1, 0);
+        if (mpRange->aStart == mpEndRange->aStart)
+            meMove = MOVE_UP;
+    }
+    else if (meMove == MOVE_UP)
+    {
+        mpScDocument->DeleteRow(*mpStartRange.get());
+        mpScDocument->InsertRow(*mpEndRange.get());
     }
-    mpScDocument->InsertRow(*(mpRange.get()));
 }
 
 bool DataStreams::ImportData()
@@ -125,8 +137,6 @@ bool DataStreams::ImportData()
         return mbRunning;
     }
 
-    SolarMutexGuard aGuard;
-    Move();
     sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
     OStringBuffer aBuf;
     OString sTmp;
@@ -136,19 +146,22 @@ bool DataStreams::ImportData()
         aBuf.append(sTmp);
         aBuf.append('\n');
     }
+    SolarMutexGuard aGuard;
     SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
-    ScImportExport aImport(mpScDocument, *(mpRange.get()));
+    ScImportExport aImport(mpScDocument, *mpRange.get());
     ScAsciiOptions aOptions;
     aOptions.SetFieldSeps( ",;" );
     aImport.SetExtOptions(aOptions);
     aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
     // ImportStream calls PostPaint for relevant area,
     // we need to call it explicitly only when moving rows.
-    if (!mbMove)
+    if (meMove == NO_MOVE)
         return mbRunning;
 
+    MoveData();
+    mpScDocShell->GetViewData()->GetView()->AlignToCursor(mpRange->aStart.Col(), mpRange->aStart.Row(), SC_FOLLOW_JUMP);
     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 );
 
     return mbRunning;
diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
index 4519c60..8f8afe1 100644
--- a/sc/source/ui/miscdlgs/datastreamsdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
@@ -96,7 +96,7 @@ IMPL_LINK_NOARG(DataStreamsDlg, StartHdl)
         sal_Int32 nLimit = 0;
         if (m_pRBMaxLimit->IsChecked())
             nLimit = m_pEdLimit->GetText().toInt32();
-        mpDataStreams->SetMove(nLimit);
+        mpDataStreams->SetMove(nLimit, m_pRBRangeDown->IsChecked());
     }
     mpDataStreams->Start();
     UpdateEnable();


More information about the Libreoffice-commits mailing list