Dear all,

As described in another thread, this patch adds an "Embedded File"
type to InsetInclude. It has a pseudo-latex name "embedded", but will
not output any latex code. Using this type of InsetInclude, arbitrary
files can be inserted, and bundled when the .lyx file is saved in
bundled format.

With this patch applied, the remaining pieces are GUI and file format
changes for individual insets. This is partly done for InsetGraphics,
and will be done for InsetInclude and InsetExternal.

I will apply this patch tomorrow if there is no objection.

Cheers,
Bo
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp	(revision 21103)
+++ src/insets/InsetInclude.cpp	(working copy)
@@ -98,6 +98,13 @@
 	return params.getCmdName() == "lstinputlisting";
 }
 
+
+bool isEmbedded(InsetCommandParams const & params)
+{
+	return params.getCmdName() == "embedded";
+}
+
+
 } // namespace anon
 
 
@@ -200,6 +207,7 @@
 	INPUT = 2,
 	VERBAST = 3,
 	LISTINGS = 4,
+	EMBEDDED = 5,
 };
 
 
@@ -209,12 +217,14 @@
 
 	if (command_name == "input")
 		return INPUT;
-	if  (command_name == "verbatiminput")
+	if (command_name == "verbatiminput")
 		return VERB;
-	if  (command_name == "verbatiminput*")
+	if (command_name == "verbatiminput*")
 		return VERBAST;
-	if  (command_name == "lstinputlisting")
+	if (command_name == "lstinputlisting")
 		return LISTINGS;
+	if (command_name == "embedded")
+		return EMBEDDED;
 	return INCLUDE;
 }
 
@@ -342,7 +352,11 @@
 			break;
 		case LISTINGS: {
 			temp = listings_label_;
+			break;
 		}
+		case EMBEDDED:
+			temp = buf.B_("Embedded");
+			break;
 	}
 
 	temp += ": ";
@@ -361,7 +375,7 @@
 /// return the child buffer if the file is a LyX doc and is loaded
 Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
 {
-	if (isVerbatim(params) || isListings(params))
+	if (isVerbatim(params) || isListings(params) || isEmbedded(params))
 		return 0;
 
 	string const included_file = includedFilename(buffer, params).absFilename();
@@ -383,7 +397,7 @@
 /// return true if the file is or got loaded.
 Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
 {
-	if (isVerbatim(params) || isListings(params))
+	if (isVerbatim(params) || isListings(params) || isEmbedded(params))
 		return 0;
 
 	string const parent_filename = parent.absFileName();
@@ -414,6 +428,10 @@
 int InsetInclude::latex(Buffer const & buffer, odocstream & os,
 			OutputParams const & runparams) const
 {
+	// embedded file does not produce any latex code
+	if (isEmbedded(params_))
+		return 0;
+
 	string incfile(to_utf8(params_["filename"]));
 
 	// Do nothing if no file name has been specified
@@ -603,7 +621,7 @@
 		os << str;
 		os << "\n]";
 		return PLAINTEXT_NEWLINE + 1; // one char on a separate line
-	} else {
+	} else if (!isEmbedded(params_)) {
 		docstring const str = '[' + getScreenLabel(buffer) + ']';
 		os << str;
 		return str.size();
@@ -614,6 +632,10 @@
 int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
 			  OutputParams const & runparams) const
 {
+	// embedded file does not produce any latex code
+	if (isEmbedded(params_))
+		return 0;
+
 	string incfile = to_utf8(params_["filename"]);
 
 	// Do nothing if no file name has been specified
@@ -911,7 +933,9 @@
 		// so it has to use the iterator of its parent paragraph
 		toc.push_back(TocItem(pit, 0, str));
 		return;
-	}
+	} else if (isEmbedded(params_))
+		return;
+
 	Buffer const * const childbuffer = getChildBuffer(buffer, params_);
 	if (!childbuffer)
 		return;
@@ -951,10 +975,8 @@
 void InsetInclude::registerEmbeddedFiles(Buffer const & buffer,
 	EmbeddedFiles & files) const
 {
-	// include and input are temprarily not considered.
-	if (isVerbatim(params_) || isListings(params_))
-		files.registerFile(includedFilename(buffer, params_).absFilename(),
-			false, this);
+	files.registerFile(includedFilename(buffer, params_).absFilename(),
+		false, this);
 }
 
 
Index: src/frontends/qt4/ui/IncludeUi.ui
===================================================================
--- src/frontends/qt4/ui/IncludeUi.ui	(revision 21103)
+++ src/frontends/qt4/ui/IncludeUi.ui	(working copy)
@@ -302,6 +302,11 @@
        <string>Program Listing</string>
       </property>
      </item>
+     <item>
+      <property name="text" >
+       <string>Embedded File</string>
+      </property>
+     </item>
     </widget>
    </item>
    <item row="1" column="3" >
Index: src/frontends/qt4/GuiInclude.h
===================================================================
--- src/frontends/qt4/GuiInclude.h	(revision 21103)
+++ src/frontends/qt4/GuiInclude.h	(working copy)
@@ -73,6 +73,8 @@
 		INCLUDE,
 		///
 		LISTINGS,
+		///
+		EMBEDDED,
 	};
 
 	///
Index: src/frontends/qt4/GuiInclude.cpp
===================================================================
--- src/frontends/qt4/GuiInclude.cpp	(revision 21103)
+++ src/frontends/qt4/GuiInclude.cpp	(working copy)
@@ -173,6 +173,14 @@
 			previewCB->setChecked(false);
 			listingsGB->setEnabled(true);
 			break;
+		// case embedded
+		case 4:
+			visiblespaceCB->setEnabled(false);
+			visiblespaceCB->setChecked(false);
+			previewCB->setEnabled(false);
+			previewCB->setChecked(false);
+			listingsGB->setEnabled(false);
+			break;
 		//case Verbatim
 		default:
 			visiblespaceCB->setEnabled(true);
@@ -207,7 +215,8 @@
 	if (cmdname != "include" &&
 	    cmdname != "verbatiminput" &&
 	    cmdname != "verbatiminput*" &&
-		cmdname != "lstinputlisting")
+		cmdname != "lstinputlisting" &&
+		cmdname != "embedded")
 		cmdname = "input";
 
 	if (cmdname == "include") {
@@ -253,6 +262,8 @@
 		// the rest is put to the extra edit box.
 		string extra = getStringFromVector(pars);
 		listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
+	} else if (cmdname == "embedded") {
+		typeCO->setCurrentIndex(4);
 	}
 }
 
@@ -278,6 +289,8 @@
 		if (!label.empty())
 			par.addParam("label", "{" + label + "}");
 		params_.setOptions(par.params());
+	} else if (item == 4) {
+		params_.setCmdName("embedded");
 	} else {
 		if (visiblespaceCB->isChecked())
 			params_.setCmdName("verbatiminput*");
@@ -298,8 +311,10 @@
 		type = INPUT;
 	else if (item == 2)
 		type = VERBATIM;
+	else if (item == 3)
+		type = LISTINGS;
 	else
-		type = LISTINGS;
+		type = EMBEDDED;
 
 	docstring const & name = browse(qstring_to_ucs4(filenameED->text()), type);
 	if (!name.empty())
@@ -355,6 +370,7 @@
 		break;
 	case VERBATIM:
 	case LISTINGS:
+	case EMBEDDED:
 		break;
 	}
 

Reply via email to