From fddc8c3db8d4bcdf370b9364756b6144aa0dc3ed Mon Sep 17 00:00:00 2001 From: Muhammad Haggag Date: Tue, 14 Feb 2012 10:46:46 +0200 Subject: [PATCH] fdo#37775: Recent Documents not updated by Save & Save As This patch changes LO behavior so that we update recent documents on file save, save as, save all, and close. The previous behavior was to only update the list on document close. = Changes = SfxPickList (sfxpicklist.cxx/hxx): . Extracted the logic to add a document to the "Recent Documents" list into a function of its own: AddDocumentToPickList - Simplified the logic used by removing the check of SfxObjectShell_impl::bWaitingForPickList (see SfxObjectShell_impl::bWaitingForPickList below for details) . Modified SfxPickList::Notify to call the aforementioned function on save, save-to, and save-as. SfxObjectShell::APISaveAs_Impl (objserv.cxx): . Modified it to allow picklist entry when doing "Save As". SfxObjectShell_impl::bWaitingForPickList (objstor.cxx, objxtor.cxx, objshimp.hxx): . Removed this flag. It was used to indicate that a document wants to be added to the picklist, then cleared after it's added. Since we now always add documents to the picklist on saving, we no longer need it. = Verification = The change is in sfx2, so it should apply to all LO apps. I verified the new behavior in both writer and calc with the following actions: . File->Save . File->Save As . File->Save All . File->Close --- sfx2/source/appl/sfxpicklist.cxx | 109 ++++++++++++++++++++++--------------- sfx2/source/doc/objserv.cxx | 3 - sfx2/source/doc/objstor.cxx | 2 - sfx2/source/doc/objxtor.cxx | 1 - sfx2/source/inc/objshimp.hxx | 1 - sfx2/source/inc/sfxpicklist.hxx | 6 ++ 6 files changed, 71 insertions(+), 51 deletions(-) diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx index b0169a5..1198732 100644 --- a/sfx2/source/appl/sfxpicklist.cxx +++ b/sfx2/source/appl/sfxpicklist.cxx @@ -164,6 +164,52 @@ SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex ) return 0; } +void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh ) +{ + SfxMedium *pMed = pDocSh->GetMedium(); + if( !pMed ) + return; + + // Unnamed Documents and embedded-Documents not in Picklist + if ( !pDocSh->HasName() || + SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() ) + return; + + // Help not in History + INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) ); + if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP ) + return; + + // only add r/w document into picklist + if ( pDocSh->IsReadOnly() || !pMed->IsUpdatePickList() ) + return; + + // add no document that forbids this (for example Message-Body) + SFX_ITEMSET_ARG( pMed->GetItemSet(), pPicklistItem, SfxBoolItem, SID_PICKLIST, sal_False ); + if ( pPicklistItem && !pPicklistItem->GetValue() ) + return; + + // ignore hidden documents + if ( !SfxViewFrame::GetFirst( pDocSh, sal_True ) ) + return; + + ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST); + ::rtl::OUString aFilter; + const SfxFilter* pFilter = pMed->GetOrigFilter(); + if ( pFilter ) + aFilter = pFilter->GetFilterName(); + + // add to svtool history options + SvtHistoryOptions().AppendItem( ePICKLIST, + aURL.GetURLNoPass( INetURLObject::NO_DECODE ), + aFilter, + aTitle, + SfxStringEncode( aURL.GetPass() ) ); + + if ( aURL.GetProtocol() == INET_PROT_FILE ) + Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ), (pFilter) ? pFilter->GetMimeType() : ::rtl::OUString() ); +} + SfxPickList& SfxPickList::Get() { static SfxPickList aUniqueInstance(SvtHistoryOptions().GetSize(ePICKLIST)); @@ -375,55 +421,30 @@ void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint ) } break; + case SFX_EVENT_SAVEDOCDONE: + case SFX_EVENT_SAVEASDOCDONE: + case SFX_EVENT_SAVETODOCDONE: case SFX_EVENT_CLOSEDOC: { - SfxMedium *pMed = pDocSh->GetMedium(); - if( !pMed ) - return; - - // Unnamed Documents and embedded-Documents not im Pickliste - if ( !pDocSh->HasName() || - SFX_CREATE_MODE_STANDARD != pDocSh->GetCreateMode() ) - return; - - // Help not in History - INetURLObject aURL( pDocSh->IsDocShared() ? pDocSh->GetSharedFileURL() : ::rtl::OUString( pMed->GetOrigURL() ) ); - if ( aURL.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP ) - return; - - // only add r/w document into picklist - if ( pDocSh->IsReadOnly() || !pMed->IsUpdatePickList() ) - return; - - // add no document that forbids this (for example Message-Body) - SFX_ITEMSET_ARG( pMed->GetItemSet(), pPicklistItem, SfxBoolItem, SID_PICKLIST, sal_False ); - if ( - (pPicklistItem && !pPicklistItem->GetValue()) || - (!(pDocSh->Get_Impl()->bWaitingForPicklist) ) - ) - return; + AddDocumentToPickList(pDocSh); + } + break; - // ignore hidden documents - if ( !SfxViewFrame::GetFirst( pDocSh, sal_True ) ) + case SFX_EVENT_SAVEASDOC: + { + SfxMedium *pMedium = pDocSh->GetMedium(); + if (!pMedium) return; - ::rtl::OUString aTitle = pDocSh->GetTitle(SFX_TITLE_PICKLIST); - ::rtl::OUString aFilter; - const SfxFilter* pFilter = pMed->GetOrigFilter(); - if ( pFilter ) - aFilter = pFilter->GetFilterName(); - - // add to svtool history options - SvtHistoryOptions().AppendItem( ePICKLIST, - aURL.GetURLNoPass( INetURLObject::NO_DECODE ), - aFilter, - aTitle, - SfxStringEncode( aURL.GetPass() ) ); - - pDocSh->Get_Impl()->bWaitingForPicklist = sal_False; - - if ( aURL.GetProtocol() == INET_PROT_FILE ) - Application::AddToRecentDocumentList( aURL.GetURLNoPass( INetURLObject::NO_DECODE ), (pFilter) ? pFilter->GetMimeType() : ::rtl::OUString() ); + // We're starting a "Save As". Add the current document (if it's + // not a "new" document) to the "Recent Documents" list before we + // switch to the new path. + // If the current document is new, path will be empty. + rtl::OUString path = pMedium->GetOrigURL(); + if (!path.isEmpty()) + { + AddDocumentToPickList(pDocSh); + } } break; } diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 9563f58..bce45ff 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -342,9 +342,6 @@ sal_Bool SfxObjectShell::APISaveAs_Impl aParams ); } - - // prevent picklist-entry - GetMedium()->SetUpdatePickList( sal_False ); } return bOk; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index a4f165d..604d824 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2605,8 +2605,6 @@ sal_Bool SfxObjectShell::CommonSaveAs_Impl if ( PreDoSaveAs_Impl(aURL.GetMainURL( INetURLObject::NO_DECODE ),aFilterName,aParams)) { - pImp->bWaitingForPicklist = sal_True; - // Update Data on media SfxItemSet *pSet = GetMedium()->GetItemSet(); pSet->ClearItem( SID_INTERACTIONHANDLER ); diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 89d42be..1cda68b 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -236,7 +236,6 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,bImportDone ( sal_False) ,bInPrepareClose( sal_False ) ,bPreparedForClose( sal_False ) - ,bWaitingForPicklist( sal_True ) ,bForbidReload( sal_False ) ,bBasicInitialized( sal_False ) ,bIsPrintJobCancelable( sal_True ) diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index 9d32752..ef75f3af 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -89,7 +89,6 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess bImportDone : 1, // Import finished already? For auto reload of Docs. bInPrepareClose : 1, bPreparedForClose : 1, - bWaitingForPicklist : 1, // Must go into pick list bForbidReload : 1, bBasicInitialized :1, bIsPrintJobCancelable :1, // Stampit disable/enable cancel button for print jobs ... default = true = enable! diff --git a/sfx2/source/inc/sfxpicklist.hxx b/sfx2/source/inc/sfxpicklist.hxx index 987e78a..85fd0a1 100644 --- a/sfx2/source/inc/sfxpicklist.hxx +++ b/sfx2/source/inc/sfxpicklist.hxx @@ -62,6 +62,12 @@ class SfxPickList : public SfxListener PickListEntry* GetPickListEntry( sal_uInt32 nIndex ); void CreatePickListEntries(); void RemovePickListEntries(); + /** + * Adds the given document to the pick list (recent documents) if it satisfies + certain requirements, e.g. being writable. Check implementation for requirement + details. + */ + void AddDocumentToPickList( SfxObjectShell* pDocShell ); public: static SfxPickList& Get(); -- 1.7.5.4