include/sfx2/templatedlglocalview.hxx | 4 + include/sfx2/uiobject.hxx | 28 +++++++++++ sfx2/Library_sfx.mk | 1 sfx2/source/control/templatedlglocalview.cxx | 7 ++ sfx2/source/control/uiobject.cxx | 65 ++++++++++++++++++++++++++ sw/qa/uitest/writer_tests8/manageTemplates.py | 40 ++++++++++++++++ 6 files changed, 145 insertions(+)
New commits: commit e7edd94565e8dd323395ec316c482ec32f14638c Author: Xisco Fauli <[email protected]> AuthorDate: Wed Jan 21 14:45:00 2026 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Fri Jan 23 08:54:14 2026 +0100 tdf#170399: sw: Add UItest (Add UI wrapper for TemplateDlgLocalView) Change-Id: I3b7fd93f8ae3533e2c5ca1acde6b79d091113ad6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197757 Reviewed-by: Xisco Fauli <[email protected]> Tested-by: Jenkins diff --git a/include/sfx2/templatedlglocalview.hxx b/include/sfx2/templatedlglocalview.hxx index fbba7c166ddd..9bfc81c18ef7 100644 --- a/include/sfx2/templatedlglocalview.hxx +++ b/include/sfx2/templatedlglocalview.hxx @@ -13,6 +13,8 @@ class TemplateDlgLocalView final : public TemplateLocalView, public ListView { + friend class TemplateDlgLocalViewUIObject; + public: TemplateDlgLocalView(std::unique_ptr<weld::ScrolledWindow> xWindow, std::unique_ptr<weld::Menu> xMenu, @@ -50,6 +52,8 @@ public: void insertItems(const std::vector<TemplateItemProperties>& rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip); + virtual FactoryFunction GetUITestFactory() const override; + private: void ContextMenuSelectHdl(std::u16string_view rIdent); diff --git a/include/sfx2/uiobject.hxx b/include/sfx2/uiobject.hxx new file mode 100644 index 000000000000..bcd18289b21e --- /dev/null +++ b/include/sfx2/uiobject.hxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + */ + +#include <vcl/uitest/uiobject.hxx> +#include <sfx2/templatedlg.hxx> + +class TemplateDlgLocalViewUIObject : public DrawingAreaUIObject +{ + TemplateDlgLocalView* mpTemplateDlgLocalView; + + virtual OUString get_name() const override; + +public: + TemplateDlgLocalViewUIObject(vcl::Window* rTemplateDlgLocalView); + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 8357dec83af8..669744b8fe7d 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -167,6 +167,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/thumbnailview \ sfx2/source/control/charmapcontainer \ sfx2/source/control/charmapcontrol \ + sfx2/source/control/uiobject \ sfx2/source/control/unoctitm \ sfx2/source/devtools/DevelopmentToolChildWindow \ sfx2/source/devtools/DevelopmentToolDockingWindow \ diff --git a/sfx2/source/control/templatedlglocalview.cxx b/sfx2/source/control/templatedlglocalview.cxx index f3439c814de8..78fd122d38fb 100644 --- a/sfx2/source/control/templatedlglocalview.cxx +++ b/sfx2/source/control/templatedlglocalview.cxx @@ -13,6 +13,7 @@ #include <inputdlg.hxx> #include <templateviewitem.hxx> #include <sfx2/sfxresid.hxx> +#include <sfx2/uiobject.hxx> #include <templatecontaineritem.hxx> #include <sfx2/strings.hrc> #include <vcl/commandevent.hxx> @@ -426,4 +427,10 @@ IMPL_LINK(TemplateDlgLocalView, KeyPressHdl, const KeyEvent&, rKEvt, bool) } return false; } + +FactoryFunction TemplateDlgLocalView::GetUITestFactory() const +{ + return TemplateDlgLocalViewUIObject::create; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/uiobject.cxx b/sfx2/source/control/uiobject.cxx new file mode 100644 index 000000000000..d486c794a24d --- /dev/null +++ b/sfx2/source/control/uiobject.cxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + */ + +#include <sfx2/uiobject.hxx> +#include <templateviewitem.hxx> + +TemplateDlgLocalViewUIObject::TemplateDlgLocalViewUIObject(vcl::Window* rTemplateDlgLocalView) + : DrawingAreaUIObject(rTemplateDlgLocalView) + , mpTemplateDlgLocalView(static_cast<TemplateDlgLocalView*>(mpController)) +{ +} + +StringMap TemplateDlgLocalViewUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + aMap[u"SelectedIndex"_ustr] = OUString::number(mpTemplateDlgLocalView->get_selected_index()); + if (TemplateViewItem* pSelectedItem = mpTemplateDlgLocalView->mpSelectedItem) + { + aMap[u"SelectedItemTitle"_ustr] = pSelectedItem->getTitle(); + } + + return aMap; +} + +void TemplateDlgLocalViewUIObject::execute(const OUString& rAction, const StringMap& rParameters) +{ + if (rAction == "EDIT" || rAction == "RENAME" || rAction == "DELETE" || rAction == "DEFAULT" + || rAction == "MOVE" || rAction == "EXPORT") + { + if (mpTemplateDlgLocalView->mpSelectedItem) + { + mpTemplateDlgLocalView->ContextMenuSelectHdl(rAction.toAsciiLowerCase()); + } + } + else if (rAction == "SELECT") + { + if (rParameters.find(u"POS"_ustr) != rParameters.end()) + { + auto itr = rParameters.find(u"POS"_ustr); + sal_uInt32 nPos = itr->second.toUInt32(); + mpTemplateDlgLocalView->set_cursor(nPos); + mpTemplateDlgLocalView->updateSelection(); + } + } + else + WindowUIObject::execute(rAction, rParameters); +} + +std::unique_ptr<UIObject> TemplateDlgLocalViewUIObject::create(vcl::Window* pWindow) +{ + return std::unique_ptr<UIObject>(new TemplateDlgLocalViewUIObject(pWindow)); +} + +OUString TemplateDlgLocalViewUIObject::get_name() const +{ + return u"TemplateDlgLocalViewUIObject"_ustr; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uitest/writer_tests8/manageTemplates.py b/sw/qa/uitest/writer_tests8/manageTemplates.py new file mode 100644 index 000000000000..4d019407606e --- /dev/null +++ b/sw/qa/uitest/writer_tests8/manageTemplates.py @@ -0,0 +1,40 @@ +# -*- 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 get_state_as_dict +from libreoffice.uno.propertyvalue import mkPropertyValues + +class ManageTemplates(UITestCase): + + def test_EditTemplate(self): + + try: + # Open "Manage Templates" dialog from the start center + with self.ui_test.execute_dialog_through_command(".uno:NewDoc", close_button="") as xDialog: + xTemplateView = xDialog.getChild("template_view") + xTemplateView.executeAction("SELECT", mkPropertyValues({"POS": "1"})) + print(get_state_as_dict(xTemplateView)) + self.assertEqual("1", get_state_as_dict(xTemplateView)["SelectedIndex"]) + self.assertTrue(get_state_as_dict(xTemplateView)["SelectedItemTitle"].startswith("Modern business letter")) + + # tdf#170399: Without the fix in place, this test would have crashed here + xTemplateView.executeAction("EDIT", tuple()) + except: + # if it fails, close the dialog before disposing + xTemplateDlg = self.xUITest.getTopFocusWindow() + xCancelBtn = xTemplateDlg.getChild("close") + self.ui_test.close_dialog_through_button(xCancelBtn) + raise + + document = self.ui_test.get_component() + self.assertTrue(document.Title.startswith("Modern_business_letter")) + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab:
