]> git.lyx.org Git - features.git/commitdiff
merge helper files;
authorAndré Pönitz <poenitz@gmx.net>
Mon, 5 Nov 2007 22:20:23 +0000 (22:20 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 5 Nov 2007 22:20:23 +0000 (22:20 +0000)
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

17 files changed:
src/frontends/frontend_helpers.cpp [deleted file]
src/frontends/frontend_helpers.h [deleted file]
src/frontends/qt4/GuiBibtex.cpp
src/frontends/qt4/GuiCharacter.h
src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiExternal.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/GuiInclude.cpp
src/frontends/qt4/GuiParagraph.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrint.cpp
src/frontends/qt4/GuiTexinfo.h
src/frontends/qt4/Makefile.am
src/frontends/qt4/alert_pimpl.cpp
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

diff --git a/src/frontends/frontend_helpers.cpp b/src/frontends/frontend_helpers.cpp
deleted file mode 100644 (file)
index 50beccb..0000000
+++ /dev/null
@@ -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
diff --git a/src/frontends/frontend_helpers.h b/src/frontends/frontend_helpers.h
deleted file mode 100644 (file)
index 0e6f5bc..0000000
+++ /dev/null
@@ -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
index 73b2ee1ec227211782a0c998a5c0152067929d08..32bcc23aa7e7c3396f600d95ed4aa9d9340171d8 100644 (file)
@@ -30,9 +30,6 @@
 #include "support/lstrings.h"
 #include "support/FileFilterList.h"
 
-#include "frontend_helpers.h"
-
-
 #include <QPushButton>
 #include <QListWidget>
 #include <QCheckBox>
index 93193e50b91db37f163a9d91234dc4b02167b2c2..b2035cba519fbe077047e304abf8891df02e5557 100644 (file)
@@ -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>
index c39c1dd212ed18edea179dee9153bcf8c063c8a8..73b8f8f01278bd6c50ab1c9811e07559a2d9cf7c 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "debug.h"
 #include "gettext.h"
-#include "frontend_helpers.h"
 #include "qt_helpers.h"
 #include "Buffer.h"
 #include "BufferParams.h"
index fb30aba07e1a127e518a8581cfa7a897a039c19f..2941113aebc94065664ffd9a424f2fdd038f0e93 100644 (file)
@@ -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"
index 7d17297513e8c43a2a93609164e01aa1e379aaf0..9b2ab0bd06852587da6c83721a1959d54ec9353d 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "GuiExternal.h"
 
-#include "frontend_helpers.h"
 #include "FuncRequest.h"
 #include "gettext.h"
 #include "Length.h"
index 30d876ca008f2c04142aefcb40763423eec2fb46..12538d86f343b56f1c4de24a0d6e79dd7527484a 100644 (file)
@@ -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)
index 41c5a05a681c510e65148f0075e66b45c85d4516..02d6aae374b5c10d3f64df51ed26fb3eb8bb145a 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "GuiInclude.h"
 
-#include "frontend_helpers.h"
-
 #include "Buffer.h"
 #include "Format.h"
 #include "FuncRequest.h"
index 39d09f64ede4a686af3c4ed6883a86068c403b0b..29b7e8c8162b1a8128d7afe51eaf7d59ad02cce2 100644 (file)
@@ -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"
index cfd73512f70c99ad2e422762e23514c6cf4f0be3..5c6fdcee6e1079259ba90a2131dc4e1f87360bc6 100644 (file)
@@ -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();
index c652bcf74d02614a5b92d38599ec4d8571047866..c57c977efc875636d8e5ef8bf9815b100f0373d7 100644 (file)
@@ -17,8 +17,6 @@
 #include "qt_helpers.h"
 #include "PrinterParams.h"
 
-#include "frontend_helpers.h"
-
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "FuncRequest.h"
index 9a72e232401046bb3ea6d23e69bfce2863212281..59d2143369ceb2e5dee23a6865e0ab56857b3e05 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "GuiDialog.h"
 #include "ui_TexinfoUi.h"
-#include "frontend_helpers.h"
+#include "qt_helpers.h"
 
 #include <map>
 #include <vector>
index ade4dc01a36c5b1529d8c146642b7efae7a998ee..2f82e8c739c97d3998abc053b0bbeaf8300dcfb4 100644 (file)
@@ -50,8 +50,6 @@ SOURCEFILES = \
        ../ButtonPolicy.h \
        ../Dialog.cpp \
        ../Dialog.h \
-       ../frontend_helpers.cpp \
-       ../frontend_helpers.h \
        Resources.cpp \
        Action.cpp \
        alert_pimpl.cpp \
index b45da0f38eed5e82e0dcfda1eeb034e5447774a4..00bc6003aac8d65c6bc57d700d5a1f646b6c8fdb 100644 (file)
 #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"
index 9734a29b087da506ebd64c1c8fb7eafb3a8f55ea..0cc436f4003c9a51082c221059b4b88c120c8170 100644 (file)
 
 #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 <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
index 9cb868d4710d58487c972c0e8a58ad9e519d2d41..c2437deb10b213103c1f34ca24a132cadb60c31b 100644 (file)
@@ -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