Author Topic: Revision 3003: gpm (ftr #2660)  (Read 7703 times)

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Revision 3003: gpm (ftr #2660)
« on: October 13, 2006, 04:50:48 pm »
To be short: Can we revert this one?  8)

Although this is a really nice feature the way it is implemented in revision 3003 just doesn't work. OK, it probably works on windows but on Linux this revision made things worse than before.
The reason is: Linux (or the X-Window-System or even another component, not sure which one) implements this feature on its own (or at least a part of it) and thus this feature workes across all running applications (in theory). Before revision 3003 you could mark any text in any application (except Code::Blocks) and paste it to any application (including Code::Blocks) using the middle mouse button. The other way round, that means mark any text in Code::Blocks and try to paste it anywhere did not work, the marked text was just ignored and the old contents of the clipboard were used.

After revision 3003 things have changed but gone worse: Marking text in Code::Blocks and pasting it in any other application using the middle mouse button does still not work - nothing surprising here as the code from revision 3003 doens't do anything in this direction.
The other way (that is, marking text in any application except Code::Blocks and pasting it to Code::Blocks) still works, as long as there is no text selected in Code::Blocks. Marking text in Code::Blocks and pasting it to itself works, as long as the clipboard (or - to be precise - the primary selection) is empty.
But if you try to paste to Code::Blocks while there is text selected in Code::Blocks *and* the primary selection is not empty, *both* texts are pasted into the Code::Blocks editor. This is really scary...

Anyway, I would suggest to leave this code untouched for windows (if it works there) and completly remove it for wxGTK-builds because this feature is handled there in the subsystem.
One drawback is of course: Selecting text in Code::Blocks doesn't use this text as primary selection. The solution for this problem probably lies in the code of wxScintilla. A part of sdk/wxscintilla/srx/ScintillaWX.cpp looks like this:
Code
// This is called by the Editor base class whenever something is selected
void ScintillaWX::ClaimSelection() {
#if 0
    // Until wxGTK is able to support using both the primary selection and the
    // clipboard at the same time I think it causes more problems than it is
    // worth to implement this method.  Selecting text should not clear the
    // clipboard.  --Robin
#ifdef __WXGTK__
    // Put the selected text in the PRIMARY selection
    if (currentPos != anchor) {
        SelectionText st;
        CopySelectionRange(&st);
        if (wxTheClipboard->Open()) {
            wxTheClipboard->UsePrimarySelection(true);
            wxString text = sci2wx(st.s, st.len);
            wxTheClipboard->SetData(new wxTextDataObject(text));
            wxTheClipboard->UsePrimarySelection(false);
            wxTheClipboard->Close();
        }
    }
#endif
#endif
}
As you can see it implements this feature for wxGTK - but it is deactivated. If we want this feature on Linux we should probably re-activate this pice of code instead of using the code from revision 3003.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Revision 3003: gpm (ftr #2660)
« Reply #1 on: October 13, 2006, 05:12:48 pm »
We can simply #if 0 it, if it doesn't work under Linux.

I wasn't aware that gpm really worked under X. I remember failing endlessly trying to get a Gnome terminal or Gedit to show any such behaviour, and I remember trying it on Code::Blocks once too, without success...
In Gnome terminal, it does work if you select "copy" from the context menu first.


Regarding Windows, and the feature's general implementation: what it does right now is paste a selected text from within Code::Blocks to within Code::Blocks (without touching the clipboard at all).

Is generally pasting text found in the clipboard instead desired behaviour? That is more like what gpm does, but it is not necessarily what we want, too. In that case, for consistency, we would have to copy the selection to the clipboard when the main frame loses focus, too.
I don't think that is a particularly good thing, since it interferes with the "normal" look and feel.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Revision 3003: gpm (ftr #2660)
« Reply #2 on: October 13, 2006, 05:26:31 pm »
Regarding Windows, and the feature's general implementation: what it does right now is paste a selected text from within Code::Blocks to within Code::Blocks (without touching the clipboard at all).
I think this is OK for windows, as such a feature like gpm is not really common there (at least I never noticed it in any windows-application)

Is generally pasting text found in the clipboard instead desired behaviour?
Probably not. It seems that there is a general distinction between the "real" clipboard (normally accessed through any Copy/Paste menu entries or "Ctrl+C" etc.) and the primary selection (Just (the most recently?) selected text) which is used when you click the middle mouse button - not the text in the clipboard. Unfortunately wxGTK seems not to make this distinction and because of this the corresponding code in wxScintilla was deactivated. I agree with the author of the comment in the source code a quoted in my last post: Better no gpm than deleting the content of the clipboard with every selection of text.
However, I don't know to what version of wxGTK this comment refers - maybe things have changed since then? I don't know and I can't find anything in the documentation of wxWidgets.

Thus I would recommend putting an "#ifndef wxGTK" around the code added in revision 3003 until the support for the primary selection in wxGTK is improved.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Revision 3003: gpm (ftr #2660)
« Reply #3 on: October 13, 2006, 05:33:13 pm »
Done.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Revision 3003: gpm (ftr #2660)
« Reply #4 on: October 13, 2006, 06:16:15 pm »
Thanks.

However, I don't know to what version of wxGTK this comment refers - maybe things have changed since then? I don't know and I can't find anything in the documentation of wxWidgets.
After updating to revision 3084 I decided to check if the code I posted in my first post here still does not work. I changed the #if 0 to #if 1 and compiled it again. And guess what: I just works. No problem as described in the comment appears. Selecting text in the editor does not overwrite the contents of the clipboard. Everything works as it should ;)

Thus, to get gpm working on wxGTK we just have to remove the "#if 0" in the code I quoted in my first post. Anyway - as this code is part of wxScintilla do we really want to change it? Or should we just notify the wxScintilla-devs and wait for them to repair this in the next release?
« Last Edit: October 13, 2006, 06:19:20 pm by Der Meister »
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Revision 3003: gpm (ftr #2660)
« Reply #5 on: October 13, 2006, 06:18:52 pm »
We should really do both... the former will be our "quick fix" for now and the latter will ensure that we don't revert inadvertedly when updating wxScintilla for the next time :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Revision 3003: gpm (ftr #2660)
« Reply #6 on: October 13, 2006, 07:21:41 pm »
OK, I posted this as a feature request in the wxCode project on sourceforge.net. Let's hope that they take care about it ;)
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9701
Re: Revision 3003: gpm (ftr #2660)
« Reply #7 on: October 13, 2006, 07:42:46 pm »
We should really do both... the former will be our "quick fix" for now and the latter will ensure that we don't revert inadvertedly when updating wxScintilla for the next time :)
No problem - I follow all changes to wxScintilla we do and have always the latest version on my C::B with all (relevant) patches applied. Thus once we decide to switch to another wxScintilla version I only need to submit. ;-)
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Revision 3003: gpm (ftr #2660)
« Reply #8 on: October 14, 2006, 11:48:23 pm »
We should really do both... the former will be our "quick fix" for now [...]
As this is not yet applied I created a patch for this and posted it on Berlios. (This feature is too nice to forget about it ;) )
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.