Index: TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultFromEditor.java
===================================================================
--- TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultFromEditor.java	(revision 0)
+++ TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultFromEditor.java	(revision 3819)
@@ -0,0 +1,205 @@
+// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté
+// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
+// Lyon 2, University of Franche-Comté, University of Nice
+// Sophia Antipolis, University of Paris 3.
+//
+// The TXM platform is free software: you can redistribute it
+// and/or modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation,
+// either version 2 of the License, or (at your option) any
+// later version.
+//
+// The TXM platform is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied
+// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+// PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General
+// Public License along with the TXM platform. If not, see
+// http://www.gnu.org/licenses.
+//
+//
+//
+// $LastChangedDate:$
+// $LastChangedRevision:$
+// $LastChangedBy:$
+//
+package org.txm.rcp.handlers.export;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.txm.core.preferences.TBXPreferences;
+import org.txm.core.results.TXMResult;
+import org.txm.rcp.JobsTimer;
+import org.txm.rcp.StatusLine;
+import org.txm.rcp.editors.ITXMResultEditor;
+import org.txm.rcp.handlers.files.EditFile;
+import org.txm.rcp.messages.TXMUIMessages;
+import org.txm.rcp.swt.dialog.LastOpened;
+import org.txm.rcp.utils.JobHandler;
+import org.txm.utils.ExecTimer;
+import org.txm.utils.logger.Log;
+
+/**
+ * Exports a result by calling the function toTxt(File f) then opens or not the result in the text editor according to the preferences.
+ * 
+ * @author mdecorde, sjacquot
+ */
+public class ExportResultFromEditor extends AbstractHandler {
+	
+	private static final String ID = ExportResultFromEditor.class.getName();
+	
+	/** The selection. */
+	private IStructuredSelection selection;
+	
+	/** The lastopenedfile. */
+	// private static String lastopenedfile;
+	
+	/**
+	 * Export a TXM result in a CSV file.
+	 *
+	 * @param event the event
+	 * @return the object
+	 * @throws ExecutionException the execution exception
+	 */
+	@Override
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		
+		IEditorPart ieditor = HandlerUtil.getActiveEditor(event);
+		if (!(ieditor instanceof ITXMResultEditor)) {
+			return null;
+		}
+		
+		ITXMResultEditor<TXMResult> editor = (ITXMResultEditor)ieditor;
+		final Object s = editor.getResult();
+		
+		Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
+		
+		// String txmhome = Toolbox.getTxmHomePath();
+		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
+		
+		String extensions[] = { "*.csv" }; //$NON-NLS-1$
+		if (s instanceof TXMResult) {
+			extensions = ((TXMResult) s).getExportTXTExtensions();
+			dialog.setFileName(((TXMResult) s).getValidFileName());
+		}
+		dialog.setFilterExtensions(extensions);
+		
+		if (LastOpened.getFile(ID) != null) {
+			dialog.setFilterPath(LastOpened.getFolder(ID));
+		}
+		
+		if (dialog.open() != null) {
+			StatusLine.setMessage(TXMUIMessages.exportingResults);
+			String filepath = dialog.getFilterPath() + "/" + dialog.getFileName(); //$NON-NLS-1$
+			if (!(filepath.endsWith(extensions[0].substring(1))))
+				filepath += extensions[0].substring(1);
+			
+			final File outfile = new File(filepath);
+			LastOpened.set(ID, outfile.getParent(), outfile.getName());
+			try {
+				outfile.createNewFile();
+			}
+			catch (IOException e1) {
+				Log.warning(NLS.bind(TXMUIMessages.exportColonCantCreateFileP0ColonP1, outfile, e1));
+			}
+			if (!outfile.canWrite()) {
+				Log.warning(NLS.bind(TXMUIMessages.impossibleToReadP0, outfile));
+				return null;
+			}
+			if (!outfile.isFile()) {
+				Log.warning("Error: " + outfile + " is not a file"); //$NON-NLS-1$ //$NON-NLS-2$
+				return null;
+			}
+			
+			final String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING);
+			String _colseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_COL_SEPARATOR);
+			final String colseparator = _colseparator;
+			String _txtseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_TXT_SEPARATOR);
+			final String txtseparator = _txtseparator;
+			
+			JobHandler jobhandler = new JobHandler(TXMUIMessages.exportingResults) {
+				
+				@Override
+				protected IStatus run(IProgressMonitor monitor) {
+					
+					// convert the monitor into sub-monitor
+					SubMonitor subMonitor = SubMonitor.convert(monitor, TXMUIMessages.exporting, 100);
+					
+					try {
+						
+						this.runInit(subMonitor);
+						JobsTimer.start();
+						
+						if (s instanceof TXMResult) {
+							TXMResult r = (TXMResult) s;
+							
+							// compute the result if needed
+							if (!r.isAltered() && r.isDirty()) {
+								r.compute(this);
+							}
+							Log.info(TXMUIMessages.bind(TXMUIMessages.exportingP0, r.getName()));
+							ExecTimer.start();
+							r.toTxt(outfile, encoding, colseparator, txtseparator);
+							Log.info(TXMUIMessages.bind(TXMUIMessages.doneInP0, ExecTimer.stop()));
+						}
+						else {
+							Log.warning(TXMUIMessages.TheExportedObjectIsNotATXMResultResult);
+							return Status.CANCEL_STATUS;
+						}
+						
+						if (outfile.exists()) {
+							// Open internal editor in the UI thread
+							if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPORT_SHOW)) {
+								this.syncExec(new Runnable() {
+									
+									@Override
+									public void run() {
+										EditFile.openfile(outfile.getAbsolutePath());
+									}
+								});
+							}
+						}
+						else {
+							Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, outfile.getAbsolutePath()));
+						}
+					}
+					catch (ThreadDeath td) {
+						TXMResult r = (TXMResult) s;
+						r.resetComputingState();
+						return Status.CANCEL_STATUS;
+					}
+					catch (Exception e) {
+						Log.warning(NLS.bind(TXMUIMessages.failedToExportResultP0ColonP1, s, e));
+						org.txm.utils.logger.Log.printStackTrace(e);
+						return Status.CANCEL_STATUS;
+					}
+					finally {
+						subMonitor.done();
+						JobsTimer.stopAndPrint();
+					}
+					return Status.OK_STATUS;
+				}
+			};
+			
+			jobhandler.startJob();
+		}
+		return null;
+	}
+}

Property changes on: TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/handlers/export/ExportResultFromEditor.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: TXM/trunk/bundles/org.txm.rcp/plugin.xml
===================================================================
--- TXM/trunk/bundles/org.txm.rcp/plugin.xml	(revision 3818)
+++ TXM/trunk/bundles/org.txm.rcp/plugin.xml	(revision 3819)
@@ -2150,21 +2150,26 @@
                      </visibleWhen>
                   </command>
                </menu>
-            <command
-                  commandId="org.txm.rcp.handlers.export.ImportResultParameters"
-                  icon="icons/functions/import_parameters.png"
-                  label="%command.label.195"
-                  style="push"
-                  tooltip="Import a calculus from a .txmcmd file">
-               <visibleWhen
-                     checkEnabled="false">
-                  <and>
-                     <reference
-                           definitionId="OneTXMResultSelected">
-                     </reference>
-                  </and>
-               </visibleWhen>
-            </command>
+            <menu
+                  icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png"
+                  id="org.txm.rcp.corporaview.import"
+                  label="Import">
+               <command
+                     commandId="org.txm.rcp.handlers.export.ImportResultParameters"
+                     icon="icons/functions/import_parameters.png"
+                     label="%command.label.102"
+                     style="push"
+                     tooltip="Import a calculus from a .txmcmd file">
+                  <visibleWhen
+                        checkEnabled="false">
+                     <and>
+                        <reference
+                              definitionId="OneTXMResultSelected">
+                        </reference>
+                     </and>
+                  </visibleWhen>
+               </command>
+            </menu>
             
             <separator
                   name="org.txm.rcp.corporaview.corpus"
@@ -2859,6 +2864,11 @@
             name="%command.name.24">
       </command>
       <command
+            defaultHandler="org.txm.rcp.handlers.export.ExportResultFromEditor"
+            id="org.txm.rcp.commands.function.ExportResultFromEditor"
+            name="ExportResultFromEditor">
+      </command>
+      <command
             defaultHandler="org.txm.rcp.handlers.export.ExportCommand"
             id="org.txm.rcp.handlers.export.ExportResultParameters"
             name="%command.name.35">
Index: TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties
===================================================================
--- TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties	(revision 3818)
+++ TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties	(revision 3819)
@@ -76,8 +76,8 @@
 command.label.139       = Autres...
 command.label.14        = \u00C0 Propos
 command.label.140       = Afficher les num\u00E9ros de ligne
-command.label.141       = Importer une commande...
-command.label.142       = Exporter commande...
+command.label.141       = Importer un calcul...
+command.label.142       = Exporter calcul...
 command.label.143       = Ex\u00E9cuter
 command.label.144       = Activer l'affichage des caract\u00E8res non imprimables
 command.label.145       = Retour \u00E0 l'\u00E9tat initial du fichier
@@ -135,7 +135,7 @@
 command.label.192       = Supprimer
 command.label.193       = Annotations au format XML-TEI...
 command.label.194       = Calcul...
-command.label.195       = Importer une commande...
+command.label.195       = Importer un calcul...
 command.label.196       = Copier
 command.label.197       = Tout copier
 command.label.198       = Couper
Index: TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle.properties
===================================================================
--- TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle.properties	(revision 3818)
+++ TXM/trunk/bundles/org.txm.rcp/OSGI-INF/l10n/bundle.properties	(revision 3819)
@@ -34,8 +34,8 @@
 command.label.10         = a binary corpus (.txm)...
 command.label.100        = Find previous
 command.label.101        = Chart...
-command.label.102        = Command...
-command.label.103        = Command...
+command.label.102        = Calculus...
+command.label.103        = Calculus...
 command.label.104        = Delete line
 command.label.105        = Merge lines
 command.label.106        = Export table to re-import
@@ -77,8 +77,8 @@
 command.label.139        = Other...
 command.label.14         = About TXM
 command.label.140        = Show Line Numbers
-command.label.141        = Import a command...
-command.label.142        = Export command......
+command.label.141        = Import a calculus...
+command.label.142        = Export calculus......
 command.label.143        = Submit
 command.label.144        = Toggle Show Non-printable Characters
 command.label.145        = Revert to saved
@@ -135,8 +135,8 @@
 command.label.191        = Add
 command.label.192        = Delete
 command.label.193        = Annotations in XML-TEI format...
-command.label.194        = Command...
-command.label.195        = Import a command...
+command.label.194        = Caculus...
+command.label.195        = Import a calculus...
 command.label.196        = Copy
 command.label.197        = Copy All
 command.label.198        = Cut
Index: TXM/trunk/bundles/org.txm.lexicaltable.rcp/plugin.xml
===================================================================
--- TXM/trunk/bundles/org.txm.lexicaltable.rcp/plugin.xml	(revision 3818)
+++ TXM/trunk/bundles/org.txm.lexicaltable.rcp/plugin.xml	(revision 3819)
@@ -12,8 +12,23 @@
    </extension>
    <extension
          point="org.eclipse.ui.menus">
+            <menuContribution
+                  locationURI="menu:menu.file.import">
+               <command
+                     commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
+                     icon="platform:/plugin/org.txm.rcp/icons/functions/import_data.png"
+                     label="Data..."
+                     style="push">
+                  <visibleWhen
+                        checkEnabled="false">
+                     <reference
+                           definitionId="OneLexicalTableSelected">
+                     </reference>
+                  </visibleWhen>
+               </command>
+            </menuContribution>
       <menuContribution
-            locationURI="popup:org.txm.rcp.views.corpora.CorporaView?after=org.txm.rcp.corporaview.corpus.manage">
+            locationURI="menu:menu.corpus">
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ComputeLexicalTable"
                icon="icons/lexicaltable.png"
@@ -33,20 +48,10 @@
                </or>
             </visibleWhen>
          </command>
-         <command
-               commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
-               icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png"
-               style="push">
-            <visibleWhen
-                  checkEnabled="false">
-               <reference
-                     definitionId="OneLexicalTableSelected">
-               </reference>
-            </visibleWhen>
-         </command>
       </menuContribution>
       <menuContribution
-            locationURI="menu:menu.corpus">
+            allPopups="false"
+            locationURI="toolbar:org.txm.rcp.toolbartools">
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ComputeLexicalTable"
                icon="icons/lexicaltable.png"
@@ -55,9 +60,6 @@
                   checkEnabled="false">
                <or>
                   <reference
-                        definitionId="OnePartitionSelected">
-                  </reference>
-                  <reference
                         definitionId="OnePartitionIndexSelected">
                   </reference>
                   <reference
@@ -68,7 +70,7 @@
          </command>
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
-               icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png"
+               icon="platform:/plugin/org.txm.rcp/icons/functions/import_data.png"
                style="push">
             <visibleWhen
                   checkEnabled="false">
@@ -80,42 +82,27 @@
       </menuContribution>
       <menuContribution
             allPopups="false"
-            locationURI="toolbar:org.txm.rcp.toolbartools">
+            locationURI="toolbar:org.txm.rcp.toolbartools?after=org.txm.partition.rcp.handlers.ComputePartitionDimensionsBarChart">
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ComputeLexicalTable"
                icon="icons/lexicaltable.png"
+               id="ComputeLexicalTableFromPartition"
                style="push">
             <visibleWhen
                   checkEnabled="false">
                <or>
                   <reference
-                        definitionId="OnePartitionIndexSelected">
+                        definitionId="OnePartitionSelected">
                   </reference>
-                  <reference
-                        definitionId="OneLexicalTableAbleSelected">
-                  </reference>
                </or>
             </visibleWhen>
          </command>
-         <command
-               commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
-               icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png"
-               style="push">
-            <visibleWhen
-                  checkEnabled="false">
-               <reference
-                     definitionId="OneLexicalTableSelected">
-               </reference>
-            </visibleWhen>
-         </command>
       </menuContribution>
       <menuContribution
-            allPopups="false"
-            locationURI="toolbar:org.txm.rcp.toolbartools?after=org.txm.partition.rcp.handlers.ComputePartitionDimensionsBarChart">
+            locationURI="popup:org.txm.rcp.views.corpora.CorporaView?after=org.txm.rcp.corporaview.corpus.manage">
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ComputeLexicalTable"
                icon="icons/lexicaltable.png"
-               id="ComputeLexicalTableFromPartition"
                style="push">
             <visibleWhen
                   checkEnabled="false">
@@ -123,11 +110,32 @@
                   <reference
                         definitionId="OnePartitionSelected">
                   </reference>
+                  <reference
+                        definitionId="OnePartitionIndexSelected">
+                  </reference>
+                  <reference
+                        definitionId="OneLexicalTableAbleSelected">
+                  </reference>
                </or>
             </visibleWhen>
          </command>
       </menuContribution>
             <menuContribution
+                  locationURI="popup:org.txm.rcp.corporaview.import">
+               <command
+                     commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
+                     icon="platform:/plugin/org.txm.rcp/icons/functions/import_data.png"
+                     label="Data..."
+                     style="push">
+                  <visibleWhen
+                        checkEnabled="false">
+                     <reference
+                           definitionId="OneLexicalTableSelected">
+                     </reference>
+                  </visibleWhen>
+               </command>
+            </menuContribution>
+            <menuContribution
             locationURI="popup:org.txm.lexicaltable.rcp.editors.LexicalTableEditor">
                <command
                      commandId="org.txm.lexicaltable.rcp.handlers.CopyLines"
@@ -149,9 +157,33 @@
          </separator>
          <command
                commandId="org.txm.lexicaltable.rcp.handlers.ImportTable"
-               icon="platform:/plugin/org.eclipse.ui/icons/full/etool16/import_wiz.png"
+               icon="platform:/plugin/org.txm.rcp/icons/functions/import_data.png"
                style="push">
          </command>
+         <command
+               commandId="org.txm.rcp.commands.function.ExportResultFromEditor"
+               icon="platform:/plugin/org.txm.rcp/icons/functions/export_data.png"
+               label="Data..."
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <and>
+                  <reference
+                        definitionId="OneTXMResultSelected">
+                  </reference>
+                  <not>
+                     <or>
+                        <reference
+                              definitionId="OnePartitionSelected">
+                        </reference>
+                        <reference
+                              definitionId="OneCorpusSelected">
+                        </reference>
+                     </or>
+                  </not>
+               </and>
+            </visibleWhen>
+         </command>
       </menuContribution>
       
    </extension>
Index: TXM/trunk/bundles/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java
===================================================================
--- TXM/trunk/bundles/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java	(revision 3818)
+++ TXM/trunk/bundles/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java	(revision 3819)
@@ -408,15 +408,15 @@
 			viewer.getTable().setLinesVisible(true);
 			viewer.getTable().setHeaderVisible(true);
 
-			viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+//			viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+//
+//				@Override
+//				public void selectionChanged(SelectionChangedEvent event) {
+//					System.out.println("sel="+viewer.getStructuredSelection().toList());
+//				}
+//			});
 
-				@Override
-				public void selectionChanged(SelectionChangedEvent event) {
-					System.out.println("sel="+viewer.getStructuredSelection().toList());
-				}
-			});
 
-
 			// viewer.setContentProvider(ArrayContentProvider.getInstance());
 
 			// FIXME: viewer comparator tests
@@ -428,7 +428,6 @@
 			// viewer.setContentProvider(ArrayContentProvider.getInstance());
 			viewer.setContentProvider(new LineContentProvider());
 
-
 			viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
 
 			// first dummy column
