mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 03:03:06 +00:00
Fix two filename bugs (from Enrico and me)
* src/support/filetools.[Ch] (fileOpenSearch): comment out since it is unused (fileSearch): Use addExtension instead of changeExtension, since we are always called without extesnion, or with the correct one. (addExtension): new function * src/lyx_main.C (LyX::init): tell fileSearch that we are also interested in the name if the file does not exist git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16361 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
0e2095ad62
commit
a1389d411c
54
Status.15x
54
Status.15x
@ -44,32 +44,6 @@ ICONS:
|
|||||||
|
|
||||||
FILE
|
FILE
|
||||||
|
|
||||||
* Change Tools->Preferences->User interface->User interface to something like
|
|
||||||
"kornel.default.ui"; save prefs; exit LyX; restart LyX; => crash;
|
|
||||||
in the preferences file, there is an entry \bind_file "/Something/kornel.default"
|
|
||||||
|
|
||||||
In QPrefsDialog.C:1736, function PrefUserInterface::select_ui() calls
|
|
||||||
form_->controller().browseUI(qstring_to_ucs4(uiFileED->text())))
|
|
||||||
which in turn calls
|
|
||||||
ControlPrefs.C:118
|
|
||||||
browseLibFile(lyx::from_ascii("ui"), file, lyx::from_ascii("ui"),
|
|
||||||
_("Choose UI file"), FileFilterList(_("LyX UI files (*.ui)")));
|
|
||||||
In this function, the extension is removed, because it is the default ("ui" in
|
|
||||||
this case). This behaviour applies to
|
|
||||||
ControlPrefs::browsebind, ControlPrefs::browseUI
|
|
||||||
ControlPrefs::browsekbmap, ControlPrefs::browsedict
|
|
||||||
Setting the default extension here to something invalid, is a hack, but works.
|
|
||||||
(Invalid may be e.g. "*")
|
|
||||||
|
|
||||||
* When loading a LyX file from a Windows directory with a German Umlaut, I get the
|
|
||||||
following error:
|
|
||||||
|
|
||||||
Assertion triggered in __thiscall lyx::support::FileName::FileName(const class
|
|
||||||
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)
|
|
||||||
by failing check "empty() || absolutePath(name_)" in file C:\...\src\support\filename.C:47
|
|
||||||
|
|
||||||
If I rename the directory (no Umlaut), I can load the file without a problem.
|
|
||||||
|
|
||||||
|
|
||||||
SPELL CHECKING (Joost 4/11/06)
|
SPELL CHECKING (Joost 4/11/06)
|
||||||
|
|
||||||
@ -614,3 +588,31 @@ CREDITS:
|
|||||||
small font size such that it becomes almost invisible on Windows.
|
small font size such that it becomes almost invisible on Windows.
|
||||||
FIXED (Enrico 2006-12-21)
|
FIXED (Enrico 2006-12-21)
|
||||||
|
|
||||||
|
* Change Tools->Preferences->User interface->User interface to something like
|
||||||
|
"kornel.default.ui"; save prefs; exit LyX; restart LyX; => crash;
|
||||||
|
in the preferences file, there is an entry \bind_file "/Something/kornel.default"
|
||||||
|
|
||||||
|
In QPrefsDialog.C:1736, function PrefUserInterface::select_ui() calls
|
||||||
|
form_->controller().browseUI(qstring_to_ucs4(uiFileED->text())))
|
||||||
|
which in turn calls
|
||||||
|
ControlPrefs.C:118
|
||||||
|
browseLibFile(lyx::from_ascii("ui"), file, lyx::from_ascii("ui"),
|
||||||
|
_("Choose UI file"), FileFilterList(_("LyX UI files (*.ui)")));
|
||||||
|
In this function, the extension is removed, because it is the default ("ui" in
|
||||||
|
this case). This behaviour applies to
|
||||||
|
ControlPrefs::browsebind, ControlPrefs::browseUI
|
||||||
|
ControlPrefs::browsekbmap, ControlPrefs::browsedict
|
||||||
|
Setting the default extension here to something invalid, is a hack, but works.
|
||||||
|
(Invalid may be e.g. "*")
|
||||||
|
FIXED (Enrico and Georg 2006-12-21)
|
||||||
|
|
||||||
|
* When loading a LyX file from a Windows directory with a German Umlaut, I get the
|
||||||
|
following error:
|
||||||
|
|
||||||
|
Assertion triggered in __thiscall lyx::support::FileName::FileName(const class
|
||||||
|
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)
|
||||||
|
by failing check "empty() || absolutePath(name_)" in file C:\...\src\support\filename.C:47
|
||||||
|
|
||||||
|
If I rename the directory (no Umlaut), I can load the file without a problem.
|
||||||
|
FIXED (Enrico and Georg 2006-12-21)
|
||||||
|
|
||||||
|
@ -480,7 +480,8 @@ int LyX::init(int & argc, char * argv[])
|
|||||||
// get absolute path of file and add ".lyx" to
|
// get absolute path of file and add ".lyx" to
|
||||||
// the filename if necessary
|
// the filename if necessary
|
||||||
pimpl_->files_to_load_.push_back(fileSearch(string(),
|
pimpl_->files_to_load_.push_back(fileSearch(string(),
|
||||||
os::internal_path(to_utf8(from_local8bit(argv[argi]))), "lyx"));
|
os::internal_path(to_utf8(from_local8bit(argv[argi]))),
|
||||||
|
"lyx", support::allow_unreadable));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first_start)
|
if (first_start)
|
||||||
|
@ -179,6 +179,7 @@ bool isDirWriteable(string const & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Uses a string of paths separated by ";"s to find a file to open.
|
// Uses a string of paths separated by ";"s to find a file to open.
|
||||||
// Can't cope with pathnames with a ';' in them. Returns full path to file.
|
// Can't cope with pathnames with a ';' in them. Returns full path to file.
|
||||||
// If path entry begins with $$LyX/, use system_lyxdir
|
// If path entry begins with $$LyX/, use system_lyxdir
|
||||||
@ -213,6 +214,7 @@ FileName const fileOpenSearch(string const & path, string const & name,
|
|||||||
}
|
}
|
||||||
return real_file;
|
return real_file;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Returns a vector of all files in directory dir having extension ext.
|
/// Returns a vector of all files in directory dir having extension ext.
|
||||||
@ -250,7 +252,7 @@ vector<string> const dirList(FileName const & dir, string const & ext)
|
|||||||
// Returns the real name of file name in directory path, with optional
|
// Returns the real name of file name in directory path, with optional
|
||||||
// extension ext.
|
// extension ext.
|
||||||
FileName const fileSearch(string const & path, string const & name,
|
FileName const fileSearch(string const & path, string const & name,
|
||||||
string const & ext)
|
string const & ext, search_mode mode)
|
||||||
{
|
{
|
||||||
// if `name' is an absolute path, we ignore the setting of `path'
|
// if `name' is an absolute path, we ignore the setting of `path'
|
||||||
// Expand Environmentvariables in 'name'
|
// Expand Environmentvariables in 'name'
|
||||||
@ -260,9 +262,15 @@ FileName const fileSearch(string const & path, string const & name,
|
|||||||
if (isFileReadable(fullname))
|
if (isFileReadable(fullname))
|
||||||
return fullname;
|
return fullname;
|
||||||
if (ext.empty())
|
if (ext.empty())
|
||||||
|
// We are done.
|
||||||
|
return mode == allow_unreadable ? fullname : FileName();
|
||||||
|
// Only add the extension if it is not already the extension of
|
||||||
|
// fullname.
|
||||||
|
if (getExtension(fullname.absFilename()) != ext)
|
||||||
|
fullname = FileName(addExtension(fullname.absFilename(), ext));
|
||||||
|
if (isFileReadable(fullname) || mode == allow_unreadable)
|
||||||
|
return fullname;
|
||||||
return FileName();
|
return FileName();
|
||||||
fullname = FileName(changeExtension(fullname.absFilename(), ext));
|
|
||||||
return isFileReadable(fullname) ? fullname : FileName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -721,11 +729,6 @@ string const addPath(string const & path, string const & path_2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Change extension of oldname to extension.
|
|
||||||
Strips path off if no_path == true.
|
|
||||||
If no extension on oldname, just appends.
|
|
||||||
*/
|
|
||||||
string const changeExtension(string const & oldname, string const & extension)
|
string const changeExtension(string const & oldname, string const & extension)
|
||||||
{
|
{
|
||||||
string::size_type const last_slash = oldname.rfind('/');
|
string::size_type const last_slash = oldname.rfind('/');
|
||||||
@ -750,6 +753,14 @@ string const removeExtension(string const & name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string const addExtension(string const & name, string const & extension)
|
||||||
|
{
|
||||||
|
if (!extension.empty() && extension[0] != '.')
|
||||||
|
return name + '.' + extension;
|
||||||
|
return name + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Return the extension of the file (not including the .)
|
/// Return the extension of the file (not including the .)
|
||||||
string const getExtension(string const & name)
|
string const getExtension(string const & name)
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,8 @@ bool createDirectory(std::string const & name, int permissions);
|
|||||||
*/
|
*/
|
||||||
FileName const createLyXTmpDir(FileName const & deflt);
|
FileName const createLyXTmpDir(FileName const & deflt);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// FIXME unused. Should this be deleted or resurrected?
|
||||||
/** Find file by searching several directories.
|
/** Find file by searching several directories.
|
||||||
Uses a string of paths separated by ";"s to find a file to open.
|
Uses a string of paths separated by ";"s to find a file to open.
|
||||||
Can't cope with pathnames with a ';' in them. Returns full path to file.
|
Can't cope with pathnames with a ';' in them. Returns full path to file.
|
||||||
@ -49,6 +51,16 @@ FileName const createLyXTmpDir(FileName const & deflt);
|
|||||||
FileName const fileOpenSearch(std::string const & path,
|
FileName const fileOpenSearch(std::string const & path,
|
||||||
std::string const & name,
|
std::string const & name,
|
||||||
std::string const & ext = std::string());
|
std::string const & ext = std::string());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// How to search files
|
||||||
|
enum search_mode {
|
||||||
|
// The file must exist (return an empty file name otherwise)
|
||||||
|
standard_mode,
|
||||||
|
/// Only do file name expansion, return the complete name even if
|
||||||
|
/// the file does not exist
|
||||||
|
allow_unreadable
|
||||||
|
};
|
||||||
|
|
||||||
/** Returns the real name of file name in directory path, with optional
|
/** Returns the real name of file name in directory path, with optional
|
||||||
extension ext.
|
extension ext.
|
||||||
@ -57,7 +69,8 @@ FileName const fileOpenSearch(std::string const & path,
|
|||||||
*/
|
*/
|
||||||
FileName const fileSearch(std::string const & path,
|
FileName const fileSearch(std::string const & path,
|
||||||
std::string const & name,
|
std::string const & name,
|
||||||
std::string const & ext = std::string());
|
std::string const & ext = std::string(),
|
||||||
|
search_mode mode = standard_mode);
|
||||||
|
|
||||||
/// Returns a vector of all files in directory dir having extension ext.
|
/// Returns a vector of all files in directory dir having extension ext.
|
||||||
std::vector<std::string> const dirList(FileName const & dir,
|
std::vector<std::string> const dirList(FileName const & dir,
|
||||||
@ -180,6 +193,14 @@ changeExtension(std::string const & oldname, std::string const & extension);
|
|||||||
/// Remove the extension from \p name
|
/// Remove the extension from \p name
|
||||||
std::string const removeExtension(std::string const & name);
|
std::string const removeExtension(std::string const & name);
|
||||||
|
|
||||||
|
/** Add the extension \p ext to \p name.
|
||||||
|
Use this instead of changeExtension if you know that \p name is without
|
||||||
|
extension, because changeExtension would wrongly interpret \p name if it
|
||||||
|
contains a dot.
|
||||||
|
*/
|
||||||
|
std::string const
|
||||||
|
addExtension(std::string const & name, std::string const & extension);
|
||||||
|
|
||||||
/// Return the extension of the file (not including the .)
|
/// Return the extension of the file (not including the .)
|
||||||
std::string const getExtension(std::string const & name);
|
std::string const getExtension(std::string const & name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user