[Libreoffice-commits] .: svx/inc svx/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Fri Aug 10 02:07:55 PDT 2012


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

New commits:
commit 31b18677987eb82169730750670faf8409206e8c
Author: Zolnai Tamás <zolniatamas at caesar.elte.hu>
Date:   Fri Aug 10 09:32:03 2012 +0200

    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

diff --git a/svx/inc/tbunosearchcontrollers.hxx b/svx/inc/tbunosearchcontrollers.hxx
index 0118f51..8fb7d33 100644
--- a/svx/inc/tbunosearchcontrollers.hxx
+++ b/svx/inc/tbunosearchcontrollers.hxx
@@ -65,6 +65,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 6752dac..382e042 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()
+{
+    OUString 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.getLength() != 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( OUString() );
                 m_bToClearTextField = sal_False;
             }
             SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
@@ -758,11 +767,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;
                     }


More information about the Libreoffice-commits mailing list