diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2023-01-08 12:31:51 +0100 |
---|---|---|
committer | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2023-01-11 06:58:42 +0000 |
commit | fbabd959060655a77188447c9fc0112e0ab8474c (patch) | |
tree | 4b3be0d14c069aac83b02c1d9448fb8870b2230c /sw | |
parent | 5dd5011eabc755d4ea8d282c32dd4854d532849a (diff) |
tdf#124088 - Propose AutoText and shortcut name based on selected text
Change-Id: I55ab9b41a32d7a4e41465f375179997a5c8dd06a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145175
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Diffstat (limited to 'sw')
-rwxr-xr-x | sw/qa/uitest/writer_tests3/tdf124088.py | 33 | ||||
-rw-r--r-- | sw/source/ui/misc/glossary.cxx | 24 |
2 files changed, 52 insertions, 5 deletions
diff --git a/sw/qa/uitest/writer_tests3/tdf124088.py b/sw/qa/uitest/writer_tests3/tdf124088.py new file mode 100755 index 000000000000..6ff65dad7631 --- /dev/null +++ b/sw/qa/uitest/writer_tests3/tdf124088.py @@ -0,0 +1,33 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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/. +# + +from uitest.framework import UITestCase +from uitest.uihelper.common import type_text, get_state_as_dict + +class tdf124088(UITestCase): + + def test_tdf124088_propose_autotext(self): + with self.ui_test.create_doc_in_start_center("writer"): + # Insert a random text greater than 25 characters and select it + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + type_text(xWriterEdit, "This is a sample paragraph") + self.xUITest.executeCommand(".uno:SelectAll") + + # Open auto text dialog and check proposed text + with self.ui_test.execute_dialog_through_command(".uno:EditGlossary") as xEditGlossaryDlg: + xName = xEditGlossaryDlg.getChild("name") + self.assertEqual(get_state_as_dict(xName)["Text"], "This is a sample") + # Click on a group entry, proposed auto text should remain + xCategory = xEditGlossaryDlg.getChild("category") + xMyAutoText = xCategory.getChild("2") + xMyAutoText.executeAction("SELECT", tuple()) + self.assertEqual(get_state_as_dict(xName)["Text"], "This is a sample") + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/ui/misc/glossary.cxx b/sw/source/ui/misc/glossary.cxx index ae3ce4f06666..a1e4a60fe883 100644 --- a/sw/source/ui/misc/glossary.cxx +++ b/sw/source/ui/misc/glossary.cxx @@ -410,12 +410,7 @@ IMPL_LINK(SwGlossaryDlg, GrpSelect, weld::TreeView&, rBox, void) ShowAutoText(::GetCurrGlosGroup(), m_xShortNameEdit->get_text()); } else - { - m_xNameED->set_text(""); - m_xShortNameEdit->set_text(""); - m_xShortNameEdit->set_sensitive(false); ShowAutoText("", ""); - } // update controls NameModify(*m_xShortNameEdit); if( SfxRequest::HasMacroRecorder( m_pShell->GetView().GetViewFrame() ) ) @@ -904,6 +899,25 @@ void SwGlossaryDlg::Init() m_xInsertTipCB->set_active( rCfg.IsAutoTextTip() ); m_xInsertTipCB->set_sensitive(!officecfg::Office::Writer::AutoFunction::Text::ShowToolTip::isReadOnly()); m_xInsertTipCB->connect_toggled(LINK(this, SwGlossaryDlg, CheckBoxHdl)); + + // tdf#124088 - propose autotext and shortcut name based on selected text + if (m_pShell->HasSelection()) + { + OUString aSelText; + m_pShell->GetSelectedText(aSelText, ParaBreakType::ToBlank); + + aSelText = aSelText.trim(); + if (aSelText.getLength() > 25) + { + aSelText = aSelText.copy(0, 25); + if (const sal_Int32 nBlankIndex = aSelText.lastIndexOf(' '); nBlankIndex != -1) + aSelText = aSelText.copy(0, nBlankIndex); + } + + m_xNameED->set_text(aSelText); + m_xNameED->select_region(0, -1); + m_xShortNameEdit->set_text(lcl_GetValidShortCut(aSelText)); + } } // KeyInput for ShortName - Edits without Spaces |