From 4a6d215d46bdf3f1ccb1f8c62671d57ff5832952 Mon Sep 17 00:00:00 2001
From: Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
Date: Fri, 7 Jan 2011 00:27:36 +0100
Subject: [PATCH] Optional replacing (.) to (,) when exporting or copying sql result's numeric values.

Signed-off-by: Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
---
 pgadmin/ctl/ctlSQLGrid.cpp          |    6 ++++++
 pgadmin/ctl/ctlSQLResult.cpp        |    5 +++++
 pgadmin/frm/frmExport.cpp           |    3 +++
 pgadmin/frm/frmOptions.cpp          |    3 +++
 pgadmin/include/ctl/ctlSQLGrid.h    |    4 ++++
 pgadmin/include/ctl/ctlSQLResult.h  |    1 +
 pgadmin/include/utils/sysSettings.h |   11 +++++++++++
 pgadmin/ui/frmOptions.xrc           |   19 ++++++++++++++++++-
 8 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/pgadmin/ctl/ctlSQLGrid.cpp b/pgadmin/ctl/ctlSQLGrid.cpp
index a714ffc..e439f6a 100644
--- a/pgadmin/ctl/ctlSQLGrid.cpp
+++ b/pgadmin/ctl/ctlSQLGrid.cpp
@@ -130,6 +130,12 @@ wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols)
 
 		wxString text = GetCellValue(row, cols[col]);
 
+		if(settings->GetDecimalMark()) {
+			if(IsColNum(cols[col])) {
+				text.Replace(wxT("."), wxT(","));
+			}
+		}
+
 		bool needQuote  = false;
 		if (settings->GetCopyQuoting() == 1)
 		{
diff --git a/pgadmin/ctl/ctlSQLResult.cpp b/pgadmin/ctl/ctlSQLResult.cpp
index 76a5c18..60c6902 100644
--- a/pgadmin/ctl/ctlSQLResult.cpp
+++ b/pgadmin/ctl/ctlSQLResult.cpp
@@ -94,6 +94,11 @@ bool ctlSQLResult::IsColText(int col)
 	return true;
 }
 
+bool ctlSQLResult::IsColNum(int col) 
+{
+	return (colTypClasses.Item(col) == PGTYPCLASS_NUMERIC);
+}
+
 
 int ctlSQLResult::Execute(const wxString &query, int resultToRetrieve, wxWindow *caller, long eventId, void *data)
 {
diff --git a/pgadmin/frm/frmExport.cpp b/pgadmin/frm/frmExport.cpp
index b789d27..29df994 100644
--- a/pgadmin/frm/frmExport.cpp
+++ b/pgadmin/frm/frmExport.cpp
@@ -249,6 +249,9 @@ bool frmExport::Export(pgSet *set)
 				switch (typOid)
 				{
 					case PGTYPCLASS_NUMERIC:
+						if(settings->GetDecimalMark())
+							text.Replace(wxT("."), wxT(","));
+						break;
 					case PGTYPCLASS_BOOL:
 						break;
 					default:
diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp
index 2f45bf2..fe314cc 100644
--- a/pgadmin/frm/frmOptions.cpp
+++ b/pgadmin/frm/frmOptions.cpp
@@ -50,6 +50,7 @@
 #define radLoglevel                 CTRL_RADIOBOX("radLoglevel")
 #define txtMaxRows                  CTRL_TEXT("txtMaxRows")
 #define txtMaxColSize               CTRL_TEXT("txtMaxColSize")
+#define chkDecimalMark				CTRL_CHECKBOX("chkDecimalMark")
 #define pickerFont                  CTRL_FONTPICKER("pickerFont")
 #define chkUnicodeFile              CTRL_CHECKBOX("chkUnicodeFile")
 #define chkWriteBOM                 CTRL_CHECKBOX("chkWriteBOM")
@@ -250,6 +251,7 @@ frmOptions::frmOptions(frmMain *parent)
 	chkIndicateNull->SetValue(settings->GetIndicateNull());
 	chkAutoRollback->SetValue(settings->GetAutoRollback());
 	chkDoubleClickProperties->SetValue(settings->GetDoubleClickProperties());
+	chkDecimalMark->SetValue(settings->GetDecimalMark());
 
 	txtPgHelpPath->SetValue(settings->GetPgHelpPath());
 	txtEdbHelpPath->SetValue(settings->GetEdbHelpPath());
@@ -562,6 +564,7 @@ void frmOptions::OnOK(wxCommandEvent &ev)
 	settings->SetPostgresqlPath(pickerPostgresqlPath->GetPath());
 	settings->SetEnterprisedbPath(pickerEnterprisedbPath->GetPath());
 	settings->SetGPDBPath(pickerGPDBPath->GetPath());
+	settings->SetDecimalMark(chkDecimalMark->GetValue());
 
 	// Setup PostgreSQL/EnterpriseDB working paths
 #if defined(__WXMSW__)
diff --git a/pgadmin/include/ctl/ctlSQLGrid.h b/pgadmin/include/ctl/ctlSQLGrid.h
index f60dc12..31cf5d2 100644
--- a/pgadmin/include/ctl/ctlSQLGrid.h
+++ b/pgadmin/include/ctl/ctlSQLGrid.h
@@ -29,6 +29,10 @@ public:
 	{
 		return false;
 	}
+	virtual bool IsColNum(int col) 
+	{
+		return false;
+	}
 	int Copy();
 
 	virtual bool CheckRowPresent(int row)
diff --git a/pgadmin/include/ctl/ctlSQLResult.h b/pgadmin/include/ctl/ctlSQLResult.h
index ba2609e..db78e6f 100644
--- a/pgadmin/include/ctl/ctlSQLResult.h
+++ b/pgadmin/include/ctl/ctlSQLResult.h
@@ -47,6 +47,7 @@ public:
 
 	wxString OnGetItemText(long item, long col) const;
 	bool IsColText(int col);
+	bool IsColNum(int col);
 	bool hasRowNumber()
 	{
 		return !rowcountSuppressed;
diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h
index ee4f2c3..fd6dee0 100644
--- a/pgadmin/include/utils/sysSettings.h
+++ b/pgadmin/include/utils/sysSettings.h
@@ -359,6 +359,17 @@ public:
 	{
 		Write(wxT("ShowLineNumber"), newval);
 	}
+	bool GetDecimalMark() const
+	{
+		bool b;
+		Read(wxT("DecimalMark"), &b, false);
+		return b;
+	}
+	void SetDecimalMark(const bool newval) 
+	{		
+		Write(wxT("DecimalMark"), newval);
+	}
+
 	bool GetUnicodeFile() const
 	{
 		bool b;
diff --git a/pgadmin/ui/frmOptions.xrc b/pgadmin/ui/frmOptions.xrc
index a412637..c763ba5 100644
--- a/pgadmin/ui/frmOptions.xrc
+++ b/pgadmin/ui/frmOptions.xrc
@@ -333,7 +333,7 @@
             <object class="wxPanel" name="pnlQuery">
               <object class="wxFlexGridSizer">
                 <cols>2</cols>
-                <rows>15</rows>
+                <rows>16</rows>
                 <vgap>5</vgap>
                 <hgap>5</hgap>
                 <growablecols>1</growablecols>
@@ -519,6 +519,23 @@
                   <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
                   <border>4</border>
                 </object>
+
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stDecimalMark">
+                    <label>Use comma (,) as decimal mark on export</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxCheckBox" name="chkDecimalMark">
+                    <label></label>
+                    <checked>0</checked>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                
                 <object class="sizeritem">
                   <object class="wxStaticText" name="stFavouritesFile">
                     <label>Favourites file path</label>
-- 
1.7.3.1.msysgit.0

