From d37a18ff0576dcbc1e776bef7dc475928c0dd948 Mon Sep 17 00:00:00 2001 From: Akshay Deep Date: Tue, 24 May 2016 01:53:56 +0530 Subject: Template Manager: Filter by Application (Default) Change-Id: I3ff4a55e3c53df15079730a8d0a283108a74f212 Reviewed-on: https://gerrit.libreoffice.org/25377 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- include/sfx2/templatedlg.hxx | 3 ++ sfx2/source/appl/appopen.cxx | 10 +++++ sfx2/source/doc/templatedlg.cxx | 86 +++++++++++++++++++++++++++++++++-------- 3 files changed, 82 insertions(+), 17 deletions(-) diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index b4f9e29c34cd..bdae55693f76 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -49,11 +49,14 @@ public: virtual ~SfxTemplateManagerDlg(); virtual void dispose() override; + virtual short Execute() override; void setDocumentModel (const css::uno::Reference &rModel); private: + void getApplicationSpecificSettings(); + void readSettings (); void writeSettings (); diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index f1cfc5a2c45c..e5ff943baa32 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -448,7 +448,17 @@ void SfxApplication::NewDocExec_Impl( SfxRequest& rReq ) bool bNewWin = false; vcl::Window* pTopWin = GetTopWindow(); + SfxObjectShell* pCurrentShell = SfxObjectShell::Current(); + Reference xModel; + + if(pCurrentShell) + xModel = pCurrentShell->GetModel(); + ScopedVclPtrInstance< SfxTemplateManagerDlg > aTemplDlg; + + if(xModel.is()) + aTemplDlg->setDocumentModel(pCurrentShell->GetModel()); + int nRet = aTemplDlg->Execute(); if ( nRet == RET_OK ) { diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index e9279fcb0a9a..13476b832c47 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -291,8 +291,6 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg(vcl::Window *parent) mpCBApp->SetSelectHdl(LINK(this, SfxTemplateManagerDlg, SelectApplicationHdl)); mpCBFolder->SetSelectHdl(LINK(this, SfxTemplateManagerDlg, SelectRegionHdl)); - readSettings(); - mpLocalView->Show(); } @@ -339,6 +337,15 @@ void SfxTemplateManagerDlg::dispose() ModalDialog::dispose(); } +short SfxTemplateManagerDlg::Execute() +{ + //use application specific settings if there's no previous setting + getApplicationSpecificSettings(); + readSettings(); + + return ModalDialog::Execute(); +} + void SfxTemplateManagerDlg::setDocumentModel(const uno::Reference &rModel) { m_xModel = rModel; @@ -373,6 +380,45 @@ void SfxTemplateManagerDlg::fillFolderComboBox() mpLocalView->ShowTooltips(true); } +void SfxTemplateManagerDlg::getApplicationSpecificSettings() +{ + if ( ! m_xModel.is() ) + { + mpCBApp->SelectEntryPos(0); + mpCBFolder->SelectEntryPos(0); + mpCurView->filterItems(ViewFilter_Application(getCurrentApplicationFilter())); + mpLocalView->showAllTemplates(); + return; + } + + SvtModuleOptions::EFactory eFactory = SvtModuleOptions::ClassifyFactoryByModel(m_xModel); + + switch(eFactory) + { + case SvtModuleOptions::EFactory::WRITER: + case SvtModuleOptions::EFactory::WRITERWEB: + case SvtModuleOptions::EFactory::WRITERGLOBAL: + mpCBApp->SelectEntryPos(MNI_WRITER); + break; + case SvtModuleOptions::EFactory::CALC: + mpCBApp->SelectEntryPos(MNI_CALC); + break; + case SvtModuleOptions::EFactory::IMPRESS: + mpCBApp->SelectEntryPos(MNI_IMPRESS); + break; + case SvtModuleOptions::EFactory::DRAW: + mpCBApp->SelectEntryPos(MNI_DRAW); + break; + default: + mpCBApp->SelectEntryPos(0); + break; + } + + mpCurView->filterItems(ViewFilter_Application(getCurrentApplicationFilter())); + mpCBFolder->SelectEntryPos(0); + mpLocalView->showAllTemplates(); +} + void SfxTemplateManagerDlg::readSettings () { OUString aLastFolder; @@ -383,22 +429,28 @@ void SfxTemplateManagerDlg::readSettings () sal_uInt16 nTmp = 0; aViewSettings.GetUserItem(TM_SETTING_LASTFOLDER) >>= aLastFolder; aViewSettings.GetUserItem(TM_SETTING_LASTAPPLICATION) >>= nTmp; - switch (nTmp) + + //open last remembered application only when application model is not set + if(!m_xModel.is()) { - case MNI_WRITER: - mpCBApp->SelectEntryPos(MNI_WRITER); - break; - case MNI_CALC: - mpCBApp->SelectEntryPos(MNI_CALC); - break; - case MNI_IMPRESS: - mpCBApp->SelectEntryPos(MNI_IMPRESS); - break; - case MNI_DRAW: - mpCBApp->SelectEntryPos(MNI_DRAW); - break; - default: - mpCBApp->SelectEntryPos(0); + switch (nTmp) + { + case MNI_WRITER: + mpCBApp->SelectEntryPos(MNI_WRITER); + break; + case MNI_CALC: + mpCBApp->SelectEntryPos(MNI_CALC); + break; + case MNI_IMPRESS: + mpCBApp->SelectEntryPos(MNI_IMPRESS); + break; + case MNI_DRAW: + mpCBApp->SelectEntryPos(MNI_DRAW); + break; + default: + mpCBApp->SelectEntryPos(0); + break; + } } } -- cgit