summaryrefslogtreecommitdiff
path: root/basctl
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 /basctl
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>
Diffstat (limited to 'basctl')
-rw-r--r--basctl/source/basicide/unomodel.cxx51
-rw-r--r--basctl/source/basicide/unomodel.hxx3
2 files changed, 54 insertions, 0 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