Page 1 of 2

[Implemented] send the DebugOutput to the ClipBoard

Posted: Mon Mar 30, 2015 9:18 pm
by Blue
We already have the ability to programmatically
(1) Clear the DebugOutput
(2) Save the DebugOutput

All that's missing is #3 : the ability to send the DebugOutput to the system's clipboard.
Can we hope to have this sometimes ???

That would be immensely useful.

As well, the Help File should mention the above related functions in the general Debugging page and should link to their Help File page.

Thank you.

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 11:57 am
by Dude
Use SetClipboardText().

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 1:22 pm
by Fangbeast
Dude wrote:Use SetClipboardText().
Blue wants the clipboard to work with debug data. SetClipboardText() does not work with debug data.

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 1:44 pm
by Dude
What I mean is, since he already knows what the debug output holds (since he put it there), why not just have an ongoing string of such output (such as DebugOutput$) and then just SetClipboardText(DebugOutput$) when the need arises?

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 3:29 pm
by Blue
Dude wrote:[...] since he already knows what the debug output holds (since he put it there), why not just have an ongoing string of such output [...]
There's always a way to do something differently. But that's besides the point here.

What you describe as a workaround is, of course, exactly what you, me and everybody else is already doing and has been doing forever. Nothing original in that solution. :?

But, again, that's not the point here, is it ?

The object of this section is to suggest, and possibly explain, ideas for additional conveniences that future releases of the IDE could benefit from.

Think of the built-in functions that PB provides to programmatically clear and save the Debug Output window. Strictly speaking, who needs them ? There already exist buttons at the top of the Debug Output window that do exactly that ! All you have to do is press them. :shock: Therefore, why did the coders of the IDE bother to provide programmatical ways to do the very same things ? Because they realized that the added functionalities would be darn convenient and useful.

By your reasoning, what is being asked here is totally ridiculous : there's already a button at the top of the Debug Output window that sends everything to the Clipboard ! :shock: All we have to do is click on it...

Maybe you should read and read again the title of the section and meditate on it. :)

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 3:47 pm
by Dude
Blue wrote:Think of the built-in functions that PB provide to clear and the Debug Output window. Strictly speaking, who needs them ?
Strictly speaking: clearing or saving the debug window at runtime is a different concept, because the programmer may need to clear or save it before each start of a recurring loop that they cannot determine the start of (thinking speed reasons mainly). You can't manually do that by clicking the mouse, so that argument is totally moot. :)

On the other hand, since I as the coder was the one who put the text in the debug output, I can already programmatically copy it to the clipboard at any time anyway, so I don't see how much more convenient a command could make it. <Shrugs>. :?

This is what I mean:

Code: Select all

For a=1 To 100
  n$+Str(Random(1000))+#CRLF$
  Debug n$ ; Send information to Debug Output.
Next

SetClipboardText(n$) ; Copy contents of Debug Output.
[Edit] Okay, I get that you want it for convenience's sake. Fair enough. I won't argue anymore. :wink:

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 3:53 pm
by Blue
Dude wrote:[...]
This is what I mean:

Code: Select all

For a=1 To 100
  n$+Str(Random(1000))+#CRLF$
  Debug n$ ; Send information to Debug Output.
Next

SetClipboardText(n$) ; Copy contents of Debug Output.
Seriously Dude, why do you insist on showing others how to do the obvious ? :(
Do you really think that your point was not clear to anyone the very first time ? :?:

Besides, supposing one codes your suggested workaround, can you not see that the requested 'convenience' could replace hundreds of 'add this to the outputSting$' lines in the code with a single request, just before the final 'End' : 'Now send everything to the clipboard' so i can just switch to my text editor, or Excel, or whatever, and start working with the pasted data... I'm exaggerating, of course, since all i have to do currently is bring the DebugOutput window to the front, click the 'Copy' button, and achieve the same outcome. Couldn't be simpler, really. 8) Oh, but wait. Yes, it could be simpler : if i could only do it programmatically... [Go back to square one] :lol:

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Tue Mar 31, 2015 3:54 pm
by Dude
Edited my post above yours. Thanks for the discussion. :)

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 5:01 am
by netmaestro
Just for fun in the meantime:

Code: Select all

Procedure EnumC(hwnd, lParam)
  cn$ = Space(255)
  GetClassName_(hwnd, @cn$, 255)
  If FindString(cn$, "RichEdit")
    PokeI(lParam, hwnd)
    ProcedureReturn 0
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure Enum(hwnd, lParam)
  wn$ = Space(255)
  edit.i
  GetWindowText_(hwnd, @wn$, 255)
  If FindString(wn$, "Debug Output -")
    EnumChildWindows_(hwnd, @EnumC(), @edit)
    PokeI(lParam, edit)
    ProcedureReturn 0
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure.s GetDebugText()
  Static lastsize=0
  Protected edit.i, result$
  EnumWindows_(@Enum(), @edit)
  size = SendMessage_(edit, #WM_GETTEXTLENGTH, 0, 0)
  start=ElapsedMilliseconds()
  While size=lastsize
    size = SendMessage_(edit, #WM_GETTEXTLENGTH, 0, 0)
    If ElapsedMilliseconds()-start>200
      Break
    EndIf
  Wend
  If size
    lastsize=size
    size+SizeOf(Character)
    result$ = Space(size)
    SendMessage_(edit, #WM_GETTEXT, size, @result$) 
    ProcedureReturn result$
  Else
    ProcedureReturn ""
  EndIf
EndProcedure

Debug "1234567890"
Debug "Hello"
Debug 99
Debug 17*3

SetClipboardText(GetDebugText())
run the code and paste into your ide... should work.

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 6:19 am
by Danilo
netmaestro's code made cross-platform:

Code: Select all

Procedure CopyDebugOutput()
    ShowDebugOutput()
    Delay(500)
    Protected tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"
    SaveDebugOutput(tempFile)
    Delay(500)
    Protected file = ReadFile(#PB_Any, tempFile, #PB_File_SharedRead|#PB_File_NoBuffering)
    If file
        Protected stringFormat = ReadStringFormat(file)
        ;ClearClipboard()
        SetClipboardText( ReadString(file,stringFormat|#PB_File_IgnoreEOL) )
        CloseFile(file)
    EndIf
    DeleteFile(tempFile,#PB_FileSystem_Force)
EndProcedure

Debug "Some text"
Debug "Some more text"
CopyDebugOutput()
MessageRequester("INFO", GetClipboardText())

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 8:43 am
by Bisonte
hm. Netmaestros code not work on Win8.1 x64

And Danilos code only works with PB5.31 x86.... why ?
With other PB versions, the output is empty (5.24 x86/x64 and 5.31x64) .....
I tested with Unicode and ASCII mode....

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 8:48 am
by netmaestro
Change all my .i to .l and PokeI to PokeL and it should work on x64.

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 8:59 am
by Danilo
Wrote it with PB 5.31 x64 and works here. But I also noticed some strange things,
that's why I had to insert the delays and ShowDebugOutput().

Without the delays and ShowDebugOutput() I get no file or empty files most of the time:

Code: Select all

Debug "abc"

tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"

SaveDebugOutput(tempFile)

Debug FileSize(tempFile) ; -1, file does not exist

Delay(500)

Debug FileSize(tempFile) ; 0, empty file
Looks like SaveDebugOutput() does not flush and close the file correctly, because
the file can only be used after a delay.
After the delay, the file is still empty and does not contain "abc". I need to use ShowDebugOutput():

Code: Select all

Debug "abc"

ShowDebugOutput() : Delay(500)

tempFile.s = GetTemporaryDirectory()+"TMP_PB_DEBUG_"+Hex(Random($FFFFFF))+".txt"

SaveDebugOutput(tempFile)

Debug FileSize(tempFile) ; -1, file does not exist

Delay(500)

Debug FileSize(tempFile) ; 5
Here is the example from the PB Help (I just used d:\ instead c:\):

Code: Select all

  For i = 1 To 100
    Debug Random(i)
  Next i
  SaveDebugOutput("d:\log.txt")
Gives me an empty file. PB 5.31 x64 on Windows 8.1

It works here when I put ShowDebugOutput() in front of the loop (before the first 'Debug' statement).

Looks like some new bugs. :)

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 2:34 pm
by Blue
@NetMaestro :
Seems to work perfectly (PB 5.31 x86 under Win 8.1 x64) so far. Thank you !
How did you just pull such a neat bit of magic out of your hat all of a sudden?
That's gotta be a mighty big hat you have there, or is it the head under the hat that is so big ?
I'll explore that mystery later, but for now, suffice it to say that your solution does wonders for my nerves.
When you're dealing with over 1000 lengthy lines of data per output, your solution is a major help and time saver.

@Danilo :
I've been using a very similar solution, but it annoyed the hell out of me as it appeared flaky and unreliable.
Thank you for smartly pointing out everything that actually goes wrong with that "Save to a file" approach.
It's a relief to have someone of your caliber confirm that it was not only my programming that was at fault.
[Edit] Putting ShowDebugOutput() at the very start indeed does wonders. Nice find.

Re: Programmatically send the DebugOutput to the ClipBoard

Posted: Thu Apr 02, 2015 2:49 pm
by blueb
Having both Netmaestro and Danilo on the PureBasic forums allows me to sleep very, very well. :mrgreen: