start some work on file dialogs

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21238 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-28 16:32:20 +00:00
parent a8551ebde2
commit 9be03a87f9
13 changed files with 149 additions and 155 deletions

View File

@ -2083,12 +2083,10 @@ bool Buffer::writeAs(string const & newname)
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";
@ -2096,7 +2094,7 @@ bool Buffer::writeAs(string const & newname)
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)));

View File

@ -1941,15 +1941,14 @@ void BufferView::menuInsertLyXFile(string const & filenm)
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());
@ -2189,13 +2188,13 @@ docstring BufferView::contentsOfPlaintextFile(string const & f,
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)

View File

@ -2190,13 +2190,12 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
// 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());
@ -2227,13 +2226,13 @@ void LyXFunc::open(string const & fname)
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());
@ -2304,11 +2303,10 @@ void LyXFunc::doImport(string const & argument)
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 += " (*.";
@ -2317,7 +2315,7 @@ void LyXFunc::doImport(string const & argument)
filter += ')';
FileDialog::Result result =
fileDlg.open(from_utf8(initpath),
dlg.open(from_utf8(initpath),
FileFilterList(filter),
docstring());

View File

@ -16,7 +16,6 @@
#include "lfuns.h"
#include "support/docstring.h"
#include <utility>
#include <string>
@ -55,14 +54,13 @@ public:
* 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,

View File

@ -34,7 +34,6 @@
using std::string;
using std::vector;
using std::pair;
using std::endl;
namespace lyx {
@ -104,45 +103,42 @@ vector<LanguagePair> const getLanguageData(bool character_dlg)
}
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;
@ -151,18 +147,18 @@ docstring const browseRelFile(docstring const & filename,
}
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()),
@ -184,19 +180,20 @@ docstring const browseLibFile(docstring const & dir,
}
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;
}

View File

@ -15,9 +15,7 @@
#include "support/docstring.h"
#include <utility>
#include <vector>
#include <string>
namespace lyx {
@ -39,15 +37,14 @@ std::vector<LanguagePair> const getLanguageData(bool character_dlg);
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
@ -56,16 +53,15 @@ browseFile(docstring const & 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
@ -73,12 +69,11 @@ browseRelFile(docstring const & 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.
@ -86,13 +81,12 @@ browseLibFile(docstring const & dir,
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

View File

@ -58,13 +58,9 @@ public:
};
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()
@ -73,6 +69,20 @@ 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)

View File

@ -90,7 +90,7 @@ GuiBibtex::GuiBibtex(LyXView & lv)
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()));
@ -379,23 +379,22 @@ bool GuiBibtex::isValid()
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);
}

View File

@ -793,14 +793,14 @@ docstring const GuiExternal::browse(docstring const & input,
{
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);
}

View File

@ -761,14 +761,15 @@ docstring const GuiGraphics::browse(docstring const & in_name) const
// 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));
}

View File

@ -364,13 +364,10 @@ docstring GuiInclude::browse(docstring const & in_name, Type in_type) const
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));
}

View File

@ -50,8 +50,7 @@ LyXFileDialog::LyXFileDialog(docstring const & t,
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));
@ -59,28 +58,31 @@ LyXFileDialog::LyXFileDialog(docstring const & 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

View File

@ -25,19 +25,20 @@ namespace support { class FileFilterList; }
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();
private:
QToolButton * b1_;
docstring b1_dir_;
QToolButton * b2_;
public Q_SLOTS:
void button1Clicked();
void button2Clicked();
private:
docstring b1_dir_;
docstring b2_dir_;
};