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>
This commit is contained in:
Andreas Heinisch 2023-01-08 12:31:51 +01:00
parent 5dd5011eab
commit fbabd95906
2 changed files with 52 additions and 5 deletions

View file

@ -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:

View file

@ -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