Kaydet (Commit) ddffb797 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Björn Michaelsen

Replace the whole content for copied documents

If the document is initialized in CreateCopy, it already contains
the initial empty paragraph. So we have to delete the content from
initial document, as we're going to replace the whole content with
the pasted document.

Change-Id: Ie6a64dcb070f7d611dfde97f2c1a721834b4167b
Reviewed-on: https://gerrit.libreoffice.org/10963Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
üst a685de59
...@@ -65,10 +65,36 @@ public: ...@@ -65,10 +65,36 @@ public:
}; };
public: public:
/** Copying of a range within or to another document. /** Copy a selected content range to a position
The position can also be within the range!
The position can be in the same or in an another document. It can also
be within the range!
\warning The range has to include at least two nodes or has to be a
SwDoc::IsColumnSelection!
Normally this functions should work only with content nodes. But there
is a special case used by SwDoc::Paste, which starts the SwPaM at the
content start node. This position doesn't contain any content:
@code
SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
@endcode
This is important, because it prevents merging of the first node of
the range into the node pointed to by \p rPos.
As a result this keeps all properties of the first real content node,
which is the 2nd, including the Flys and the page description. In this
case the first (fake) node is silently dropped and all other nodes are
just copied.
@param rPam
The source node range to copy
@param rPos
The target copy destination
*/ */
virtual bool CopyRange(SwPaM&, SwPosition&, const bool bCopyAll ) const = 0; virtual bool CopyRange(SwPaM& rPam, SwPosition& rPos, const bool bCopyAll ) const = 0;
/** Delete section containing the node. /** Delete section containing the node.
*/ */
......
...@@ -915,6 +915,12 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const ...@@ -915,6 +915,12 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
// copy content // copy content
pRet->Paste( *this ); pRet->Paste( *this );
if ( bCallInitNew ) {
// delete leading page / initial content from target document
SwNodeIndex aDeleteIdx( pRet->GetNodes().GetEndOfExtras(), 2 );
pRet->GetNodes().Delete( aDeleteIdx, 1 );
}
// remove the temporary shell if it is there as it was done before // remove the temporary shell if it is there as it was done before
pRet->SetTmpDocShell( (SfxObjectShell*)NULL ); pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
...@@ -926,12 +932,14 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const ...@@ -926,12 +932,14 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
// copy document content - code from SwFEShell::Paste( SwDoc* ) // copy document content - code from SwFEShell::Paste( SwDoc* )
void SwDoc::Paste( const SwDoc& rSource ) void SwDoc::Paste( const SwDoc& rSource )
{ {
// this has to be empty const sal_uInt16 nStartPageNumber = GetPhyPageNum(); // GetEndOfExtras + 1 = StartOfContent == no content node!
// until the end of the NodesArray // this ensures, that we have at least two nodes in the SwPaM.
SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 2 ); // @see IDocumentContentOperations::CopyRange
SwPaM aCpyPam( aSourceIdx ); //DocStart SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
SwNodeIndex aTargetIdx( GetNodes().GetEndOfExtras(), 2 ); SwPaM aCpyPam( aSourceIdx );
SwPaM aInsertPam( aTargetIdx ); //replaces PCURCRSR from SwFEShell::Paste()
SwNodeIndex aTargetIdx( GetNodes().GetEndOfContent() );
SwPaM aInsertPam( aTargetIdx );
aCpyPam.SetMark(); aCpyPam.SetMark();
aCpyPam.Move( fnMoveForward, fnGoDoc ); aCpyPam.Move( fnMoveForward, fnGoDoc );
......
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