Index: TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/export/ExportTextsContentMacro.groovy
===================================================================
--- TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/export/ExportTextsContentMacro.groovy	(revision 3623)
+++ TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/export/ExportTextsContentMacro.groovy	(revision 3624)
@@ -16,9 +16,9 @@
 import org.txm.rcp.swt.widget.parameters.*
 
 if (!(corpusViewSelection instanceof CQPCorpus)) {
-	println "Please select a corpus"
-	return
-}
+	monitorShowError("Erreur : la sélection dans la vue Corpus n'est pas un corpus ou un sous-corpus ($corpusViewSelection).")
+	return false
+} 
 
 // PARAMETERS
 
@@ -31,7 +31,7 @@
 @Field @Option(name="oneWordPerLine", usage="output one word per line", widget="Boolean", required=false, def="false")
 def oneWordPerLine
 
-@Field @Option(name="oneSentencePerLine", usage="output one sentence per line", widget="Boolean", required=false, def="true")
+@Field @Option(name="oneSentencePerLine", usage="output one sentence per line", widget="Boolean", required=false, def="false")
 def oneSentencePerLine
 
 @Field @Option(name="sentenceStructureName", usage="name of the structure encoding sentences", widget="String", required=false, def="")
@@ -44,6 +44,8 @@
 if (!outputDirectory.exists()) outputDirectory.mkdirs()
 
 def corpus = corpusViewSelection
+corpus.compute()
+def mainCorpus = corpus.getMainCorpus()
 def corpusName = corpus.getName()
 def CQI = CQPSearchEngine.getCqiClient()
 
@@ -78,53 +80,73 @@
 	return 1
 }
 
-def textidProperty = corpus.getStructuralUnit("text").getProperty("id")
-def textStartBoundaries = corpus.getTextStartLimits()
-def textEndBoundaries = corpus.getTextEndLimits()
+def textidProperty = mainCorpus.getStructuralUnit("text").getProperty("id")
+def textStartBoundaries = mainCorpus.getTextStartLimits()
+def textEndBoundaries = mainCorpus.getTextEndLimits()
+
 int[] struct_pos = CQI.cpos2Struc(textidProperty.getQualifiedName(), textStartBoundaries)
-String[] textids =  CQI.struc2Str(textidProperty.getQualifiedName(), struct_pos)
+String[] allTextIds =  CQI.struc2Str(textidProperty.getQualifiedName(), struct_pos)
 
-if (textStartBoundaries.size() == 1) {
-	println "1 text"
+corpusTextIds = new HashSet<String>(corpus.getStructuralUnit("text").getProperty("id").getValues(corpus))
+
+// https://stackoverflow.com/questions/150750/hashset-vs-list-performance
+
+if (corpusTextIds.size() == 1) {
+	println "1 text ("+corpusTextIds+")"
 	} else {
-	println ""+textStartBoundaries.size()+" texts"
+	println ""+corpusTextIds.size()+" texts ("+corpusTextIds+")"
 }
 
-for (int i = 0 ; i < textStartBoundaries.size() ; i++) {
-	int start = textStartBoundaries[i]
-	int end = textEndBoundaries[i]
+for (int i = 0; i < textStartBoundaries.size(); i++) {
 
-	File txtFile = new File(outputDirectory, textids[i]+".txt")
-	print "."
-	def writer = txtFile.newWriter("UTF-8")
-	int[] positions = new int[end - start + 1]
-	int c = 0
-	for (int p : start..end) {
-		positions[c++] = p
-	}
-	int[] idx = CQI.cpos2Id(wordPropertyI.getQualifiedName(), positions)
-	def words = CQI.id2Str(wordPropertyI.getQualifiedName(), idx)
-	def tmp = []
-	for (int j = 0 ; j < positions.length ; j++) {
-		int p = positions[j]
-		tmp << words[j]
-		if (oneSentencePerLine && breaks_pos.contains(p)) {
-			if (oneWordPerLine) {
-				tmp.each { word -> writer.println word }
-			} else {
-				writer.println LangFormater.format(tmp.join(" "), corpus.getLang())
-			}
-			tmp = []
-		} 
-	}
-	if (tmp.size() > 0) {
-		if (oneWordPerLine) {
-			tmp.each { word -> writer.println word }
-		} else {
-			writer.println LangFormater.format(tmp.join(" "), corpus.getLang())
-		}
-	} 
-	writer.close()
+    if (corpusTextIds.contains(allTextIds[i])) {
+        
+        int start = textStartBoundaries[i]
+        int end = textEndBoundaries[i]
+        File txtFile = new File(outputDirectory, allTextIds[i] + ".txt")
+
+        def writer = txtFile.newWriter("UTF-8")
+        int [] positions = new int [end - start + 1]
+        int c = 0
+        for (int p: start..end) {
+            positions[c++] = p
+        }
+        int [] idx = CQI.cpos2Id(wordPropertyI.getQualifiedName(), positions)
+        def words = CQI.id2Str(wordPropertyI.getQualifiedName(), idx)
+        def tmp = []
+        for (int j = 0; j < positions.length; j++) {
+            int p = positions[j]
+            tmp << words[j]
+            if (oneSentencePerLine && breaks_pos.contains(p)) {
+                if (oneWordPerLine) {
+                    tmp.each {
+                        word -> writer.println word
+                    }
+                } else {
+                    writer.println LangFormater.format(tmp.join(" "), corpus.getLang())
+                }
+                tmp = []
+            }
+        }
+        if (tmp.size() > 0) {
+            if (oneWordPerLine) {
+                tmp.each {
+                    word -> writer.println word
+                }
+            } else {
+                writer.println LangFormater.format(tmp.join(" "), corpus.getLang())
+            }
+        }
+        writer.close()
+    }
 }  
 
-println "\nDone, result saved in "+outputDirectory.getAbsolutePath()
\ No newline at end of file
+println "Done, result saved in "+outputDirectory.getAbsolutePath()
+
+def monitorShowError(String message) {
+	monitor.syncExec(new Runnable() {
+		public void run() {
+			org.eclipse.jface.dialogs.MessageDialog.openError(org.eclipse.swt.widgets.Display.getCurrent().getActiveShell(), "Erreur", message)
+		}
+	})
+}
