html -> string statements helper app
Posted: Sun Jan 27, 2008 8:47 pm
I use this to convert html text into string statements to be used with the new setGadgetItemText(id, #PB_WEB_HTMLCODE, html()) command.
It captures clipboard data ctrl-c'ed from your fav html editor, stringifies it and puts it back on the clipboard ready for you to 'ctrl-v' it back into
your app to be streamed int the webgadget. Saves a lot of work.
To check it out, run it, then r-click here, select view source, ctrl-a, click convert, ctrl-v back to see the resultting string statements.
It captures clipboard data ctrl-c'ed from your fav html editor, stringifies it and puts it back on the clipboard ready for you to 'ctrl-v' it back into
your app to be streamed int the webgadget. Saves a lot of work.
To check it out, run it, then r-click here, select view source, ctrl-a, click convert, ctrl-v back to see the resultting string statements.
Code: Select all
;-program notes
;PB4.10, 20080104, converts html on the clipboard into string statements
enumeration
#WIN
#FRAME
#TEXT
#EDIT
#CONVERT
#CANCEL
endEnumeration
declare openMainWindow()
declare convertTostring()
;-program entry
openMainWindow()
;-program event handler
repeat
event = waitWindowEvent()
select event
case #PB_EVENT_GADGET
select eventGadget()
case #CONVERT
convertTostring()
messageRequester("Done", "Converted html is placed on the clipboard")
setWindowState(#WIN, #PB_WINDOW_MINIMIZE)
case #CANCEL
end
endSelect
case #PB_EVENT_CLOSEWINDOW
end
endSelect
forever
procedure openMainWindow()
flags = #PB_WINDOW_SCREENCENTERED | #PB_WINDOW_SYSTEMMENU | #PB_WINDOW_MINIMIZEGADGET
if openWindow(#WIN, 0, 0, 540, 380, "Converter", flags)
stickyWindow(#WIN, 1)
if createGadgetList(windowID(#WIN))
frame3DGadget(#FRAME, 20, 10, 500, 350, "Html To String Converter")
textGadget(#TEXT, 60, 50, 420, 100, "Click 'Convert' to convert clipboard data to string statements")
editorGadget(#EDIT, 0, 0, 0, 0)
buttonGadget(#CONVERT, 330, 320, 80, 22, "Convert")
buttonGadget(#CANCEL, 420, 320, 80, 22, "Cancel")
endIf
endIf
endProcedure
procedure convertToString()
;get clipboard text
sendMessage_(gadgetId(#EDIT), #EM_PASTESPECIAL, #CF_TEXT, 0)
lines = countGadgetItems(#EDIT)
for line = 0 to lines - 1
text.s = getGadgetItemText(#EDIT, line)
text = replaceString(text, #DQUOTE$, #DQUOTE$ + " + chr(34) + " + #DQUOTE$)
;add dquotes and cr
if line = 0
text = chr(9) + "s.s + " + #DQUOTE$ + text + #DQUOTE$ + " + chr(13)"
else
text = chr(9) + "s + " + #DQUOTE$ + text + #DQUOTE$ + " + chr(13)"
endIf
;put it back
setGAdgetItemText(#EDIT, line, text)
next line
;copy converted text back to the clipboard
sendMessage_(gadgetId(#EDIT), #EM_SETSEL, 0, -1)
sendMessage_(gadgetId(#EDIT), #WM_CUT, 0, 0)
endProcedure