Subject: [PATCH] Beautify line-ends handling yet more.

From: Nikolai Zhubr <[email-masked]>
Date: Wed, 07 Oct 2015 21:47:24 +0300

Hello Dave,

Attached are two more patches, mostly cosmetic:

*  Make a better guess of default line-end type based on platform type.
*  Get rid of #ifdef -- let wxTextBuffer::Translate do all the work.

Sending as attachments, let me know if inserting inline is preferred.

Tested on windows only, but I think should not break other platforms.

Thank you,
Nikolai

 Make a better guess of line-end type default based on platform type.

--- pgadmin/include/utils/sysSettings.h.orig	Mon Oct 05 18:16:13 2015
+++ pgadmin/include/utils/sysSettings.h	Wed Oct 07 20:09:59 2015
@@ -433,7 +433,17 @@
 	int GetLineEndingType() const
 	{
 		int i;
-		Read(wxT("LineEndingType"), &i, 2);
+		int defval = 2;
+#ifdef __WXMAC__
+		defval = 1; /* SC_EOL_CR in Scintilla.h */
+#else
+#ifdef __WXMSW__
+		defval = 0; /* SC_EOL_CRLF in Scintilla.h */
+#else
+		defval = 2; /* SC_EOL_LF in Scintilla.h */
+#endif
+#endif
+		Read(wxT("LineEndingType"), &i, defval);
 		return i;
 	}
 	void SetLineEndingType(const int newval)

 Instead of ifdef, let wxTextBuffer::Translate do conversions in all the 
 cases automatically.

--- pgadmin/frm/frmMain.cpp.orig	Wed Oct 07 15:07:06 2015
+++ pgadmin/frm/frmMain.cpp	Wed Oct 07 20:28:09 2015
@@ -659,11 +659,7 @@
 			{
 				text.Append(lv->GetText(row, col) + wxT("\t"));
 			}
-#ifdef __WXMSW__
-			text.Append(wxT("\r\n"));
-#else
 			text.Append(wxT("\n"));
-#endif
 			row = lv->GetNextSelected(row);
 		}
 		text = text.Trim();
@@ -673,13 +669,13 @@
 	ctlSQLBox *sb = dynamic_cast<ctlSQLBox *>(currentControl);
 	if (sb)
 	{
-		text = wxTextBuffer::Translate(sb->GetSelectedText());
+		text = sb->GetSelectedText();
 	}
 
 	// Set the clipboard text
 	if (text.Length() > 0 && wxTheClipboard->Open())
 	{
-		wxTheClipboard->SetData(new wxTextDataObject(text));
+		wxTheClipboard->SetData(new wxTextDataObject(wxTextBuffer::Translate(text)));
 		wxTheClipboard->Close();
 	}
 }

-- 
Sent via pgadmin-hackers mailing list ([email-masked])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

---

From: Dave Page <[email-masked]>
Date: Fri, 9 Oct 2015 14:31:02 +0100

Hi

> *  Make a better guess of default line-end type based on platform type.

I committed a modified version of this - Mac OS X uses \n as a
line-end, so that makes a better default than the old-style \r used on
Mac classic.

> *  Get rid of #ifdef -- let wxTextBuffer::Translate do all the work.

Committed.

> Sending as attachments, let me know if inserting inline is preferred.

Please use attachments created with "git diff > foo.diff". I had to
manually apply the patches above for some reason, but git diff should
usually work fine (and inlining them is just painful!) :-)

Thanks!

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

---

From: Nikolai Zhubr <[email-masked]>
Date: Sat, 10 Oct 2015 15:33:47 +0300

Hello Dave,
09.10.2015 16:31, Dave Page wrote:
[...]
> line-end, so that makes a better default than the old-style \r used on

Ah, I didn't know that, thanks for explanation.

I suppose it is unlikely someone will use current (and future) releases 
of pgamin3 on Mac classic, therefore I'd propose to also update the 
corresponding preferences menu. Right now it shows 3 possibilities:

* Unix (LF)
* DOS (CRLF)
* Mac (CR)

Maybe it would make sense to only provide 2 with the following naming:

* Unix/Mac (LF)
* DOS/Windows (CRLF)

If it is OK then I'll craft a git diff for that (eventually).

Thank you,
Nikolai

---

From: Dave Page <[email-masked]>
Date: Sat, 10 Oct 2015 14:51:03 +0100

> On 10 Oct 2015, at 13:33, Nikolai Zhubr <[email-masked]> wrote:
> 
> Hello Dave,
> I suppose it is unlikely someone will use current (and future) releases of pgamin3 on Mac classic, therefore I'd propose to also update the corresponding preferences menu. Right now it shows 3 possibilities:
> 
> * Unix (LF)
> * DOS (CRLF)
> * Mac (CR)
> 

I'm not sure we should - it may be useful for someone working with legacy systems, and it's not like it's a massive amount of code bloating the app or overly complicating the UI.

---

From: Nikolai Zhubr <[email-masked]>
Date: Sat, 10 Oct 2015 17:36:54 +0300

Hello Dave,
10.10.2015 16:51, Dave Page wrote:
[...]
> I'm not sure we should - it may be useful for someone working with legacy systems, and it's not like it's a massive amount of code bloating the app or overly complicating the UI.

Ok, understood.

And btw special thanks for bringing back windows xp compatability in 
beta1. It works fine for me so far.

Thank you,
Nikolai

---

From: Szabolcs Hubai <[email-masked]>
Date: Sat, 10 Oct 2015 20:45:22 +0200

As an alternative solution you could do it as Notepad++ does:
Unix/Mac, DOS/Windows, old Mac.