Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

I have forgotten the [Libreoffice] guard in my previous mail... just in
case....

Thanks


Benoit


---------- Forwarded message ----------
From: Benoit Dolives <benoit.dolives@gmail.com>
Date: 2011/7/1
Subject: [PATCH] Writer: Bug 36181 - EasyHack: Replace with "Notes" option
doesn't work with text selected
To: libreoffice@lists.freedesktop.org


Hi,

Please find in attachment the patch for the bug 36181.

Bug:
While using "Replace" in the "Find&Replace" dialog of writer, the selected
text was always replaced even if it does not match the searched string.

Correction:
Check that the selected text is the search string, otherwise select the
first occurence if any.

This is my first contribution to LibreOffice, therefore please feel
confortable to give me advices, remarks, ...


Best Regards,

-- 
Benoit Dolives



-- 
Benoit Dolives
From fb6b0340c819202ea3ffd74e47cc1ba17bba8dae Mon Sep 17 00:00:00 2001
From: Dolives Benoit <benoit.dolives@gmail.com>
Date: Fri, 1 Jul 2011 00:44:49 +0200
Subject: [PATCH] writer: bug correction : selected text was always replaced (bugzilla 36181)

When using "Find&Replace" dialog, the selected text was always replaced.
Correction: check that the selected text is the search string, otherwise select the first occurence 
if any.
---
 sw/source/ui/uiview/viewsrch.cxx |   78 ++++++++++++++++++++++++++++++++-----
 1 files changed, 67 insertions(+), 11 deletions(-)

diff --git a/sw/source/ui/uiview/viewsrch.cxx b/sw/source/ui/uiview/viewsrch.cxx
index b3e8d6e..488e848 100644
--- a/sw/source/ui/uiview/viewsrch.cxx
+++ b/sw/source/ui/uiview/viewsrch.cxx
@@ -589,18 +591,72 @@ void SwView::Replace()
     {
         if (GetPostItMgr()->HasActiveSidebarWin())
             GetPostItMgr()->Replace(pSrchItem);
-        sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
-                                            pSrchItem->GetRegExp());
 
-        if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
-        {
-            SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
-                                    aTxtFmtCollSetRange );
-            if( pReplList->Get( aReplSet ).Count() )
-            {
-                ::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
-                pWrtShell->SwEditShell::SetAttr( aReplSet );
+        sal_Bool bReqReplace = true;
+
+        if(pWrtShell->HasSelection()){
+            /* check that the selection has the same length as the required string */
+            if (pWrtShell->SwCrsrShell::GetSelTxt().Len() != pSrchItem->GetSearchString().Len() ){
+                //it differs, therefore do not replace the selection
+                bReqReplace = false;
+                //next call to replace will find the next matching string
             }
+            else{
+                /* check that the selection match the search string*/
+                //save state
+                SwPosition aStartPos = (* pWrtShell->GetSwCrsr()->Start());
+                SwPosition aEndPos = (* pWrtShell->GetSwCrsr()->End());
+                sal_Bool   bHasSelection = pSrchItem->GetSelection();
+                sal_uInt16 nOldCmd = pSrchItem->GetCommand();
+
+                //set state for checking if current selection has a match
+                pSrchItem->SetCommand( SVX_SEARCHCMD_FIND );
+                pSrchItem->SetSelection(true);
+
+                //check if it matchs
+                SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
+                if( ! FUNC_Search(aOpts) ){
+
+                    //no matching therefore should not replace selection
+                    // => remove selection
+
+                    if(! pSrchItem->GetBackward() ){
+                        (* pWrtShell->GetSwCrsr()->Start()) = aStartPos;
+                        (* pWrtShell->GetSwCrsr()->End()) = aEndPos;
+                    }
+                    else{
+                        (* pWrtShell->GetSwCrsr()->Start()) = aEndPos;
+                        (* pWrtShell->GetSwCrsr()->End()) = aStartPos;
+                    }
+                    bReqReplace = false;
+                }
+
+                //set back old search state
+                pSrchItem->SetCommand( nOldCmd );
+                pSrchItem->SetSelection(bHasSelection);
+            }
+        }
+        /*
+         * remove current selection
+         * otherwise it is always replaced
+         * no matter if the search string exists or not in the selection
+         * Now the selection is removed and the next matching string is selected
+         */
+
+        if( bReqReplace ){
+
+            sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
+                                                                  pSrchItem->GetRegExp());
+            if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
+                {
+                    SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
+                                         aTxtFmtCollSetRange );
+                    if( pReplList->Get( aReplSet ).Count() )
+                        {
+                            ::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
+                            pWrtShell->SwEditShell::SetAttr( aReplSet );
+                        }
+                }
         }
     }
 
-- 
1.7.0.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.