cui/source/dialogs/cuihyperdlg.cxx            |    6 +--
 cui/source/dialogs/hlinettp.cxx               |   39 ++++++++++++++++++++--
 cui/source/dialogs/hltpbase.cxx               |   46 ++------------------------
 sw/qa/uitest/writer_tests3/hyperlinkdialog.py |   25 ++++++++++++++
 4 files changed, 70 insertions(+), 46 deletions(-)

New commits:
commit bbbb0c62eb26957a30f1d7ec43a73c7eda4cb339
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Sun Nov 10 17:39:36 2024 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Nov 12 09:25:21 2024 +0100

    tdf#162753 - Propose clipboard content only for option internet
    
    Change-Id: I030bc4c824ba8946104fe2e6adfd3b445de2b238
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176348
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176386

diff --git a/cui/source/dialogs/cuihyperdlg.cxx 
b/cui/source/dialogs/cuihyperdlg.cxx
index 41d5a17c4a7d..2270ab330f0b 100644
--- a/cui/source/dialogs/cuihyperdlg.cxx
+++ b/cui/source/dialogs/cuihyperdlg.cxx
@@ -138,9 +138,6 @@ SvxHpLinkDlg::SvxHpLinkDlg(SfxBindings* pBindings, 
SfxChildWindow* pChild, weld:
 
     SetInputSet (mpItemSet.get());
 
-    // tdf#90496 - remember last used view in hyperlink dialog
-    SetCurPageId(msRememberedPageId);
-
     // insert pages
     AddTabPage(u"internet"_ustr, SvxHyperlinkInternetTp::Create);
     AddTabPage(u"mail"_ustr, SvxHyperlinkMailTp::Create);
@@ -150,6 +147,9 @@ SvxHpLinkDlg::SvxHpLinkDlg(SfxBindings* pBindings, 
SfxChildWindow* pChild, weld:
         AddTabPage(u"newdocument"_ustr, SvxHyperlinkNewDocTp::Create);
     }
 
+    // tdf#90496 - remember last used view in hyperlink dialog
+    SetCurPageId(msRememberedPageId);
+
     // Init Dialog
     Start();
 
diff --git a/cui/source/dialogs/hlinettp.cxx b/cui/source/dialogs/hlinettp.cxx
index 90348fe3f508..c64f8e7fa01b 100644
--- a/cui/source/dialogs/hlinettp.cxx
+++ b/cui/source/dialogs/hlinettp.cxx
@@ -23,6 +23,7 @@
 
 #include <hlinettp.hxx>
 #include <hlmarkwn_def.hxx>
+#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
 
 
 /*************************************************************************
@@ -72,8 +73,42 @@ SvxHyperlinkInternetTp::~SvxHyperlinkInternetTp()
 |************************************************************************/
 void SvxHyperlinkInternetTp::FillDlgFields(const OUString& rStrURL)
 {
-    INetURLObject aURL(rStrURL);
-    OUString aStrScheme(GetSchemeFromURL(rStrURL));
+    // tdf#146576 - propose clipboard content when inserting a hyperlink
+    OUString aStrURL(rStrURL);
+    if (aStrURL.isEmpty())
+    {
+        if (auto xClipboard = GetSystemClipboard())
+        {
+            if (auto xTransferable = xClipboard->getContents())
+            {
+                css::datatransfer::DataFlavor aFlavor;
+                SotExchange::GetFormatDataFlavor(SotClipboardFormatId::STRING, 
aFlavor);
+                if (xTransferable->isDataFlavorSupported(aFlavor))
+                {
+                    OUString aClipBoardContent;
+                    try
+                    {
+                        if (xTransferable->getTransferData(aFlavor) >>= 
aClipBoardContent)
+                        {
+                            // tdf#162753 - allow only syntactically valid 
hyperlink targets
+                            INetURLObject aURL(aClipBoardContent);
+                            if (!aURL.HasError())
+                                aStrURL
+                                    = 
aURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
+                        }
+                    }
+                    // tdf#158345: Opening Hyperlink dialog leads to crash
+                    // MimeType = "text/plain;charset=utf-16"
+                    catch (const 
css::datatransfer::UnsupportedFlavorException&)
+                    {
+                    }
+                }
+            }
+        }
+    }
+
+    INetURLObject aURL(aStrURL);
+    OUString aStrScheme(GetSchemeFromURL(aStrURL));
 
     // set URL-field
     // Show the scheme, #72740
diff --git a/cui/source/dialogs/hltpbase.cxx b/cui/source/dialogs/hltpbase.cxx
index 48b1e65d32ea..8595b1fd5889 100644
--- a/cui/source/dialogs/hltpbase.cxx
+++ b/cui/source/dialogs/hltpbase.cxx
@@ -37,7 +37,6 @@
 #include <strings.hrc>
 #include <dialmgr.hxx>
 #include <bitmaps.hlst>
-#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
 
 namespace {
 
@@ -438,7 +437,7 @@ void SvxHyperlinkTabPageBase::GetDataFromCommonFields( 
OUString& aStrName,
 }
 
 // reset dialog-fields
-void SvxHyperlinkTabPageBase::Reset( const SfxItemSet& rItemSet)
+void SvxHyperlinkTabPageBase::Reset( const SfxItemSet& rItemSet )
 {
 
     // Set dialog-fields from create-itemset
@@ -449,49 +448,14 @@ void SvxHyperlinkTabPageBase::Reset( const SfxItemSet& 
rItemSet)
 
     if ( pHyperlinkItem )
     {
-        // tdf#146576 - propose clipboard content when inserting a hyperlink
-        OUString aStrURL(pHyperlinkItem->GetURL());
-        // Store initial URL
-        maStrInitURL = aStrURL;
-        // tdf#162753 - propose clipboard content only for options internet 
and mail
-        if (aStrURL.isEmpty()
-            && (mpDialog->GetCurPageId() == "internet" || 
mpDialog->GetCurPageId() == "mail"))
-        {
-            if (auto xClipboard = GetSystemClipboard())
-            {
-                if (auto xTransferable = xClipboard->getContents())
-                {
-                    css::datatransfer::DataFlavor aFlavor;
-                    
SotExchange::GetFormatDataFlavor(SotClipboardFormatId::STRING, aFlavor);
-                    if (xTransferable->isDataFlavorSupported(aFlavor))
-                    {
-                        OUString aClipBoardContent;
-                        try
-                        {
-                            if (xTransferable->getTransferData(aFlavor) >>= 
aClipBoardContent)
-                            {
-                                // tdf#162753 - allow only syntactically valid 
hyperlink targets
-                                INetURLObject aURL(aClipBoardContent);
-                                if (!aURL.HasError())
-                                    aStrURL
-                                        = 
aURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
-                            }
-                        }
-                        // tdf#158345: Opening Hyperlink dialog leads to crash
-                        // MimeType = "text/plain;charset=utf-16"
-                        catch(const 
css::datatransfer::UnsupportedFlavorException&)
-                        {
-                        }
-                    }
-                }
-            }
-        }
-
         // set dialog-fields
         FillStandardDlgFields (pHyperlinkItem);
 
         // set all other fields
-        FillDlgFields(aStrURL);
+        FillDlgFields(pHyperlinkItem->GetURL());
+
+        // Store initial URL
+        maStrInitURL = pHyperlinkItem->GetURL();
     }
 }
 
diff --git a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py 
b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
index 0ee8e52c6ffd..1ab08e6facdc 100644
--- a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
+++ b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
@@ -122,6 +122,31 @@ class HyperlinkDialog(UITestCase):
                 xTarget = xDialog.getChild("target")
                 self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), 
"http://www.libreoffice.org/";)
 
+    def test_tdf162753_propose_clipboard_content_internet(self):
+        with self.ui_test.create_doc_in_start_center("writer"):
+            # Insert a sample URL
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+            xWriterEdit = xWriterDoc.getChild("writer_edit")
+            xWriterEdit.executeAction("TYPE", mkPropertyValues({"TEXT": 
"http://www.libreoffice.org"}))
+
+            # Copy URL and open the hyperlink dialog
+            self.xUITest.executeCommand(".uno:SelectAll")
+            self.xUITest.executeCommand(".uno:Copy")
+            with 
self.ui_test.execute_dialog_through_command(".uno:HyperlinkDialog", 
close_button="cancel") as xDialog:
+                xTab = xDialog.getChild("tabcontrol")
+                select_pos(xTab, "0")
+                # Check if the content of the clipboard is proposed as URL in 
the hyperlink dialog
+                xTarget = xDialog.getChild("target")
+                self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), 
"http://www.libreoffice.org/";)
+                select_pos(xTab, "2")
+                # Select document dialog and check if the content of the 
clipboard is not proposed as URL
+                xPath = xDialog.getChild("path")
+                self.assertEqual(get_state_as_dict(xPath)["Text"], "")
+                # Select internet dialog and check if the content of the 
clipboard is again proposed as URL
+                select_pos(xTab, "0")
+                xTarget = xDialog.getChild("target")
+                self.assertEqual(get_state_as_dict(xTarget)["Text"].lower(), 
"http://www.libreoffice.org/";)
+
     def test_tdf162753_propose_invalid_clipboard_content(self):
         with self.ui_test.create_doc_in_start_center("writer"):
             # Insert an invalid sample URL

Reply via email to