mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
merge helper files;
remove duplicated lyx::frontend::setAutoTextCB(QCheckBox*, QLineEdit*, LengthCombo*) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21455 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7ced3deb52
commit
77821e11c1
@ -1,241 +0,0 @@
|
||||
/**
|
||||
* \file frontend_helpers.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
* \author Herbert Voß
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#include "Language.h"
|
||||
|
||||
#include "frontends/FileDialog.h"
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
#include "support/Path.h"
|
||||
#include "support/Systemcall.h"
|
||||
|
||||
#include <boost/cregex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::endl;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
using support::addName;
|
||||
using support::bformat;
|
||||
using support::FileFilterList;
|
||||
using support::FileName;
|
||||
using support::getExtension;
|
||||
using support::getVectorFromString;
|
||||
using support::libFileSearch;
|
||||
using support::makeAbsPath;
|
||||
using support::makeRelPath;
|
||||
using support::onlyFilename;
|
||||
using support::onlyPath;
|
||||
using support::package;
|
||||
using support::prefixIs;
|
||||
using support::quoteName;
|
||||
using support::removeExtension;
|
||||
using support::Systemcall;
|
||||
using support::token;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
struct Sorter
|
||||
{
|
||||
bool operator()(LanguagePair const & lhs, LanguagePair const & rhs) const {
|
||||
return lhs.first < rhs.first;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
vector<LanguagePair> const getLanguageData(bool character_dlg)
|
||||
{
|
||||
vector<LanguagePair>::size_type const size = character_dlg ?
|
||||
languages.size() + 2 : languages.size();
|
||||
|
||||
vector<LanguagePair> langs(size);
|
||||
|
||||
if (character_dlg) {
|
||||
langs[0].first = _("No change");
|
||||
langs[0].second = "ignore";
|
||||
langs[1].first = _("Reset");
|
||||
langs[1].second = "reset";
|
||||
}
|
||||
|
||||
vector<string>::size_type i = character_dlg ? 2 : 0;
|
||||
for (Languages::const_iterator cit = languages.begin();
|
||||
cit != languages.end(); ++cit) {
|
||||
langs[i].first = _(cit->second.display());
|
||||
langs[i].second = cit->second.lang();
|
||||
++i;
|
||||
}
|
||||
|
||||
// Don't sort "ignore" and "reset"
|
||||
vector<LanguagePair>::iterator begin = character_dlg ?
|
||||
langs.begin() + 2 : langs.begin();
|
||||
|
||||
std::sort(begin, langs.end(), Sorter());
|
||||
|
||||
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
|
||||
support::Path p(package().user_support());
|
||||
FileName const command = libFileSearch("scripts", "TeXFiles.py");
|
||||
Systemcall one;
|
||||
int const status = one.startscript(Systemcall::Wait,
|
||||
lyx::support::os::python() + ' ' +
|
||||
quoteName(command.toFilesystemEncoding()));
|
||||
if (status == 0)
|
||||
return;
|
||||
// FIXME UNICODE
|
||||
Alert::error(_("Could not update TeX information"),
|
||||
bformat(_("The script `%s' failed."), from_utf8(command.absFilename())));
|
||||
}
|
||||
|
||||
|
||||
void getTexFileList(string const & filename, std::vector<string> & list)
|
||||
{
|
||||
list.clear();
|
||||
FileName const file = libFileSearch("", filename);
|
||||
if (file.empty())
|
||||
return;
|
||||
|
||||
list = getVectorFromString(file.fileContents(), "\n");
|
||||
|
||||
// Normalise paths like /foo//bar ==> /foo/bar
|
||||
boost::RegEx regex("/{2,}");
|
||||
std::vector<string>::iterator it = list.begin();
|
||||
std::vector<string>::iterator end = list.end();
|
||||
for (; it != end; ++it)
|
||||
*it = regex.Merge((*it), "/");
|
||||
|
||||
// remove empty items and duplicates
|
||||
list.erase(std::remove(list.begin(), list.end(), ""), list.end());
|
||||
eliminate_duplicates(list);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
@ -1,105 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file frontend_helpers.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
* \author Herbert Voß
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef FRONTEND_HELPERS_H
|
||||
#define FRONTEND_HELPERS_H
|
||||
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace support { class FileFilterList; }
|
||||
|
||||
namespace frontend {
|
||||
|
||||
///
|
||||
typedef std::pair<docstring, std::string> LanguagePair;
|
||||
|
||||
/** If the caller is the character dialog, add "No change" and "Reset"
|
||||
* to the vector.
|
||||
*/
|
||||
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
|
||||
of the form "../baz/foo.txt", an absolute path is returned. This is
|
||||
intended to be useful for insets which encapsulate files/
|
||||
*/
|
||||
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
|
||||
* 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 rescanTexStyles();
|
||||
|
||||
/** Fill \c contents from one of the three texfiles.
|
||||
* Each entry in the file list is returned as a name_with_path
|
||||
*/
|
||||
void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // FRONTEND_HELPERS_H
|
@ -30,9 +30,6 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/FileFilterList.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QListWidget>
|
||||
#include <QCheckBox>
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "GuiDialog.h"
|
||||
#include "ui_CharacterUi.h"
|
||||
#include "frontend_helpers.h" // for LanguagePair
|
||||
#include "qt_helpers.h" // for LanguagePair
|
||||
#include "Font.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "debug.h"
|
||||
#include "gettext.h"
|
||||
#include "frontend_helpers.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "Encoding.h"
|
||||
#include "FloatPlacement.h"
|
||||
#include "frontend_helpers.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "GuiBranches.h"
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include "GuiExternal.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "Length.h"
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "LyXRC.h"
|
||||
#include "qt_helpers.h"
|
||||
#include "Validator.h"
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
@ -95,7 +94,7 @@ using support::token;
|
||||
* checkbox is unchecked and clearing the line edit if it previously
|
||||
* said "text".
|
||||
*/
|
||||
void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
LengthCombo * lengthCombo/*, string text = "auto"*/)
|
||||
{
|
||||
if (!checkBox->isChecked())
|
||||
@ -106,8 +105,6 @@ void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
lengthCombo->currentLengthItem());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Pair>
|
||||
vector<typename Pair::first_type> const
|
||||
getFirst(vector<Pair> const & pr)
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
#include "GuiInclude.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "Format.h"
|
||||
#include "FuncRequest.h"
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "debug.h"
|
||||
//#include "DialogView.h"
|
||||
//#include "DockView.h"
|
||||
#include "frontend_helpers.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "GuiView.h"
|
||||
|
@ -42,8 +42,6 @@
|
||||
|
||||
#include "graphics/GraphicsTypes.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Application.h"
|
||||
|
||||
@ -1445,7 +1443,7 @@ PrefLanguage::PrefLanguage(QWidget * parent)
|
||||
defaultLanguageCO->clear();
|
||||
|
||||
// store the lang identifiers for later
|
||||
std::vector<LanguagePair> const langs = frontend::getLanguageData(false);
|
||||
std::vector<LanguagePair> const langs = getLanguageData(false);
|
||||
std::vector<LanguagePair>::const_iterator lit = langs.begin();
|
||||
std::vector<LanguagePair>::const_iterator lend = langs.end();
|
||||
lang_.clear();
|
||||
|
@ -17,8 +17,6 @@
|
||||
#include "qt_helpers.h"
|
||||
#include "PrinterParams.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "FuncRequest.h"
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "GuiDialog.h"
|
||||
#include "ui_TexinfoUi.h"
|
||||
#include "frontend_helpers.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
@ -50,8 +50,6 @@ SOURCEFILES = \
|
||||
../ButtonPolicy.h \
|
||||
../Dialog.cpp \
|
||||
../Dialog.h \
|
||||
../frontend_helpers.cpp \
|
||||
../frontend_helpers.h \
|
||||
Resources.cpp \
|
||||
Action.cpp \
|
||||
alert_pimpl.cpp \
|
||||
|
@ -14,9 +14,10 @@
|
||||
#include "Alert_pimpl.h"
|
||||
#include "alert.h"
|
||||
|
||||
#include "ui_AskForTextUi.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "ui_AskForTextUi.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include "gettext.h"
|
||||
|
@ -18,26 +18,56 @@
|
||||
|
||||
#include "debug.h"
|
||||
#include "gettext.h"
|
||||
#include "Language.h"
|
||||
#include "Length.h"
|
||||
|
||||
#include "support/os.h"
|
||||
#include "frontends/FileDialog.h"
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
#include "support/Path.h"
|
||||
#include "support/Systemcall.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QPalette>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/cregex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::endl;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::addName;
|
||||
using support::bformat;
|
||||
using support::FileFilterList;
|
||||
using support::FileName;
|
||||
using support::getExtension;
|
||||
using support::getVectorFromString;
|
||||
using support::libFileSearch;
|
||||
using support::makeAbsPath;
|
||||
using support::makeRelPath;
|
||||
using support::onlyFilename;
|
||||
using support::onlyPath;
|
||||
using support::package;
|
||||
using support::prefixIs;
|
||||
using support::quoteName;
|
||||
using support::removeExtension;
|
||||
using support::Systemcall;
|
||||
using support::token;
|
||||
using support::isStrDbl;
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)
|
||||
{
|
||||
@ -106,20 +136,6 @@ void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
}
|
||||
|
||||
|
||||
//NOTE "CB" here because we probably will want one of these
|
||||
//for labeled sets, as well.
|
||||
void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
||||
LengthCombo * lengthCombo)
|
||||
{
|
||||
if (!checkBox->isChecked())
|
||||
lengthToWidgets(lineEdit, lengthCombo,
|
||||
"auto", lengthCombo->currentLengthItem());
|
||||
else if (lineEdit->text() == "auto")
|
||||
lengthToWidgets(lineEdit, lengthCombo, string(),
|
||||
lengthCombo->currentLengthItem());
|
||||
}
|
||||
|
||||
|
||||
void setValid(QWidget * widget, bool valid)
|
||||
{
|
||||
if (valid) {
|
||||
@ -131,6 +147,7 @@ void setValid(QWidget * widget, bool valid)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
|
||||
QString const qt_(char const * str, const char *)
|
||||
{
|
||||
@ -143,4 +160,183 @@ QString const qt_(string const & str)
|
||||
return toqstr(_(str));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct Sorter
|
||||
{
|
||||
bool operator()(LanguagePair const & lhs, LanguagePair const & rhs) const {
|
||||
return lhs.first < rhs.first;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
vector<LanguagePair> const getLanguageData(bool character_dlg)
|
||||
{
|
||||
vector<LanguagePair>::size_type const size = character_dlg ?
|
||||
languages.size() + 2 : languages.size();
|
||||
|
||||
vector<LanguagePair> langs(size);
|
||||
|
||||
if (character_dlg) {
|
||||
langs[0].first = _("No change");
|
||||
langs[0].second = "ignore";
|
||||
langs[1].first = _("Reset");
|
||||
langs[1].second = "reset";
|
||||
}
|
||||
|
||||
vector<string>::size_type i = character_dlg ? 2 : 0;
|
||||
for (Languages::const_iterator cit = languages.begin();
|
||||
cit != languages.end(); ++cit) {
|
||||
langs[i].first = _(cit->second.display());
|
||||
langs[i].second = cit->second.lang();
|
||||
++i;
|
||||
}
|
||||
|
||||
// Don't sort "ignore" and "reset"
|
||||
vector<LanguagePair>::iterator begin = character_dlg ?
|
||||
langs.begin() + 2 : langs.begin();
|
||||
|
||||
std::sort(begin, langs.end(), Sorter());
|
||||
|
||||
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
|
||||
support::Path p(package().user_support());
|
||||
FileName const command = libFileSearch("scripts", "TeXFiles.py");
|
||||
Systemcall one;
|
||||
int const status = one.startscript(Systemcall::Wait,
|
||||
lyx::support::os::python() + ' ' +
|
||||
quoteName(command.toFilesystemEncoding()));
|
||||
if (status == 0)
|
||||
return;
|
||||
// FIXME UNICODE
|
||||
frontend::Alert::error(_("Could not update TeX information"),
|
||||
bformat(_("The script `%s' failed."), from_utf8(command.absFilename())));
|
||||
}
|
||||
|
||||
|
||||
void getTexFileList(string const & filename, std::vector<string> & list)
|
||||
{
|
||||
list.clear();
|
||||
FileName const file = libFileSearch("", filename);
|
||||
if (file.empty())
|
||||
return;
|
||||
|
||||
list = getVectorFromString(file.fileContents(), "\n");
|
||||
|
||||
// Normalise paths like /foo//bar ==> /foo/bar
|
||||
boost::RegEx regex("/{2,}");
|
||||
std::vector<string>::iterator it = list.begin();
|
||||
std::vector<string>::iterator end = list.end();
|
||||
for (; it != end; ++it)
|
||||
*it = regex.Merge((*it), "/");
|
||||
|
||||
// remove empty items and duplicates
|
||||
list.erase(std::remove(list.begin(), list.end(), ""), list.end());
|
||||
eliminate_duplicates(list);
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "support/qstring_helpers.h"
|
||||
#include "support/strfwd.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QCheckBox;
|
||||
@ -27,6 +29,10 @@ class LengthCombo;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace support { class FileFilterList; }
|
||||
|
||||
namespace frontend {
|
||||
|
||||
/// method to get a Length from widgets (LengthCombo)
|
||||
std::string widgetsToLength(QLineEdit const * input, LengthCombo const * combo);
|
||||
/// method to get a Length from widgets (QComboBox)
|
||||
@ -35,20 +41,22 @@ Length widgetsToLength(QLineEdit const * input, QComboBox const * combo);
|
||||
//FIXME It would be nice if defaultUnit were a default argument
|
||||
/// method to set widgets from a Length
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT default_unit);
|
||||
Length const & len, Length::UNIT default_unit);
|
||||
/// method to set widgets from a string
|
||||
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
std::string const & len, Length::UNIT default_unit);
|
||||
std::string const & len, Length::UNIT default_unit);
|
||||
/// method to set widgets from a Length with optional "auto" if zero
|
||||
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
|
||||
Length const & len, Length::UNIT defaultUnit);
|
||||
Length const & len, Length::UNIT defaultUnit);
|
||||
|
||||
/// colors a widget red if invalid
|
||||
void setValid(QWidget * widget, bool valid);
|
||||
|
||||
} // namespace frontend
|
||||
|
||||
|
||||
/**
|
||||
* qt_ - i18nize string and convert to QString
|
||||
* qt_ - i18nize string and convert to QString
|
||||
*
|
||||
* Use this in qt4/ instead of _()
|
||||
*/
|
||||
@ -62,6 +70,82 @@ QString const qt_(char const * str, const char * comment = 0);
|
||||
*/
|
||||
QString const qt_(std::string const & str);
|
||||
|
||||
///
|
||||
typedef std::pair<docstring, std::string> LanguagePair;
|
||||
|
||||
/** If the caller is the character dialog, add "No change" and "Reset"
|
||||
* to the vector.
|
||||
*/
|
||||
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
|
||||
of the form "../baz/foo.txt", an absolute path is returned. This is
|
||||
intended to be useful for insets which encapsulate files/
|
||||
*/
|
||||
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
|
||||
* 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 rescanTexStyles();
|
||||
|
||||
/** Fill \c contents from one of the three texfiles.
|
||||
* Each entry in the file list is returned as a name_with_path
|
||||
*/
|
||||
void getTexFileList(std::string const & filename, std::vector<std::string> & contents);
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif // QTHELPERS_H
|
||||
|
Loading…
Reference in New Issue
Block a user