mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 23:07:43 +00:00
make browsing for lyxdir files DTRT
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8872 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9e25f077c3
commit
56c470c33d
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -20,9 +20,7 @@
|
||||
#include "funcrequest.h"
|
||||
#include "LColor.h"
|
||||
|
||||
#include "support/filetools.h"
|
||||
#include "support/globbing.h"
|
||||
#include "support/path_defines.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -36,10 +34,7 @@ extern BufferList bufferlist;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::AddName;
|
||||
using support::FileFilterList;
|
||||
using support::system_lyxdir;
|
||||
using support::user_lyxdir;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
@ -123,37 +118,22 @@ void ControlPrefs::updateScreenFonts()
|
||||
|
||||
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)"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
* 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.
|
||||
@ -18,7 +19,8 @@
|
||||
#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;
|
||||
@ -30,12 +32,18 @@ extern const char * stringFromUnit(int);
|
||||
|
||||
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 {
|
||||
|
||||
@ -101,6 +109,38 @@ string const browseRelFile(string const & filename,
|
||||
}
|
||||
|
||||
|
||||
|
||||
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,
|
||||
|
@ -44,11 +44,11 @@ browseFile(std::string const & filename,
|
||||
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,
|
||||
@ -62,6 +62,19 @@ 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.
|
||||
|
Loading…
Reference in New Issue
Block a user