[Libreoffice-commits] .: Branch 'feature/calc-xml-source' - sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 10 22:22:38 PDT 2012


 sc/source/ui/inc/xmlsourcedlg.hxx       |    4 +++
 sc/source/ui/xmlsource/xmlsourcedlg.cxx |   37 ++++++++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)

New commits:
commit d6508155a14e786cacca720191a3b85a8c0f86fd
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Oct 11 01:22:21 2012 -0400

    Use sensible directory path for file picker, handle tree item select.
    
    Change-Id: I2638b1d870ee6b7e6c8697a38df07872184df8c6

diff --git a/sc/source/ui/inc/xmlsourcedlg.hxx b/sc/source/ui/inc/xmlsourcedlg.hxx
index c145f8b..965dae7 100644
--- a/sc/source/ui/inc/xmlsourcedlg.hxx
+++ b/sc/source/ui/inc/xmlsourcedlg.hxx
@@ -52,6 +52,8 @@ class ScXMLSourceDlg : public ScAnyRefDlg
     rtl::OUString maStrCellLink;
     rtl::OUString maStrRangeLink;
 
+    rtl::OUString maSrcPath;
+
     ScDocument* mpDoc;
 
     formula::RefEdit* mpActiveEdit;
@@ -74,10 +76,12 @@ private:
     void LoadSourceFileStructure(const OUString& rPath);
     void HandleGetFocus(Control* pCtrl);
     void HandleLoseFocus(Control* pCtrl);
+    void TreeItemSelected();
 
     DECL_LINK(GetFocusHdl, Control*);
     DECL_LINK(LoseFocusHdl, Control*);
     DECL_LINK(BtnPressedHdl, Button*);
+    DECL_LINK(TreeItemSelectHdl, void*);
 };
 
 #endif
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index 3a07997..cc255b8 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -16,6 +16,9 @@
 #include "filter.hxx"
 #include "reffact.hxx"
 
+#include "unotools/pathoptions.hxx"
+#include "tools/urlobj.hxx"
+
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
@@ -60,6 +63,8 @@ ScXMLSourceDlg::ScXMLSourceDlg(
     maEdit.SetLoseFocusHdl(aLink);
     maBtnRb.SetLoseFocusHdl(aLink);
 
+    aLink = LINK(this, ScXMLSourceDlg, TreeItemSelectHdl);
+    maLbTree.SetSelectHdl(aLink);
     maFtMappedCellTitle.SetText(maStrCellLink);
 }
 
@@ -125,6 +130,19 @@ void ScXMLSourceDlg::SelectSourceFile()
     if (!xFilePicker.is())
         return;
 
+    if (maSrcPath.isEmpty())
+        // Use default path.
+        xFilePicker->setDisplayDirectory(SvtPathOptions().GetWorkPath());
+    else
+    {
+        // Use the directory of current source file.
+        INetURLObject aURL(maSrcPath);
+        aURL.removeSegment();
+        aURL.removeFinalSlash();
+        OUString aPath = aURL.GetMainURL(INetURLObject::NO_DECODE);
+        xFilePicker->setDisplayDirectory(aPath);
+    }
+
     if (xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
         // File picker dialog cancelled.
         return;
@@ -133,10 +151,11 @@ void ScXMLSourceDlg::SelectSourceFile()
     if (!aFiles.getLength())
         return;
 
+    maSrcPath = aFiles[0];
     // There should only be one file returned from the file picker.
-    maFtSourceFile.SetText(aFiles[0]);
+    maFtSourceFile.SetText(maSrcPath);
 
-    LoadSourceFileStructure(aFiles[0]);
+    LoadSourceFileStructure(maSrcPath);
 }
 
 void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
@@ -163,6 +182,14 @@ void ScXMLSourceDlg::HandleLoseFocus(Control* /*pCtrl*/)
 {
 }
 
+void ScXMLSourceDlg::TreeItemSelected()
+{
+    SvLBoxEntry* pEntry = maLbTree.GetCurEntry();
+    OUString aName = maLbTree.GetEntryText(pEntry);
+    fprintf(stdout, "ScXMLSourceDlg::TreeItemSelected:   name = '%s'\n",
+            rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr());
+}
+
 IMPL_LINK(ScXMLSourceDlg, GetFocusHdl, Control*, pCtrl)
 {
     HandleGetFocus(pCtrl);
@@ -182,4 +209,10 @@ IMPL_LINK(ScXMLSourceDlg, BtnPressedHdl, Button*, pBtn)
     return 0;
 }
 
+IMPL_LINK_NOARG(ScXMLSourceDlg, TreeItemSelectHdl)
+{
+    TreeItemSelected();
+    return 0;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list