summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cui/source/dialogs/hltpbase.cxx33
-rw-r--r--sw/qa/uitest/writer_tests3/hyperlinkdialog.py16
2 files changed, 45 insertions, 4 deletions
diff --git a/cui/source/dialogs/hltpbase.cxx b/cui/source/dialogs/hltpbase.cxx
index 01776c80d25e..f2448460ee66 100644
--- a/cui/source/dialogs/hltpbase.cxx
+++ b/cui/source/dialogs/hltpbase.cxx
@@ -450,14 +450,39 @@ 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;
+ 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 aClipBoardConentent;
+ if (xTransferable->getTransferData(aFlavor) >>= aClipBoardConentent)
+ {
+ INetURLObject aURL;
+ aURL.SetSmartURL(aClipBoardConentent);
+ if (!aURL.HasError())
+ aStrURL
+ = aURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
+ }
+ }
+ }
+ }
+ }
+
// set dialog-fields
FillStandardDlgFields (pHyperlinkItem);
// set all other fields
- FillDlgFields ( pHyperlinkItem->GetURL() );
-
- // Store initial URL
- maStrInitURL = pHyperlinkItem->GetURL();
+ FillDlgFields(aStrURL);
}
}
diff --git a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
index 6390310810d5..531b5f42a866 100644
--- a/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
+++ b/sw/qa/uitest/writer_tests3/hyperlinkdialog.py
@@ -105,6 +105,22 @@ class HyperlinkDialog(UITestCase):
# i.e. the last used tab in the hyperlink dialog was not remembered
self.assertEqual("1", get_state_as_dict(xTab)["CurrPagePos"])
+ def test_tdf146576_propose_clipboard_content(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": "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/")
def test_tdf141166(self):
# Skip this test for --with-help=html and --with-help=online, as that would fail with a