The attached patch moves functionality out of ControlSendto and into
the core, where it belongs. However, I'm unsure of two things:

1. The name. We have an LFUN_EXPORT. Maybe LFUN_SENDTO would be better
off as LFUN_EXPORT_CUSTOM?

2. Where the code should go. All these different dispatch functions
leaves me confused ;-) I've put it in LyXFunc::dispatch. Please feel
free to tell me that's not the right place. You'll have to explain
why though ;-)

Feedback???

-- 
Angus
Index: src/LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.192
diff -u -p -r1.192 LyXAction.C
--- src/LyXAction.C	17 Mar 2004 21:21:44 -0000	1.192
+++ src/LyXAction.C	27 Mar 2004 18:51:12 -0000
@@ -324,6 +324,7 @@ void LyXAction::init()
 		{ LFUN_REPEAT, "repeat", NoBuffer },
 		{ LFUN_WORD_FIND, "word-find", Noop },
 		{ LFUN_WORD_REPLACE, "word-replace", Noop },
+		{ LFUN_SENDTO, "sendto", ReadOnly },
 		{ LFUN_NOACTION, "", Noop }
 	};
 
Index: src/lfuns.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lfuns.h,v
retrieving revision 1.29
diff -u -p -r1.29 lfuns.h
--- src/lfuns.h	25 Mar 2004 09:16:15 -0000	1.29
+++ src/lfuns.h	27 Mar 2004 18:51:12 -0000
@@ -335,6 +335,7 @@ enum kb_action {
 	LFUN_WORD_FIND,
 	LFUN_WORD_REPLACE,
 	// 255
+	LFUN_SENDTO,
 
 	LFUN_LASTACTION                  // end of the table
 };
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.589
diff -u -p -r1.589 lyxfunc.C
--- src/lyxfunc.C	25 Mar 2004 17:24:13 -0000	1.589
+++ src/lyxfunc.C	27 Mar 2004 18:51:14 -0000
@@ -78,6 +78,7 @@
 #include "support/globbing.h"
 #include "support/path.h"
 #include "support/path_defines.h"
+#include "support/systemcall.h"
 #include "support/tostr.h"
 #include "support/std_sstream.h"
 #include "support/os.h"
@@ -88,6 +89,7 @@ using lyx::support::AddName;
 using lyx::support::AddPath;
 using lyx::support::bformat;
 using lyx::support::ChangeExtension;
+using lyx::support::contains;
 using lyx::support::FileFilterList;
 using lyx::support::FileInfo;
 using lyx::support::FileSearch;
@@ -103,7 +105,9 @@ using lyx::support::rtrim;
 using lyx::support::split;
 using lyx::support::strToInt;
 using lyx::support::strToUnsignedInt;
+using lyx::support::subst;
 using lyx::support::system_lyxdir;
+using lyx::support::Systemcall;
 using lyx::support::token;
 using lyx::support::trim;
 using lyx::support::user_lyxdir;
@@ -477,6 +481,7 @@ FuncStatus LyXFunc::getStatus(FuncReques
 	case LFUN_KMAP_SEC:
 	case LFUN_KMAP_TOGGLE:
 	case LFUN_REPEAT:
+	case LFUN_SENDTO:
 	case LFUN_SEQUENCE:
 	case LFUN_SAVEPREFERENCES:
 	case LFUN_SCREEN_FONT_UPDATE:
@@ -681,6 +686,49 @@ void LyXFunc::dispatch(FuncRequest const
 				view()->showErrorList(BufferFormat(*owner->buffer()));
 			}
 			break;
+
+		case LFUN_SENDTO: {
+			string format_name;
+			string command = split(argument, format_name, ' ');
+			Format const * format = formats.getFormat(format_name);
+			if (!format) {
+				lyxerr << "Format \"" << format_name
+				       << "\" not recognized!"
+				       << std::endl;
+				break;
+			}
+
+			Buffer * buffer = owner->buffer();
+
+			// The name of the file created by the conversion process
+			string filename;
+
+			// Output to filename
+			if (format->name() == "lyx") {
+				string const latexname =
+					buffer->getLatexName(false);
+				filename = ChangeExtension(latexname,
+							   format->extension());
+				filename = AddName(buffer->temppath(), filename);
+
+				if (!buffer->writeFile(filename))
+					break;
+
+			} else {
+				Exporter::Export(buffer, format_name, true,
+						 filename);
+			}
+
+			// Substitute $$FName for filename
+			if (!contains(command, "$$FName"))
+				command = "( " + command + " ) < $$FName";
+			command = subst(command, "$$FName", filename);
+
+			// Execute the command in the background
+			Systemcall call;
+			call.startscript(Systemcall::DontWait, command);
+			break;
+		}
 
 		case LFUN_IMPORT:
 			doImport(argument);
Index: src/frontends/controllers/ControlSendto.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlSendto.C,v
retrieving revision 1.24
diff -u -p -r1.24 ControlSendto.C
--- src/frontends/controllers/ControlSendto.C	25 Feb 2004 12:00:49 -0000	1.24
+++ src/frontends/controllers/ControlSendto.C	27 Mar 2004 18:51:14 -0000
@@ -16,18 +16,16 @@
 #include "buffer.h"
 #include "converter.h"
 #include "format.h"
-#include "exporter.h"
+#include "funcrequest.h"
+#include "lyxfunc.h"
 #include "lyxrc.h"
 
+#include "frontends/LyXView.h"
+
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/systemcall.h"
 
 using lyx::support::AddName;
-using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::subst;
-using lyx::support::Systemcall;
 using lyx::support::trim;
 
 using std::vector;
@@ -48,15 +46,13 @@ vector<Format const *> const ControlSend
 	exports.push_back("lyx");
 	exports.push_back("text");
 
-#warning Can the doc ever be all/any of these at the same time? (Lgb)
-	// I think some if else if is in order.
 	if (buffer().isLatex())
 		exports.push_back("latex");
-	if (buffer().isLinuxDoc())
+	else if (buffer().isLinuxDoc())
 		exports.push_back("linuxdoc");
-	if (buffer().isDocBook())
+	else if (buffer().isDocBook())
 		exports.push_back("docbook");
-	if (buffer().isLiterate())
+	else if (buffer().isLiterate())
 		exports.push_back("literate");
 
 	// Loop over these native formats and ascertain what formats we
@@ -110,32 +106,9 @@ void ControlSendto::apply()
 
 	view().apply();
 
-	if (command_.empty() || !format_)
+	if (command_.empty() || !format_ || format_->name().empty())
 		return;
 
-	// The name of the file created by the conversion process
-	string filename;
-
-	// Output to filename
-	if (format_->name() == "lyx") {
-		filename = ChangeExtension(buffer()->getLatexName(false),
-					   format_->extension());
-		filename = AddName(buffer()->temppath(), filename);
-
-		if (!buffer()->writeFile(filename))
-			return;
-
-	} else {
-		Exporter::Export(buffer(), format_->name(), true, filename);
-	}
-
-	// Substitute $$FName for filename
-	string command = command_;
-	if (!contains(command, "$$FName"))
-		command = "( " + command + " ) < $$FName";
-	command = subst(command, "$$FName", filename);
-
-	// Execute the command in the background
-	Systemcall call;
-	call.startscript(Systemcall::DontWait, command);
+	string const data = format_->name() + " " + command_;
+	lv_.getLyXFunc().dispatch(FuncRequest(LFUN_SENDTO, data));
 }

Reply via email to