[PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)

From: Nikolai Zhubr <n-a-zhubr(at)yandex(dot)ru>
To: pgadmin-hackers(at)postgresql(dot)org, Dave Page <dpage(at)pgadmin(dot)org>
Subject: [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)
Date: 2015-10-07 00:10:11
Message-ID: 561462E3.606@yandex.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers

Hello Dave,

Apparently the problem was accidentally introduced by some little
refactoring as a part of this big commit:

http://git.postgresql.org/gitweb/?p=pgadmin3.git;a=commitdiff;h=ac60bb573155cd24fc45aa08a41887c1bb612677

Previously, frmMain::OnCopy() used to call sqlPane->Copy() to push
contents from ctlSQLbox (of SQL Pane) to clipboard. I think that call
performed the appropriate line-ends conversions automagically.

After the change, it turned essentially into:
text = sqlPane->GetSelectedText();
wxTheClipboard->SetData(new wxTextDataObject(text));
and line-ends conversion was gone.

Now looking at ScintillaWX::CopyToClipboard(...) as an example we see:
wxString text = wxTextBuffer::Translate(stc2wx(st.s, st.len-1));
wxTheClipboard->SetData(new wxTextDataObject(text));

The difference is that there is a wxTextBuffer::Translate() in between.

Adding it to frmMain::OnCopy() fixed the problem for me.
So I'd propose the following patch:

--- pgadmin/frm/frmMain.cpp.orig Mon Oct 05 18:16:13 2015
+++ pgadmin/frm/frmMain.cpp Wed Oct 07 01:47:41 2015
@@ -28,6 +28,7 @@
#include <wx/imaglist.h>
#include <wx/busyinfo.h>
#include <wx/sysopt.h>
+#include <wx/textbuf.h>
#include <wx/clipbrd.h>

// wxAUI
@@ -672,7 +673,7 @@
ctlSQLBox *sb = dynamic_cast<ctlSQLBox *>(currentControl);
if (sb)
{
- text = sb->GetSelectedText();
+ text = wxTextBuffer::Translate(sb->GetSelectedText());
}

// Set the clipboard text

Thank you,
Nikolai

07.10.2015 1:23, I wrote:
> Hi all,
>
> As I've now found, a lot of pgXXX::GetSql() functions autogenerate sql
> code using hardcoded LF line ends ('\n\n'), and this has been so for
> ages, therefore probably it is OK.
>
> But, in order for 'copy to clipboard' to work well (also on ms windows),
> these LF line ends have to be somehow "compensated". Generally, it could
> possibly be arranged in two places:
>
> -- convert to the system line ending before passing it _to_ ctlSQLBox;
> -- or convert just before copying to clipboard _from_ ctlSQLBox.
>
> I'm not quite sure how it was initially supposed to work, but it did
> work correctly on windows previously. Right now though I can not see any
> such automatic conversions anywhere. Sure I could add some, but I'd like
> to understand the whole picture first...
>
>
> Thank you,
> Nikolai

In response to

Responses

Browse pgadmin-hackers by date

  From Date Subject
Next Message Dave Page 2015-10-07 07:59:11 Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.
Previous Message Nikolai Zhubr 2015-10-06 22:23:29 Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.