diff --git a/Status.15x b/Status.15x index 3408cff1ad..4796a8e5b2 100644 --- a/Status.15x +++ b/Status.15x @@ -44,32 +44,6 @@ ICONS: 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,class std::allocator > &) - 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) @@ -614,3 +588,31 @@ CREDITS: small font size such that it becomes almost invisible on Windows. 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,class std::allocator > &) + 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) + diff --git a/src/lyx_main.C b/src/lyx_main.C index 980582e901..add424f8b0 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -480,7 +480,8 @@ int LyX::init(int & argc, char * argv[]) // get absolute path of file and add ".lyx" to // the filename if necessary 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) diff --git a/src/support/filetools.C b/src/support/filetools.C index 2eab4b38cf..8ba5c0f595 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -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. // Can't cope with pathnames with a ';' in them. Returns full path to file. // 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; } +#endif /// Returns a vector of all files in directory dir having extension ext. @@ -250,7 +252,7 @@ vector const dirList(FileName const & dir, string const & ext) // Returns the real name of file name in directory path, with optional // extension ext. 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' // Expand Environmentvariables in 'name' @@ -260,9 +262,15 @@ FileName const fileSearch(string const & path, string const & name, if (isFileReadable(fullname)) return fullname; if (ext.empty()) - return FileName(); - fullname = FileName(changeExtension(fullname.absFilename(), ext)); - return isFileReadable(fullname) ? fullname : FileName(); + // 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(); } @@ -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::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 .) string const getExtension(string const & name) { diff --git a/src/support/filetools.h b/src/support/filetools.h index abf637ca84..aadb39c4b6 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -39,6 +39,8 @@ bool createDirectory(std::string const & name, int permissions); */ FileName const createLyXTmpDir(FileName const & deflt); +#if 0 +// FIXME unused. Should this be deleted or resurrected? /** Find file by searching several directories. 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. @@ -49,6 +51,16 @@ FileName const createLyXTmpDir(FileName const & deflt); FileName const fileOpenSearch(std::string const & path, std::string const & name, 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 extension ext. @@ -57,7 +69,8 @@ FileName const fileOpenSearch(std::string const & path, */ FileName const fileSearch(std::string const & path, 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. std::vector const dirList(FileName const & dir, @@ -180,6 +193,14 @@ changeExtension(std::string const & oldname, std::string const & extension); /// Remove the extension from \p 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 .) std::string const getExtension(std::string const & name);