diff options
Diffstat (limited to 'basctl/source/basicide/baside3.cxx')
-rw-r--r-- | basctl/source/basicide/baside3.cxx | 258 |
1 files changed, 100 insertions, 158 deletions
diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx index 6e20187055c9..4a6b1dfbfb5c 100644 --- a/basctl/source/basicide/baside3.cxx +++ b/basctl/source/basicide/baside3.cxx @@ -50,7 +50,7 @@ #include <svl/whiter.hxx> #include <svx/svdundo.hxx> #include <svx/svxids.hrc> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/urlobj.hxx> #include <vcl/commandevent.hxx> #include <vcl/weld.hxx> @@ -70,9 +70,9 @@ using namespace ::com::sun::star::resource; using namespace ::com::sun::star::ui::dialogs; #ifdef _WIN32 -OUStringLiteral const FilterMask_All = u"*.*"; +constexpr OUString FilterMask_All = u"*.*"_ustr; #else -constexpr OUStringLiteral FilterMask_All = u"*"; +constexpr OUString FilterMask_All = u"*"_ustr; #endif DialogWindow::DialogWindow(DialogWindowLayout* pParent, ScriptDocument const& rDocument, @@ -232,12 +232,10 @@ void DialogWindow::NotifyUndoActionHdl( std::unique_ptr<SdrUndoAction> ) void DialogWindow::DoInit() { - GetHScrollBar()->Show(); - GetVScrollBar()->Show(); m_pEditor->SetScrollBars( GetHScrollBar(), GetVScrollBar() ); } -void DialogWindow::DoScroll( ScrollBar* ) +void DialogWindow::DoScroll( Scrollable* ) { m_pEditor->DoScroll(); } @@ -315,7 +313,7 @@ void DialogWindow::GetState( SfxItemSet& rSet ) case SID_SHOW_PROPERTYBROWSER: { Shell* pShell = GetShell(); - SfxViewFrame* pViewFrame = pShell ? pShell->GetViewFrame() : nullptr; + SfxViewFrame* pViewFrame = pShell ? &pShell->GetViewFrame() : nullptr; if ( pViewFrame && !pViewFrame->HasChildWindow( SID_SHOW_PROPERTYBROWSER ) && !m_pEditor->GetView().AreObjectsMarked() ) rSet.DisableItem( nWh ); @@ -603,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,133 +617,109 @@ void DialogWindow::SaveDialog() if( aDlg.Execute() != ERRCODE_NONE ) return; - Sequence< OUString > aPaths = xFP->getSelectedFiles(); - - // 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() ); + OUString aSelectedFileURL = xFP->getSelectedFiles()[0]; + Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) ); Reference< XOutputStream > xOutput; try { - if( xSFI->exists( aPaths[0] ) ) - xSFI->kill( aPaths[0] ); - xOutput = xSFI->openFileWrite( aPaths[0] ); + if( xSFI->exists(aSelectedFileURL) ) + xSFI->kill(aSelectedFileURL); + xOutput = xSFI->openFileWrite(aSelectedFileURL); } 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(""); - 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 + "_" ; - sal_Int32 nCount = aContentSeq.getLength(); - const OUString* pFiles = aContentSeq.getConstArray(); - for( int i = 0 ; i < nCount ; i++ ) + OUString aPureName; + OUString aExtension; + sal_Int32 iDot = rCompleteName.lastIndexOf( '.' ); + if( iDot != -1 ) { - OUString aCompleteName = pFiles[i]; - OUString aPureName; - OUString aExtension; - sal_Int32 iDot = aCompleteName.lastIndexOf( '.' ); - sal_Int32 iSlash = aCompleteName.lastIndexOf( '/' ); - if( iDot != -1 ) - { - sal_Int32 iCopyFrom = (iSlash != -1) ? iSlash + 1 : 0; - aPureName = aCompleteName.copy( iCopyFrom, iDot-iCopyFrom ); - aExtension = aCompleteName.copy( iDot + 1 ); - } + sal_Int32 iSlash = rCompleteName.lastIndexOf( '/' ); + 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( aCompleteName ); - } - 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(); - const lang::Locale* pLocales = aLocaleSeq.getConstArray(); - sal_Int32 nLocaleCount = aLocaleSeq.getLength(); - for( sal_Int32 iLocale = 0 ; iLocale < nLocaleCount ; iLocale++ ) - { - const lang::Locale& rLocale = pLocales[ iLocale ]; - 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(); } } @@ -760,32 +728,15 @@ static std::vector< lang::Locale > implGetLanguagesOnlyContainedInFirstSeq { std::vector< lang::Locale > avRet; - const lang::Locale* pFirst = aFirstSeq.getConstArray(); - const lang::Locale* pSecond = aSecondSeq.getConstArray(); - sal_Int32 nFirstCount = aFirstSeq.getLength(); - sal_Int32 nSecondCount = aSecondSeq.getLength(); - - for( sal_Int32 iFirst = 0 ; iFirst < nFirstCount ; iFirst++ ) - { - const lang::Locale& rFirstLocale = pFirst[ iFirst ]; - - bool bAlsoContainedInSecondSeq = false; - for( sal_Int32 iSecond = 0 ; iSecond < nSecondCount ; iSecond++ ) - { - const lang::Locale& rSecondLocale = pSecond[ iSecond ]; - - bool bMatch = localesAreEqual( rFirstLocale, rSecondLocale ); - if( bMatch ) - { - bAlsoContainedInSecondSeq = true; - break; - } - } - - if( !bAlsoContainedInSecondSeq ) - avRet.push_back( rFirstLocale ); - } - + std::copy_if(aFirstSeq.begin(), aFirstSeq.end(), + std::back_inserter(avRet), + [&aSecondSeq](const lang::Locale& rFirstLocale) { + return std::none_of( + aSecondSeq.begin(), aSecondSeq.end(), + [&rFirstLocale](const lang::Locale& rSecondLocale) { + return localesAreEqual(rFirstLocale, rSecondLocale); + }); + }); return avRet; } @@ -840,18 +791,12 @@ bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const aDlg.SetContext(sfx2::FileDialogHelper::BasicImportDialog); 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); - OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME)); xFP->appendFilter( aDialogStr, "*.xdl" ); xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All ); xFP->setCurrentFilter( aDialogStr ); - if( aDlg.Execute() != ERRCODE_NONE ) + if( aDlg.Execute() == ERRCODE_NONE ) { Sequence< OUString > aPaths = xFP->getSelectedFiles(); @@ -993,15 +938,13 @@ bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const { // Check if import default belongs to only import languages and use it then lang::Locale aImportDefaultLocale = xImportStringResource->getDefaultLocale(); - lang::Locale aTmpLocale; - for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i ) + + if (std::any_of(aOnlyInImportLanguages.begin(), aOnlyInImportLanguages.end(), + [&aImportDefaultLocale](const lang::Locale& aTmpLocale) { + return localesAreEqual(aImportDefaultLocale, aTmpLocale); + })) { - aTmpLocale = aOnlyInImportLanguages[i]; - if( localesAreEqual( aImportDefaultLocale, aTmpLocale ) ) - { - aFirstLocale = aImportDefaultLocale; - break; - } + aFirstLocale = aImportDefaultLocale; } } @@ -1011,13 +954,11 @@ bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const { Sequence< lang::Locale > aRemainingLocaleSeq( nOnlyInImportLanguageCount - 1 ); auto pRemainingLocaleSeq = aRemainingLocaleSeq.getArray(); - lang::Locale aTmpLocale; int iSeq = 0; - for( int i = 0 ; i < nOnlyInImportLanguageCount ; ++i ) + for( const lang::Locale& rLocale : aOnlyInImportLanguages ) { - aTmpLocale = aOnlyInImportLanguages[i]; - if( !localesAreEqual( aFirstLocale, aTmpLocale ) ) - pRemainingLocaleSeq[iSeq++] = aTmpLocale; + if( !localesAreEqual( aFirstLocale, rLocale ) ) + pRemainingLocaleSeq[iSeq++] = rLocale; } pCurMgr->handleAddLocales( aRemainingLocaleSeq ); } @@ -1236,7 +1177,7 @@ void DialogWindow::InitSettings() SetTextColor( rStyleSettings.GetFieldTextColor() ); SetTextFillColor(); - SetBackground( rStyleSettings.GetFieldColor() ); + SetBackground(rStyleSettings.GetFaceColor()); } css::uno::Reference< css::accessibility::XAccessible > DialogWindow::CreateAccessible() @@ -1244,10 +1185,11 @@ css::uno::Reference< css::accessibility::XAccessible > DialogWindow::CreateAcces return new AccessibleDialogWindow(this); } -OString DialogWindow::GetHid () const +OUString DialogWindow::GetHid () const { return HID_BASICIDE_DIALOGWINDOW; } + ItemType DialogWindow::GetType () const { return TYPE_DIALOG; |