From dba3cd508116780cf5d115f964b7311dd61e180d Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 3 Jan 2018 13:34:46 +0100 Subject: tdf#113357 cui: fix duplicate 'Formatted text [Richtext]' paste option Prefer RTF when we have both RICHTEXT and RTF. Change-Id: Ib4133ae4fdecc32429d89b56b0c9466dd3451522 Reviewed-on: https://gerrit.libreoffice.org/47316 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- cui/Module_cui.mk | 4 ++++ cui/UITest_cui_dialogs.mk | 16 ++++++++++++++ cui/qa/uitest/dialogs/pastedlg.py | 46 +++++++++++++++++++++++++++++++++++++++ cui/source/dialogs/pastedlg.cxx | 11 ++++++++++ 4 files changed, 77 insertions(+) create mode 100644 cui/UITest_cui_dialogs.mk create mode 100644 cui/qa/uitest/dialogs/pastedlg.py (limited to 'cui') diff --git a/cui/Module_cui.mk b/cui/Module_cui.mk index 888cd2a9f3cd..58026c6939fd 100644 --- a/cui/Module_cui.mk +++ b/cui/Module_cui.mk @@ -26,4 +26,8 @@ $(eval $(call gb_Module_add_screenshot_targets,cui,\ CppunitTest_cui_dialogs_test_4 \ )) +$(eval $(call gb_Module_add_uicheck_targets,cui,\ + UITest_cui_dialogs \ +)) + # vim: set noet sw=4 ts=4: diff --git a/cui/UITest_cui_dialogs.mk b/cui/UITest_cui_dialogs.mk new file mode 100644 index 000000000000..d3ad2dc64102 --- /dev/null +++ b/cui/UITest_cui_dialogs.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_UITest_UITest,cui_dialogs)) + +$(eval $(call gb_UITest_add_modules,cui_dialogs,$(SRCDIR)/cui/qa/uitest,\ + dialogs/ \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/cui/qa/uitest/dialogs/pastedlg.py b/cui/qa/uitest/dialogs/pastedlg.py new file mode 100644 index 000000000000..93973178c254 --- /dev/null +++ b/cui/qa/uitest/dialogs/pastedlg.py @@ -0,0 +1,46 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.framework import UITestCase +from uitest.uihelper.common import get_state_as_dict + + +# Test for SvPasteObjectDialog. +class Test(UITestCase): + + def testGetFormat(self): + # Copy a string in Impress. + self.ui_test.create_doc_in_start_center("impress") + template = self.xUITest.getTopFocusWindow() + self.ui_test.close_dialog_through_button(template.getChild("cancel")) + doc = self.xUITest.getTopFocusWindow() + editWin = doc.getChild("impress_win") + # Select the title shape. + editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"})) + editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"})) + self.xUITest.executeCommand(".uno:SelectAll") + self.xUITest.executeCommand(".uno:Copy") + + # Now use paste special to see what formats are offered. + self.ui_test.execute_dialog_through_command(".uno:PasteSpecial") + pasteSpecial = self.xUITest.getTopFocusWindow() + formats = pasteSpecial.getChild("list") + entryCount = int(get_state_as_dict(formats)["EntryCount"]) + items = [] + for index in range(entryCount): + formats.executeAction("SELECT", mkPropertyValues({"POS": str(index)})) + items.append(get_state_as_dict(formats)["SelectEntryText"]) + + # Make sure there is no RTF vs Richtext duplication. + self.assertTrue("Formatted text [RTF]" in items) + self.assertFalse("Formatted text [Richtext]" in items) + + # Close the dialog and the document. + self.ui_test.close_dialog_through_button(pasteSpecial.getChild("cancel")) + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/cui/source/dialogs/pastedlg.cxx b/cui/source/dialogs/pastedlg.cxx index 721cf06e1821..33fafa758654 100644 --- a/cui/source/dialogs/pastedlg.cxx +++ b/cui/source/dialogs/pastedlg.cxx @@ -161,6 +161,17 @@ SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelpe else if( aName.isEmpty() ) aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat ); + // Show RICHTEXT only in case RTF is not present. + if (nFormat == SotClipboardFormatId::RICHTEXT) + { + auto it = std::find_if(pFormats->begin(), pFormats->end(), + [](const DataFlavorEx& rFlavor) { + return rFlavor.mnSotId == SotClipboardFormatId::RTF; + }); + if (it != pFormats->end()) + continue; + } + if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) ) ObjectLB().SetEntryData( ObjectLB().InsertEntry( aName ), reinterpret_cast(nFormat) ); -- cgit