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
#61
Sorry, I always thought that the design was prepared for the variables in the Autotext, please forgive me!

I am not in a hurry to use these features, I don’t want to delay your rest time. Heart

Learning these complicated programming techniques is really not an easy task for me. I can only continue to explore, I know too little.
#62
@kevin

I modified the original code as I needed it.

There are currently two features not implemented. I have no idea to solve it.  Shy

Button +sel_Name
Button +var_Name



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 0x54012003 0x0 64 120 122 10 "Template for KeyAutoInputDialog" "Check here if statement is a Template for KeyAutoInputDialog"
;13 Button 0x54012003 0x0 252 120 99 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 0x54230243 0x0 64 160 135 213 ""
;6 Static 0x54000000 0x0 8 160 44 16 "Add to:"
;7 Static 0x54000000 0x4 8 8 44 16 "Abbreviation:"
;8 Static 0x54000000 0x4 8 32 44 16 "Statement:"
;11 Static 0x54000000 0x0 8 136 44 16 "Comment:"
;10 Button 0x54030000 0x4 240 184 48 14 "Add"
;15 Button 0x54032000 0x0 6 50 48 14 "+ inp_name"
;16 Button 0x54032000 0x4 6 71 48 14 "+ sel_name"
;17 Button 0x54032000 0x4 6 92 48 14 "+ var_name"
;18 Button 0x54030000 0x4 162 184 61 14 "Add + Open" "After adding open the AutoText, hotkey: Ctrl+Enter"
;2 Button 0x54030000 0x4 304 184 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4 9 13 12 5"
str e3tex e4Sta c9Tem c13Mul e12 cb5
if s.len
,e4Sta=s
c9Tem=1
cb5=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
str cbt
findrx(cb5 "\s[a-zA-Z0-9]{1,100}" 0 1 cbt)
cbt.trim
str Abbreviation=e3tex
str statement=e4Sta
str comment=e12
mac+ cbt
ARRAY(str) atl
;if(numlines(statement) >1)
atl=statement
for i 0 atl.len
,atl[i].from(" " atl[i])
statement=atl
statement.rtrim
if(c13Mul=1)
,statement- "_s= []"
,statement+ "[]paste _s"
else
,;atl=statement
,;for i 0 atl.len
,,;atl[i].from(" " atl[i])
,;statement=atl
,;statement.rtrim
,statement- "_s=[]F[]"
,statement+ "[]PasteAutoInputDialog(_s)"
;else
,,;statement- "''"
,,;statement+ "''"
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_GOTOLINE 1 0)
InsertStatement(F"{statement}" comment "" 2)
int r=sub.GetInsertedTextCaretPosition(1)
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)
cp+7
SendMessage(h SCI.SCI_GOTOPOS cp 0)

#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")
,;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET|TVGN_FIRSTVISIBLE q.htvi
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 10 ;;Add
,DT_Ok hDlg
,case 13 ;;Multiline/Singlelin Autotext
,if but(id(13 hDlg))
,,but- id(9 hDlg)
,case 9 ;;Template for KeyAutoInputDialog
,if but(id(9 hDlg))
,,but- id(13 hDlg)
,case 15 ;;+ inp_name
,_s.getsel(0 0 id(4 hDlg))
,str s.from("$inp_" _s "$")
,s.setsel(0 id(4 hDlg))
,case 400 ;;+ inp_name
,_s.getsel
,str s1.from("$inp_" _s "$")
,s1.setsel
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
#63
you broke the multi functionality of the dialog  .If you only just waited till i posted updated code.
your add+ button still makes no sense as it doesn't do what it says it does
#64
I use Google Translate, I don't understand what you are describing, please forgive me.  Smile

I commented out some of the judgment code and added two pieces of code about $inp_name$, It's not a message box, you need to select a word to be able to operate because I don't know the way the message box

I will wait for you to release the perfect code, I am now learning the programming knowledge of getting started, some code may have errors, please advise, thank you

My English replies, I completely used Google Translate, because I didn't study English during school, so if there is a problem with my description, please forgive me. Big Grin
#65
I will post code in a little while. Pc that has this code is currently doing windows updates
#66
I have two new ideas.  Idea

1. Convert the read-only combo box into an editable combo box and support auto-completion. There is related code below, but I don't know how to use it.

2. If I enter a name that does not exist in the combo box, first create an AutoText file (Its name is the name entered in the previous step.) and insert the phrase into the new file.


Function dlg_combo_autocomplete
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str cb3
cb3="&one[]two[]three[]four[]five[]six[]seven[]eight[]nine"
if(!ShowDialog("dlg_combo_autocomplete" &dlg_combo_autocomplete &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A48 0x100 0 0 220 132 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 ComboBox 0x54230342 0x0 6 4 96 213 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case CBN_EDITCHANGE<<16|3
,CB_AutoComplete lParam
,case IDOK
,case IDCANCEL
ret 1

Function CB_AutoComplete
Code:
Copy      Help
/
function hcb

;Automatically completes when you type in combo box.
;Call from dialog procedure, on CBN_EDITCHANGE.
;hcb - combo box handle (use lParam).

;EXAMPLE
,;case CBN_EDITCHANGE<<16|3
,;CB_AutoComplete lParam


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)
#67
@kevin

I found the function code to get the AutoText items.

Should be able to use this method to get sel_name and var_name



Function GetItems
Code:
Copy      Help
;get QM editor text

str s.getmacro; if(!s.len) ret

;find all '#sub Name' and ' $BkM optional name' lines
ARRAY(CHARRANGE) a; int i
if(0=findrx(s "(?m)^(?:#sub +(\w+)| \$BkM\b([^\r\n]*))" 0 4 a)) ret

;format items text for ListDialog
str items t
for i 0 a.len
,int isBM=s[a[0 i].cpMin]!='#'
,CHARRANGE& r=a[1+isBM i]
,int n=r.cpMax-r.cpMin; if(n>0) t.get(s r.cpMin n); t.trim; else t=""
,items.formata("%i %s[]" isBM t)

i=ListDialog(items "Subfunctions and code bookmarks" "Go to" 128|4 0 0 0 0 0 "$qm$\function.ico[]$qm$\favorites.ico")-1
out i
if(i<0) ret
int c=GetQmCodeEditor
SendMessage(c SCI.SCI_GOTOPOS a[0 i].cpMin 0)
#68
Thanks But i Already have Working code for That. Will post in a little bit. Sorry been really busy or would have posted sooner
#69
Ok, I will wait for your release, Smile thanks
#70
try this out

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"
;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[a-zA-Z0-9]{1,100}" 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(F"{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)
cp+7
SendMessage(h SCI.SCI_GOTOPOS cp 0)
#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
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
#71
Very beautiful, fully achieved the goal   Tongue

@kevin

Can you add an editing function?

Sometimes, I need to modify an item in an AutoText. After clicking the Edit button (This button is gray when no item is selected), a list of the selected AutoText items will pop up. When I click on the list name, I will jump to the subfunction of the item.

I found a filtering problem, please see the picture

Macro Macro2
Code:
Copy      Help
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 sList
sList=atn
;sList=
;;one
;;two
;;three
;;four

ARRAY(str) aList=sList
IQmDropdown ddl
int inERS

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 ComboBox 0x54230641 0x0 113 8 102 99 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4"
str e3 cb4
cb4=sList

if(!ShowDialog(dd &sub.DlgProc &controls)) ret

out
out e3
out cb4


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case EN_CHANGE<<16|3 sub.OnTextChanged lParam
,case CBN_EDITCHANGE<<16|4 sub.OnTextChanged lParam

ret 1


#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret

if(ShowDropdownList(x i 0 1 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(i+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1
inERS=0


Attached Files Image(s)
       
#72
the filter works left to right not the same as that 1
#73
New file name, can't use Chinese or unicode


Attached Files Image(s)
   
#74
wasn't designed for chinese
#75
I just learned that I can't use these features because most of my AutoText is Chinese names. Sad
#76
the qm item name or the autotext inside ?
#77
I tried using the code below and can't support it.

findrx(cb5 "\s[\u4e00-\u9fa5_a-zA-Z0-9]{1,100}" 0 1 cbt)

AutoText name
#78
sorry not sure i can help with that.
 will need Gintaras or another member experienced in unicode. as i am not.
#79
try this line 

findrx(cb5 "\s[\x80-\xff]+|\s[a-zA-Z0-9]+" 0 1 cbt)
worked for me for both english and chinese
#80
Thank you very much, support Chinese, very perfect
#81
I tried to add the code to the edit button  Smile

But there are three problems  Huh
1. No comments are displayed in the list
2. The row of the positioning subfunction is not at the top (How to make the line where the anchor point is displayed at the top of the editor and highlight it)
3. I can't use the list box continuously for positioning. For example, I first locate sub1 and then locate sub2. These need to close the dialog and reopen.



Macro Macro6
Trigger AV     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 0x54032000 0x0 214 160 41 14 "Edit"
;2 Button 0x54030000 0x4 304 184 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

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[\u4e00-\u9fa5_a-zA-Z0-9]{1,100}" 0 1 cbt)
findrx(cb5 "\s[\x80-\xff]+|\s[a-zA-Z0-9]+" 0 1 cbt) ;;
;findrx(cb5 "\s[a-zA-Z0-9]{1,100}" 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(F"{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)
cp+7
SendMessage(h SCI.SCI_GOTOPOS cp 0)

#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
,_s.getwintext(id(5 hDlg))
,str items=sub.gotoitemedit(_s)
,_i=ListDialog(items "Which item to Edit" "Select item")-1
,if(_i<0) ret
,mac+ _s
,int c=GetQmCodeEditor
,SendMessage(c SCI.SCI_GOTOPOS a[0 _i].cpMin 0)
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 gotoitemedit
function~ ~name
str s.getmacro(name 0); if(!s.len) ret

ARRAY(CHARRANGE)+ a; int i
if(0=findrx(s "(?m)^(?:#sub +(\w+))" 0 4 a)) ret

str items t
for i 0 a.len
,int isBM=s[a[0 i].cpMin]!='#'
,CHARRANGE& r=a[1+isBM i]
,int n=r.cpMax-r.cpMin; if(n>0) t.get(s r.cpMin n); t.trim; else t=""
,items.formata("%i %s[]" isBM t)

ret items
#82
How to use regular expressions, Replace the item fields in the Autotext (Divided into three segments, each with a tab indent), As the picture below looks like

How to modify?
"(?m)^(?:#sub +(\w+))"   


The following code has a minor problem that will be reordered, for example,
The original order of the items is
Sub3
Sub2
Sub1
Sub4

But after processing, the order becomes
Sub1
Sub2
Sub3
Sub4

How to save the original order?

 
Code:
Copy      Help
#sub gotoitemedit
function~ ~name
str s.getmacro(name 0); if(!s.len) ret

ARRAY(CHARRANGE)+ a; int i
if(0=findrx(s "(?m)^(?:#sub +(\w+))" 0 4 a)) ret

str items t
for i 0 a.len
int isBM=s[a[0 i].cpMin]!='#'
CHARRANGE& r=a[1+isBM i]
int n=r.cpMax-r.cpMin; if(n>0) t.get(s r.cpMin n); t.trim; else t=""
items.formata("%i %s[]" isBM t)

ret items

Autotext test
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
ta :sub.Sub3 ;;tc Comment
ta :sub.Sub2 ;;tb Comment
ta :sub.Sub1 ;;ta Comment
ta :sub.Sub4 ;;td Comment


#sub Sub1 m
_s=
F
;ta test
PasteAutoInputDialog(_s)


#sub Sub2 m
_s=
F
;tb test
PasteAutoInputDialog(_s)


#sub Sub3 m
_s=
F
;tc test
PasteAutoInputDialog(_s)


#sub Sub4 m
_s=
F
;td test
PasteAutoInputDialog(_s)


Attached Files Image(s)
   
#83
I finally got it.  Smile

My programming level is limited and I can only use the most clumsy method.

I hope someone can provide a better way 
Heart

Thank you very much for the help of kevin. Without your help, this Function is impossible.  Heart Heart

 
Code:
Copy      Help
case 14 ;;Edit
_s.getwintext(id(5 hDlg))
str items=sub.gotoitemedit(_s)
items.findreplace(":sub." "     ")
items.findreplace(";;" "     ")
_i=ListDialog(items "Which item to Edit" "Select item")
if(_i=0) ret
mac+ _s
int c=GetQmCodeEditor
out _i

SendMessage(c SCI.SCI_GOTOLINE _i 0)
int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
cp+12
SendMessage(c SCI.SCI_GOTOPOS cp 0)


 
Code:
Copy      Help
#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub.Sub\d.*)"

_s.getmacro(name 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
#84
@kevin

Hello, I am using it and found a strange problem.

The comment cannot be the same as the first few words of the statement. Otherwise, it will not be able to add comment. Huh

Please see the following GIF animation demo. I tried a lot of methods, no solution, can you help me? thank you very much Heart


Attached Files Image(s)
   
#85
seems to be a bug with InsertStatement which is a Built in qm function. Gintaras will need to fix the possible bug or give a work around.
#86
Thank you for your reminder  Smile

Can only use the following method to close the AutoText after adding it? Huh

Is there a way to add an AutoText without opening QM?
 
Code:
Copy      Help
 
 if(c8Ope=0)
men 33285 _hwndqm ;;Close active item
men 33013  _hwndqm ;;Close Qm Window
 OnScreenDisplay F"Acronym: {s1} has been added successfully" 2
#87
You mean the qm item (aka the autotext function) or qm itself?
#88
qm item + qm itself

When I click the Add button, the Add AutoText dialog closes and QM window does not display . Is this possible?
#89
oh btw you have a few things that should be changed in your edit button code
 your code will only work if sub function name is sub.sub1 sub.sub2 ect ect ect . If you have a subfunction not named that wont find it and your list will be off.

also there is no need to use a global variable and especially not one that has a local name in another subfunction


here is updated code
 
Code:
Copy      Help
;case 14 ;;Edit
_s.getwintext(id(5 hDlg))
str ssss items=sub.gotoitemedit(_s)
items.replacerx("\Q:sub.\E|\;" "     ") 
_i=ListDialog(items "Which item to Edit" "Select item")
if(_i=0) ret
mac+ _s
int c=GetQmCodeEditor
SendMessage(c SCI.SCI_GOTOLINE _i 0)
ssss.getl(items _i-1)
ssss.trim
int ii=find(ssss "Sub." 0 1)
int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
cp+ii
SendMessage(c SCI.SCI_GOTOPOS cp 0)

#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_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
#90
the code i posted will find the autotext line and place the cursor so you can press F2 and goto sub function  with code


Forum Jump:


Users browsing this thread: 2 Guest(s)