public inbox for [email protected]  
help / color / mirror / Atom feed
Copy to clipboard from ctlSQLBox on windows has line ends broken.
5+ messages / 2 participants
[nested] [flat]

* Copy to clipboard from ctlSQLBox on windows has line ends broken.
@ 2015-10-06 13:45  Nikolai Zhubr <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Nikolai Zhubr @ 2015-10-06 13:45 UTC (permalink / raw)
  To: pgadmin-hackers

Hi all,

Just discovered this. Only applicable for ms windows probably.
Copying several lines of text to clipboard from the SQL info panel - the 
one normally located in the bottom-right corner of the main pgadmin 
window (not editable) - results in broken line-ends when pasting. It 
used to work perfectly fine in some more older (well, ancient) versions...

Specifically, all text pasted appears as one huge single line, because 
line ends seem to be all unix style (LF). (Saving such pasted text to a 
file and looking at it in hex proves that LFs are there indeed instead 
of CRLFs)

Now, for the SQL editor the problem does not really exist because there 
is a respective preference setting, so going to menu and changing it as 
appropriate helps (when copying from the editor). However, there is 
apparently no preference setting for the (read-only) SQL info panel.

The problem was introduced before last release. It was present at least 
in 1.18.1, maybe even earlier.

I'd appreciate if someone using ms windows confirmed the problem.

Meanwhile I'll try to see if I can fix it. I think copying to clipboard 
should always use platform-default line-ends anyway...


Thank you,
Nikolai


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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.
@ 2015-10-06 22:23  Nikolai Zhubr <[email protected]>
  parent: Nikolai Zhubr <[email protected]>
  0 siblings, 2 replies; 5+ messages in thread

From: Nikolai Zhubr @ 2015-10-06 22:23 UTC (permalink / raw)
  To: pgadmin-hackers

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


06.10.2015 16:45, I wrote:
> Hi all,
>
> Just discovered this. Only applicable for ms windows probably.
> Copying several lines of text to clipboard from the SQL info panel - the
> one normally located in the bottom-right corner of the main pgadmin
> window (not editable) - results in broken line-ends when pasting. It
> used to work perfectly fine in some more older (well, ancient) versions...
>
> Specifically, all text pasted appears as one huge single line, because
> line ends seem to be all unix style (LF). (Saving such pasted text to a
> file and looking at it in hex proves that LFs are there indeed instead
> of CRLFs)
>
> Now, for the SQL editor the problem does not really exist because there
> is a respective preference setting, so going to menu and changing it as
> appropriate helps (when copying from the editor). However, there is
> apparently no preference setting for the (read-only) SQL info panel.
>
> The problem was introduced before last release. It was present at least
> in 1.18.1, maybe even earlier.
>
> I'd appreciate if someone using ms windows confirmed the problem.
>
> Meanwhile I'll try to see if I can fix it. I think copying to clipboard
> should always use platform-default line-ends anyway...
>
>
> Thank you,
> Nikolai
>
>



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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)
@ 2015-10-07 00:10  Nikolai Zhubr <[email protected]>
  parent: Nikolai Zhubr <[email protected]>
  1 sibling, 1 reply; 5+ messages in thread

From: Nikolai Zhubr @ 2015-10-07 00:10 UTC (permalink / raw)
  To: pgadmin-hackers; Dave Page <[email protected]>

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=ac60bb573155cd24fc45aa08a41887c1bb61...

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



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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.
@ 2015-10-07 07:59  Dave Page <[email protected]>
  parent: Nikolai Zhubr <[email protected]>
  1 sibling, 0 replies; 5+ messages in thread

From: Dave Page @ 2015-10-07 07:59 UTC (permalink / raw)
  To: Nikolai Zhubr <[email protected]>; +Cc: pgadmin-hackers

On Tue, Oct 6, 2015 at 11:23 PM, Nikolai Zhubr <[email protected]> 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...

Yeah, I don't think any of that code has changed in many years. Any
chance you can try it with an older version of wxWidgets to rule that
out?

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

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


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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)
@ 2015-10-07 12:10  Dave Page <[email protected]>
  parent: Nikolai Zhubr <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Dave Page @ 2015-10-07 12:10 UTC (permalink / raw)
  To: Nikolai Zhubr <[email protected]>; +Cc: pgadmin-hackers

Thanks - applied.

On Wed, Oct 7, 2015 at 1:10 AM, Nikolai Zhubr <[email protected]> wrote:
> 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=ac60bb573155cd24fc45aa08a41887c1bb61...
>
> 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
>
>



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

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


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




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2015-10-07 12:10 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-10-06 13:45 Copy to clipboard from ctlSQLBox on windows has line ends broken. Nikolai Zhubr <[email protected]>
2015-10-06 22:23 ` Nikolai Zhubr <[email protected]>
2015-10-07 00:10   ` [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken) Nikolai Zhubr <[email protected]>
2015-10-07 12:10     ` Re: [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken) Dave Page <[email protected]>
2015-10-07 07:59   ` Dave Page <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox