Hi, Miklós Required changes have done.
Regards, Zolnai Tamás
>From 44e45fc2f99c78b014952dbe3d38e7822ae2340f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolnai=20Tam=C3=A1s?= <zolniata...@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..bd18647 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() +{ + ::rtl::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( ::rtl::OUString() ); 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
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice