+2004-08-08 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
+
+ * helper_funcs.C (browseLibFile): new function. Tries to do the
+ right thing to look for a file in lyxdir
+
+ * ControlPrefs.C (browsebind, browseUI, browsekbmap): use
+ browseLibFile
+
2004-08-07 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlBibtex.C (browseBst): new method, specialized to lookup
#include "funcrequest.h"
#include "LColor.h"
-#include "support/filetools.h"
#include "support/globbing.h"
-#include "support/path_defines.h"
#include <sstream>
namespace lyx {
-using support::AddName;
using support::FileFilterList;
-using support::system_lyxdir;
-using support::user_lyxdir;
namespace frontend {
string const ControlPrefs::browsebind(string const & file) const
{
- pair<string,string> dir1(_("System Bind|#S#s"),
- AddName(system_lyxdir(), "bind"));
-
- pair<string,string> dir2(_("User Bind|#U#u"),
- AddName(user_lyxdir(), "bind"));
-
- return browseFile(file, _("Choose bind file"),
- FileFilterList("*.bind"), false, dir1, dir2);
+ return browseLibFile("bind", file, "bind", _("Choose bind file"),
+ FileFilterList("LyX bind files (*.bind)"));
}
string const ControlPrefs::browseUI(string const & file) const
{
- pair<string,string> const dir1(_("Sys UI|#S#s"),
- AddName(system_lyxdir(), "ui"));
-
- pair<string,string> const dir2(_("User UI|#U#u"),
- AddName(user_lyxdir(), "ui"));
-
- return browseFile(file, _("Choose UI file"),
- FileFilterList("*.ui"), false, dir1, dir2);
+ return browseLibFile("ui", file, "ui", _("Choose UI file"),
+ FileFilterList("LyX UI files (*.ui)"));
}
string const ControlPrefs::browsekbmap(string const & file) const
{
- pair<string, string> dir(_("Key maps|#K#k"),
- AddName(system_lyxdir(), "kbd"));
-
- return browseFile(file, _("Choose keyboard map"),
- FileFilterList("*.kmap"), false, dir);
+ return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
+ FileFilterList("LyX keyboard maps (*.kmap)"));
}
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
+ * \author Jean-Marc Lasgouttes
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
#include "frontends/Alert.h"
#include "frontends/FileDialog.h"
-#include "support/filetools.h" // OnlyPath, OnlyFilename
+#include "support/filetools.h"
+#include "support/path_defines.h"
#include "support/globbing.h"
using std::pair;
namespace lyx {
+using support::AddName;
+using support::ChangeExtension;
using support::FileFilterList;
+using support::GetExtension;
+using support::LibFileSearch;
using support::MakeAbsPath;
using support::MakeRelPath;
using support::OnlyFilename;
using support::OnlyPath;
using support::prefixIs;
+using support::system_lyxdir;
+using support::user_lyxdir;
namespace frontend {
}
+
+string const browseLibFile(string const & dir,
+ string const & name,
+ string const & ext,
+ string const & title,
+ FileFilterList const & filters)
+{
+ pair<string,string> const dir1(_("System files|#S#s"),
+ AddName(system_lyxdir(), dir));
+
+ pair<string,string> const dir2(_("User files|#U#u"),
+ AddName(user_lyxdir(), dir));
+
+ string const result = browseFile(LibFileSearch(dir, name, ext), title,
+ filters, false, dir1, dir2);
+
+ // remove the extension if it is the default one
+ string noextresult;
+ if (GetExtension(result) == ext)
+ noextresult = ChangeExtension(result, string());
+ else
+ noextresult = result;
+
+ // remove the directory, if it is the default one
+ string const file = OnlyFilename(noextresult);
+ if (LibFileSearch(dir, file, ext) == result)
+ return file;
+ else
+ return noextresult;
+}
+
+
string const browseDir(string const & pathname,
string const & title,
pair<string,string> const & dir1,
std::make_pair(std::string(), std::string()));
-/* 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/
+/** 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/
*/
std::string const
browseRelFile(std::string const & filename,
std::make_pair(std::string(), std::string()));
+/** 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
+ * lyx::support::LibFileSearch function.
+ */
+std::string const
+browseLibFile(std::string const & dir,
+ std::string const & name,
+ std::string const & ext,
+ std::string 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.