[Libreoffice-commits] core.git: basctl/source include/sfx2 sfx2/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 14 14:30:30 UTC 2021


 basctl/source/basicide/baside2.cxx   |   30 +++++++++++------------
 basctl/source/basicide/baside2.hxx   |    1 
 basctl/source/basicide/baside3.cxx   |   44 ++++++++++++++++-------------------
 basctl/source/inc/baside3.hxx        |    2 -
 basctl/source/inc/basidesh.hxx       |    2 -
 include/sfx2/filedlghelper.hxx       |    4 +++
 sfx2/source/dialog/filedlghelper.cxx |    8 ++++++
 7 files changed, 49 insertions(+), 42 deletions(-)

New commits:
commit 9a55b97e980bbf2a0ce12841f6168f1f7545ac96
Author:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
AuthorDate: Wed Jul 14 09:44:38 2021 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbrodt at allotropia.de>
CommitDate: Wed Jul 14 16:29:54 2021 +0200

    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 at allotropia.de>

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;
diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx
index 2c85c6b7b115..8587820b1813 100644
--- a/include/sfx2/filedlghelper.hxx
+++ b/include/sfx2/filedlghelper.hxx
@@ -86,6 +86,10 @@ public:
         BaseDataSource,
         BaseSaveAs,
         BasicExportPackage,
+        BasicExportDialog,
+        BasicExportSource,
+        BasicImportDialog,
+        BasicImportSource,
         BasicInsertLib,
         BulletsAddImage,
         ExtensionManager,
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index bdee75776901..267801a16e80 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -2457,8 +2457,16 @@ OUString FileDialogHelper::contextToString(Context context)
             return "BaseDataSource";
         case BaseSaveAs:
             return "BaseSaveAs";
+        case BasicExportDialog:
+            return "BasicExportDialog";
         case BasicExportPackage:
             return "BasicExportPackage";
+        case BasicExportSource:
+            return "BasicExportSource";
+        case BasicImportDialog:
+            return "BasicImportDialog";
+        case BasicImportSource:
+            return "BasicImportSource";
         case BasicInsertLib:
             return "BasicInsertLib";
         case BulletsAddImage:


More information about the Libreoffice-commits mailing list