03-20-2019, 02:15 AM (This post was last modified: 03-20-2019, 03:13 AM by win.)
In order to make the AutoText definition easier, I wrote the following code. There are four pieces of code. I don't understand how to write it. I hope someone can provide some suggestions. Thanks in advance.
_________________________________________________________
Because the private function TO_Text inside QM cannot be used, most of the code uses simulation operations, I think there should be a simpler method.
The following code is usable, you need to open the AutoText file first, then position the cursor behind the last acronym field. Operation is not convenient
str s1 ;;string variable. If need numeric, replace str with int or double. if(!inp(s1 "Enter AutoText Abbreviation""""text"))ret str s2 ;;string variable. If need numeric, replace str with int or double. if(!inp(s2 "Enter a phrase description""""description"))ret ; ;1.code:Get a list of all AutoText files, The code below is an example, Suppose there are four AutoText files.
;2.code:Open selected Autotext??? file ;3.code:The cursor is positioned at the end of the last AutoText field
int w=win("QM TOOLBAR""QM_toolbar") act w lef129id(9999 w)1;;toolbar, press button 'Text'
paste s
int w1=win("Text""#32770") lef97id(6 w1)1;;Check box 'Multiline' lef484id(5 w1)1;;List, list item 'Paste (use clipboard)'
;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2
When I enter an abbreviation, there may be some circumstances that need to be judged. For example, if the entered abbreviation already exists, the user is prompted to change it. If the user confirms, the selected row is inserted in the next line where the abbreviation already exists
03-20-2019, 03:17 AM (This post was last modified: 03-20-2019, 03:51 AM by win.)
This feature is very practical, easy to use, it can help a lot of people save a lot of input time and define time, I very much hope that developers can consider improving
Or use a dialog box, it will be easier
str s1 ;;string variable. If need numeric, replace str with int or double. if(!inp(s1 "Enter AutoText Abbreviation""""text"))ret str s2 ;;string variable. If need numeric, replace str with int or double. if(!inp(s2 "Enter a phrase description""""description"))ret ; ;1.code:Get a list of all AutoText files, The code below is an example, Suppose there are four AutoText files.
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn int ii=ListDialog(_s);if(ii=0)ret ;2.code:Open selected Autotext SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog
also several other mistakes
TO_Fav "TO_Text" 0 0 opens text dialog with options text and paste using clipboard already selected
03-26-2019, 02:29 AM (This post was last modified: 03-26-2019, 02:35 AM by win.)
The following code works fine, currently only the last step of the code
I think the code in the third and fourth steps is very difficult. It needs to read some fields of the file, then analyze the file positioning cursor, and finally write the characters to the corresponding position.
str s1 ;;string variable. If need numeric, replace str with int or double. if(!inp(s1 "Enter AutoText Abbreviation""""text"))ret str s2 ;;string variable. If need numeric, replace str with int or double. if(!inp(s2 "Enter a phrase description""""description"))ret ; ;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn int ii=ListDialog(_s);if(ii=0)ret ;2.code:Open selected Autotext SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog
TO_Fav"TO_Text"00 int w1=act(win("Text""#32770"))
;3.code:The cursor is positioned at the end of the last AutoText field
paste s butid(6 w1);;check box 'Multiline'
;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2
03-26-2019, 03:10 AM (This post was last modified: 03-26-2019, 03:15 AM by win.)
str s.getsel
str s1 ;;string variable. If need numeric, replace str with int or double.
if(!inp(s1 "Enter AutoText Abbreviation" "" "test")) ret
str s2 ;;string variable. If need numeric, replace str with int or double.
if(!inp(s2 "Enter a phrase description" "" "description")) ret
4.code:Replace the default Abbreviation (text) with the variable s1, Add a description with the variable s2 Just like below
After some tests, I found a problem. After adding the AutoText, I need to close it. Otherwise, the insertion point will be wrong when I add it later. How can I close the open AutoText in a simple way?
out str s.getsel str s1 ;;string variable. If need numeric, replace str with int or double. if(!inp(s1 "Enter AutoText Abbreviation""""text"))ret str s2 ;;string variable. If need numeric, replace str with int or double. if(!inp(s2 "Enter a phrase description""""description"))ret
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn int ii=ListDialog(_s);if(ii=0)ret ;2.code:Open selected Autotext SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog ;3.code:The cursor is positioned at the end of the last AutoText field
_s.getl(_s ii-1) ;find insertion point sub.InsertionPoint(_s) ;insert autotext TO_Fav"TO_Text"00 int w=wait(0 WA win("Text""#32770")) butid(6 w);;check box 'Multiline'
s.setwintext(id(3 w)) butid(1 w);; close to text window and insert code into autotext function ;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2 wait(0 WD win("Text""#32770")) int h int r=sub.GetInsertedTextCaretPosition(1 h) int line=SendMessage(h SCI.SCI_LINEFROMPOSITION r 0) int lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0) SendMessage(h SCI.SCI_SETSEL r lpe) SendMessage(h SCI.SCI_COPY00)
_s.getclip()
_s.findreplace("text" s1)
_s+F";;{s2}"
_s.setclip SendMessage(h SCI.SCI_PASTE00)
#sub InsertionPoint function~name int i =qmitem(name)
_s.getmacro(i) str ss int ii ln pos lpe foreach ss _s ,if ss.beg("#sub") ,,ln= ii-1 ,,break ,ii+1 mac+ name int h=GetQmCodeEditor if ln>0 ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ln 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ln 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h else ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ii 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ii 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h ,key Y ;; Enter
#sub GetInsertedTextCaretPosition function# [flags][&c];;flags: 1 go to that position if(!c) ,c=GetQmCodeEditor SendMessage(c SCI.SCI_UNDO00) int r=SendMessage(c SCI.SCI_GETCURRENTPOS00) SendMessage(c SCI.SCI_REDO00) if(flags&1)SendMessage(c SCI.SCI_GOTOPOS r 0) ret r
out str s.getsel str s1 ;;string variable. If need numeric, replace str with int or double. if(!inp(s1 "Enter AutoText Abbreviation""""text"))ret str s2 ;;string variable. If need numeric, replace str with int or double. if(!inp(s2 "Enter a phrase description""""description"))ret
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn int ii=ListDialog(_s);if(ii=0)ret ;2.code:Open selected Autotext SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog
_s.getl(_s ii-1) ;3.code:The cursor is positioned ;find insertion point int h sub.InsertionPoint(_s h) ;insert autotext TO_Fav"TO_Text"00 int w=wait(0 WA win("Text""#32770")) butid(6 w);;check box 'Multiline'
s.setwintext(id(3 w)) butid(1 w);; close to text window and insert code into autotext function ;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2 wait(0 WD win("Text""#32770")) int r=sub.GetInsertedTextCaretPosition(1) int line=SendMessage(h SCI.SCI_LINEFROMPOSITION r 0) int lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0) SendMessage(h SCI.SCI_SETSEL r lpe) SendMessage(h SCI.SCI_COPY00)
_s.getclip()
_s.findreplace("text" s1)
_s+F";;{s2}"
_s.setclip SendMessage(h SCI.SCI_PASTE00)
#sub InsertionPoint function~name int&h int i =qmitem(name)
_s.getmacro(i) str ss int ii ln pos lpe foreach ss _s ,if ss.beg("#sub") ,,ln= ii-1 ,,break ,ii+1 mac+ name
h=GetQmCodeEditor if ln>0 ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ln 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ln 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h else ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ii 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ii 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h ,key Y ;; Enter
#sub GetInsertedTextCaretPosition function# [flags] ;;flags: 1 go to that position int c=GetQmCodeEditor SendMessage(c SCI.SCI_UNDO00) int r=SendMessage(c SCI.SCI_GETCURRENTPOS00) SendMessage(c SCI.SCI_REDO00) if(flags&1)SendMessage(c SCI.SCI_GOTOPOS r 0) ret r
if still having issues i will get back to you after i awaken.
In addition, I also need to consider a situation, if the defined phrase acronym already exists, the new phrase, created to the existing at the next line, can be achieved?
04-04-2019, 12:20 AM (This post was last modified: 04-04-2019, 02:27 AM by win.)
I added an input box, In the input dialog, I added two ways to display the AutoText.
One is the combo box. In this way, after selecting the item, you need to press the ok button.
One is a list box. In this way, after double-clicking the project, execute it directly. How to achieve?
I have an idea:
When the AutoText file is opened, the insertion point is always positioned immediately at the beginning of the second line. Please see the position of the image below.
In this way, the newly added phrase is always at the top and there will never be an unknown error.
The newly added phrase is always at the top, very convenient to view. At present, I don't understand the main code. Can you help me to modify it? thank you very much
Macro Add autotext
Trigger CSAa
out str s.getsel ;str s1 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s1 "Enter AutoText Abbreviation" "" "text")) ret ;str s2 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s2 "Enter a phrase description" "" "description")) ret
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
;2.code:Open selected Autotext ;int ii=ListDialog(_s); if(ii=0) ret ;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog ;_s.getl(_s ii-1) int ii=val(cb5) SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii];; opens autotext file selected in dialog
_s.getl(_s ii) ;3.code:The cursor is positioned ;find insertion point int h sub.InsertionPoint(_s h) ;insert autotext TO_Fav"TO_Text"00 int w=wait(0 WA win("Text""#32770")) butid(6 w);;check box 'Multiline'
s.setwintext(id(3 w)) butid(1 w);; close to text window and insert code into autotext function ;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2 wait(0 WD win("Text""#32770")) int r=sub.GetInsertedTextCaretPosition(1) int line=SendMessage(h SCI.SCI_LINEFROMPOSITION r 0) int lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0) SendMessage(h SCI.SCI_SETSEL r lpe) SendMessage(h SCI.SCI_COPY00)
_s.getclip()
_s.findreplace("text" s1)
_s+F";;{s2}"
_s.setclip SendMessage(h SCI.SCI_PASTE00)
#sub InsertionPoint function~name int&h int i =qmitem(name)
_s.getmacro(i) str ss int ii ln pos lpe foreach ss _s ,if ss.beg("#sub") ,,ln= ii-1 ,,break ,ii+1 mac+ name
h=GetQmCodeEditor if ln>0 ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ln 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ln 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h else ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ii 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ii 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h ,key Y ;; Enter
#sub GetInsertedTextCaretPosition function# [flags] ;;flags: 1 go to that position int c=GetQmCodeEditor SendMessage(c SCI.SCI_UNDO00) int r=SendMessage(c SCI.SCI_GETCURRENTPOS00) SendMessage(c SCI.SCI_REDO00) if(flags&1)SendMessage(c SCI.SCI_GOTOPOS r 0) ret r
At present, the AutoText list does not show the folder where it is located. How to display the AutoText in the form of a directory tree, please see the image below.
I didn't find this control in the dialog editor, I hope someone can provide an example for this function, thank you very much
04-04-2019, 02:45 AM (This post was last modified: 04-04-2019, 02:49 AM by Kevin.)
you need to go back and read again qm help about dialogs as you really don't understand at all how they work or the controls in them work. In the post with the list box and the combo box the list box will not work how you want. You created a dialog with no dialog procedure. the list box is useless.
Again i will say the list box is useless in its current configuration it will never do what you want. You really need to understand dialogs and controls before trying to implement them
04-04-2019, 03:01 AM (This post was last modified: 04-04-2019, 03:05 AM by win.)
@kevin
thank you for your help, The code has been updated,
Currently, using the controls in the dialog box, there is no problem, I want to make the operation more perfect, but my programming level is limited.
The code of the dialog example, I can understand some, but the actual application is a bit difficult
Code using a list box
out str s.getsel ;str s1 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s1 "Enter AutoText Abbreviation" "" "text")) ret ;str s2 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s2 "Enter a phrase description" "" "description")) ret
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn
;2.code:Open selected Autotext ;int ii=ListDialog(_s); if(ii=0) ret ;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog ;_s.getl(_s ii-1)
;int ii=val(cb5) ;;use cb5 int ii=val(lb6);;use lb6 SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii];; opens autotext file selected in dialog
_s.getl(_s ii) ;3.code:The cursor is positioned ;find insertion point int h sub.InsertionPoint(_s h) ;insert autotext TO_Fav"TO_Text"00 int w=wait(0 WA win("Text""#32770")) butid(6 w);;check box 'Multiline'
s.setwintext(id(3 w)) butid(1 w);; close to text window and insert code into autotext function ;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2 wait(0 WD win("Text""#32770")) int r=sub.GetInsertedTextCaretPosition(1) int line=SendMessage(h SCI.SCI_LINEFROMPOSITION r 0) int lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0) SendMessage(h SCI.SCI_SETSEL r lpe) SendMessage(h SCI.SCI_COPY00)
_s.getclip()
_s.findreplace("text" s1)
_s+F";;{s2}"
_s.setclip SendMessage(h SCI.SCI_PASTE00)
#sub InsertionPoint function~name int&h int i =qmitem(name)
_s.getmacro(i) str ss int ii ln pos lpe foreach ss _s ,if ss.beg("#sub") ,,ln= ii-1 ,,break ,ii+1 mac+ name
h=GetQmCodeEditor if ln>0 ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ln 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ln 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h else ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ii 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ii 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h ,key Y ;; Enter
#sub GetInsertedTextCaretPosition function# [flags] ;;flags: 1 go to that position int c=GetQmCodeEditor SendMessage(c SCI.SCI_UNDO00) int r=SendMessage(c SCI.SCI_GETCURRENTPOS00) SendMessage(c SCI.SCI_REDO00) if(flags&1)SendMessage(c SCI.SCI_GOTOPOS r 0) ret r
out str s.getsel ;str s1 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s1 "Enter AutoText Abbreviation" "" "text")) ret ;str s2 ;;string variable. If need numeric, replace str with int or double. ;if(!inp(s2 "Enter a phrase description" "" "description")) ret
;1.code:Get a list of all AutoText files QMITEM q;int i ARRAY(str) atn ARRAY(int) htvi rep ,i=qmitem(-i 1|16&q 1|2|4|8) ,if(i=0)break ,if q.itype=4 ,,atn[]=q.name ,,htvi[]=q.htvi
_s=atn
str s1 s2
s1=e3
s2=e4 ;2.code:Open selected Autotext ;int ii=ListDialog(_s); if(ii=0) ret ;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog ;_s.getl(_s ii-1)
;int ii=val(cb5) ;;use cb5 int ii=val(lb6);;use lb6 SendMessageid(2202 _hwndqm)TVM_SELECTITEMTVGN_CARET htvi[ii];; opens autotext file selected in dialog
_s.getl(_s ii) ;3.code:The cursor is positioned ;find insertion point int h sub.InsertionPoint(_s h) ;insert autotext TO_Fav"TO_Text"00 int w=wait(0 WA win("Text""#32770")) butid(6 w);;check box 'Multiline'
s.setwintext(id(3 w)) butid(1 w);; close to text window and insert code into autotext function ;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2 wait(0 WD win("Text""#32770")) int r=sub.GetInsertedTextCaretPosition(1) int line=SendMessage(h SCI.SCI_LINEFROMPOSITION r 0) int lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION line 0) SendMessage(h SCI.SCI_SETSEL r lpe) SendMessage(h SCI.SCI_COPY00)
_s.getclip()
_s.findreplace("text" s1)
_s+F";;{s2}"
_s.setclip SendMessage(h SCI.SCI_PASTE00)
#sub InsertionPoint function~name int&h int i =qmitem(name)
_s.getmacro(i) str ss int ii ln pos lpe foreach ss _s ,if ss.beg("#sub") ,,ln= ii-1 ,,break ,ii+1 mac+ name
h=GetQmCodeEditor if ln>0 ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ln 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ln 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h else ,pos=SendMessage(h SCI.SCI_POSITIONFROMLINE ii 0) ,lpe=SendMessage(h SCI.SCI_GETLINEENDPOSITION ii 0) ,SendMessage(h SCI.SCI_GOTOPOS lpe 0) ,act h ,key Y ;; Enter
#sub GetInsertedTextCaretPosition function# [flags] ;;flags: 1 go to that position int c=GetQmCodeEditor SendMessage(c SCI.SCI_UNDO00) int r=SendMessage(c SCI.SCI_GETCURRENTPOS00) SendMessage(c SCI.SCI_REDO00) if(flags&1)SendMessage(c SCI.SCI_GOTOPOS r 0) ret r
meaning no matter what you enter in the dialog the abbreviation will always be "text" and the comment aka what you call a description will always be "description"
04-04-2019, 03:36 AM (This post was last modified: 04-04-2019, 04:06 AM by win.)
The above code has been fixed, my English is not well expressed, using Google Translate, this is also a big obstacle for me to learn programming, and Google search engine is not available in China.
Currently, after adding an AutoText, it will open. I want to add a checkbox to the dialog that will be open when it is selected. This will be more convenient