summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Lima <rafael.palma.lima@gmail.com>2024-01-25 23:54:39 +0100
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2024-02-01 13:37:16 +0100
commit7bcce4180d11f6f49a71f681eeefc556fc2302ba (patch)
tree3a3b1a2a45299c8af965687405656733f5b7dd43
parent6d0fddb697fd619d11da3469f4dd72782334f3bb (diff)
tdf#131641 Enter selected text in the search bar (Basic IDE)
This patch makes the selected text in the code editor be automatically inserted in the search bar. Change-Id: Ibbe64aa3375a5a47dedb762001ed4b99f4b22e46 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162548 Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de> Tested-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
-rw-r--r--basctl/source/basicide/unomodel.cxx51
-rw-r--r--basctl/source/basicide/unomodel.hxx3
-rw-r--r--svx/source/tbxctrls/tbunosearchcontrollers.cxx20
3 files changed, 70 insertions, 4 deletions
diff --git a/basctl/source/basicide/unomodel.cxx b/basctl/source/basicide/unomodel.cxx
index 5d3946b426c6..180bf3d17fa7 100644
--- a/basctl/source/basicide/unomodel.cxx
+++ b/basctl/source/basicide/unomodel.cxx
@@ -19,6 +19,7 @@
#include "basdoc.hxx"
+#include <basidesh.hxx>
#include <iderdll.hxx>
#include <com/sun/star/io/IOException.hpp>
#include <comphelper/sequence.hxx>
@@ -29,6 +30,41 @@
#include "unomodel.hxx"
+
+namespace {
+
+// Implements XEnumeration to hold a single selected portion of text
+// This will actually only hold a single string value
+class SelectionEnumeration : public ::cppu::WeakImplHelper<css::container::XEnumeration>
+{
+private:
+ OUString m_sText;
+ bool m_bHasElements;
+
+public:
+ explicit SelectionEnumeration(OUString& sSelectedText)
+ : m_sText(sSelectedText)
+ , m_bHasElements(true) {}
+
+ virtual sal_Bool SAL_CALL hasMoreElements() override
+ {
+ return m_bHasElements;
+ }
+
+ virtual css::uno::Any SAL_CALL nextElement() override
+ {
+ if (m_bHasElements)
+ {
+ m_bHasElements = false;
+ return css::uno::Any(m_sText);
+ }
+
+ throw css::container::NoSuchElementException();
+ }
+};
+
+} // End of unnamed namespace
+
namespace basctl
{
@@ -114,6 +150,21 @@ void SIDEModel::notImplemented()
throw io::IOException("Can't store IDE model" );
}
+// XModel
+css::uno::Reference< css::uno::XInterface > SAL_CALL SIDEModel::getCurrentSelection()
+{
+ SolarMutexGuard aGuard;
+ uno::Reference<container::XEnumeration> xEnum;
+ Shell* pShell = GetShell();
+
+ if (pShell)
+ {
+ OUString sText = GetShell()->GetSelectionText(false);
+ xEnum = new SelectionEnumeration(sText);
+ }
+ return xEnum;
+}
+
} // namespace basctl
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
diff --git a/basctl/source/basicide/unomodel.hxx b/basctl/source/basicide/unomodel.hxx
index b47873005699..9b0289032660 100644
--- a/basctl/source/basicide/unomodel.hxx
+++ b/basctl/source/basicide/unomodel.hxx
@@ -53,6 +53,9 @@ public:
const css::uno::Sequence< css::beans::PropertyValue >& seqArguments ) override;
virtual void SAL_CALL storeToURL( const OUString& sURL,
const css::uno::Sequence< css::beans::PropertyValue >& seqArguments ) override;
+
+ // XModel
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getCurrentSelection() override;
};
} // namespace basctl
diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
index f8c4436443bc..2f23bfaa97f4 100644
--- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx
+++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
@@ -45,6 +45,7 @@
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/ui/XUIElement.hpp>
+#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/SearchAlgorithms.hpp>
@@ -253,11 +254,22 @@ void FindTextFieldControl::SetTextToSelected_Impl()
else
{
uno::Reference<frame::XModel> xModel(xController->getModel(), uno::UNO_SET_THROW);
- uno::Reference<container::XIndexAccess> xIndexAccess(xModel->getCurrentSelection(), uno::UNO_QUERY_THROW);
- if (xIndexAccess->getCount() > 0)
+ uno::Reference<uno::XInterface> xSelection = xModel->getCurrentSelection();
+ uno::Reference<container::XIndexAccess> xIndexAccess(xSelection, uno::UNO_QUERY);
+ if (xIndexAccess.is())
{
- uno::Reference<text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
- aString = xTextRange->getString();
+ if (xIndexAccess->getCount() > 0)
+ {
+ uno::Reference<text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
+ aString = xTextRange->getString();
+ }
+ }
+ else
+ {
+ // The Basic IDE returns a XEnumeration with a single item
+ uno::Reference<container::XEnumeration> xEnum(xSelection, uno::UNO_QUERY_THROW);
+ if (xEnum->hasMoreElements())
+ xEnum->nextElement() >>= aString;
}
}
}