[Libreoffice-commits] core.git: sw/source

Matúš Kukan matus.kukan at collabora.com
Wed Nov 26 05:38:15 PST 2014


 sw/source/core/inc/UndoBookmark.hxx |   18 +++++++++++
 sw/source/core/undo/unbkmk.cxx      |   57 ++++++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unobkm.cxx   |   34 +++++++--------------
 3 files changed, 87 insertions(+), 22 deletions(-)

New commits:
commit c7fa6687e544e7f9702da23aadbd31c1f2e0115e
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Wed Nov 26 11:58:13 2014 +0100

    Writer: Set document as modified and add undo when renaming bookmarks
    
    Change-Id: Id0d4695b6a7c5eae0493e679345bd41d4687d6d7

diff --git a/sw/source/core/inc/UndoBookmark.hxx b/sw/source/core/inc/UndoBookmark.hxx
index b7e0d56..eaa0fcb 100644
--- a/sw/source/core/inc/UndoBookmark.hxx
+++ b/sw/source/core/inc/UndoBookmark.hxx
@@ -67,6 +67,24 @@ public:
     virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
 };
 
+class SwUndoRenameBookmark : public SwUndo
+{
+    const OUString m_sOldName;
+    const OUString m_sNewName;
+    const sal_uLong m_nNode;
+    const sal_Int32 m_nCntnt;
+
+public:
+    SwUndoRenameBookmark( const ::sw::mark::IMark&, const OUString& rNewName );
+    virtual ~SwUndoRenameBookmark();
+
+private:
+    virtual SwRewriter GetRewriter() const SAL_OVERRIDE;
+    void Rename( ::sw::UndoRedoContext &, const OUString& sFrom, const OUString& sTo );
+    virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
+    virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
+};
+
 #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOBOOKMARK_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/undo/unbkmk.cxx b/sw/source/core/undo/unbkmk.cxx
index 569fe21..eb11aa9 100644
--- a/sw/source/core/undo/unbkmk.cxx
+++ b/sw/source/core/undo/unbkmk.cxx
@@ -19,6 +19,7 @@
 
 #include <UndoBookmark.hxx>
 
+#include <comcore.hrc>
 #include "doc.hxx"
 #include "docary.hxx"
 #include "swundo.hxx"
@@ -85,4 +86,60 @@ void SwUndoInsBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
     SetInDoc( &rContext.GetDoc() );
 }
 
+SwUndoRenameBookmark::SwUndoRenameBookmark( const ::sw::mark::IMark& rBkmk, const OUString& rOldName )
+    : SwUndo( UNDO_BOOKMARK_RENAME )
+    , m_sOldName( rOldName )
+    , m_sNewName( rBkmk.GetName() )
+    , m_nNode( rBkmk.GetMarkPos().nNode.GetIndex() )
+    , m_nCntnt( rBkmk.GetMarkPos().nContent.GetIndex() )
+{
+}
+
+SwUndoRenameBookmark::~SwUndoRenameBookmark()
+{
+}
+
+static OUString lcl_QuoteName(const OUString& rName)
+{
+    static const OUString sStart = SW_RES(STR_START_QUOTE);
+    static const OUString sEnd = SW_RES(STR_END_QUOTE);
+    return sStart + rName + sEnd;
+}
+
+SwRewriter SwUndoRenameBookmark::GetRewriter() const
+{
+    SwRewriter aRewriter;
+    aRewriter.AddRule(UndoArg1, lcl_QuoteName(m_sOldName));
+    aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
+    aRewriter.AddRule(UndoArg3, lcl_QuoteName(m_sNewName));
+    return aRewriter;
+}
+
+void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext & rContext, const OUString& sFrom, const OUString& sTo)
+{
+    IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
+    for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
+          ppBkmk != pMarkAccess->getAllMarksEnd();
+          ++ppBkmk )
+    {
+        if ( m_nNode == ppBkmk->get()->GetMarkPos().nNode.GetIndex()
+             && m_nCntnt == ppBkmk->get()->GetMarkPos().nContent.GetIndex()
+             && sFrom == ppBkmk->get()->GetName() )
+        {
+            pMarkAccess->renameMark( ppBkmk->get(), sTo );
+            break;
+        }
+    }
+}
+
+void SwUndoRenameBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
+{
+    Rename(rContext, m_sNewName, m_sOldName);
+}
+
+void SwUndoRenameBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
+{
+    Rename(rContext, m_sOldName, m_sNewName);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index 569fcd2..3697649 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -24,17 +24,17 @@
 #include <vcl/svapp.hxx>
 
 #include <TextCursorHelper.hxx>
+#include <UndoBookmark.hxx>
 #include <unotextrange.hxx>
 #include <unomap.hxx>
 #include <unoprnms.hxx>
 #include <IMark.hxx>
 #include <crossrefbookmark.hxx>
 #include <doc.hxx>
+#include <IDocumentState.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <docary.hxx>
 #include <swundo.hxx>
-#include <comcore.hrc>
-#include <SwRewriter.hxx>
 #include <docsh.hxx>
 #include <xmloff/odffields.hxx>
 #include <comphelper/servicehelper.hxx>
@@ -42,16 +42,6 @@
 using namespace ::sw::mark;
 using namespace ::com::sun::star;
 
-namespace
-{
-    static OUString lcl_QuoteName(const OUString& rName)
-    {
-        static const OUString sStart = SW_RES(STR_START_QUOTE);
-        static const OUString sEnd = SW_RES(STR_END_QUOTE);
-        return sStart + rName + sEnd;
-    }
-}
-
 class SwXBookmark::Impl
     : public SwClient
 {
@@ -359,16 +349,16 @@ throw (uno::RuntimeException, std::exception)
         *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
     }
 
-    SwRewriter aRewriter;
-    aRewriter.AddRule(UndoArg1, lcl_QuoteName(getName()));
-    aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
-    aRewriter.AddRule(UndoArg3, lcl_QuoteName(rName));
-
-    m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo(
-            UNDO_BOOKMARK_RENAME, &aRewriter);
-    pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName);
-    m_pImpl->m_pDoc->GetIDocumentUndoRedo().EndUndo(
-            UNDO_BOOKMARK_RENAME, &aRewriter);
+    const OUString sOldName(m_pImpl->m_pRegisteredBookmark->GetName());
+    if (pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName))
+    {
+        if (m_pImpl->m_pDoc->GetIDocumentUndoRedo().DoesUndo())
+        {
+            m_pImpl->m_pDoc->GetIDocumentUndoRedo().AppendUndo(
+                    new SwUndoRenameBookmark(*m_pImpl->m_pRegisteredBookmark, sOldName));
+        }
+        m_pImpl->m_pDoc->getIDocumentState().SetModified();
+    }
 }
 
 OUString SAL_CALL


More information about the Libreoffice-commits mailing list