Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get a list of all AutoText files in the left pane
Function Dialog_Edit_Autotext
Code:
Copy      Help
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)         

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 188 "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 ""
;1 Button 0x54030001 0x4 116 200 48 14 "OK"
;2 Button 0x54030000 0x4 168 200 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
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 hDlg)) id(4 hDlg)
,,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(":" "     ")
,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)
,,_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
,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
ret 1

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

#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
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

using this code can run edit existing autotext from add autotext dialog

Function Add_AutoText_Dialog_New
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
out 
str s.getsel
QMITEM q; int i
ARRAY(str) atn
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
_s=atn
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 360 208 "Add AutoText"
;3 Edit 0x54030080 0x200 64 8 287 16 "text" "• text that you must type to execute statements.[]• Can be used any characters, including spaces, tabs and line breaks.[]• Can be used escapesequences.[]"
;4 Edit 0x54231044 0x200 64 32 287 80 "Statements" "statements - []• Full text[]• any commands that you can use in macros.[]• To separate multiple statements, use semicolons.[]"
;9 Button 0x54012009 0x0 64 120 122 10 "Template for KeyAutoInputDialog" "Check here if statement is a Template for KeyAutoInputDialog"
;13 Button 0x54012009 0x0 248 120 103 10 "Multiline/Singleline Autotext" "Click here if statement is for multiline or singleline Autotext(default)"
;12 Edit 0x54030080 0x200 64 136 287 16 "" "A brief explanantion for a popup list when autotext has multiple items of the same Abbreviation[]or when Autotext confirmation option is set"
;5 ComboBox 0x54230242 0x0 64 160 135 213 ""
;6 Static 0x54000000 0x0 8 160 44 16 "Add to:"
;7 Static 0x54000000 0x4 8 8 48 16 "Abbreviation:"
;8 Static 0x54000000 0x4 8 32 44 16 "Statement:"
;11 Static 0x54000000 0x0 8 136 44 16 "Comment:"
;15 Button 0x44030F00 0x0 6 50 48 14 "+ inp_name"
;16 Button 0x44030F00 0x4 6 71 48 14 "+ sel_name"
;17 Button 0x44032000 0x4 6 92 48 14 "+ var_name"
;10 Button 0x54030000 0x4 240 184 48 14 "Add"
;14 Button 0x54030000 0x0 8 184 79 14 "Edit Existing Autotext"
;2 Button 0x54030000 0x4 304 184 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4 9 13 12 5"
str e3tex e4Sta o9Tem o13Mul e12 cb5
if s.len
,e4Sta=s
o13Mul=1
cb5=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
str cbt
findrx(cb5 "\s[\x80-\xff]+|\s[a-zA-Z0-9]+" 0 1 cbt)
cbt.trim
str result=val(cb5)
if(result =-1)
,int ni=newitem(cbt "/b/i/c/m" "Autotext" "$t" "" 4)
str Abbreviation=iif((e3tex=" " or empty(e3tex)) "Text" e3tex) 
str comment=iif((e12=" " or empty(e12)) "Description" e12)
str statement=e4Sta
mac+ cbt
err
,mac+ ni
ARRAY(str) atl
if(numlines(statement) >1)
,atl=statement
,for i 0 atl.len
,,atl[i].from(" " atl[i])
,statement=atl
,statement.rtrim
,if(o13Mul=1)    
,,statement- "_s= []"
,,statement+ "[]paste _s"
,else
,,statement- "_s=[]F[]"
,,statement+ "[]PasteAutoInputDialog(_s)"        
else
,,if(o13Mul=1)
,,,statement- "''"
,,,statement+ "''"
,,else
,,,atl=statement
,,,for i 0 atl.len
,,,,atl[i].from(" " atl[i])
,,,statement=atl
,,,statement.rtrim
,,,statement- "_s=[]F[]"
,,,statement+ "[]PasteAutoInputDialog(_s)"            
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_GOTOLINE 1 0)
InsertStatement(statement comment "" 2)
int r
if(result != -1)
,r=sub.GetInsertedTextCaretPosition(1)
else
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,r=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
SendMessage(h SCI.SCI_SETSEL r r+4)
Abbreviation.setclip
SendMessage(h SCI.SCI_PASTE 0 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
sub.check_for_comment(cp h comment)
cp+7
SendMessage(h SCI.SCI_GOTOPOS cp 0)
sub.FlashCodeLine(cp h)
#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,SendMessage id(3 hDlg) EM_SETCUEBANNER TRUE @"Enter Text"
,SendMessage id(4 hDlg) EM_SETCUEBANNER TRUE @"Enter Statements"    
,SendMessage id(12 hDlg) EM_SETCUEBANNER TRUE @"Enter Comment"
,SendMessage id(5 hDlg) CB_SETCUEBANNER 0 @"Select Autotext file to add text to"
,DT_SetAccelerators(hDlg "400 Az")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case CBN_EDITCHANGE<<16|5
,sub.CB_AutoComplete lParam    
,case IDOK
,case IDCANCEL
,case 10 ;;Add
,DT_Ok hDlg
,case 13 ;;Multiline/Singlelin Autotext
,hid id(15 hDlg)
,hid id(16 hDlg)
,hid id(17 hDlg) 
,case 9 ;;Template for KeyAutoInputDialog
,hid- id(15 hDlg)
,hid- id(16 hDlg)
,hid- id(17 hDlg)
,case [15, 400];;+ inp_name
,_s.getsel(0 0 id(4 hDlg))
,if _s.len
,,str s.from("$inp_" _s "$")
,,s.setsel(0 id(4 hDlg))
,else
,,mes "You must first select  a word in the edit box"
,case 16 ;;+ sel_name
,str aid_sel=sub.Get_AID_sel_AID_var("sel")
,_i=ListDialog(aid_sel "Select an  option from the list below" "AID_sel")
,if(_i=0) ret
,aid_sel.getl(aid_sel _i-1)
,act id(4 hDlg)
,paste aid_sel
,case 17 ;;+ var_name
,str aid_var=sub.Get_AID_sel_AID_var("var")
,_i=ListDialog(aid_var "Select an  option from the list below" "AID_var")
,if(_i=0) ret
,aid_var.getl(aid_var _i-1)
,act id(4 hDlg)
,paste aid_var
,case 14 ;;Edit Existing Autotext
,0;
,sub.LaunchEditDialog
ret 1

#sub GetInsertedTextCaretPosition
function# [flags] ;;flags: 1 go to that position
int c=GetQmCodeEditor
SendMessage(c SCI.SCI_UNDO 0 0)
int r=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
SendMessage(c SCI.SCI_REDO 0 0)
if(flags&1) SendMessage(c SCI.SCI_GOTOPOS r 0)
ret r

#sub CB_AutoComplete
function hcb

ifk(B) ret
ifk(X) ret
str s ss; int i
s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)
#sub Get_AID_sel_AID_var
function~ ~option 
str oName pattern
sel option
,case "sel"
,oName="AID_sel"
,pattern="\$(?:sel)_(.+?)\$"
,case "var"
,oName="AID_var"
,pattern="\$(?:var)_(.+?)\$"    
_s.getmacro(oName 0)
str ss d
int i
ARRAY(str) aid_S
foreach ss _s
,findrx(ss pattern 0 4 aid_S)
,for i 0 aid_S.len
,,d.formata("%s[]" aid_S[0 i])
ret d.trim

#sub check_for_comment
function curPos h ~comment 
str s ss
if(!h); h=GetQmCodeEditor
int line=SendMessage(h SCI.SCI_LINEFROMPOSITION curPos 0)
SendMessage(h SCI.SCI_GOTOLINE line 0) 
int sp=SendMessage(h SCI.SCI_POSITIONFROMLINE line 0);
int ep=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0)
int ll=ep-sp
s.fix(SendMessage(h SCI.SCI_GETLINE line s.all(ll+1)))
s.trim
if(findrx(s ";;") <0)
,ss.from(";;" comment)
,SendMessage(h SCI.SCI_GOTOPOS ep 0)
,SendMessage(h SCI.SCI_INSERTTEXT -1 ss)

#sub FlashCodeLine
function curPos hce
if(!hce) hce=GetQmCodeEditor
int indicator=9
int line=SendMessage(hce SCI.SCI_LINEFROMPOSITION curPos 0)
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 LaunchEditDialog
Dialog_Edit_Autotext


Messages In This Thread
RE: How to get a list of all AutoText files in the left pane - by Kevin - 05-02-2019, 05:13 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)