Jean-Marc Lasgouttes wrote:
>>>>> I have to admit that the length of this patch makes me nervous.
>>>>> Isn't it possible to devise a `just good enough' solution that
>>>>> could go in 1.3.6?
>>>
> Angus> Sure. Describe what you would like to see.
>>> I do not know precisely... Could we get away without the nifty
>>> validators, so that the result is not as good as 1.4.x, but better
>>> than 1.3.5?
>
> Angus> In that case, we should leave the code almost as it is now, but
> Angus> make the loop in the browser code understand
> Angus> \tex_allows_spaces.
>
> I think I'd prefer that, if it is possible and not too complicated.
> Basically I just want to allow people to work with paths with spaces
> transparently in cases where it is possible.
Ok, try this. Super simple, no?
--
Angus
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.273.2.16
diff -u -p -r1.273.2.16 ChangeLog
--- src/frontends/controllers/ChangeLog 10 May 2005 15:00:13 -0000 1.273.2.16
+++ src/frontends/controllers/ChangeLog 18 May 2005 21:13:56 -0000
@@ -1,3 +1,11 @@
+2005-05-18 Angus Leeming <[EMAIL PROTECTED]>
+
+ * helper_funcs.C (get_invalid_chars_latex, printable_list): new
+ helper functions, used by ...
+ (browseFile, browseDir): to ensure that the browsed for file name
+ doesn't contain any characters that will cause LaTeX to keel over.
+ In particular, get_invalid_chars() now honours lyxrc.tex_allow_spaces.
+
2005-05-09 Angus Leeming <[EMAIL PROTECTED]>
* ControlSpellchecker.C: clean-up the creation of the wrappers to
Index: src/frontends/controllers/helper_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/helper_funcs.C,v
retrieving revision 1.25.2.1
diff -u -p -r1.25.2.1 helper_funcs.C
--- src/frontends/controllers/helper_funcs.C 7 Dec 2004 10:49:06 -0000 1.25.2.1
+++ src/frontends/controllers/helper_funcs.C 18 May 2005 21:13:56 -0000
@@ -14,17 +14,55 @@
#include "LString.h"
#include "helper_funcs.h"
+#include "buffer.h"
+#include "gettext.h"
+#include "lyxrc.h"
+
+#include "frontends/Alert.h"
#include "frontends/FileDialog.h"
+#include "frontends/LyXView.h"
+
#include "support/filetools.h" // OnlyPath, OnlyFilename
#include "support/lstrings.h"
-#include "gettext.h" // _()
-#include "frontends/Alert.h"
using std::pair;
using std::vector;
using std::make_pair;
+namespace {
+
+string const get_invalid_chars_latex()
+{
+ string invalid_chars("#$%{}()[]:\"^");
+ if (!lyxrc.tex_allows_spaces)
+ invalid_chars += ' ';
+ return invalid_chars;
+}
+
+
+string const printable_list(string const & invalid_chars)
+{
+ ostringstream ss;
+ string::const_iterator const begin = invalid_chars.begin();
+ string::const_iterator const end = invalid_chars.end();
+ string::const_iterator it = begin;
+
+ for (; it != end; ++it) {
+ if (it != begin)
+ ss << ", ";
+ if (*it == ' ')
+ ss << _("space");
+ else
+ ss << *it;
+ }
+
+ return STRCONV(ss.str());
+}
+
+} // namespace anon
+
+
string const browseFile(LyXView * lv, string const & filename,
string const & title,
string const & pattern,
@@ -39,6 +77,9 @@ string const browseFile(LyXView * lv, st
FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
FileDialog::Result result;
+ string const & result_path = result.second;
+ string const invalid_chars = lv->buffer()->isLatex() ?
+ get_invalid_chars_latex() : string();
while (true) {
if (save)
@@ -48,20 +89,19 @@ string const browseFile(LyXView * lv, st
result = fileDlg.open(lastPath, pattern,
OnlyFilename(filename));
- if (result.second.empty())
- return result.second;
-
- lastPath = OnlyPath(result.second);
-
- if (result.second.find_first_of("#~$% ") == string::npos)
+ if (invalid_chars.empty())
+ break;
+ if (result_path.empty())
+ break;
+ if (result_path.find_first_of(invalid_chars) == string::npos)
break;
- Alert::alert(_("Filename can't contain any "
- "of these characters:"),
- _("space, '#', '~', '$' or '%'."));
+ Alert::alert(_("Invalid filename"),
+ _("No LaTeX support for paths containing any of these characters:\n") +
+ printable_list(invalid_chars));
}
- return result.second;
+ return result_path;
}
@@ -97,25 +137,28 @@ string const browseDir(LyXView * lv, str
FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
FileDialog::Result result;
+ string const & result_path = result.second;
+ string const invalid_chars = lv->buffer()->isLatex() ?
+ get_invalid_chars_latex() : string();
while (true) {
result = fileDlg.opendir(lastPath,
OnlyFilename(pathname));
- if (result.second.empty())
- return result.second;
-
- lastPath = OnlyPath(result.second);
-
- if (result.second.find_first_of("#~$% ") == string::npos)
+ if (invalid_chars.empty())
+ break;
+ if (result_path.empty())
+ break;
+ if (result_path.find_first_of(invalid_chars) == string::npos)
break;
- Alert::alert(_("directory name can't contain any "
- "of these characters:"),
- _("space, '#', '~', '$' or '%'."));
+ lastPath = OnlyPath(result_path);
+ Alert::alert(_("Invalid directory name"),
+ _("No LaTeX support for paths containing any of these characters:\n") +
+ printable_list(invalid_chars));
}
- return result.second;
+ return result_path;
}