Re: [PATCH 13x] inputing files with spaces

2005-05-19 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

  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.

Angus Ok, try this. Super simple, no?

This looks just like what I wanted :)

JMarc


Re: [PATCH 13x] inputing files with spaces

2005-05-19 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:
  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.
 
 Angus Ok, try this. Super simple, no?
 
 This looks just like what I wanted :)

:) Now committed.

-- 
Angus



Re: [PATCH 13x] inputing "files with spaces"

2005-05-19 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

>>  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.

Angus> Ok, try this. Super simple, no?

This looks just like what I wanted :)

JMarc


Re: [PATCH 13x] inputing "files with spaces"

2005-05-19 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:
>>>  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.
> 
> Angus> Ok, try this. Super simple, no?
> 
> This looks just like what I wanted :)

:) Now committed.

-- 
Angus



Re: [PATCH 13x] inputing files with spaces

2005-05-18 Thread Angus Leeming
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?

-- 
AngusIndex: 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 -	1.273.2.16
+++ src/frontends/controllers/ChangeLog	18 May 2005 21:13:56 -
@@ -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 -	1.25.2.1
+++ src/frontends/controllers/helper_funcs.C	18 May 2005 21:13:56 -
@@ -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 

Re: [PATCH 13x] inputing "files with spaces"

2005-05-18 Thread Angus Leeming
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?

-- 
AngusIndex: 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 -	1.273.2.16
+++ src/frontends/controllers/ChangeLog	18 May 2005 21:13:56 -
@@ -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 -	1.25.2.1
+++ src/frontends/controllers/helper_funcs.C	18 May 2005 21:13:56 -
@@ -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 

[PATCH 13x] inputing files with spaces

2005-05-17 Thread Angus Leeming
Jean-Marc,

here's a backport of the 1.4.x changes to enable the user to specify a file
whose name contains spaces, but only if LaTeX can handle such a name.

I guess that we should also get LyX to use the cleandvi script on the wiki
pages, no?

Did you get any where with your enquiries on the tex newsgroups about
fixing latex itself?

-- 
Angus

invalid_filenames_13x.diff.gz
Description: GNU Zip compressed data


Re: [PATCH 13x] inputing files with spaces

2005-05-17 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

Angus Jean-Marc, here's a backport of the 1.4.x changes to enable the
Angus user to specify a file whose name contains spaces, but only if
Angus LaTeX can handle such a name.

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 I guess that we should also get LyX to use the cleandvi script
Angus on the wiki pages, no?

Angus Did you get any where with your enquiries on the tex newsgroups
Angus about fixing latex itself?

Well I did get answers, but I failed to followup correctly. Will do.

JMarc


Re: [PATCH 13x] inputing files with spaces

2005-05-17 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:
 Angus Jean-Marc, here's a backport of the 1.4.x changes to enable the
 Angus user to specify a file whose name contains spaces, but only if
 Angus LaTeX can handle such a name.
 
 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?

Sure. Describe what you would like to see.

-- 
Angus



Re: [PATCH 13x] inputing files with spaces

2005-05-17 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

  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?

JMarc


Re: [PATCH 13x] inputing files with spaces

2005-05-17 Thread Angus Leeming
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?

In that case, we should leave the code almost as it is now, but make the
loop in the browser code understand \tex_allows_spaces.

-- 
Angus



Re: [PATCH 13x] inputing files with spaces

2005-05-17 Thread Jean-Marc Lasgouttes
 Angus == Angus Leeming [EMAIL PROTECTED] writes:

Angus 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.

JMarc


[PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Angus Leeming
Jean-Marc,

here's a backport of the 1.4.x changes to enable the user to specify a file
whose name contains spaces, but only if LaTeX can handle such a name.

I guess that we should also get LyX to use the cleandvi script on the wiki
pages, no?

Did you get any where with your enquiries on the tex newsgroups about
fixing latex itself?

-- 
Angus

invalid_filenames_13x.diff.gz
Description: GNU Zip compressed data


Re: [PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

Angus> Jean-Marc, here's a backport of the 1.4.x changes to enable the
Angus> user to specify a file whose name contains spaces, but only if
Angus> LaTeX can handle such a name.

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> I guess that we should also get LyX to use the cleandvi script
Angus> on the wiki pages, no?

Angus> Did you get any where with your enquiries on the tex newsgroups
Angus> about fixing latex itself?

Well I did get answers, but I failed to followup correctly. Will do.

JMarc


Re: [PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Angus Leeming
Jean-Marc Lasgouttes wrote:
> Angus> Jean-Marc, here's a backport of the 1.4.x changes to enable the
> Angus> user to specify a file whose name contains spaces, but only if
> Angus> LaTeX can handle such a name.
> 
> 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?

Sure. Describe what you would like to see.

-- 
Angus



Re: [PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

>>  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?

JMarc


Re: [PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Angus Leeming
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?

In that case, we should leave the code almost as it is now, but make the
loop in the browser code understand \tex_allows_spaces.

-- 
Angus



Re: [PATCH 13x] inputing "files with spaces"

2005-05-17 Thread Jean-Marc Lasgouttes
> "Angus" == Angus Leeming <[EMAIL PROTECTED]> writes:

Angus> 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.

JMarc