diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2012-09-23 21:49:45 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2012-09-23 22:00:57 +0200 |
commit | 0513e10635c85fc1aa214948de4992d4b76d555c (patch) | |
tree | 45bf6af83c16bc35c2917111184ddc606fe4b01b /editeng/source | |
parent | e9cd84cfaa323ca744fc39096bb90d8f564a1411 (diff) |
fdo#49350 Speedup "OK" action of auto-correct dialog
Instead of synchronizing the main list and the list of entries in the
dialog, just remember what was added and removed and only add / remove
those entries in the main "SvxAutoCorrect" list.
Additional add MakeCombinedChanges which adds and remove entries in
one call and only writes changes to the "acor" file once.
Change-Id: Idcc4c64d25e050c3f6eb9960a59c4a55d06b5ca1
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 9d618a6d327e..9c5809009587 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -1610,6 +1610,23 @@ sal_Bool SvxAutoCorrect::DeleteText( const String& rShort, LanguageType eLang ) return nTmpVal->second->DeleteText(rShort); return sal_False; } +sal_Bool SvxAutoCorrect::MakeCombinedChanges( std::vector<SvxAutocorrWord>& aNewEntries, + std::vector<SvxAutocorrWord>& aDeleteEntries, + LanguageType eLang ) +{ + boost::ptr_map<LanguageType, SvxAutoCorrectLanguageLists>::iterator nTmpVal = pLangTable->find(eLang); + if(nTmpVal != pLangTable->end()) + { + return nTmpVal->second->MakeCombinedChanges( aNewEntries, aDeleteEntries ); + } + else if(CreateLanguageFile( eLang )) + { + return pLangTable->find( eLang )->second->MakeCombinedChanges( aNewEntries, aDeleteEntries ); + } + return sal_False; + +} + // - return the replacement text (only for SWG-Format, all other // can be taken from the word list!) @@ -2482,8 +2499,88 @@ sal_Bool SvxAutoCorrectLanguageLists::MakeBlocklist_Imp( SvStorage& rStg ) return bRet; } -sal_Bool SvxAutoCorrectLanguageLists::PutText( const String& rShort, - const String& rLong ) +sal_Bool SvxAutoCorrectLanguageLists::MakeCombinedChanges( std::vector<SvxAutocorrWord>& aNewEntries, std::vector<SvxAutocorrWord>& aDeleteEntries ) +{ + // First get the current list! + GetAutocorrWordList(); + + MakeUserStorage_Impl(); + SotStorageRef xStorage = new SotStorage( sUserAutoCorrFile, STREAM_READWRITE, sal_True ); + + sal_Bool bRet = xStorage.Is() && SVSTREAM_OK == xStorage->GetError(); + + if( bRet ) + { + for ( sal_uInt32 i=0; i < aDeleteEntries.size(); i++ ) + { + SvxAutocorrWord aWordToDelete = aDeleteEntries[i]; + SvxAutocorrWordList::iterator iterator = pAutocorr_List->find( &aWordToDelete ); + if( iterator != pAutocorr_List->end() ) + { + SvxAutocorrWord* pFoundEntry = *iterator; + if( !pFoundEntry->IsTextOnly() ) + { + String aName( aWordToDelete.GetShort() ); + if (xStorage->IsOLEStorage()) + EncryptBlockName_Imp( aName ); + else + GeneratePackageName ( aWordToDelete.GetShort(), aName ); + + if( xStorage->IsContained( aName ) ) + { + xStorage->Remove( aName ); + bRet = xStorage->Commit(); + } + } + // Update the word list + delete pFoundEntry; + pAutocorr_List->erase( iterator ); + } + } + + for ( sal_uInt32 i=0; i < aNewEntries.size(); i++ ) + { + SvxAutocorrWord* aWordToAdd = new SvxAutocorrWord( aNewEntries[i].GetShort(), aNewEntries[i].GetLong(), sal_True ); + SvxAutocorrWordList::iterator iterator = pAutocorr_List->find( aWordToAdd ); + if( iterator != pAutocorr_List->end() ) + { + if( !(*iterator)->IsTextOnly() ) + { + // Still have to remove the Storage + String sStorageName( aWordToAdd->GetShort() ); + if (xStorage->IsOLEStorage()) + { + EncryptBlockName_Imp( sStorageName ); + } + else + { + GeneratePackageName ( aWordToAdd->GetShort(), sStorageName); + } + + if( xStorage->IsContained( sStorageName ) ) + xStorage->Remove( sStorageName ); + } + delete *iterator; + pAutocorr_List->erase( iterator ); + } + bRet = pAutocorr_List->insert( aWordToAdd ).second; + + if ( !bRet ) + { + delete aWordToAdd; + break; + } + } + + if ( bRet ) + { + bRet = MakeBlocklist_Imp( *xStorage ); + } + } + return bRet; +} + +sal_Bool SvxAutoCorrectLanguageLists::PutText( const String& rShort, const String& rLong ) { // First get the current list! GetAutocorrWordList(); |