Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to locate the item After sorting
#31
the reason it does that is because you have full autotext code in sub.Sub205.
Code:
Copy      Help
#sub Sub205 m ;;en    _解密字符串
en :"Decrypt Text"; 'Y; mou 0.5 0.5


change it to 
Code:
Copy      Help
#sub Sub205 m ;;en    _解密字符串
"Decrypt Text"; 'Y; mou 0.5 0.5
 
and sort works just fine
#32
@Kevin
Thanks for your reminding
Now the code works well
Smile
#33
@Kevin

1.How to define the following code as a sub function? I expect to replace line 96 with the subfunction
Code:
Copy      Help
 
case 7 ;;Sort autotext in qm not dialog
int sep
LB_SelectedItem(id(4 hDlg)  _s)
str s=sub.getAutotextItem(_s sep)
ARRAY(str) a=s
a.sort(2 sub.Callback_q_sort)
s=a
s.rtrim
  code: Write the sort result to the original file
mac+ _s
h=GetQmCodeEditor
act h
SendMessage(h SCI.SCI_GOTOLINE 1 0)
int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
SendMessage(h SCI.SCI_SETSEL ssp sep)
s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

2.How to determine whether an AutoText item has been sorted before executing the sort subfunction, use it when I click the sort button

3.Can sorting AutoText items be realized without opening the AutoText file?


I think it can be more stable and convenient. Any suggestions are welcome. Thanks in advance

Macro Dialog_Edit_Autotext_mod3
Code:
Copy      Help
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 196 192 48 14 "Sort" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." "     ")
,;itemslb2.findreplace(";;" "     ")
,;itemslb2.findreplace(":" "     ")
,itemslb2.replacerx(":sub.Sub\d+\s;;" "    ") ;;Replace extra characters
,foreach lb2ii itemslb2
,,LB_Add(hlb2 lb2ii)
,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,but% id(7 hDlg) ;;Sort autotext
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb2t)
,int lb6ic=LB_GetCount(lParam)
,if(lb6ic<>lb6lc)
,,ARRAY(str) b=itemslb2
,,for i 0 b.len
,,,if(StrCompare(b[i] lb2t)=0)
,,,,_i=i
,,,,break
,LB_SelectedItem(id(4 hDlg)  _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(lb2t "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg)  _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2 sub.Callback_q_sort)
,s=a
,s.rtrim
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
ret 1

#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort(2 sub.Callback_q_sort) ;;add Multi condition sorting
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d

#sub Callback_q_sort
function# param str&a str&b

str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)
,
#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)

#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)

ret R

#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)

ret R

#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd

#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items
#34
#1 your solution is not a good idea at all.
Bad idea to sort the the autotext list in qm every time I removed this. I also removed the sort you added to sub.gotoitemedit as it is also not needed there at all. I have also made it so the list is sorted and will find autotext in qm without actually sorting the autotext function in qm. everything should work now.

oh leave the dialog as a function not a macro

Function Dialog_Edit_Autotext_mod4
Code:
Copy      Help
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 196 192 48 14 "Sort" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2 itemslb2a itemslb2b
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,itemslb2b=itemslb2
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." "     ")
,;itemslb2.findreplace(";;" "     ")
,;itemslb2.findreplace(":" "     ")
,if(itemslb2.len)
,,itemslb2.replacerx(":sub.Sub\d+\s;;" "    ") ;;Replace extra characters
,,itemslb2a=itemslb2
,,ARRAY(str) lb2items
,,lb2items=itemslb2
,,lb2items.sort(2 sub.Callback_q_sort)
,,itemslb2=lb2items;     itemslb2.rtrim;
,,foreach lb2ii itemslb2
,,,LB_Add(hlb2 lb2ii)
,,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,LB_SelectedItem(lParam lb2t)
,ARRAY(str) b=itemslb2a
,for i 0 b.len
,,if(StrCompare(b[i] lb2t)=0)
,,,_i=i
,,,break
,LB_SelectedItem(id(4 hDlg)  _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,str lineText.getl(itemslb2b _i) 
,int ii=find(lineText "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii+4
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg)  _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2 sub.Callback_q_sort)
,s=a
,s.rtrim
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
ret 1

#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d

#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)

#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)

#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)

ret R

#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)

ret R

#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd

#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items
#35
By ordering the AutoText items, I can know which items are the same

If they are distributed in different locations, they cannot be quickly found and edited

So, I really need sorting AutoText items


Sometimes, I also need to control the order in which items with the same abbreviation are displayed
#36
You don't understand.

The list in the 2nd listbox  is sorted everytime you select an item from listbox1. When you click on an item in listbox2 it will take you to that item in qm and make it so you can then press F2 to go to the subfunction. You can always use the sort button to sort the autotext code in qm  But for what this is designed to do there is no need to sort in qm every time you want to go to an autotext item.

Try the dialog you will see what I mean.
#37
I have an idea.

When the dialog starts, sort the items first, so that all the problems are solved
Smile

How to add sort switches in the following sub functions?

Can you help me realize this function? Thank you very much!


Macro Dialog_Edit_Autotext_mod3
Code:
Copy      Help
#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd
#38
to sort the list in listbox1 is simple

find line
Code:
Copy      Help
atItems=atn
 
add a new line above it
Code:
Copy      Help
atn.sort(8)
 
so subfunction would look like this now
Code:
Copy      Help
#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atn.sort(8)
atItems=atn
atditems=atd
#39
Sorry, my statement above is incorrect

I want to add the following function to sub function #sub DisableEnableAutoText
________________________________________________________________________________
    case 7 ;;Sort autotext in qm not dialog
    int sep
    LB_SelectedItem(id(4 hDlg)  _s)
    str s=sub.getAutotextItem(_s sep)
    ARRAY(str) a=s
    a.sort(2 sub.Callback_q_sort)
    s=a
    s.rtrim
      code: Write the sort result to the original file
    mac+ _s
    h=GetQmCodeEditor
    act h
    SendMessage(h SCI.SCI_GOTOLINE 1 0)
    int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
    SendMessage(h SCI.SCI_SETSEL ssp sep)
    s.setclip
    SendMessage(h SCI.SCI_PASTE 0 0)
__________________________________________________________________________________

Without this sort function, I can't control the order of the same items

[Image: aa.png]

Autotext Autotext
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
zz :sub.Sub1 ;;0test
abc :sub.Sub4 ;;3test
abc :sub.Sub2 ;;1test
abc :sub.Sub3 ;;2test


#sub Sub1 m ;;zz    0test
mes 0

#sub Sub2 m ;;abc    1test
mes 2


#sub Sub3 m ;;abc    2test
mes 3


#sub Sub4 m ;;abc    3test
mes 4
#40
No that is not the place to add that would interfere with the dialog loading
But i can do this for you.
When an item is selected its checks if its sorted.
If it is not, will ask if you want to sort it. If you click yes it will sort the autotext in qm.

Function Dialog_Edit_Autotext_mod5
Code:
Copy      Help
out
str- sItems sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 188 192 89 14 "Sort AutoText Code in QM" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2 itemslb2a itemslb2b
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,itemslb2b=itemslb2
,mac "sub.IsSorted" "" itemslb2b hDlg
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." "     ")
,;itemslb2.findreplace(";;" "     ")
,;itemslb2.findreplace(":" "     ")
,if(itemslb2.len)
,,itemslb2.replacerx(":sub.Sub\d+\s;;" "    ") ;;Replace extra characters
,,itemslb2a=itemslb2
,,ARRAY(str) lb2items
,,lb2items=itemslb2
,,lb2items.sort(2 sub.Callback_q_sort)
,,itemslb2=lb2items;     itemslb2.rtrim;
,,foreach lb2ii itemslb2
,,,LB_Add(hlb2 lb2ii)
,,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,LB_SelectedItem(lParam lb2t)
,ARRAY(str) b=itemslb2a
,for i 0 b.len
,,if(StrCompare(b[i] lb2t)=0)
,,,_i=i
,,,break
,LB_SelectedItem(id(4 hDlg)  _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,str lineText.getl(itemslb2b _i) 
,int ii=find(lineText "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii+4
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext  code in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg)  _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2 sub.Callback_q_sort)
,s=a
,s.rtrim
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
,;clo hDlg
ret 1

#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d

#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)

#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)

#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)

ret R

#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)

ret R

#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atn.sort(8)
atItems=atn
atditems=atd

#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items

#sub IsSorted
function ~atOriginal hwnd
ARRAY(str) a b
a=atOriginal ;;sorted
b=atOriginal ;;original
a.sort(2 sub.Callback_q_sort)
int i; 
for(i 0 b.len)
,if(StrCompare(a[i] b[i])    <>0)
,,goto bottom
ret
;bottom
if(mes("The items in this Autotext function are not sorted.[]Would you like to sort them now?" "Autotext code Not Sorted" "YN")!='Y') ret
but+ id(7 hwnd)
_i=LB_SelectedItem(id(4 hwnd))
0.5
LB_SelectItem(id(4 hwnd) -1)
0.2
LB_SelectItem(id(4 hwnd) _i)
0.1
act hwnd
ret
#41
@Kevin

Thanks for sharing. I've created a new post, https://www.quickmacros.com/forum/showth...3#pid34913
use these two functions(getmacro and setmacro) to sort in the background, 
It will be more convenient, In this way, many sort codes can be deleted in the dialog box
I can sort before the dialog box opens
Is it possible?
#42
There is no need for a new Topic. There is a reason I didn't use setmacro to replace the text.
If the autotext function is not loaded . the changes cannot be undone.
from qm help
Quote:The user can Undo if the item is currently open (is in the "Open items" list).

I will caution you to be aware of this. If you have a coding mistake like in you had in a previous post of this topic  and the autotext function is not loaded in qm memory(is in the "Open items" list) you cannot undo the changes. With that said, here is mod 6

Function Dialog_Edit_Autotext_mod6
Code:
Copy      Help
out
str- sItems sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 188 192 89 14 "Sort AutoText Code in QM" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2 itemslb2a itemslb2b
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,sub.IsSorted(lb1si)    
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,itemslb2b=itemslb2
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." "     ")
,;itemslb2.findreplace(";;" "     ")
,;itemslb2.findreplace(":" "     ")
,if(itemslb2.len)
,,itemslb2.replacerx(":sub.Sub\d+\s;;" "    ") ;;Replace extra characters
,,itemslb2a=itemslb2
,,foreach lb2ii itemslb2
,,,LB_Add(hlb2 lb2ii)
,,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,LB_SelectedItem(lParam lb2t)
,ARRAY(str) b=itemslb2a
,for i 0 b.len
,,if(StrCompare(b[i] lb2t)=0)
,,,_i=i
,,,break
,LB_SelectedItem(id(4 hDlg)  _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,str lineText.getl(itemslb2b _i) 
,int ii=find(lineText "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii+4
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext  code in qm not dialog
,LB_SelectedItem(id(4 hDlg)  _s)
,int retVal=sub.IsSorted(_s hDlg 1)
,if(retVal=0)
,,mac "sub.ShowMessage" "" F"Sorting of Autotext code in {_s} is not rquired at this time" "Sort Message"
,else
,,mac "sub.ShowMessage" "" F"Autotext code in {_s} has been sorted" "Sort Message"
ret 1

#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d

#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)

#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)

#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)

ret R

#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)

ret R

#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atn.sort(8)
atItems=atn
atditems=atd

#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items

#sub IsSorted 
function ~name [hwnd] [mode]
str s.getmacro(name 0)
str ss atCode=sub.gotoitemedit(name)
ARRAY(str) a b c
a=atCode; b=atCode; c=s
a.sort(2 sub.Callback_q_sort)
int i sval
for(i 0 b.len)
,if(StrCompare(a[i] b[i])    <>0)
,,sval=1
,,break
if(sval =0)
,ret
i=0
for int'j 1 c.len
,if(i<a.len)
,,c[j]=a[i]
,i+1
ss=c
ss.rtrim
ss.setmacro(name)
if(mode=1)
,_i=LB_SelectedItem(id(4 hwnd))
,LB_SelectItem(id(4 hwnd) _i-1)
,0.5
,LB_SelectItem(id(4 hwnd) _i)
ret 1

#sub ShowMessage
function ~text ~caption
mes text caption
#43
@kevin
Thank you very much.
The above code works well

setmacro to replace the text. the changes cannot be undone.  
I see. Undo is very useful

Before using the setmacro function,
Backup the original file to the temporary file first, which will be more secure
Where to add temporary Newitem code?

The backup Item files store it in the folder below
Do not add triggers $t
View this file when an accident occurs


[Image: tem.png]
#44
that's a good idea. Keep in mind,
Temporary items disappear when closing file.

Function Dialog_Edit_Autotext_mod6a
Code:
Copy      Help
str- sItems sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 188 192 89 14 "Sort AutoText Code in QM" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2 itemslb2a itemslb2b
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,sub.IsSorted(lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,itemslb2b=itemslb2
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." "     ")
,;itemslb2.findreplace(";;" "     ")
,;itemslb2.findreplace(":" "     ")
,if(itemslb2.len)
,,itemslb2.replacerx(":sub.Sub\d+\s;;" "    ") ;;Replace extra characters
,,itemslb2a=itemslb2
,,foreach lb2ii itemslb2
,,,LB_Add(hlb2 lb2ii)
,,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,LB_SelectedItem(lParam lb2t)
,ARRAY(str) b=itemslb2a
,for i 0 b.len
,,if(StrCompare(b[i] lb2t)=0)
,,,_i=i
,,,break
,LB_SelectedItem(id(4 hDlg)  _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,str lineText.getl(itemslb2b _i)
,int ii=find(lineText "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii+4
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext  code in qm not dialog
,LB_SelectedItem(id(4 hDlg)  _s)
,int retVal=sub.IsSorted(_s hDlg 1)
,if(retVal=0)
,,mac "sub.ShowMessage" "" F"Sorting of Autotext code in {_s} is not rquired at this time" "Sort Message"
,else
,,mac "sub.ShowMessage" "" F"Autotext code in {_s} has been sorted" "Sort Message"
ret 1

#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d

#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)

#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)

#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)

ret R

#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)

ret R

#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atn.sort(8)
atItems=atn
atditems=atd

#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items

#sub IsSorted
function ~name [hwnd] [mode]
str s.getmacro(name 0)
str ss atCode=sub.gotoitemedit(name)
ARRAY(str) a b c
a=atCode; b=atCode; c=s
a.sort(2 sub.Callback_q_sort)
int i sval
for(i 0 b.len)
,if(StrCompare(a[i] b[i])    <>0)
,,sval=1
,,break
if(sval =0)
,ret
;; create backup of autotetx function as Temp Item
int ni=newitem(F"Temp_{name}_" s "Autotext" "" "" 128)
str tempName.getmacro(ni 1)
out F"<> a backup of {name} has been created as <open>{tempName}</open> in the Temp folder"
i=0
for int'j 1 c.len
,if(i<a.len)
,,c[j]=a[i]
,i+1
ss=c
ss.rtrim
ss.setmacro(name)
if(mode=1)
,_i=LB_SelectedItem(id(4 hwnd))
,LB_SelectItem(id(4 hwnd) _i-1)
,0.5
,LB_SelectItem(id(4 hwnd) _i)
ret 1

#sub ShowMessage
function ~text ~caption
mes text caption

or we can create the backup in a new folder. Then you can delete when you like.
#45
Is the sort button still useful?

Sort related code, seems to be able to delete all?

[Image: er.png]


Forum Jump:


Users browsing this thread: 1 Guest(s)