if (newname.empty()) { /// No argument? Ask user through dialog
// FIXME UNICODE
- FileDialog fileDlg(_("Choose a filename to save document as"),
- LFUN_BUFFER_WRITE_AS,
- make_pair(_("Documents|#o#O"),
- from_utf8(lyxrc.document_path)),
- make_pair(_("Templates|#T#t"),
- from_utf8(lyxrc.template_path)));
+ FileDialog dlg(_("Choose a filename to save document as"),
+ LFUN_BUFFER_WRITE_AS);
+ dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+ dlg.setButton2(_("Templates|#T#t"), from_utf8(lyxrc.template_path));
if (!support::isLyXFilename(fname))
fname += ".lyx";
support::FileFilterList const filter(_("LyX Documents (*.lyx)"));
FileDialog::Result result =
- fileDlg.save(from_utf8(onlyPath(fname)),
+ dlg.save(from_utf8(onlyPath(fname)),
filter,
from_utf8(onlyFilename(fname)));
initpath = trypath;
// FIXME UNICODE
- FileDialog fileDlg(_("Select LyX document to insert"),
- LFUN_FILE_INSERT,
- make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
- make_pair(_("Examples|#E#e"),
- from_utf8(addPath(package().system_support().absFilename(),
- "examples"))));
+ FileDialog dlg(_("Select LyX document to insert"), LFUN_FILE_INSERT);
+ dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+ dlg.setButton2(_("Examples|#E#e"),
+ from_utf8(addPath(package().system_support().absFilename(),
+ "examples")));
FileDialog::Result result =
- fileDlg.open(from_utf8(initpath),
+ dlg.open(from_utf8(initpath),
FileFilterList(_("LyX Documents (*.lyx)")),
docstring());
FileName fname(f);
if (fname.empty()) {
- FileDialog fileDlg(_("Select file to insert"),
+ FileDialog dlg(_("Select file to insert"),
( asParagraph
? LFUN_FILE_INSERT_PLAINTEXT_PARA
: LFUN_FILE_INSERT_PLAINTEXT) );
FileDialog::Result result =
- fileDlg.open(from_utf8(buffer().filePath()),
+ dlg.open(from_utf8(buffer().filePath()),
FileFilterList(), docstring());
if (result.first == FileDialog::Later)
// The template stuff
string templname;
if (fromTemplate) {
- FileDialog fileDlg(_("Select template file"),
- LFUN_SELECT_FILE_SYNC,
- make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
- make_pair(_("Templates|#T#t"), from_utf8(lyxrc.template_path)));
+ FileDialog dlg(_("Select template file"));
+ dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+ dlg.setButton1(_("Templates|#T#t"), from_utf8(lyxrc.template_path));
FileDialog::Result result =
- fileDlg.open(from_utf8(lyxrc.template_path),
+ dlg.open(from_utf8(lyxrc.template_path),
FileFilterList(_("LyX Documents (*.lyx)")),
docstring());
string filename;
if (fname.empty()) {
- FileDialog fileDlg(_("Select document to open"),
- LFUN_FILE_OPEN,
- make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
- make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support().absFilename(), "examples"))));
+ FileDialog dlg(_("Select document to open"), LFUN_FILE_OPEN);
+ dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+ dlg.setButton2(_("Examples|#E#e"),
+ from_utf8(addPath(package().system_support().absFilename(), "examples")));
FileDialog::Result result =
- fileDlg.open(from_utf8(initpath),
+ dlg.open(from_utf8(initpath),
FileFilterList(_("LyX Documents (*.lyx)")),
docstring());
docstring const text = bformat(_("Select %1$s file to import"),
formats.prettyName(format));
- FileDialog fileDlg(text,
- LFUN_BUFFER_IMPORT,
- make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
- make_pair(_("Examples|#E#e"),
- from_utf8(addPath(package().system_support().absFilename(), "examples"))));
+ FileDialog dlg(text, LFUN_BUFFER_IMPORT);
+ dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
+ dlg.setButton2(_("Examples|#E#e"),
+ from_utf8(addPath(package().system_support().absFilename(), "examples")));
docstring filter = formats.prettyName(format);
filter += " (*.";
filter += ')';
FileDialog::Result result =
- fileDlg.open(from_utf8(initpath),
+ dlg.open(from_utf8(initpath),
FileFilterList(filter),
docstring());
#include "lfuns.h"
#include "support/docstring.h"
-#include <utility>
#include <string>
* additional directories in the navigation (an empty
* directory is interpreted as getcwd())
*/
- FileDialog(docstring const & title,
- kb_action a = LFUN_SELECT_FILE_SYNC,
- Button b1 = Button(docstring(), docstring()),
- Button b2 = Button(docstring(), docstring()));
-
+ FileDialog(docstring const & title, kb_action a = LFUN_SELECT_FILE_SYNC);
~FileDialog();
+ void setButton1(docstring const & label, docstring const & dir);
+ void setButton2(docstring const & label, docstring const & dir);
+
/// Choose a file for opening, starting in directory \c path.
Result const open(docstring const & path,
support::FileFilterList const & filters,
using std::string;
using std::vector;
-using std::pair;
using std::endl;
namespace lyx {
}
-docstring const browseFile(docstring const & filename,
- docstring const & title,
- FileFilterList const & filters,
- bool save,
- pair<docstring,docstring> const & dir1,
- pair<docstring,docstring> const & dir2)
+docstring browseFile(docstring const & filename, docstring const & title,
+ FileFilterList const & filters, bool save,
+ docstring const & label1, docstring const & dir1,
+ docstring const & label2, docstring const & dir2)
{
docstring lastPath = from_ascii(".");
if (!filename.empty())
lastPath = from_utf8(onlyPath(to_utf8(filename)));
- FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
+ FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
+ dlg.setButton1(label1, dir1);
+ dlg.setButton2(label2, dir2);
FileDialog::Result result;
if (save)
- result = fileDlg.save(lastPath, filters,
+ result = dlg.save(lastPath, filters,
from_utf8(onlyFilename(to_utf8(filename))));
else
- result = fileDlg.open(lastPath, filters,
+ result = dlg.open(lastPath, filters,
from_utf8(onlyFilename(to_utf8(filename))));
return result.second;
}
-docstring const browseRelFile(docstring const & filename,
- docstring const & refpath,
- docstring const & title,
- FileFilterList const & filters,
- bool save,
- pair<docstring,docstring> const & dir1,
- pair<docstring,docstring> const & dir2)
+docstring browseRelFile(docstring const & filename, docstring const & refpath,
+ docstring const & title, FileFilterList const & filters, bool save,
+ docstring const & label1, docstring const & dir1,
+ docstring const & label2, docstring const & dir2)
{
docstring const fname = from_utf8(makeAbsPath(
to_utf8(filename), to_utf8(refpath)).absFilename());
docstring const outname = browseFile(fname, title, filters, save,
- dir1, dir2);
+ label1, dir1, label2, dir2);
docstring const reloutname = makeRelPath(outname, refpath);
if (prefixIs(reloutname, from_ascii("../")))
return outname;
}
-docstring const browseLibFile(docstring const & dir,
- docstring const & name,
- docstring const & ext,
- docstring const & title,
- FileFilterList const & filters)
+docstring browseLibFile(docstring const & dir, docstring const & name,
+ docstring const & ext, docstring const & title,
+ FileFilterList const & filters)
{
// FIXME UNICODE
- pair<docstring, docstring> const dir1(_("System files|#S#s"),
- from_utf8(addName(package().system_support().absFilename(), to_utf8(dir))));
+ docstring const label1 = _("System files|#S#s");
+ docstring const dir1 =
+ from_utf8(addName(package().system_support().absFilename(), to_utf8(dir)));
- pair<docstring, docstring> const dir2(_("User files|#U#u"),
- from_utf8(addName(package().user_support().absFilename(), to_utf8(dir))));
+ docstring const label2 = _("User files|#U#u");
+ docstring const dir2 =
+ from_utf8(addName(package().user_support().absFilename(), to_utf8(dir)));
docstring const result = browseFile(from_utf8(
libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()),
}
-docstring const browseDir(docstring const & pathname,
- docstring const & title,
- pair<docstring,docstring> const & dir1,
- pair<docstring,docstring> const & dir2)
+docstring browseDir(docstring const & pathname, docstring const & title,
+ docstring const & label1, docstring const & dir1,
+ docstring const & label2, docstring const & dir2)
{
docstring lastPath = from_ascii(".");
if (!pathname.empty())
lastPath = from_utf8(onlyPath(to_utf8(pathname)));
- FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
+ FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
+ dlg.setButton1(label1, dir1);
+ dlg.setButton2(label2, dir2);
FileDialog::Result const result =
- fileDlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname))));
+ dlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname))));
return result.second;
}
#include "support/docstring.h"
-#include <utility>
#include <vector>
-#include <string>
namespace lyx {
pattern: *.ps etc.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
-docstring const
-browseFile(docstring const & filename,
- docstring const & title,
- support::FileFilterList const & filters,
- bool save = false,
- std::pair<docstring, docstring> const & dir1 =
- std::make_pair(docstring(), docstring()),
- std::pair<docstring, docstring> const & dir2 =
- std::make_pair(docstring(), docstring()));
+docstring browseFile(docstring const & filename,
+ docstring const & title,
+ support::FileFilterList const & filters,
+ bool save = false,
+ docstring const & label1 = docstring(),
+ docstring const & dir1 = docstring(),
+ docstring const & label2 = docstring(),
+ docstring const & dir2 = docstring());
/** Wrapper around browseFile which tries to provide a filename
of the form "../baz/foo.txt", an absolute path is returned. This is
intended to be useful for insets which encapsulate files/
*/
-docstring const
-browseRelFile(docstring const & filename,
- docstring const & refpath,
- docstring const & title,
- support::FileFilterList const & filters,
- bool save = false,
- std::pair<docstring, docstring> const & dir1 =
- std::make_pair(docstring(), docstring()),
- std::pair<docstring, docstring> const & dir2 =
- std::make_pair(docstring(), docstring()));
+docstring browseRelFile(docstring const & filename,
+ docstring const & refpath,
+ docstring const & title,
+ support::FileFilterList const & filters,
+ bool save = false,
+ docstring const & label1 = docstring(),
+ docstring const & dir1 = docstring(),
+ docstring const & label2 = docstring(),
+ docstring const & dir2 = docstring());
/** Wrapper around browseFile which tries to provide a filename
* parameters have the same meaning as in the
* support::LibFileSearch function.
*/
-docstring const
-browseLibFile(docstring const & dir,
- docstring const & name,
- docstring const & ext,
- docstring const & title,
- support::FileFilterList const & filters);
+docstring browseLibFile(docstring const & dir,
+ docstring const & name,
+ docstring const & ext,
+ docstring const & title,
+ support::FileFilterList const & filters);
/** Launch a file dialog and return the chosen directory.
title: the title of the dialog.
dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
*/
-docstring const
-browseDir(docstring const & pathname,
- docstring const & title,
- std::pair<docstring, docstring> const & dir1 =
- std::make_pair(docstring(), docstring()),
- std::pair<docstring, docstring> const & dir2 =
- std::make_pair(docstring(), docstring()));
+docstring browseDir(docstring const & pathname,
+ docstring const & title,
+ docstring const & label1 = docstring(),
+ docstring const & dir1 = docstring(),
+ docstring const & label2 = docstring(),
+ docstring const & dir2 = docstring());
/** Build filelists of all availabe bst/cls/sty-files. Done through
};
-FileDialog::FileDialog(docstring const & t,
- kb_action s, Button b1, Button b2)
+FileDialog::FileDialog(docstring const & t, kb_action s)
: private_(new FileDialog::Private), title_(t), success_(s)
-{
- private_->b1 = b1;
- private_->b2 = b2;
-}
+{}
FileDialog::~FileDialog()
}
+void FileDialog::setButton1(docstring const & label, docstring const & dir)
+{
+ private_->b1.first = label;
+ private_->b1.second = dir;
+}
+
+
+void FileDialog::setButton2(docstring const & label, docstring const & dir)
+{
+ private_->b2.first = label;
+ private_->b2.second = dir;
+}
+
+
FileDialog::Result const FileDialog::save(docstring const & path,
FileFilterList const & filters,
docstring const & suggested)
add_bc_.setCancel(add_->closePB);
add_bc_.addCheckedLineEdit(add_->bibED, 0);
- connect(add_->bibED, SIGNAL(textChanged(const QString &)),
+ connect(add_->bibED, SIGNAL(textChanged(QString)),
this, SLOT(bibEDChanged()));
connect(add_->addPB, SIGNAL(clicked()),
this, SLOT(addDatabase()));
docstring const GuiBibtex::browseBib(docstring const & in_name) const
{
// FIXME UNICODE
- pair<docstring, docstring> dir1(_("Documents|#o#O"),
- from_utf8(lyxrc.document_path));
+ docstring const label1 = _("Documents|#o#O");
+ docstring const dir1 = from_utf8(lyxrc.document_path);
FileFilterList const filter(_("BibTeX Databases (*.bib)"));
return browseRelFile(in_name, from_utf8(bufferFilepath()),
- _("Select a BibTeX database to add"),
- filter, false, dir1);
+ _("Select a BibTeX database to add"), filter, false, label1, dir1);
}
docstring const GuiBibtex::browseBst(docstring const & in_name) const
{
// FIXME UNICODE
- pair<docstring, docstring> dir1(_("Documents|#o#O"),
- from_utf8(lyxrc.document_path));
+ docstring const label1 = _("Documents|#o#O");
+ docstring const dir1 = from_utf8(lyxrc.document_path);
FileFilterList const filter(_("BibTeX Styles (*.bst)"));
return browseRelFile(in_name, from_utf8(bufferFilepath()),
- _("Select a BibTeX style"), filter, false, dir1);
+ _("Select a BibTeX style"), filter, false, label1, dir1);
}
{
docstring const title = _("Select external file");
- docstring const bufpath = lyx::from_utf8(bufferFilepath());
+ docstring const bufpath = from_utf8(bufferFilepath());
FileFilterList const filter =
- FileFilterList(lyx::from_utf8(getTemplateFilters(lyx::to_utf8(template_name))));
+ FileFilterList(from_utf8(getTemplateFilters(to_utf8(template_name))));
- std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
- lyx::from_utf8(lyxrc.document_path));
+ docstring const label1 = _("Documents|#o#O");
+ docstring const dir1 = from_utf8(lyxrc.document_path);
- return browseRelFile(input, bufpath, title, filter, false, dir1);
+ return browseRelFile(input, bufpath, title, filter, false, label1, dir1);
}
// Does user clipart directory exist?
string clipdir = addName(package().user_support().absFilename(), "clipart");
FileName clip(clipdir);
+
+ // bail out to system clipart directory
if (!clip.exists() && clip.isDirectory())
- // No - bail out to system clipart directory
clipdir = addName(package().system_support().absFilename(), "clipart");
- pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
- pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
- // Show the file browser dialog
+
return browseRelFile(in_name, from_utf8(bufferFilepath()),
- title, FileFilterList(), false, dir1, dir2);
+ title, FileFilterList(), false,
+ _("Clipart|#C#c"), from_utf8(clipdir),
+ _("Documents|#o#O"), from_utf8(lyxrc.document_path));
}
break;
}
- pair<docstring, docstring> dir1(_("Documents|#o#O"),
- from_utf8(lyxrc.document_path));
-
docstring const docpath = from_utf8(onlyPath(buffer().absFileName()));
- return browseRelFile(in_name, docpath, title,
- filters, false, dir1);
+ return browseRelFile(in_name, docpath, title, filters, false,
+ _("Documents|#o#O"), from_utf8(lyxrc.document_path));
}
FileDialog::Button const & b2)
// FIXME replace that with theApp->gui()->currentView()
: QFileDialog(qApp->focusWidget(),
- toqstr(t), toqstr(p), toqstr(filters.as_string())),
- b1_(0), b2_(0)
+ toqstr(t), toqstr(p), toqstr(filters.as_string()))
{
setWindowTitle(toqstr(t));
if (!b1.first.empty()) {
b1_dir_ = b1.second;
- b1_ = new QToolButton(this);
- connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
- b1_->setText(toqstr(getLabel(b1.first)));
- layout.at(0)->addWidget(b1_);
+ QToolButton * tb = new QToolButton(this);
+ connect(tb, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+ tb->setText(toqstr(getLabel(b1.first)));
+ layout.at(0)->addWidget(tb);
}
if (!b2.first.empty()) {
b2_dir_ = b2.second;
- b2_ = new QToolButton(this);
- connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
- b2_->setText(toqstr(getLabel(b2.first)));
- layout.at(0)->addWidget(b2_);
+ QToolButton * tb = new QToolButton(this);
+ connect(tb, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+ tb->setText(toqstr(getLabel(b2.first)));
+ layout.at(0)->addWidget(tb);
}
}
-void LyXFileDialog::buttonClicked()
+void LyXFileDialog::button1Clicked()
{
- if (sender() == b1_)
- setDirectory(toqstr(b1_dir_));
- else if (sender() == b2_)
- setDirectory(toqstr(b2_dir_));
+ setDirectory(toqstr(b1_dir_));
+}
+
+
+void LyXFileDialog::button2Clicked()
+{
+ setDirectory(toqstr(b2_dir_));
}
} // namespace lyx
class LyXFileDialog : public QFileDialog
{
Q_OBJECT
+
public:
LyXFileDialog(docstring const & title,
docstring const & path,
support::FileFilterList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2);
+
public Q_SLOTS:
- void buttonClicked();
+ void button1Clicked();
+ void button2Clicked();
+
private:
- QToolButton * b1_;
docstring b1_dir_;
-
- QToolButton * b2_;
docstring b2_dir_;
};