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


Hi,

At last I managed to get Findbar to behave with Ctrl+f as excepted. Details in patch description.


Regards,
Zolnai Tamás
From 7403288c94b25ce3391d0d0fcc7624b68dd8316a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolnai=20Tam=C3=A1s?= <zolniatamas@caesar.elte.hu>
Date: Fri, 10 Aug 2012 09:32:03 +0200
Subject: [PATCH] fdo#37791 Insert selected text to Findbar by Ctrl+f

The dispatch function of FindbarDispatcher class is called when
Ctrl+f is pressed. This function makes Toolbar visible and takes
focus to TextField. So expand this function to insert the selected
text to TextField at the same time. With dynamic_cast convert
Window pointer, which point to the TextField and call TextField's new
function: SetTextToSelected_Impl(), which makes the mentioned
insertion.
Plus make a little cleanup. Replace one string, which is defined by
a macro.

Change-Id: I2a8a3b10a016f5b28ea58fa3e63a3f31c9a816bf
---
 svx/inc/tbunosearchcontrollers.hxx             |    1 +
 svx/source/tbxctrls/tbunosearchcontrollers.cxx |   50 +++++++++++++++---------
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/svx/inc/tbunosearchcontrollers.hxx b/svx/inc/tbunosearchcontrollers.hxx
index 032662c..3cd6b859 100644
--- a/svx/inc/tbunosearchcontrollers.hxx
+++ b/svx/inc/tbunosearchcontrollers.hxx
@@ -64,6 +64,7 @@ public:
 
     void InitControls_Impl();
     void Remember_Impl(const String& rStr);
+    void SetTextToSelected_Impl();
 
 private:
 
diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx 
b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
index e58bd7f..088e0ab 100644
--- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx
+++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
@@ -115,6 +115,32 @@ void FindTextFieldControl::Remember_Impl(const String& rStr)
     InsertEntry(rStr, 0);
 }
 
+void FindTextFieldControl::SetTextToSelected_Impl()
+{
+    String aString;
+
+    try
+    {
+        css::uno::Reference<css::frame::XController> xController(m_xFrame->getController(), 
css::uno::UNO_QUERY_THROW);
+        css::uno::Reference<css::frame::XModel> xModel(xController->getModel(), 
css::uno::UNO_QUERY_THROW);
+        css::uno::Reference<css::container::XIndexAccess> 
xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW);
+        if (xIndexAccess->getCount() > 0)
+        {
+            css::uno::Reference<css::text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), 
css::uno::UNO_QUERY_THROW);
+            aString = xTextRange->getString();
+        }
+    }
+    catch ( ... )
+    {
+    }
+
+    if ( aString.Len() != 0 )
+    {
+        SetText( aString );
+        m_bToClearTextField = sal_False;
+    }
+}
+
 void FindTextFieldControl::Modify()
 {
     ComboBox::Modify();
@@ -184,24 +210,7 @@ long FindTextFieldControl::PreNotify( NotifyEvent& rNEvt )
         case EVENT_GETFOCUS:
             if ( m_bToClearTextField )
             {
-                String aString;
-
-                try
-                {
-                    css::uno::Reference<css::frame::XController> 
xController(m_xFrame->getController(), css::uno::UNO_QUERY_THROW);
-                    css::uno::Reference<css::frame::XModel> xModel(xController->getModel(), 
css::uno::UNO_QUERY_THROW);
-                    css::uno::Reference<css::container::XIndexAccess> 
xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW);
-                    if (xIndexAccess->getCount() > 0)
-                    {
-                        css::uno::Reference<css::text::XTextRange> 
xTextRange(xIndexAccess->getByIndex(0), css::uno::UNO_QUERY_THROW);
-                        aString = xTextRange->getString();
-                    }
-                }
-                catch ( ... )
-                {
-                }
-
-                SetText( aString );
+                SetText( String() );
                 m_bToClearTextField = sal_False;
             }
             SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
@@ -738,11 +747,14 @@ void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const 
css
             for ( sal_uInt16 i=0; i<nItemCount; ++i )
             {
                 ::rtl::OUString sItemCommand = pToolBox->GetItemCommand(i);
-                if ( sItemCommand == ".uno:FindText" )
+                if ( sItemCommand == COMMAND_FINDTEXT )
                 {
                     Window* pItemWin = pToolBox->GetItemWindow( i );
                     if ( pItemWin )
                     {
+                        FindTextFieldControl* pFindTextFieldControl = 
dynamic_cast<FindTextFieldControl*>(pItemWin);
+                        if ( pFindTextFieldControl )
+                            pFindTextFieldControl->SetTextToSelected_Impl();
                         pItemWin->GrabFocus();
                         return;
                     }
-- 
1.7.7


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.