]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/FileDialog.C
Enable the file dialog to open files with non-latin filenames.
[lyx.git] / src / frontends / qt2 / FileDialog.C
index 90f358615f3f31142273caafdeefda5988d98ebe..fb4c463c958f7419c986b87403d534eb90d32073 100644 (file)
@@ -5,28 +5,18 @@
  *
  * \author John Levon
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include <config.h>
 
-#include "commandtags.h"
-#include "LString.h"
+#include "debug.h"
 #include "frontends/FileDialog.h"
 #include "FileDialog_private.h"
-#include "debug.h"
 #include "qt_helpers.h"
+#include "gettext.h"
 
-#include <qapplication.h>
-
-#include <utility>
-
-using std::make_pair;
-using std::pair;
 using std::endl;
 
 
@@ -36,9 +26,9 @@ struct FileDialog::Private {
 };
 
 
-FileDialog::FileDialog(LyXView * lv, string const & t,
+FileDialog::FileDialog(string const & t,
                       kb_action s, Button b1, Button b2)
-       : private_(new FileDialog::Private), lv_(lv), title_(t), success_(s)
+       : private_(new FileDialog::Private), title_(t), success_(s)
 {
        private_->b1 = b1;
        private_->b2 = b2;
@@ -57,7 +47,7 @@ FileDialog::Result const FileDialog::save(string const & path,
 {
        string filter(mask);
        if (mask.empty())
-               filter = qt_("All files (*)");
+               filter = _("All files (*)");
 
        LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
        lyxerr[Debug::GUI] << "Select with path \"" << path
@@ -70,12 +60,12 @@ FileDialog::Result const FileDialog::save(string const & path,
                dlg.setSelection(toqstr(suggested));
 
        FileDialog::Result result;
-       lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
+       lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
        result.first = FileDialog::Chosen;
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = string(dlg.selectedFile().data());
+               result.second = fromqstr(dlg.selectedFile());
        dlg.hide();
        return result;
 }
@@ -87,7 +77,7 @@ FileDialog::Result const FileDialog::open(string const & path,
 {
        string filter(mask);
        if (mask.empty())
-               filter = qt_("*|All files");
+               filter = _("All files (*)");
 
        LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
        lyxerr[Debug::GUI] << "Select with path \"" << path
@@ -98,12 +88,38 @@ FileDialog::Result const FileDialog::open(string const & path,
                dlg.setSelection(toqstr(suggested));
 
        FileDialog::Result result;
-       lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl;
+       lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
+       result.first = FileDialog::Chosen;
+       int res = dlg.exec();
+       lyxerr[Debug::GUI] << "result " << res << endl;
+       if (res == QDialog::Accepted)
+               result.second = fromqstr(dlg.selectedFile());
+       dlg.hide();
+       return result;
+}
+
+
+FileDialog::Result const FileDialog::opendir(string const & path,
+                                           string const & suggested)
+{
+       string filter = _("Directories");
+
+       LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
+       lyxerr[Debug::GUI] << "Select with path \"" << path
+                          << "\", suggested \"" << suggested << endl;
+
+       dlg.setMode(QFileDialog::DirectoryOnly);
+
+       if (!suggested.empty())
+               dlg.setSelection(toqstr(suggested));
+
+       FileDialog::Result result;
+       lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
        result.first = FileDialog::Chosen;
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = string(dlg.selectedFile().data());
+               result.second = fromqstr(dlg.selectedFile());
        dlg.hide();
        return result;
 }