basctl/source/basicide/baside3.cxx | 160 +++++++++++++++---------------------- 1 file changed, 68 insertions(+), 92 deletions(-)
New commits: commit 90ac25f12cecd5850607096acf4d97f29baaa710 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Apr 29 14:24:43 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Apr 29 14:30:27 2023 +0200 Simplify a bit Change-Id: Id768a3e10eb593af84bdea423ddfd090df33eef2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151182 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx index 61bbbc056956..0e51f00be348 100644 --- a/basctl/source/basicide/baside3.cxx +++ b/basctl/source/basicide/baside3.cxx @@ -601,18 +601,12 @@ void DialogWindow::UpdateBrowser() void DialogWindow::SaveDialog() { - Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext()); - sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD, + sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, FileDialogFlags::NONE, this->GetFrameWeld()); aDlg.SetContext(sfx2::FileDialogHelper::BasicExportDialog); Reference<XFilePicker3> xFP = aDlg.GetFilePicker(); - Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY); - xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false); - Any aValue; - aValue <<= true; - xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue); - + xFP.queryThrow<XFilePickerControlAccess>()->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, Any(true)); xFP->setDefaultName( GetName() ); OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME)); @@ -625,11 +619,7 @@ void DialogWindow::SaveDialog() OUString aSelectedFileURL = xFP->getSelectedFiles()[0]; - // export dialog model to xml - Reference< container::XNameContainer > xDialogModel = GetDialog(); - Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, GetDocument().isDocument() ? GetDocument().getDocument() : Reference< frame::XModel >() ); - Reference< XInputStream > xInput( xISP->createInputStream() ); - + Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) ); Reference< XOutputStream > xOutput; @@ -642,108 +632,94 @@ void DialogWindow::SaveDialog() catch(const Exception& ) {} - if( xOutput.is() ) + if (!xOutput) { - Sequence< sal_Int8 > bytes; - sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() ); - for (;;) - { - if( nRead ) - xOutput->writeBytes( bytes ); + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), + VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_COULDNTWRITE))); + xBox->run(); + return; + } - nRead = xInput->readBytes( bytes, 1024 ); - if (! nRead) - break; - } + // export dialog model to xml + auto xInput(xmlscript::exportDialogModel(GetDialog(), xContext, GetDocument().getDocumentOrNull())->createInputStream()); - // With resource? - Reference< beans::XPropertySet > xDialogModelPropSet( xDialogModel, UNO_QUERY ); - Reference< resource::XStringResourceResolver > xStringResourceResolver; - if( xDialogModelPropSet.is() ) - { - try - { - Any aResourceResolver = xDialogModelPropSet->getPropertyValue( "ResourceResolver" ); - aResourceResolver >>= xStringResourceResolver; - } - catch(const beans::UnknownPropertyException& ) - {} - } + for (Sequence<sal_Int8> bytes; xInput->readBytes(bytes, xInput->available());) + xOutput->writeBytes(bytes); - bool bResource = false; - if( xStringResourceResolver.is() ) + // With resource? + Reference< resource::XStringResourceResolver > xStringResourceResolver; + if (auto xDialogModelPropSet = GetDialog().query<beans::XPropertySet>()) + { + try { - Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales(); - if( aLocaleSeq.hasElements() ) - bResource = true; + Any aResourceResolver = xDialogModelPropSet->getPropertyValue( "ResourceResolver" ); + aResourceResolver >>= xStringResourceResolver; } + catch(const beans::UnknownPropertyException& ) + {} + } - if( bResource ) + Sequence<lang::Locale> aLocaleSeq; + if (xStringResourceResolver) + aLocaleSeq = xStringResourceResolver->getLocales(); + if (aLocaleSeq.hasElements()) + { + INetURLObject aURLObj(aSelectedFileURL); + aURLObj.removeExtension(); + OUString aDialogName( aURLObj.getName() ); + aURLObj.removeSegment(); + OUString aURL( aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); + OUString aComment = "# " + aDialogName + " strings" ; + Reference< task::XInteractionHandler > xDummyHandler; + + // Remove old properties files in case of overwriting Dialog files + if( xSFI->isFolder( aURL ) ) { - INetURLObject aURLObj(aSelectedFileURL); - aURLObj.removeExtension(); - OUString aDialogName( aURLObj.getName() ); - aURLObj.removeSegment(); - OUString aURL( aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); - OUString aComment = "# " + aDialogName + " strings" ; - Reference< task::XInteractionHandler > xDummyHandler; + Sequence< OUString > aContentSeq = xSFI->getFolderContents( aURL, false ); - // Remove old properties files in case of overwriting Dialog files - if( xSFI->isFolder( aURL ) ) + OUString aDialogName_ = aDialogName + "_" ; + for( const OUString& rCompleteName : aContentSeq ) { - Sequence< OUString > aContentSeq = xSFI->getFolderContents( aURL, false ); - - OUString aDialogName_ = aDialogName + "_" ; - for( const OUString& rCompleteName : aContentSeq ) + OUString aPureName; + OUString aExtension; + sal_Int32 iDot = rCompleteName.lastIndexOf( '.' ); + if( iDot != -1 ) { - OUString aPureName; - OUString aExtension; - sal_Int32 iDot = rCompleteName.lastIndexOf( '.' ); sal_Int32 iSlash = rCompleteName.lastIndexOf( '/' ); - if( iDot != -1 ) - { - sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0; - aPureName = rCompleteName.copy( iCopyFrom, iDot-iCopyFrom ); - aExtension = rCompleteName.copy( iDot + 1 ); - } + sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0; + aPureName = rCompleteName.copy( iCopyFrom, iDot-iCopyFrom ); + aExtension = rCompleteName.copy( iDot + 1 ); + } - if( aExtension == "properties" || aExtension == "default" ) + if( aExtension == "properties" || aExtension == "default" ) + { + if( aPureName.startsWith( aDialogName_ ) ) { - if( aPureName.startsWith( aDialogName_ ) ) + try { - try - { - xSFI->kill( rCompleteName ); - } - catch(const uno::Exception& ) - {} + xSFI->kill( rCompleteName ); } + catch(const uno::Exception& ) + {} } } } + } - Reference< XStringResourceWithLocation > xStringResourceWithLocation = - StringResourceWithLocation::create( xContext, aURL, false/*bReadOnly*/, - xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler ); + Reference< XStringResourceWithLocation > xStringResourceWithLocation = + StringResourceWithLocation::create( xContext, aURL, false/*bReadOnly*/, + xStringResourceResolver->getDefaultLocale(), aDialogName, aComment, xDummyHandler ); - // Add locales - Sequence< lang::Locale > aLocaleSeq = xStringResourceResolver->getLocales(); - for( const lang::Locale& rLocale : aLocaleSeq ) - { - xStringResourceWithLocation->newLocale( rLocale ); - } + // Add locales + for( const lang::Locale& rLocale : aLocaleSeq ) + { + xStringResourceWithLocation->newLocale( rLocale ); + } - LocalizationMgr::copyResourceForDialog( xDialogModel, - xStringResourceResolver, xStringResourceWithLocation ); + LocalizationMgr::copyResourceForDialog( GetDialog(), + xStringResourceResolver, xStringResourceWithLocation ); - xStringResourceWithLocation->store(); - } - } - else - { - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(), - VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_COULDNTWRITE))); - xBox->run(); + xStringResourceWithLocation->store(); } }