[chronojump] Fixed export all curves



commit 8de10a52c3eb4761bb4409ccaac003f7a7a94596
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Feb 3 21:36:16 2013 +0100

    Fixed export all curves

 encoder/graph.R      |    2 +-
 src/constants.cs     |    1 +
 src/exportSession.cs |   15 ++-------
 src/gui/encoder.cs   |   77 ++++++++++++++++++++++++++++++++++++++++++++++++--
 src/util.cs          |   10 ++++++-
 5 files changed, 89 insertions(+), 16 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 45e1923..f995b26 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -1071,7 +1071,7 @@ doProcess <- function(options) {
 	}
 	if(Analysis=="exportCSV") {
 		print("Starting export...")
-		file=OutputData1;
+		File=OutputData1;
 		curvesNum = length(curves[,1])
 
 		maxLength = 0
diff --git a/src/constants.cs b/src/constants.cs
index 123dcc6..b8516ab 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -173,6 +173,7 @@ public class Constants
 	public static string TakeOffWeightName = "TakeOffWeight"; //translate (take off?)
 
 
+	public static string SpreadsheetString = "\n\n" + Catalog.GetString("When import from your spreadsheet (OpenOffice, R, MS Excel, ...)\nremember the separator character is semicolon: <b>;</b>");
 
 /*	OLD, check this
 	public static string PotencyLewisCMJFormula = Catalog.GetString("Peak Power")+ " CMJ (Lewis) " +
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 1c6bb8a..e6a816b 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -86,7 +86,7 @@ public class ExportSession
 				fileName = addHtmlIfNeeded(fileName);
 			} else {
 				//add ".csv" if needed
-				fileName = addCsvIfNeeded(fileName);
+				fileName = Util.AddCsvIfNeeded(fileName);
 			}
 			try {
 				if (File.Exists(fileName)) {
@@ -149,15 +149,6 @@ public class ExportSession
 		return myFile;
 	}
 	
-	private string addCsvIfNeeded(string myFile)
-	{
-		int posOfDot = myFile.LastIndexOf('.');
-		if (posOfDot == -1) 
-			myFile += ".csv";
-		
-		return myFile;
-	}
-	
 	protected virtual void getData() 
 	{
 		myPersons = SqlitePersonSession.SelectCurrentSessionPersons(mySession.UniqueID);
@@ -873,7 +864,7 @@ public class ExportSessionCSV : ExportSession
 		this.mySession = mySession;
 		this.prefsDigitsNumber = prefsDigitsNumber;
 	
-		spreadsheetString = "\n\n" + Catalog.GetString("When import from your spreadsheet (OpenOffice, R, MS Excel, ...)\nremember the separator character is semicolon: <b>;</b>");
+		spreadsheetString = Constants.SpreadsheetString;
 
 		checkFile("CSV");
 	}
@@ -907,8 +898,10 @@ public class ExportSessionCSV : ExportSession
 	protected override void printFooter()
 	{
 		Log.WriteLine( "Correctly exported" );
+		/*
 		string myString = Catalog.GetString ("Exported to file: ") + fileName;
 		new DialogMessage(Constants.MessageTypes.INFO, myString);
+		*/
 	}
 	
 	~ExportSessionCSV() {}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 90bd9fc..d953171 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -491,6 +491,11 @@ public partial class ChronoJumpWindow
 	
 	void on_button_encoder_export_all_curves_clicked (object o, EventArgs args) 
 	{
+		checkFile();
+	}
+	
+	void on_button_encoder_export_all_curves_file_selected (string selectedFileName) 
+	{
 		string analysisOptions = "-";
 		if(checkbutton_encoder_propulsive.Active)
 			analysisOptions = "p";
@@ -514,7 +519,7 @@ public partial class ChronoJumpWindow
 		EncoderStruct encoderStruct = new EncoderStruct(
 				dataFileName, 
 				Util.GetEncoderGraphTempFileName(),
-				Util.GetEncoderExportTempFileName(), "NULL", ep);
+				selectedFileName, "NULL", ep);
 
 		Util.RunEncoderGraph(
 				Util.ChangeSpaceForUnderscore(currentPerson.Name) + "-" + 
@@ -522,8 +527,74 @@ public partial class ChronoJumpWindow
 					"-(" + findMass(true) + "Kg)",
 				encoderStruct);
 
-		encoder_pulsebar_capture.Text = string.Format(Catalog.GetString(
-					"Exported to {0}."), Util.GetEncoderExportTempFileName());
+		//encoder_pulsebar_capture.Text = string.Format(Catalog.GetString(
+		//			"Exported to {0}."), Util.GetEncoderExportTempFileName());
+	}
+
+	string exportFileName;	
+	protected void checkFile ()
+	{
+		string exportString = Catalog.GetString ("Export session in format CSV");
+		
+		Gtk.FileChooserDialog fc=
+			new Gtk.FileChooserDialog(exportString,
+					app1,
+					FileChooserAction.Save,
+					Catalog.GetString("Cancel"),ResponseType.Cancel,
+					Catalog.GetString("Export"),ResponseType.Accept
+					);
+
+		if (fc.Run() == (int)ResponseType.Accept) 
+		{
+			exportFileName = fc.Filename;
+			//add ".csv" if needed
+			exportFileName = Util.AddCsvIfNeeded(exportFileName);
+			try {
+				if (File.Exists(exportFileName)) {
+					Log.WriteLine(string.Format(
+								"File {0} exists with attributes {1}, created at {2}", 
+								exportFileName, 
+								File.GetAttributes(exportFileName), 
+								File.GetCreationTime(exportFileName)));
+					Log.WriteLine("Overwrite...");
+					ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString(
+								"Are you sure you want to overwrite file: "), "", 
+							exportFileName);
+					confirmWin.Button_accept.Clicked += new EventHandler(on_overwrite_file_accepted);
+				} else {
+					on_button_encoder_export_all_curves_file_selected (exportFileName);
+
+					string myString = string.Format(Catalog.GetString("Exported to {0}"), 
+							exportFileName) + Constants.SpreadsheetString;
+					new DialogMessage(Constants.MessageTypes.INFO, myString);
+				}
+			} 
+			catch {
+				string myString = string.Format(
+						Catalog.GetString("Cannot export to file {0} "), exportFileName);
+				new DialogMessage(Constants.MessageTypes.WARNING, myString);
+			}
+		}
+		else {
+			Log.WriteLine("cancelled");
+			//report does not currently send the appBar reference
+			new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Cancelled."));
+			fc.Hide ();
+			return ;
+		}
+		
+		//Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
+		fc.Destroy();
+		
+		return;
+	}
+	private void on_overwrite_file_accepted(object o, EventArgs args)
+	{
+		on_button_encoder_export_all_curves_file_selected (exportFileName);
+
+		string myString = string.Format(Catalog.GetString("Exported to {0}"), 
+				exportFileName) + Constants.SpreadsheetString;
+		new DialogMessage(Constants.MessageTypes.INFO, myString);
 	}
 	
 	void on_button_encoder_delete_signal_clicked (object o, EventArgs args) 
diff --git a/src/util.cs b/src/util.cs
index 4ca5ac1..4f5bb1f 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1514,7 +1514,15 @@ public class Util
 		return array;
 	}
 
-
+	public static string AddCsvIfNeeded(string myFile)
+	{
+		int posOfDot = myFile.LastIndexOf('.');
+		if (posOfDot == -1) 
+			myFile += ".csv";
+		
+		return myFile;
+	}
+	
 
 	public static bool IntToBool (int myInt) {
 		if(myInt == 1)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]