[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
Тема [PATCH] Perform conversion to platform line-ends when copying to clipboard (Was: Copy to clipboard from ctlSQLBox on windows has line ends broken)
Дата
Msg-id 561462E3.606@yandex.ru
обсуждение исходный текст
Ответ на Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.  (Nikolai Zhubr <n-a-zhubr@yandex.ru>)
Ответы 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 <dpage@pgadmin.org>)
Список 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



В списке pgadmin-hackers по дате отправления:

Предыдущее
От: Nikolai Zhubr
Дата:
Сообщение: Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.
Следующее
От: Dave Page
Дата:
Сообщение: Re: Copy to clipboard from ctlSQLBox on windows has line ends broken.