};
-FileDialog::FileDialog(docstring const & t, kb_action s)
+FileDialog::FileDialog(QString const & t, kb_action s)
: private_(new FileDialog::Private), title_(t), success_(s)
{}
}
-void FileDialog::setButton1(docstring const & label, docstring const & dir)
+void FileDialog::setButton1(QString const & label, QString const & dir)
{
private_->b1.first = label;
private_->b1.second = dir;
}
-void FileDialog::setButton2(docstring const & label, docstring const & dir)
+void FileDialog::setButton2(QString const & label, QString const & dir)
{
private_->b2.first = label;
private_->b2.second = dir;
}
-FileDialog::Result const FileDialog::save(docstring const & path,
+FileDialog::Result FileDialog::save(QString const & path,
FileFilterList const & filters,
- docstring const & suggested)
+ QString const & suggested)
{
- LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path)
+ LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", mask \"" << to_utf8(filters.as_string())
- << "\", suggested \"" << to_utf8(suggested) << '"');
+ << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- docstring const startsWith = from_utf8(
+ QString const startsWith = from_utf8(
makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
QString const name =
QFileDialog::getSaveFileName(qApp->focusWidget(),
dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setConfirmOverwrite(false);
- if (!suggested.empty())
- dlg.selectFile(toqstr(suggested));
+ if (!suggested.isEmpty())
+ dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted)
- result.second = from_utf8(internal_path(
- fromqstr(dlg.selectedFiles()[0])));
+ result.second = internalPath(dlg.selectedFiles()[0]);
dlg.hide();
#endif
return result;
}
-FileDialog::Result const FileDialog::open(docstring const & path,
+FileDialog::Result FileDialog::open(QString const & path,
FileFilterList const & filters,
- docstring const & suggested)
+ QString const & suggested)
{
- LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path)
- << "\", mask \"" << to_utf8(filters.as_string())
- << "\", suggested \"" << to_utf8(suggested) << '"');
+ LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
+ << "\", mask \"" << filters.as_string()
+ << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- docstring const startsWith = from_utf8(
- makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
- result.second = from_utf8(internal_path(fromqstr(
+ QString const startsWith = toqstr(
+ makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
+ result.second = internalPath(
QFileDialog::getOpenFileName(qApp->focusWidget(),
- toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ))));
+ toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) ));
#else
LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
- if (!suggested.empty())
- dlg.selectFile(toqstr(suggested));
+ if (!suggested.isEmpty())
+ dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted)
- result.second = from_utf8(internal_path(
- fromqstr(dlg.selectedFiles()[0])));
+ result.second = internalPath(dlg.selectedFiles()[0]);
dlg.hide();
#endif
return result;
}
-FileDialog::Result const FileDialog::opendir(docstring const & path,
- docstring const & suggested)
+FileDialog::Result FileDialog::opendir(QString const & path,
+ QString const & suggested)
{
- LYXERR(Debug::GUI, "Select with path \"" << to_utf8(path)
- << "\", suggested \"" << to_utf8(suggested) << '"');
+ LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
+ << "\", suggested \"" << fromqstr(suggested) << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
#ifdef USE_NATIVE_FILEDIALOG
- docstring const startsWith = from_utf8(
- makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename());
+ QString const startsWith = toqstr(
+ makeAbsPath(fromqstr(suggested), fromqstr(path)).absFilename());
result.second = from_utf8(internal_path(fromqstr(
QFileDialog::getExistingDirectory(qApp->focusWidget(),
toqstr(title_),toqstr(startsWith)))));
dlg.setFileMode(QFileDialog::DirectoryOnly);
- if (!suggested.empty())
- dlg.selectFile(toqstr(suggested));
+ if (!suggested.isEmpty())
+ dlg.selectFile(suggested);
LYXERR(Debug::GUI, "Synchronous FileDialog: ");
int res = dlg.exec();
LYXERR(Debug::GUI, "result " << res);
if (res == QDialog::Accepted)
- result.second = from_utf8(internal_path(
- fromqstr(dlg.selectedFiles()[0])));
+ result.second = internalPath(dlg.selectedFiles()[0]);
dlg.hide();
#endif
return result;
#define FILEDIALOG_H
#include "lfuns.h"
-#include "support/docstring.h"
-#include <string>
+#include <QString>
+#include <utility>
namespace lyx {
{
public:
/// label, directory path button
- typedef std::pair<docstring, docstring> Button;
+ typedef std::pair<QString, QString> Button;
/// result type
enum ResultType {
};
/// result return
- typedef std::pair<FileDialog::ResultType, docstring> Result;
+ typedef std::pair<FileDialog::ResultType, QString> Result;
/**
* Constructs a file dialog with title \param title.
* additional directories in the navigation (an empty
* directory is interpreted as FileName::getcwd())
*/
- FileDialog(docstring const & title, kb_action a = LFUN_SELECT_FILE_SYNC);
+ FileDialog(QString 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);
+ void setButton1(QString const & label, QString const & dir);
+ void setButton2(QString const & label, QString const & dir);
/// Choose a file for opening, starting in directory \c path.
- Result const open(docstring const & path,
+ Result open(QString const & path,
support::FileFilterList const & filters,
- docstring const & suggested);
+ QString const & suggested = QString());
/// Choose a directory, starting in directory \c path.
- Result const opendir(docstring const & path = docstring(),
- docstring const & suggested = docstring());
+ Result opendir(QString const & path = QString(),
+ QString const & suggested = QString());
/// Choose a file for saving, starting in directory \c path.
- Result const save(docstring const & path,
+ Result save(QString const & path,
support::FileFilterList const & filters,
- docstring const & suggested);
+ QString const & suggested = QString());
private:
class Private;
Private * private_;
/// the dialog title
- docstring title_;
+ QString title_;
/// success action to perform if not synchronous
kb_action success_;
}
vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end();
- for (; it != end; ++it) {
- *it = onlyFilename(*it);
- }
+ for (; it != end; ++it)
+ *it = support::onlyFilename(*it);
// sort on filename only (no path)
sort(data.begin(), data.end());
}
}
vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end();
- for (; it != end; ++it) {
- *it = onlyFilename(*it);
- }
+ for (; it != end; ++it)
+ *it = support::onlyFilename(*it);
// sort on filename only (no path)
sort(data.begin(), data.end());
}
FileFilterList const filter(filterSpec);
// show save dialog for the graphic
- FileDialog dlg(_("Choose a filename to save the pasted graphic as"));
+ FileDialog dlg(qt_("Choose a filename to save the pasted graphic as"));
FileDialog::Result result =
- dlg.save(from_utf8(filename.onlyPath().absFilename()), filter,
- from_utf8(filename.onlyFileName()));
+ dlg.save(toqstr(filename.onlyPath().absFilename()), filter,
+ toqstr(filename.onlyFileName()));
if (result.first == FileDialog::Later)
return FileName();
- string newFilename = to_utf8(result.second);
+ string newFilename = fromqstr(result.second);
if (newFilename.empty()) {
cur.bv().message(_("Canceled."));
return FileName();
break;
}
- docstring const docpath = from_utf8(onlyPath(buffer().absFileName()));
+ docstring const docpath = from_utf8(support::onlyPath(buffer().absFileName()));
return browseRelFile(in_name, docpath, title, filters, false,
_("Documents|#o#O"), from_utf8(lyxrc.document_path));
else
// tex file or other text file in verbatim mode
formats.edit(buffer(),
- makeAbsPath(file, onlyPath(buffer().absFileName())),
+ makeAbsPath(file, support::onlyPath(buffer().absFileName())),
"text");
}
#include "BufferList.h"
#include "Color.h"
#include "ConverterCache.h"
+#include "FileDialog.h"
#include "FuncRequest.h"
#include "GuiFontExample.h"
#include "GuiKeySymbol.h"
namespace lyx {
namespace frontend {
+/////////////////////////////////////////////////////////////////////
+//
+// Browser Helpers
+//
+/////////////////////////////////////////////////////////////////////
+
+FileName libFileSearch(QString const & dir, QString const & name,
+ QString const & ext = QString())
+{
+ return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
+}
+
+
+/** Launch a file dialog and return the chosen file.
+ filename: a suggested filename.
+ title: the title of the dialog.
+ pattern: *.ps etc.
+ dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+QString browseFile(QString const & filename,
+ QString const & title,
+ support::FileFilterList const & filters,
+ bool save = false,
+ QString const & label1 = QString(),
+ QString const & dir1 = QString(),
+ QString const & label2 = QString(),
+ QString const & dir2 = QString())
+{
+ QString lastPath = ".";
+ if (!filename.isEmpty())
+ lastPath = onlyPath(filename);
+
+ FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
+ dlg.setButton2(label1, dir1);
+ dlg.setButton2(label2, dir2);
+
+ FileDialog::Result result;
+
+ if (save)
+ result = dlg.save(lastPath, filters, onlyFilename(filename));
+ else
+ result = dlg.open(lastPath, filters, onlyFilename(filename));
+
+ return result.second;
+}
+
+
+/** Wrapper around browseFile which tries to provide a filename
+* relative to the user or system directory. The dir, name and ext
+* parameters have the same meaning as in the
+* support::LibFileSearch function.
+*/
+QString browseLibFile(QString const & dir,
+ QString const & name,
+ QString const & ext,
+ QString const & title,
+ support::FileFilterList const & filters)
+{
+ // FIXME UNICODE
+ QString const label1 = qt_("System files|#S#s");
+ QString const dir1 =
+ toqstr(addName(package().system_support().absFilename(), fromqstr(dir)));
+
+ QString const label2 = qt_("User files|#U#u");
+ QString const dir2 =
+ toqstr(addName(package().user_support().absFilename(), fromqstr(dir)));
+
+ QString const result = browseFile(toqstr(
+ libFileSearch(dir, name, ext).absFilename()),
+ title, filters, false, dir1, dir2);
+
+ // remove the extension if it is the default one
+ QString noextresult;
+ if (toqstr(getExtension(fromqstr(result))) == ext)
+ noextresult = toqstr(removeExtension(fromqstr(result)));
+ else
+ noextresult = result;
+
+ // remove the directory, if it is the default one
+ QString const file = onlyFilename(noextresult);
+ if (toqstr(libFileSearch(dir, file, ext).absFilename()) == result)
+ return file;
+ else
+ return noextresult;
+}
+
+
+/** Launch a file dialog and return the chosen directory.
+ pathname: a suggested pathname.
+ title: the title of the dialog.
+ dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+QString browseDir(QString const & pathname,
+ QString const & title,
+ QString const & label1 = QString(),
+ QString const & dir1 = QString(),
+ QString const & label2 = QString(),
+ QString const & dir2 = QString())
+{
+ QString lastPath = ".";
+ if (!pathname.isEmpty())
+ lastPath = onlyPath(pathname);
+
+ FileDialog dlg(title, LFUN_SELECT_FILE_SYNC);
+ dlg.setButton1(label1, dir1);
+ dlg.setButton2(label2, dir2);
+
+ FileDialog::Result const result =
+ dlg.opendir(lastPath, onlyFilename(pathname));
+
+ return result.second;
+}
+
+
+QString browseRelFile(QString const & filename, QString const & refpath,
+ QString const & title, FileFilterList const & filters, bool save,
+ QString const & label1, QString const & dir1,
+ QString const & label2, QString const & dir2)
+{
+ QString const fname = toqstr(makeAbsPath(
+ fromqstr(filename), fromqstr(refpath)).absFilename());
+
+ QString const outname =
+ browseFile(fname, title, filters, save, label1, dir1, label2, dir2);
+
+ QString const reloutname =
+ toqstr(makeRelPath(qstring_to_ucs4(outname), qstring_to_ucs4(refpath)));
+
+ if (reloutname.startsWith("../"))
+ return outname;
+ else
+ return reloutname;
+}
+
+} // namespace frontend
+
+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)
+{
+ return qstring_to_ucs4(frontend::browseRelFile(
+ toqstr(filename), toqstr(refpath),
+ toqstr(title), filters, save,
+ toqstr(label1), toqstr(dir1),
+ toqstr(label2), toqstr(dir2)));
+}
+
/////////////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////////////
+namespace frontend {
+
template<class A>
static size_t findPos_helper(vector<A> const & vec, A const & val)
{
if (!foundry.empty())
fontname += " [" + toqstr(foundry) + ']';
- for (int i = 0; i < cb->count(); ++i) {
+ for (int i = 0; i != cb->count(); ++i) {
if (cb->itemText(i) == fontname) {
cb->setCurrentIndex(i);
return;
/////////////////////////////////////////////////////////////////////
PrefPlaintext::PrefPlaintext(QWidget * parent)
- : PrefModule(_("Plain text"), 0, parent)
+ : PrefModule(qt_("Plain text"), 0, parent)
{
setupUi(this);
connect(plaintextLinelengthSB, SIGNAL(valueChanged(int)),
/////////////////////////////////////////////////////////////////////
PrefDate::PrefDate(QWidget * parent)
- : PrefModule(_("Date format"), 0, parent)
+ : PrefModule(qt_("Date format"), 0, parent)
{
setupUi(this);
connect(DateED, SIGNAL(textChanged(QString)),
/////////////////////////////////////////////////////////////////////
PrefInput::PrefInput(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Keyboard/Mouse"), form, parent)
+ : PrefModule(qt_("Keyboard/Mouse"), form, parent)
{
setupUi(this);
QString PrefInput::testKeymap(QString keymap)
{
- return toqstr(form_->browsekbmap(from_utf8(internal_path(fromqstr(keymap)))));
+ return form_->browsekbmap(toqstr(internal_path(fromqstr(keymap))));
}
/////////////////////////////////////////////////////////////////////
PrefLatex::PrefLatex(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("LaTeX"), form, parent)
+ : PrefModule(qt_("LaTeX"), form, parent)
{
setupUi(this);
connect(latexEncodingED, SIGNAL(textChanged(QString)),
/////////////////////////////////////////////////////////////////////
PrefScreenFonts::PrefScreenFonts(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Screen fonts"), form, parent)
+ : PrefModule(qt_("Screen fonts"), form, parent)
{
setupUi(this);
} // namespace anon
PrefColors::PrefColors(GuiPreferences * form, QWidget * parent)
- : PrefModule( _("Colors"), form, parent)
+ : PrefModule(qt_("Colors"), form, parent)
{
setupUi(this);
/////////////////////////////////////////////////////////////////////
PrefDisplay::PrefDisplay(QWidget * parent)
- : PrefModule(_("Graphics"), 0, parent)
+ : PrefModule(qt_("Graphics"), 0, parent)
{
setupUi(this);
connect(instantPreviewCO, SIGNAL(activated(int)),
/////////////////////////////////////////////////////////////////////
PrefPaths::PrefPaths(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Paths"), form, parent)
+ : PrefModule(qt_("Paths"), form, parent)
{
setupUi(this);
connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir()));
void PrefPaths::select_exampledir()
{
- docstring file(form_->browsedir(
- from_utf8(internal_path(fromqstr(exampleDirED->text()))),
- _("Select directory for example files")));
- if (!file.empty())
- exampleDirED->setText(toqstr(file));
+ QString file = form_->browsedir(internalPath(exampleDirED->text()),
+ qt_("Select directory for example files"));
+ if (!file.isEmpty())
+ exampleDirED->setText(file);
}
void PrefPaths::select_templatedir()
{
- docstring file(form_->browsedir(
- from_utf8(internal_path(fromqstr(templateDirED->text()))),
- _("Select a document templates directory")));
- if (!file.empty())
- templateDirED->setText(toqstr(file));
+ QString file = form_->browsedir(internalPath(templateDirED->text()),
+ qt_("Select a document templates directory"));
+ if (!file.isEmpty())
+ templateDirED->setText(file);
}
void PrefPaths::select_tempdir()
{
- docstring file(form_->browsedir(
- from_utf8(internal_path(fromqstr(tempDirED->text()))),
- _("Select a temporary directory")));
- if (!file.empty())
- tempDirED->setText(toqstr(file));
+ QString file = form_->browsedir(internalPath(tempDirED->text()),
+ qt_("Select a temporary directory"));
+ if (!file.isEmpty())
+ tempDirED->setText(file);
}
void PrefPaths::select_backupdir()
{
- docstring file(form_->browsedir(
- from_utf8(internal_path(fromqstr(backupDirED->text()))),
- _("Select a backups directory")));
- if (!file.empty())
- backupDirED->setText(toqstr(file));
+ QString file = form_->browsedir(internalPath(backupDirED->text()),
+ qt_("Select a backups directory"));
+ if (!file.isEmpty())
+ backupDirED->setText(file);
}
void PrefPaths::select_workingdir()
{
- docstring file(form_->browsedir(
- from_utf8(internal_path(fromqstr(workingDirED->text()))),
- _("Select a document directory")));
- if (!file.empty())
- workingDirED->setText(toqstr(file));
+ QString file = form_->browsedir(internalPath(workingDirED->text()),
+ qt_("Select a document directory"));
+ if (!file.isEmpty())
+ workingDirED->setText(file);
}
void PrefPaths::select_lyxpipe()
{
- docstring file(form_->browse(
- from_utf8(internal_path(fromqstr(lyxserverDirED->text()))),
- _("Give a filename for the LyX server pipe")));
- if (!file.empty())
- lyxserverDirED->setText(toqstr(file));
+ QString file = form_->browse(internalPath(lyxserverDirED->text()),
+ qt_("Give a filename for the LyX server pipe"));
+ if (!file.isEmpty())
+ lyxserverDirED->setText(file);
}
/////////////////////////////////////////////////////////////////////
PrefSpellchecker::PrefSpellchecker(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Spellchecker"), form, parent)
+ : PrefModule(qt_("Spellchecker"), form, parent)
{
setupUi(this);
void PrefSpellchecker::select_dict()
{
- docstring file(form_->browsedict(
- from_utf8(internal_path(fromqstr(persDictionaryED->text())))));
- if (!file.empty())
- persDictionaryED->setText(toqstr(file));
+ QString file = form_->browsedict(internalPath(persDictionaryED->text()));
+ if (!file.isEmpty())
+ persDictionaryED->setText(file);
}
PrefConverters::PrefConverters(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Converters"), form, parent)
+ : PrefModule(qt_("Converters"), form, parent)
{
setupUi(this);
PrefFileformats::PrefFileformats(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("File formats"), form, parent)
+ : PrefModule(qt_("File formats"), form, parent)
{
setupUi(this);
formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
/////////////////////////////////////////////////////////////////////
PrefLanguage::PrefLanguage(QWidget * parent)
- : PrefModule(_("Language"), 0, parent)
+ : PrefModule(qt_("Language"), 0, parent)
{
setupUi(this);
/////////////////////////////////////////////////////////////////////
PrefPrinter::PrefPrinter(QWidget * parent)
- : PrefModule(_("Printer"), 0, parent)
+ : PrefModule(qt_("Printer"), 0, parent)
{
setupUi(this);
/////////////////////////////////////////////////////////////////////
PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("User interface"), form, parent)
+ : PrefModule(qt_("User interface"), form, parent)
{
setupUi(this);
void PrefUserInterface::select_ui()
{
- docstring const name =
- from_utf8(internal_path(fromqstr(uiFileED->text())));
- docstring file = form_->browseUI(name);
- if (!file.empty())
- uiFileED->setText(toqstr(file));
+ QString file = form_->browseUI(internalPath(uiFileED->text()));
+ if (!file.isEmpty())
+ uiFileED->setText(file);
}
PrefShortcuts::PrefShortcuts(GuiPreferences * form, QWidget * parent)
- : PrefModule(_("Shortcuts"), form, parent)
+ : PrefModule(qt_("Shortcuts"), form, parent)
{
setupUi(this);
void PrefShortcuts::select_bind()
{
- docstring const name =
- from_utf8(internal_path(fromqstr(bindFileED->text())));
- docstring file = form_->browsebind(name);
- if (!file.empty()) {
- bindFileED->setText(toqstr(file));
+ QString file = form_->browsebind(internalPath(bindFileED->text()));
+ if (!file.isEmpty()) {
+ bindFileED->setText(file);
system_bind_ = KeyMap();
- system_bind_.read(to_utf8(file));
+ system_bind_.read(fromqstr(file));
updateShortcutsTW();
}
}
/////////////////////////////////////////////////////////////////////
PrefIdentity::PrefIdentity(QWidget * parent)
- : PrefModule(_("Identity"), 0, parent)
+ : PrefModule(qt_("Identity"), 0, parent)
{
setupUi(this);
void GuiPreferences::add(PrefModule * module)
{
BOOST_ASSERT(module);
- prefsPS->addPanel(module, toqstr(module->title()));
+ prefsPS->addPanel(module, module->title());
connect(module, SIGNAL(changed()), this, SLOT(change_adaptor()));
modules_.push_back(module);
}
}
-docstring const GuiPreferences::browsebind(docstring const & file) const
+QString GuiPreferences::browsebind(QString const & file) const
{
- return browseLibFile(from_ascii("bind"), file, from_ascii("bind"),
- _("Choose bind file"),
+ return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
FileFilterList(_("LyX bind files (*.bind)")));
}
-docstring const GuiPreferences::browseUI(docstring const & file) const
+QString GuiPreferences::browseUI(QString const & file) const
{
- return browseLibFile(from_ascii("ui"), file, from_ascii("ui"),
- _("Choose UI file"),
+ return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
FileFilterList(_("LyX UI files (*.ui)")));
}
-docstring const GuiPreferences::browsekbmap(docstring const & file) const
+QString GuiPreferences::browsekbmap(QString const & file) const
{
- return browseLibFile(from_ascii("kbd"), file, from_ascii("kmap"),
- _("Choose keyboard map"),
+ return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
FileFilterList(_("LyX keyboard maps (*.kmap)")));
}
-docstring const GuiPreferences::browsedict(docstring const & file) const
+QString GuiPreferences::browsedict(QString const & file) const
{
- if (lyxrc.use_spell_lib)
- return browseFile(file,
- _("Choose personal dictionary"),
- FileFilterList(_("*.pws")));
- else
- return browseFile(file,
- _("Choose personal dictionary"),
- FileFilterList(_("*.ispell")));
+ return browseFile(file, qt_("Choose personal dictionary"),
+ FileFilterList(lyxrc.use_spell_lib ? _("*.pws") : _("*.ispell")));
}
-docstring const GuiPreferences::browse(docstring const & file,
- docstring const & title) const
+QString GuiPreferences::browse(QString const & file,
+ QString const & title) const
{
return browseFile(file, title, FileFilterList(), true);
}
-docstring const GuiPreferences::browsedir(docstring const & path,
- docstring const & title) const
+QString GuiPreferences::browsedir(QString const & path,
+ QString const & title) const
{
return browseDir(path, title);
}
{
Q_OBJECT
public:
- PrefModule(docstring const & t,
+ PrefModule(QString const & t,
GuiPreferences * form = 0, QWidget * parent = 0)
: QWidget(parent), title_(t), form_(form)
{}
virtual void apply(LyXRC & rc) const = 0;
virtual void update(LyXRC const & rc) = 0;
- docstring const & title() const { return title_; }
+ QString const & title() const { return title_; }
protected:
- docstring title_;
+ QString title_;
GuiPreferences * form_;
Q_SIGNALS:
bool isBufferDependent() const { return false; }
/// various file pickers
- docstring const browsebind(docstring const & file) const;
- docstring const browseUI(docstring const & file) const;
- docstring const browsekbmap(docstring const & file) const;
- docstring const browsedict(docstring const & file) const;
+ QString browsebind(QString const & file) const;
+ QString browseUI(QString const & file) const;
+ QString browsekbmap(QString const & file) const;
+ QString browsedict(QString const & file) const;
/// general browse
- docstring const browse(docstring const & file,
- docstring const & title) const;
+ QString browse(QString const & file, QString const & title) const;
/// browse directory
- docstring const browsedir(docstring const & path,
- docstring const & title) const;
+ QString browsedir(QString const & path, QString const & title) const;
/// set a color
void setColor(ColorCode col, std::string const & hex);
void GuiShowFile::updateContents()
{
- setWindowTitle(toqstr(onlyFilename(filename_.absFilename())));
+ setWindowTitle(onlyFilename(toqstr(filename_.absFilename())));
QString contents = toqstr(filename_.fileContents("UTF-8"));
if (contents.isEmpty())
string classfile = token(allClasses, '\n', entries);
int count = 0;
while ((!contains(classfile, file) ||
- (onlyFilename(classfile) != file)) &&
+ (support::onlyFilename(classfile) != file)) &&
(++count < 1000)) {
classfile = token(allClasses, '\n', ++entries);
}
vector<string>::iterator it1 = data.begin();
vector<string>::iterator end1 = data.end();
for (; it1 != end1; ++it1)
- *it1 = onlyFilename(*it1);
+ *it1 = support::onlyFilename(*it1);
// sort on filename only (no path)
sort(data.begin(), data.end());
static FileName selectTemplateFile()
{
- 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 dlg(qt_("Select template file"));
+ dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+ dlg.setButton1(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
FileDialog::Result result =
- dlg.open(from_utf8(lyxrc.template_path),
- FileFilterList(_("LyX Documents (*.lyx)")),
- docstring());
+ dlg.open(toqstr(lyxrc.template_path),
+ FileFilterList(_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return FileName();
- if (result.second.empty())
+ if (result.second.isEmpty())
return FileName();
- return FileName(to_utf8(result.second));
+ return FileName(fromqstr(result.second));
}
string filename;
if (fname.empty()) {
- 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 dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
+ dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+ dlg.setButton2(qt_("Examples|#E#e"),
+ toqstr(addPath(package().system_support().absFilename(), "examples")));
FileDialog::Result result =
- dlg.open(from_utf8(initpath),
- FileFilterList(_("LyX Documents (*.lyx)")),
- docstring());
+ dlg.open(toqstr(initpath), FileFilterList(_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return;
- filename = to_utf8(result.second);
+ filename = fromqstr(result.second);
// check selected filename
if (filename.empty()) {
docstring const text = bformat(_("Select %1$s file to import"),
formats.prettyName(format));
- 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")));
+ FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
+ dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+ dlg.setButton2(qt_("Examples|#E#e"),
+ toqstr(addPath(package().system_support().absFilename(), "examples")));
docstring filter = formats.prettyName(format);
filter += " (*.";
filter += ')';
FileDialog::Result result =
- dlg.open(from_utf8(initpath),
- FileFilterList(filter),
- docstring());
+ dlg.open(toqstr(initpath), FileFilterList(filter));
if (result.first == FileDialog::Later)
return;
- filename = to_utf8(result.second);
+ filename = fromqstr(result.second);
// check selected filename
if (filename.empty())
initpath = trypath;
// FIXME UNICODE
- 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(),
+ FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
+ dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+ dlg.setButton2(qt_("Examples|#E#e"),
+ toqstr(addPath(package().system_support().absFilename(),
"examples")));
FileDialog::Result result =
- dlg.open(from_utf8(initpath),
- FileFilterList(_("LyX Documents (*.lyx)")),
- docstring());
+ dlg.open(toqstr(initpath),
+ FileFilterList(_("LyX Documents (*.lyx)")));
if (result.first == FileDialog::Later)
return;
// FIXME UNICODE
- filename.set(to_utf8(result.second));
+ filename.set(fromqstr(result.second));
// check selected filename
if (filename.empty()) {
return;
}
- FileDialog dlg(_("Select file to insert"), (asParagraph ?
+ FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
- FileDialog::Result result = dlg.open(from_utf8(bv->buffer().filePath()),
- FileFilterList(), docstring());
+ FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
+ FileFilterList());
if (result.first == FileDialog::Later)
return;
// FIXME UNICODE
- filename.set(to_utf8(result.second));
+ filename.set(fromqstr(result.second));
// check selected filename
if (filename.empty()) {
/// No argument? Ask user through dialog.
// FIXME UNICODE
- FileDialog dlg(_("Choose a filename to save document as"),
+ FileDialog dlg(qt_("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));
+ dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+ dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
if (!isLyXFilename(fname.absFilename()))
fname.changeExtension(".lyx");
FileFilterList const filter(_("LyX Documents (*.lyx)"));
FileDialog::Result result =
- dlg.save(from_utf8(fname.onlyPath().absFilename()),
+ dlg.save(toqstr(fname.onlyPath().absFilename()),
filter,
- from_utf8(fname.onlyFileName()));
+ toqstr(fname.onlyFileName()));
if (result.first == FileDialog::Later)
return false;
- fname.set(to_utf8(result.second));
+ fname.set(fromqstr(result.second));
if (fname.empty())
return false;
namespace lyx {
/// return the Qt form of the label
-static docstring const getLabel(docstring const & ucs4str)
+static QString getLabel(QString const & qstr)
{
- // FIXME UNICODE
- string str = to_utf8(ucs4str);
+ // FIXME UNICODE (or "qt-ify")
+ string str = fromqstr(qstr);
string label;
string sc = split(str, label, '|');
if (sc.length() < 2)
- return from_utf8(label);
+ return toqstr(label);
size_t pos = label.find(sc[1]);
if (pos != string::npos)
label.insert(pos, 1, '&');
- return from_utf8(label);
+ return toqstr(label);
}
-LyXFileDialog::LyXFileDialog(docstring const & t,
- docstring const & p,
+LyXFileDialog::LyXFileDialog(QString const & title,
+ QString const & path,
support::FileFilterList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2)
// FIXME replace that with guiApp->currentView()
- : QFileDialog(qApp->focusWidget(),
- toqstr(t), toqstr(p), toqstr(filters.as_string()))
+ : QFileDialog(qApp->focusWidget(), title, path, toqstr(filters.as_string()))
{
- QString const path = toqstr(p);
QDir dir(path);
// FIXME: workaround for a bug in qt which makes LyX crash
// with hidden paths (bug 4513). Recheck with recent Qt versions.
if (path.contains("/."))
dir.setFilter(QDir::Hidden);
setDirectory(dir);
- setWindowTitle(toqstr(t));
+ setWindowTitle(title);
QList<QHBoxLayout *> layout = findChildren<QHBoxLayout *>();
- if (!b1.first.empty()) {
+ if (!b1.first.isEmpty()) {
b1_dir_ = b1.second;
QToolButton * tb = new QToolButton(this);
connect(tb, SIGNAL(clicked()), this, SLOT(button1Clicked()));
- tb->setText(toqstr(getLabel(b1.first)));
+ tb->setText(getLabel(b1.first));
layout.at(0)->addWidget(tb);
}
- if (!b2.first.empty()) {
+ if (!b2.first.isEmpty()) {
b2_dir_ = b2.second;
QToolButton * tb = new QToolButton(this);
connect(tb, SIGNAL(clicked()), this, SLOT(button2Clicked()));
- tb->setText(toqstr(getLabel(b2.first)));
+ tb->setText(getLabel(b2.first));
layout.at(0)->addWidget(tb);
}
}
void LyXFileDialog::button1Clicked()
{
- setDirectory(toqstr(b1_dir_));
+ setDirectory(b1_dir_);
}
void LyXFileDialog::button2Clicked()
{
- setDirectory(toqstr(b2_dir_));
+ setDirectory(b2_dir_);
}
} // namespace lyx
Q_OBJECT
public:
- LyXFileDialog(docstring const & title,
- docstring const & path,
+ LyXFileDialog(QString const & title,
+ QString const & path,
support::FileFilterList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2);
void button2Clicked();
private:
- docstring b1_dir_;
- docstring b2_dir_;
+ QString b1_dir_;
+ QString b2_dir_;
};
} // namespace lyx
return langs;
}
-
-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 dlg(title, LFUN_SELECT_FILE_SYNC);
- dlg.setButton1(label1, dir1);
- dlg.setButton2(label2, dir2);
-
- FileDialog::Result result;
-
- if (save)
- result = dlg.save(lastPath, filters,
- from_utf8(onlyFilename(to_utf8(filename))));
- else
- result = dlg.open(lastPath, filters,
- from_utf8(onlyFilename(to_utf8(filename))));
-
- return result.second;
-}
-
-
-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,
- label1, dir1, label2, dir2);
- docstring const reloutname = makeRelPath(outname, refpath);
- if (prefixIs(reloutname, from_ascii("../")))
- return outname;
- else
- return reloutname;
-}
-
-
-docstring browseLibFile(docstring const & dir, docstring const & name,
- docstring const & ext, docstring const & title,
- FileFilterList const & filters)
-{
- // FIXME UNICODE
- docstring const label1 = _("System files|#S#s");
- docstring const dir1 =
- from_utf8(addName(package().system_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()),
- title, filters, false, dir1, dir2);
-
- // remove the extension if it is the default one
- docstring noextresult;
- if (from_utf8(getExtension(to_utf8(result))) == ext)
- noextresult = from_utf8(removeExtension(to_utf8(result)));
- else
- noextresult = result;
-
- // remove the directory, if it is the default one
- docstring const file = from_utf8(onlyFilename(to_utf8(noextresult)));
- if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result)
- return file;
- else
- return noextresult;
-}
-
-
-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 dlg(title, LFUN_SELECT_FILE_SYNC);
- dlg.setButton1(label1, dir1);
- dlg.setButton2(label2, dir2);
-
- FileDialog::Result const result =
- dlg.opendir(lastPath, from_utf8(onlyFilename(to_utf8(pathname))));
-
- return result.second;
-}
-
-
void rescanTexStyles()
{
// Run rescan in user lyx directory
eliminate_duplicates(list);
}
+
+QString internalPath(const QString & str)
+{
+ return toqstr(os::internal_path(fromqstr(str)));
+}
+
+
+QString onlyFilename(const QString & str)
+{
+ return toqstr(support::onlyFilename(fromqstr(str)));
+}
+
+
+QString onlyPath(const QString & str)
+{
+ return toqstr(support::onlyPath(fromqstr(str)));
+}
+
} // namespace lyx
*/
std::vector<LanguagePair> const getLanguageData(bool character_dlg);
-/** Launch a file dialog and return the chosen file.
- filename: a suggested filename.
- title: the title of the dialog.
- pattern: *.ps etc.
- dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
-*/
-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
relative to relpath. If the relative path is of the form "foo.txt"
or "bar/foo.txt", then it is returned as relative. OTOH, if it is
docstring const & dir2 = docstring());
-/** Wrapper around browseFile which tries to provide a filename
-* relative to the user or system directory. The dir, name and ext
-* parameters have the same meaning as in the
-* support::LibFileSearch function.
-*/
-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.
- pathname: a suggested pathname.
- title: the title of the dialog.
- dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
-*/
-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
* kpsewhich and an external script, saved in *Files.lst.
*/
*/
void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
+// wrapper around the docstring versions
+QString internalPath(const QString &);
+QString onlyFilename(const QString & str);
+QString onlyPath(const QString & str);
+
} // namespace lyx
#endif // QTHELPERS_H