Thread: Copy to clipboard from ctlSQLBox on windows has line ends broken.
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
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 > >
[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
Date:
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
On Tue, Oct 6, 2015 at 11:23 PM, Nikolai Zhubr <n-a-zhubr@yandex.ru> 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
Re: [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)
From
Dave Page
Date:
Thanks - applied. On Wed, Oct 7, 2015 at 1:10 AM, Nikolai Zhubr <n-a-zhubr@yandex.ru> 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=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 > > -- Dave Page Blog: http://pgsnake.blogspot.com Twitter: @pgsnake EnterpriseDB UK: http://www.enterprisedb.com The Enterprise PostgreSQL Company