diff options
author | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-07-14 09:44:38 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-07-14 16:29:54 +0200 |
commit | 9a55b97e980bbf2a0ce12841f6168f1f7545ac96 (patch) | |
tree | 239fc31032e911d4c95159e63b7ad09c0676f8e3 /basctl | |
parent | e49ffd9ea4f3e183004f9f4aa4749f8fec46eb7f (diff) |
tdf#40068 Remember last directory for basic/dialog import/export
Change-Id: I9dee98a2018beb0b8d5a0e57b66dbd9d5390c71c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118883
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'basctl')
-rw-r--r-- | basctl/source/basicide/baside2.cxx | 30 | ||||
-rw-r--r-- | basctl/source/basicide/baside2.hxx | 1 | ||||
-rw-r--r-- | basctl/source/basicide/baside3.cxx | 44 | ||||
-rw-r--r-- | basctl/source/inc/baside3.hxx | 2 | ||||
-rw-r--r-- | basctl/source/inc/basidesh.hxx | 2 |
5 files changed, 37 insertions, 42 deletions
diff --git a/basctl/source/basicide/baside2.cxx b/basctl/source/basicide/baside2.cxx index ce654b998904..4e562420ef19 100644 --- a/basctl/source/basicide/baside2.cxx +++ b/basctl/source/basicide/baside2.cxx @@ -45,6 +45,7 @@ #include <svl/srchdefs.hxx> #include <sfx2/bindings.hxx> #include <sfx2/docfile.hxx> +#include <sfx2/filedlghelper.hxx> #include <sfx2/request.hxx> #include <sfx2/viewfrm.hxx> #include <sot/exchange.hxx> @@ -423,22 +424,20 @@ void ModulWindow::BasicStop() void ModulWindow::LoadBasic() { - Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE); - - if ( !m_sCurPath.isEmpty() ) - xFP->setDisplayDirectory ( m_sCurPath ); + sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, + FileDialogFlags::NONE, this->GetFrameWeld()); + aDlg.SetContext(sfx2::FileDialogHelper::BasicImportSource); + Reference<XFilePicker3> xFP = aDlg.GetFilePicker(); xFP->appendFilter( "BASIC" , "*.bas" ); xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All ); xFP->setCurrentFilter( "BASIC" ); - if( xFP->execute() != RET_OK ) + if( aDlg.Execute() != ERRCODE_NONE ) return; Sequence< OUString > aPaths = xFP->getSelectedFiles(); - m_sCurPath = aPaths[0]; - SfxMedium aMedium( m_sCurPath, StreamMode::READ | StreamMode::SHARE_DENYWRITE | StreamMode::NOCREATE ); + SfxMedium aMedium( aPaths[0], StreamMode::READ | StreamMode::SHARE_DENYWRITE | StreamMode::NOCREATE ); SvStream* pStream = aMedium.GetInStream(); if ( pStream ) { @@ -470,7 +469,10 @@ void ModulWindow::LoadBasic() void ModulWindow::SaveBasicSource() { Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD); + sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD, + FileDialogFlags::NONE, this->GetFrameWeld()); + aDlg.SetContext(sfx2::FileDialogHelper::BasicExportSource); + const Reference<XFilePicker3>& xFP = aDlg.GetFilePicker(); Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY); xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false); @@ -478,19 +480,15 @@ void ModulWindow::SaveBasicSource() aValue <<= true; xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue); - if ( !m_sCurPath.isEmpty() ) - xFP->setDisplayDirectory ( m_sCurPath ); - xFP->appendFilter( "BASIC", "*.bas" ); xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All ); xFP->setCurrentFilter( "BASIC" ); - if( xFP->execute() != RET_OK ) + if( aDlg.Execute() != ERRCODE_NONE ) return; Sequence< OUString > aPaths = xFP->getSelectedFiles(); - m_sCurPath = aPaths[0]; - SfxMedium aMedium( m_sCurPath, StreamMode::WRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC ); + SfxMedium aMedium( aPaths[0], StreamMode::WRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC ); SvStream* pStream = aMedium.GetOutStream(); if ( pStream ) { @@ -518,7 +516,7 @@ void ModulWindow::ImportDialog() { const ScriptDocument& rDocument = GetDocument(); OUString aLibName = GetLibName(); - implImportDialog(GetFrameWeld(), m_sCurPath, rDocument, aLibName); + implImportDialog(GetFrameWeld(), rDocument, aLibName); } void ModulWindow::ToggleBreakPoint( sal_uInt16 nLine ) diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx index 06045356bccb..ab6d7102bd15 100644 --- a/basctl/source/basicide/baside2.hxx +++ b/basctl/source/basicide/baside2.hxx @@ -281,7 +281,6 @@ private: VclPtr<ComplexEditorWindow> m_aXEditorWindow; BasicStatus m_aStatus; SbModuleRef m_xModule; - OUString m_sCurPath; OUString m_aModule; void CheckCompileBasic(); diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx index b2ed314ebf25..12aa15589739 100644 --- a/basctl/source/basicide/baside3.cxx +++ b/basctl/source/basicide/baside3.cxx @@ -43,6 +43,7 @@ #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> #include <comphelper/processfactory.hxx> #include <sfx2/dispatch.hxx> +#include <sfx2/filedlghelper.hxx> #include <sfx2/request.hxx> #include <sfx2/viewfrm.hxx> #include <svl/visitem.hxx> @@ -602,8 +603,11 @@ void DialogWindow::UpdateBrowser() void DialogWindow::SaveDialog() { - Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); - Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD); + Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext()); + sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD, + 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); @@ -611,9 +615,6 @@ void DialogWindow::SaveDialog() aValue <<= true; xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue); - if ( !m_sCurPath.isEmpty() ) - xFP->setDisplayDirectory ( m_sCurPath ); - xFP->setDefaultName( GetName() ); OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME)); @@ -621,11 +622,10 @@ void DialogWindow::SaveDialog() xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All ); xFP->setCurrentFilter( aDialogStr ); - if( xFP->execute() != RET_OK ) + if( aDlg.Execute() != ERRCODE_NONE ) return; Sequence< OUString > aPaths = xFP->getSelectedFiles(); - m_sCurPath = aPaths[0]; // export dialog model to xml Reference< container::XNameContainer > xDialogModel = GetDialog(); @@ -637,9 +637,9 @@ void DialogWindow::SaveDialog() Reference< XOutputStream > xOutput; try { - if( xSFI->exists( m_sCurPath ) ) - xSFI->kill( m_sCurPath ); - xOutput = xSFI->openFileWrite( m_sCurPath ); + if( xSFI->exists( aPaths[0] ) ) + xSFI->kill( aPaths[0] ); + xOutput = xSFI->openFileWrite( aPaths[0] ); } catch(const Exception& ) {} @@ -830,12 +830,15 @@ public: } -bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& aLibName) +bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const OUString& aLibName) { bool bDone = false; - Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); - Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE); + Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext()); + sfx2::FileDialogHelper aDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, + FileDialogFlags::NONE, pWin); + aDlg.SetContext(sfx2::FileDialogHelper::BasicImportDialog); + Reference<XFilePicker3> xFP = aDlg.GetFilePicker(); Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY); xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false); @@ -843,22 +846,17 @@ bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const Script aValue <<= true; xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue); - OUString aCurPath( rCurPath ); - if ( !aCurPath.isEmpty() ) - xFP->setDisplayDirectory ( aCurPath ); - OUString aDialogStr(IDEResId(RID_STR_STDDIALOGNAME)); xFP->appendFilter( aDialogStr, "*.xdl" ); xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All ); xFP->setCurrentFilter( aDialogStr ); - if( xFP->execute() == RET_OK ) + if( aDlg.Execute() != ERRCODE_NONE ) { Sequence< OUString > aPaths = xFP->getSelectedFiles(); - aCurPath = aPaths[0]; OUString aBasePath; - OUString aOUCurPath( aCurPath ); + OUString aOUCurPath( aPaths[0] ); sal_Int32 iSlash = aOUCurPath.lastIndexOf( '/' ); if( iSlash != -1 ) aBasePath = aOUCurPath.copy( 0, iSlash + 1 ); @@ -873,8 +871,8 @@ bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const Script Reference< XSimpleFileAccess3 > xSFI( SimpleFileAccess::create(xContext) ); Reference< XInputStream > xInput; - if( xSFI->exists( aCurPath ) ) - xInput = xSFI->openFileRead( aCurPath ); + if( xSFI->exists( aOUCurPath ) ) + xInput = xSFI->openFileRead( aOUCurPath ); ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.isDocument() ? rDocument.getDocument() : Reference< frame::XModel >() ); @@ -1106,7 +1104,7 @@ void DialogWindow::ImportDialog() { const ScriptDocument& rDocument = GetDocument(); OUString aLibName = GetLibName(); - implImportDialog(GetFrameWeld(), m_sCurPath, rDocument, aLibName); + implImportDialog(GetFrameWeld(), rDocument, aLibName); } DlgEdModel& DialogWindow::GetModel() const diff --git a/basctl/source/inc/baside3.hxx b/basctl/source/inc/baside3.hxx index 15f157565fb2..86c37ea20a44 100644 --- a/basctl/source/inc/baside3.hxx +++ b/basctl/source/inc/baside3.hxx @@ -43,7 +43,7 @@ class DlgEdView; class DialogWindowLayout; class ObjectCatalog; -bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& rLibName); +bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const OUString& rLibName); class DialogWindow: public BaseWindow { diff --git a/basctl/source/inc/basidesh.hxx b/basctl/source/inc/basidesh.hxx index f3127186ce93..2d494cd8d4ee 100644 --- a/basctl/source/inc/basidesh.hxx +++ b/basctl/source/inc/basidesh.hxx @@ -59,7 +59,7 @@ public: private: friend class JavaDebuggingListenerImpl; friend class LocalizationMgr; - friend bool implImportDialog(weld::Window* pWin, const OUString& rCurPath, const ScriptDocument& rDocument, const OUString& rLibName); // defined in baside3.cxx + friend bool implImportDialog(weld::Window* pWin, const ScriptDocument& rDocument, const OUString& rLibName); // defined in baside3.cxx WindowTable aWindowTable; sal_uInt16 nCurKey; |