Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transfer macros/functions from forum to QM
#1
Macro ForumFunctionsToQm
Code:
Select All      Help
;WHEN TO USE
;To quickly transfer macros, functions, etc from a QM forum post to QM.
;Use when they are embedded in the post, not attached as qm file.

;HOW TO USE
;In QM forum select whole or part of the post and copy to the clipboard (Ctrl+C).
;Then switch to QM and run this macro.
;This macro parses clipboard text, creates folder "from forum", and creates the macros/functions there.

;MORE INFO
;The post must contain one or more properly formatted QM code blocks (macros, functions, etc).
;You can copy only part of post. If there is function name or other info above code, include it.
;This macro tries to extract QM item name, type and trigger from the one or two lines above the code.
;If there is no name, gives default name, eg "Macro23". On conflict renames.

;RECOMMENDED TRIGGER
;Add this macro to a menu whose trigger is QM events -> Add to a menu -> Menu bar.

;___________________________________________________________________________________

;out

;get clipboard text in HTML format
str s s1 s2
s.getclip("HTML Format")
;out s
if(!s.len)
,;ge1
,mes- "The clipboard does not contain text copied from QM forum in HTML clipboard format." "" "x"

;get selected fragment
int i j
i=find(s "StartFragment:")
j=find(s "EndFragment:")
if(i<0 or j<0) goto ge1
i=val(s+i+14)
j=val(s+j+12)
if(!i or !j) goto ge1
s.get(s i j-i)
s-"<HTML><HEAD></HEAD><BODY>"; s+"</BODY></HTML>"
if(!_unicode) s.ConvertEncoding(CP_UTF8 0)
;out s


;parse HTML
HtmlDoc d.InitFromText(s)
;out d.GetHtml
;ret

type TNTI ~text ~name ~trigger ~itype
ARRAY(TNTI) a

;get text of code blocks
ARRAY(MSHTML.IHTMLElement) ae
d.GetHtmlElements(ae "div")
for i 0 ae.len
,MSHTML.IHTMLElement e=ae[i]
,s=e.className; if(s!="cod") continue
,s=e.innerText
,a[].text=s
,s-"<-<58321>->"; e.innerText=s ;;mark to find name and trigger later
,
if(!a.len) mes- "There is no code in the clipboard. In QM forum select text with one or more blocks of properly formatted QM code." "" "x"

;get name, item type and trigger
s=d.GetText
;out s
ARRAY(str) as
if(findrx(s "^((.+ \?[]){0,2})\s*<-<58321>->" 0 8|4 as)!=a.len) ret
for i 0 a.len
,TNTI& r=a[i]
,s=as[1 i]
,s1.getl(s 0)
,s2.getl(s 1)
,if(s1.len)
,,s1.trim("?")
,,sel s1 3
,,,case "Member Function *" r.itype="Member"; r.name.get(s1 16)
,,,case "T.S. Menu *" r.itype="T.S. Menu"; r.name.get(s1 10)
,,,case "TS Menu *" r.itype="T.S. Menu"; r.name.get(s1 8)
,,,case else r.itype.gett(s1 0); r.name.gett(s1 1 "" 2)
,,r.name.trim
,else r.name=""
,if(s2.len and s2.begi("Trigger "))
,,r.trigger.get(s2 8 s2.len-10)
,,r.trigger.trim
,;out r.name; out r.itype; out r.trigger; out r.text; out "------"

;correct text
for i 0 a.len
,&r=a[i]
,lpstr k=r.text
,rep
,,rep() sel(k[0]) case ',' k[0]=9; k+1; case ';' k[0]=32; k+1; case else break
,,k=strchr(k 10)+1; if(k=1) break

;create QM items
int ifolder=newitem("from forum" "" "Folder")
for i 0 a.len
,&r=a[i]
,newitem r.name r.text r.itype r.trigger +ifolder 16
Reply
#2
I tried to tranfer to QM TS Menu functions found in

http://www.quickmacros.com/forum/showthr...0#pid20270

but I failed. I am using ForumFunctionsToQm since a long time, it works perfectly. Does it has something to do with TS-Menus? I use QM 2.3.3.3. Please advise.
Reply
#3
ForumFunctionsToQm incorrectly parses string when it contains "T.S. Menu". Will fix it when have time.
Reply
#4
Fixed.
Reply
#5
Extremely fast! Many thanks. Regards!
Reply
#6
Is possible update it to work in Chrome?
Reply
#7
It works in Chrome.
Reply
#8
Error (RT) in ForumFToQm: cannot create new item: template not found.

note:

in Firefox works...
unicode not active.
Reply
#9
What is the copied text?
Reply
#10
s=


Version:0.9
StartHTML:0000000175
EndHTML:0000064941
StartFragment:0000000211
EndFragment:0000064905
SourceURL:http://www.quickmacros.com/forum/viewtopic.php?p=18118
<html>
<body>
<!--StartFragment--><span style="color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.200000762939453px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(236, 236, 236); display: inline !important; float: none; ">Macro<span class="Apple-converted-space"> </span></span><span style="margin: 0px; padding: 0px; color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18.200000762939453px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(236, 236, 236); font-weight: bold; ">ForumFunctionsToQm</span><span style="color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height:
....
</div><!--EndFragment-->
</body>
</html>
Error (RT) in ForumFToQm: cannot create new item: template not found. ?
Reply
#11
Now will work. Added this line.
if(!_unicode) s.ConvertEncoding(CP_UTF8 0)
Reply
#12
Perfect!

Thanks.
Reply
#13
Just a suggestion to improve this function
stops the "from forum" folder from being created over and over again.
and selects newly created item

Code:
Select All      Help
;create QM items
int ifolder=newitem("from forum" "" "Folder" "" "" 3|4)
for i 0 a.len
,&r=a[i]
,newitem r.name r.text r.itype r.trigger +ifolder 4|16
added flag 3 to prevent this from creating the folder over and over again added flag 4 to open the folder and select the newly created macro so don't have to go searching for it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)