tdf#139647 refresh renamed items
*Update templates names after rename (faster than reload).
*Fix some warnings.
Change-Id: I47387af91964afae8de8753289d49d19e6080863
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119919
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx
index 588a307..940973f 100644
--- a/include/sfx2/templatedlg.hxx
+++ b/include/sfx2/templatedlg.hxx
@@ -78,7 +78,6 @@ protected:
DECL_LINK(ExportTemplateHdl, void*, void);
void SearchUpdate();
void FilterSearch();
DECL_LINK(SearchUpdateHdl, weld::Entry&, void);
DECL_LINK(GetFocusHdl, weld::Widget&, void);
diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx
index fbf730a..2ad8139 100644
--- a/include/sfx2/templatelocalview.hxx
+++ b/include/sfx2/templatelocalview.hxx
@@ -126,6 +126,8 @@ public:
sal_uInt16 getCurRegionId () const { return mnCurRegionId;}
void setCurRegionId (sal_uInt16 nCurRegionId) { mnCurRegionId = nCurRegionId;}
void setOpenRegionHdl(const Link<void*,void> &rLink);
void setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink);
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 0ba60c0..4d0571e 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -613,7 +613,41 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe
nDocId = pDocItem->mnDocId;
}
return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
bool bRes = mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
if(bRes)
{
for (auto & pRegion : maRegions)
{
if (pRegion->mnId == nRegionId + 1 )
{
for(auto & aTemplate : pRegion->maTemplates)
{
if(aTemplate.nId == nDocId + 1)
{
aTemplate.aName = sNewTitle;
break;
}
}
break;
}
}
OUString sRegionName;
for (auto & aTemplate : maAllTemplates)
{
if (aTemplate.nRegionId == nRegionId && aTemplate.nDocId == nDocId)
{
aTemplate.aName = sNewTitle;
sRegionName = aTemplate.aRegionName;
break;
}
}
OUString sHelpText = SfxResId(STR_TEMPLATE_TOOLTIP);
sHelpText = (sHelpText.replaceFirst("$1", sNewTitle)).replaceFirst("$2", sRegionName);
pItem->setHelpText(sHelpText);
pItem->maTitle = sNewTitle;
}
return bRes;
}
void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip)
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index c4dbc7c..5f5760c 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -68,9 +68,7 @@ constexpr OUStringLiteral TM_SETTING_VIEWMODE = u"ViewMode";
#define MNI_ACTION_DEFAULT_CALC "default calc"
#define MNI_ACTION_DEFAULT_IMPRESS "default impress"
#define MNI_ACTION_DEFAULT_DRAW "default draw"
#define MNI_ACTION_MOVE "move template"
#define MNI_ACTION_IMPORT "import template"
#define MNI_ACTION_EXPORT "export template"
#define MNI_ACTION_EXTENSIONS "extensions"
#define MNI_ALL_APPLICATIONS 0
#define MNI_WRITER 1
@@ -231,10 +229,8 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg(weld::Window *pParent)
fillFolderComboBox();
mxActionBar->set_item_visible(MNI_ACTION_EXTENSIONS, true);
mxActionBar->set_item_visible(MNI_ACTION_EXPORT, true);
mxActionBar->set_item_visible(MNI_ACTION_MOVE, true);
mxActionBar->set_item_visible(MNI_ACTION_RENAME_FOLDER, true);
mxActionBar->set_item_visible(MNI_ACTION_DELETE_FOLDER, true);
mxActionBar->set_item_visible(MNI_ACTION_IMPORT, true);
mxActionBar->set_item_visible(MNI_ACTION_NEW_FOLDER, true);
mxOKButton->set_label(SfxResId(STR_OPEN));
@@ -493,18 +489,16 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SelectRegionHdl, weld::ComboBox&, void)
if(mxCBFolder->get_active() == 0)
{
mxLocalView->showAllTemplates();
mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
}
else
{
mxLocalView->showRegion(sSelectedRegion);
bool bIsBuiltInRegion = mxLocalView->IsBuiltInRegion(sSelectedRegion);
mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, !bIsBuiltInRegion);
mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, !bIsBuiltInRegion);
}
FilterSearch();
SearchUpdate();
}
IMPL_LINK(SfxTemplateManagerDlg, TVItemStateHdl, const ThumbnailViewItem*, pItem, void)
@@ -526,7 +520,7 @@ IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, const OString&, rIdent, void)
else if (rIdent == MNI_ACTION_REFRESH)
{
mxLocalView->reload();
FilterSearch();
SearchUpdate();
}
else if (rIdent == MNI_ACTION_DEFAULT)
{
@@ -607,7 +601,7 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, MoveTemplateHdl, void*, void)
}
mxLocalView->reload();
FilterSearch();
SearchUpdate();
}
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg, ExportTemplateHdl, void*, void)
@@ -646,23 +640,15 @@ void SfxTemplateManagerDlg::ImportActionHdl()
}
else
OnTemplateImportCategory(sCategory);
mxLocalView->reload();
mxLocalView->showAllTemplates();
FilterSearch();
mxCBApp->set_active(0);
mxCBFolder->set_active(0);
mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
}
}
else
{
const auto sCategory = mxCBFolder->get_active_text();
OnTemplateImportCategory(sCategory);
mxLocalView->reload();
FilterSearch();
}
mxLocalView->reload();
SearchUpdate();
}
void SfxTemplateManagerDlg::ExtensionsActionHdl()
@@ -866,38 +852,22 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, FocusRectLocalHdl, weld::Widget&, tools::
bMakeSelItemVisible = false;
return tools::Rectangle();
}
void SfxTemplateManagerDlg::FilterSearch()
{
OUString aKeyword = mxSearchFilter->get_text();
if (!aKeyword.isEmpty())
{
mxLocalView->Clear();
std::vector<TemplateItemProperties> aItems =
mxLocalView->getFilteredItems(SearchView_Keyword(aKeyword, getCurrentApplicationFilter()));
mxLocalView->insertItems(aItems, mxCBFolder->get_active()==0, true);
mxLocalView->Invalidate();
}
}
void SfxTemplateManagerDlg::SearchUpdate()
{
const OUString sSelectedRegion = mxCBFolder->get_active_text();
mxLocalView->setCurRegionId(mxLocalView->getRegionId(sSelectedRegion));
OUString aKeyword = mxSearchFilter->get_text();
if (!aKeyword.isEmpty())
{
mxLocalView->Clear();
std::vector<TemplateItemProperties> aItems =
mxLocalView->getFilteredItems(SearchView_Keyword(aKeyword, getCurrentApplicationFilter()));
mxLocalView->insertItems(aItems, mxCBFolder->get_active()==0, true);
mxLocalView->Invalidate();
}
else
{
mxLocalView->deselectItems();
mxLocalView->filterItems(ViewFilter_Application(getCurrentApplicationFilter()));
mxLocalView->reload();
OUString sLastFolder = mxCBFolder->get_active_text();
mxLocalView->showRegion(sLastFolder);
mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, true);
}
mxLocalView->Clear();
std::function<bool(const TemplateItemProperties &)> aFunc =
[&](const TemplateItemProperties &rItem)->bool
{
return aKeyword.isEmpty() || SearchView_Keyword(aKeyword, getCurrentApplicationFilter())(rItem);
};
std::vector<TemplateItemProperties> aItems = mxLocalView->getFilteredItems(aFunc);
mxLocalView->insertItems(aItems, mxCBFolder->get_active()!=0, true);
mxLocalView->Invalidate();
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg, GetFocusHdl, weld::Widget&, void)
@@ -941,16 +911,6 @@ void SfxTemplateManagerDlg::OnTemplateState (const ThumbnailViewItem *pItem)
}
}
if(maSelTemplates.empty())
{
mxActionBar->set_item_sensitive(MNI_ACTION_MOVE, false);
mxActionBar->set_item_sensitive(MNI_ACTION_EXPORT, false);
}
else
{
mxActionBar->set_item_sensitive(MNI_ACTION_MOVE, true);
mxActionBar->set_item_sensitive(MNI_ACTION_EXPORT, true);
}
}
void SfxTemplateManagerDlg::OnTemplateImportCategory(std::u16string_view sCategory)
@@ -1161,7 +1121,7 @@ void SfxTemplateManagerDlg::OnCategoryRename()
mxCBFolder->set_active(nPos);
mxLocalView->reload();
mxLocalView->showRegion(aName);
SearchUpdate();
}
else
{
@@ -1201,6 +1161,7 @@ void SfxTemplateManagerDlg::OnCategoryDelete()
mxLocalView->showAllTemplates();
mxCBApp->set_active(0);
mxCBFolder->set_active(0);
SearchUpdate();
mxActionBar->set_item_sensitive(MNI_ACTION_RENAME_FOLDER, false);
mxActionBar->set_item_sensitive(MNI_ACTION_DELETE_FOLDER, false);
updateMenuItems();