FileDialog::Result FileDialog::open(QString const & path,
QStringList const & filters, QString const & suggested)
+{
+ FileDialog::Result result;
+ FileDialog::Results results = openMulti(path, filters, suggested, false);
+ result.first = results.first;
+ result.second = results.second.at(0);
+ return result;
+}
+
+
+FileDialog::Results FileDialog::openMulti(QString const & path,
+ QStringList const & filters, QString const & suggested, bool multi)
{
LYXERR(Debug::GUI, "Select with path \"" << path
<< "\", mask \"" << filters.join(";;")
<< "\", suggested \"" << suggested << '"');
- FileDialog::Result result;
- result.first = FileDialog::Chosen;
+ FileDialog::Results results;
+ results.first = FileDialog::Chosen;
if (lyxrc.use_native_filedialog) {
QString const startsWith = makeAbsPath(suggested, path);
- QString const file = QFileDialog::getOpenFileName(qApp->focusWidget(),
- title_, startsWith, filters.join(";;"));
- if (file.isNull())
- result.first = FileDialog::Later;
+ QStringList files;
+ if (multi)
+ files = QFileDialog::getOpenFileNames(qApp->focusWidget(),
+ title_, startsWith, filters.join(";;"));
else
- result.second = internalPath(file);
+ files << QFileDialog::getOpenFileName(qApp->focusWidget(),
+ title_, startsWith, filters.join(";;"));
+ if (files.isEmpty())
+ results.first = FileDialog::Later;
+ else {
+ for (const auto& file : files)
+ results.second << internalPath(file);
+ }
} else {
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted)
- result.second = internalPath(dlg.selectedFiles()[0]);
+ results.second << internalPath(dlg.selectedFiles()[0]);
else
- result.first = FileDialog::Later;
+ results.first = FileDialog::Later;
dlg.hide();
}
- return result;
+ return results;
}
}
-void GuiView::openDocument(string const & fname, int origin)
+void GuiView::openDocuments(string const & fname, int origin)
{
string initpath = lyxrc.document_path;
initpath = trypath;
}
- string filename;
+ QStringList files;
if (fname.empty()) {
- FileDialog dlg(qt_("Select document to open"));
+ FileDialog dlg(qt_("Select documents to open"));
dlg.setButton1(qt_("D&ocuments"), toqstr(lyxrc.document_path));
dlg.setButton2(qt_("&Examples"), toqstr(lyxrc.example_path));
qt_("LyX Document Backups (*.lyx~)"),
qt_("All Files (*.*)")
});
- FileDialog::Result result =
- dlg.open(toqstr(initpath), filter);
+ FileDialog::Results results =
+ dlg.openMulti(toqstr(initpath), filter);
- if (result.first == FileDialog::Later)
+ if (results.first == FileDialog::Later)
return;
- filename = fromqstr(result.second);
+ files = results.second;
// check selected filename
- if (filename.empty()) {
+ if (files.isEmpty()) {
message(_("Canceled."));
return;
}
} else
- filename = fname;
-
- // get absolute path of file and add ".lyx" to the filename if
- // necessary.
- FileName const fullname =
- fileSearch(string(), filename, "lyx", support::may_not_exist);
- if (!fullname.empty())
- filename = fullname.absFileName();
-
- if (!fullname.onlyPath().isDirectory()) {
- Alert::warning(_("Invalid filename"),
- bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
- from_utf8(fullname.absFileName())));
- return;
- }
+ files << toqstr(fname);
+
+ // iterate over all selected files
+ for (auto const & file : files) {
+ string filename = fromqstr(file);
+
+ // get absolute path of file and add ".lyx" to the filename if
+ // necessary.
+ FileName const fullname =
+ fileSearch(string(), filename, "lyx", support::may_not_exist);
+ if (!fullname.empty())
+ filename = fullname.absFileName();
+
+ if (!fullname.onlyPath().isDirectory()) {
+ Alert::warning(_("Invalid filename"),
+ bformat(_("The directory in the given path\n%1$s\ndoes not exist."),
+ from_utf8(fullname.absFileName())));
+ continue;
+ }
- // if the file doesn't exist and isn't already open (bug 6645),
- // let the user create one
- if (!fullname.exists() && !theBufferList().exists(fullname) &&
- !LyXVC::file_not_found_hook(fullname)) {
- // see bug #12609
- if (origin == FuncRequest::MENU) {
- docstring const & msg =
- bformat(_("File\n"
- "%1$s\n"
- "does not exist. Create empty file?"),
- from_utf8(filename));
- int ret = Alert::prompt(_("File does not exist"),
- msg, 0, 1,
- _("Create &File"),
- _("&Cancel"));
- if (ret == 1)
- return;
+ // if the file doesn't exist and isn't already open (bug 6645),
+ // let the user create one
+ if (!fullname.exists() && !theBufferList().exists(fullname) &&
+ !LyXVC::file_not_found_hook(fullname)) {
+ // see bug #12609
+ if (origin == FuncRequest::MENU) {
+ docstring const & msg =
+ bformat(_("File\n"
+ "%1$s\n"
+ "does not exist. Create empty file?"),
+ from_utf8(filename));
+ int ret = Alert::prompt(_("File does not exist"),
+ msg, 0, 1,
+ _("Create &File"),
+ _("&Cancel"));
+ if (ret == 1)
+ continue;
+ }
+ Buffer * const b = newFile(filename, string(), true);
+ if (b)
+ setBuffer(b);
+ continue;
}
- Buffer * const b = newFile(filename, string(), true);
- if (b)
- setBuffer(b);
- return;
- }
- docstring const disp_fn = makeDisplayPath(filename);
- message(bformat(_("Opening document %1$s..."), disp_fn));
+ docstring const disp_fn = makeDisplayPath(filename);
+ message(bformat(_("Opening document %1$s..."), disp_fn));
- docstring str2;
- Buffer * buf = loadDocument(fullname);
- if (buf) {
- str2 = bformat(_("Document %1$s opened."), disp_fn);
- if (buf->lyxvc().inUse())
- str2 += " " + from_utf8(buf->lyxvc().versionString()) +
- " " + _("Version control detected.");
- } else {
- str2 = bformat(_("Could not open document %1$s"), disp_fn);
+ docstring str2;
+ Buffer * buf = loadDocument(fullname);
+ if (buf) {
+ str2 = bformat(_("Document %1$s opened."), disp_fn);
+ if (buf->lyxvc().inUse())
+ str2 += " " + from_utf8(buf->lyxvc().versionString()) +
+ " " + _("Version control detected.");
+ } else {
+ str2 = bformat(_("Could not open document %1$s"), disp_fn);
+ }
+ message(str2);
}
- message(str2);
}
// FIXME: clean that