[IDE Tool] Paste as String

Working on new editor enhancements?
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

[IDE Tool] Paste as String

Post by Mr.L »

Here is a simple tool to insert text from the clipboard formatted as a string into the IDE.
The result looks like this:
"line1" + #CRLF$ +
"line2" + #CRLF$ +
"line3" + #CRLF$ +
...

Code: Select all

Procedure PasteAsString()
	Protected sci = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
	
	If sci = 0
		MessageRequester("", "Scintilla not found", #PB_MessageRequester_Error)
	Else
		Protected text$ = GetClipboardText()
		
		If text$ <> ""
			Protected output$
			Protected i, lines = CountString(text$, #LF$) + 1
			For i = 1 To lines
				Protected line$ = RTrim(StringField(text$, i, #LF$), #CR$)
				line$ = ReplaceString(line$, #DOUBLEQUOTE$, #DOUBLEQUOTE$ + " + #DOUBLEQUOTE$ + " + #DOUBLEQUOTE$)
				line$ = RemoveString(line$, " + " + #DOUBLEQUOTE$ + #DOUBLEQUOTE$)
				If i > 1
					CompilerIf #PB_Compiler_OS = #PB_OS_Windows
						output$ + " + #CRLF$ + " + #CRLF$
					CompilerElse
						output$ + " + #LF$ + " + #LF$
					CompilerEndIf
				EndIf
				output$ + #DOUBLEQUOTE$ + line$ + #DOUBLEQUOTE$
			Next
			
			If output$ <> ""
				SetClipboardText(output$)
				SendMessage_(sci, #SCI_PASTE, 0, 0)
				SetClipboardText(text$)
			EndIf
		EndIf
	EndIf
EndProcedure

PasteAsString()
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: [IDE Tool] Paste as String

Post by Quin »

Works perfectly here, thanks for sharing 8)
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: [IDE Tool] Paste as String

Post by boddhi »

:shock: Strange! I get "Scintilla not found" error!??

EDIT: After reinstalling my PB 6.11 version, snippet works very well!
I don't understand why this matter 🤔
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply