[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - dbaccess/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 4 08:52:39 UTC 2021


 dbaccess/source/ui/control/sqledit.cxx |   75 +++++++++++++++++++++++++++++++++
 dbaccess/source/ui/inc/sqledit.hxx     |    1 
 2 files changed, 76 insertions(+)

New commits:
commit c44574f6d28d8bb38e0a54ba079ca76b044bb346
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sun Oct 3 19:53:05 2021 +0100
Commit:     Adolfo Jayme Barrientos <fitojb at ubuntu.com>
CommitDate: Mon Oct 4 10:52:04 2021 +0200

    tdf#144674 no context menu in SQL Query
    
    Change-Id: I3c6e9e7896da171d089579165f466b4b6e59a1a4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122938
    Tested-by: Jenkins
    Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>

diff --git a/dbaccess/source/ui/control/sqledit.cxx b/dbaccess/source/ui/control/sqledit.cxx
index 18eac53dee60..cae055b20558 100644
--- a/dbaccess/source/ui/control/sqledit.cxx
+++ b/dbaccess/source/ui/control/sqledit.cxx
@@ -34,8 +34,10 @@
 #include <cppuhelper/implbase.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <svl/itemset.hxx>
+#include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
 #include <vcl/settings.hxx>
+#include <vcl/specialchars.hxx>
 #include <vcl/svapp.hxx>
 
 using namespace dbaui;
@@ -355,6 +357,79 @@ bool SQLEditView::KeyInput(const KeyEvent& rKEvt)
     return WeldEditView::KeyInput(rKEvt);
 }
 
+bool SQLEditView::Command(const CommandEvent& rCEvt)
+{
+    if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
+    {
+        ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
+        weld::Widget* pPopupParent = GetDrawingArea();
+        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "vcl/ui/editmenu.ui"));
+        std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
+
+        bool bEnableCut = true;
+        bool bEnableCopy = true;
+        bool bEnableDelete = true;
+        bool bEnablePaste = true;
+        bool bEnableSpecialChar = true;
+
+        EditView* pEditView = GetEditView();
+
+        if (!pEditView->HasSelection())
+        {
+            bEnableCut = false;
+            bEnableCopy = false;
+            bEnableDelete = false;
+        }
+
+        if (pEditView->IsReadOnly())
+        {
+            bEnableCut = false;
+            bEnablePaste = false;
+            bEnableDelete = false;
+            bEnableSpecialChar = false;
+        }
+
+        xContextMenu->set_sensitive("cut", bEnableCut);
+        xContextMenu->set_sensitive("copy", bEnableCopy);
+        xContextMenu->set_sensitive("delete", bEnableDelete);
+        xContextMenu->set_sensitive("paste", bEnablePaste);
+        xContextMenu->set_sensitive("specialchar", bEnableSpecialChar);
+        xContextMenu->set_visible("undo", false);
+        xContextMenu->set_visible("specialchar", vcl::GetGetSpecialCharsFunction() != nullptr);
+
+        OString sCommand = xContextMenu->popup_at_rect(pPopupParent, aRect);
+
+        if (sCommand == "cut")
+            pEditView->Cut();
+        else if (sCommand == "copy")
+            pEditView->Copy();
+        else if (sCommand == "paste")
+            pEditView->Paste();
+        else if (sCommand == "delete")
+            pEditView->DeleteSelected();
+        else if (sCommand == "selectall")
+        {
+            sal_Int32 nPar = m_xEditEngine->GetParagraphCount();
+            if (nPar)
+            {
+                sal_Int32 nLen = m_xEditEngine->GetTextLen(nPar - 1);
+                pEditView->SetSelection(ESelection(0, 0, nPar - 1, nLen));
+            }
+        }
+        else if (sCommand == "specialchar")
+        {
+            OUString aChars = vcl::GetGetSpecialCharsFunction()(pPopupParent, m_xEditEngine->GetStandardFont(0));
+            if (!aChars.isEmpty())
+            {
+                pEditView->InsertText(aChars);
+            }
+        }
+
+        return true;
+    }
+    return WeldEditView::Command(rCEvt);
+}
+
 void SQLEditView::ConfigurationChanged(utl::ConfigurationBroadcaster*, ConfigurationHints)
 {
     UpdateData();
diff --git a/dbaccess/source/ui/inc/sqledit.hxx b/dbaccess/source/ui/inc/sqledit.hxx
index 6f85ba825a71..99d5e636c24e 100644
--- a/dbaccess/source/ui/inc/sqledit.hxx
+++ b/dbaccess/source/ui/inc/sqledit.hxx
@@ -69,6 +69,7 @@ namespace dbaui
         virtual ~SQLEditView() override;
 
         virtual bool KeyInput(const KeyEvent& rKEvt) override;
+        virtual bool Command(const CommandEvent& rCEvt) override;
 
         void SetTextAndUpdate(const OUString& rNewText);
 


More information about the Libreoffice-commits mailing list