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
#1
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. Smile
_________________________________________________________
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  Confused


Macro Add AutoText
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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, The code below is an example, Suppose there are four AutoText files.

sel(ListDialog("Autotext1[]Autotext2[]Autotext3[]Autotext4"))
,case 1
,goto insert
,case 2
,goto insert
,case 3
,goto insert
,case 4
,goto insert
,case else ret

;insert

;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
lef 12 9 id(9999 w) 1 ;;toolbar, press button 'Text'

paste s

int w1=win("Text" "#32770")
lef 9 7 id(6 w1) 1 ;;Check box 'Multiline'
lef 48 4 id(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
#2
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  Shy

Or use a dialog box, it will be easier 

Function Add_AutoText_dialog
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 210 136 "Add AutoText"
;3 Edit 0x54030080 0x200 84 16 96 13 "text"
;4 Edit 0x54030080 0x200 84 40 96 13 "Description"
;5 ComboBox 0x54230243 0x0 84 64 96 213 ""
;6 Static 0x54000000 0x0 24 64 48 13 "Add to:"
;7 Static 0x54000000 0x4 24 16 48 13 "Abbreviation:"
;8 Static 0x54000000 0x4 24 40 48 13 "Description:"
;9 Button 0x54012003 0x0 60 92 116 8 "Open AutoText file after adding"
;1 Button 0x54030001 0x4 88 112 48 14 "Add"
;2 Button 0x54030000 0x4 152 112 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040800 "*" "" "" ""

str controls = "3 4 5 9"
str e3tex e4Des cb5 c9Ope
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
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
ret 1


Attached Files Image(s)
   
#3
this will get all the autotext files in left side
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

To_Text can be used

called like so
Code:
Copy      Help
TO_Fav "TO_Text" 0 0
#4
@kevin

Thanks for your help, the code has been modified, but it is still not finished.

The following code, the current test is normal!  Smile

Missing 2nd, 3rd, 4th step code  Idea

Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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, The code below is an example, Suppose there are four AutoText files.

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

int iSel=ListDialog(_s)
out atn[iSel]

TO_Fav "TO_Text" 0 0
int w1=act(win("Text" "#32770"))

;2.code:Open atn[iSel] file
;3.code:The cursor is positioned at the end of the last AutoText field

paste s
but id(6 w1) ;;check box 'Multiline'

;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2
#5
the problem is your understanding of the code
it errors because your count is off.
Code:
Copy      Help
;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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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
 
Code:
Copy      Help
TO_Fav "TO_Text" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
#6
The following code works fine, currently only the last step of the code   Tongue

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. Undecided


Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET htvi[ii-1];; opens autotext file selected in list dialog

TO_Fav "TO_Text" 0 0
int w1=act(win("Text" "#32770"))

;3.code:The cursor is positioned at the end of the last AutoText field

paste s
but id(6 w1) ;;check box 'Multiline'

;4.code:Replace the default Abbreviation with the variable s1, Add a description with the variable s2
#7
don't change the code don't need act at all

use setwintext
Code:
Copy      Help
TO_Fav "TO_Text" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
#8
setwintext  Is a good idea Exclamation
#9
better would probably be this

Code:
Copy      Help
TO_Fav "TO_Text" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s2.setwintext(id(3 w))
#10
s2 ???
It is a description  Huh
#11
you mean comment?

auto is formatted as such
 Autotext list text is a list of items, each in separate line. Item format:

Text - text that you must type to execute statements.
  • Can be used any characters, including spaces, tabs and line breaks.
  • Can be used escape sequences.
statements - any commands that you can use in macros.
  • To separate multiple statements, use semicolons.
also why always make auto text use multiline?  most common autotext  is a single replacement

then again i don't know what your selecting at the beginning of the function either.
#12
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

Autotext Autotext2
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/p3

test :sub.Sub1 ;;description (It is the value of the variable s2) | test (It is the value of the variable s1)



#sub Sub1 m
_s=
;test autotext
paste _s
#13
what are you selecting before running this function?
#14
I set the global hotkey: CTRL+SHIFT+ALT+A

When I see useful code on some documents or web pages, select it, then press the hotkey, I can run the above code, which is very convenient


Now the code can do most of the work, but still need to manually modify the acronym, then add a comment Smile
#15
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?
#16
Now that only the last step has not been completed, developers can provide some solutions? Wink thank you very much
#17
this should do what ya need . Finds insertion position so no need to open the AutoText file and position cursor

Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
but id(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_COPY 0 0)
_s.getclip()
_s.findreplace("text" s1)
_s+ F";;{s2}"
_s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

#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_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
#18
Thank you for the work you have done for me, I am prompted for errors after testing.


Attached Files Image(s)
   
#19
try this 

Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
but id(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_COPY 0 0)
_s.getclip()
_s.findreplace("text" s1)
_s+ F";;{s2}"
_s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

#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_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


if still having issues i will get back to you after i awaken.
#20
There will be blank lines ,

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?


Attached Files Image(s)
   
#21
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?  Huh

Exclamation 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. Smile

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     Help - how to add the trigger to the macro
Code:
Copy      Help
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


str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 150 210 "Dialog" "4"
;3 Edit 0x54030080 0x200 28 19 96 12 ""
;4 Edit 0x54030080 0x200 28 42 96 12 ""
;5 ComboBox 0x54230243 0x0 28 64 96 213 ""
;6 ListBox 0x54230101 0x200 28 84 96 90 ""
;1 Button 0x54030001 0x4 24 182 48 14 "OK"
;2 Button 0x54030000 0x4 80 182 48 14 "Cancel"
;7 Button 0x54020007 0x0 8 4 134 198 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4 5 6"
str e3 e4 cb5 lb6
e3="text"
e4="description"
str s1 s2
s1=e3
s2=e4
_s=atn
cb5=_s
lb6=_s
if(!ShowDialog(dd 0 &controls)) ret

;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)
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
but id(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_COPY 0 0)
_s.getclip()
_s.findreplace("text" s1)
_s+ F";;{s2}"
_s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

#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_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


Attached Files Image(s)
   
#22
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


Attached Files Image(s)
   
#23
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.
#24
The three problems I am currently experiencing:

1. How to display the last modified item in the combo box, red arrow

2. How to double-click the item in the list box to execute immediately, without clicking the ok button, pink arrow

3. How to display the autotext list in the way of the directory tree, blue rectangle


Attached Files Image(s)
   
#25
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
#26
@kevin
thank you for your help, Heart 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 Shy

Code using a list box


Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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 dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 150 210 "Dialog" "4"
;3 Edit 0x54030080 0x200 28 19 96 12 ""
;4 Edit 0x54030080 0x200 28 42 96 12 ""
;5 ComboBox 0x54230243 0x0 28 64 96 213 ""
;6 ListBox 0x54230101 0x200 28 84 96 90 ""
;1 Button 0x54030001 0x4 24 182 48 14 "OK"
;2 Button 0x54030000 0x4 80 182 48 14 "Cancel"
;7 Button 0x54020007 0x0 8 4 134 198 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4 5 6"
str e3 e4 cb5 lb6
e3="text"
e4="description"
str s1 s2
s1=e3
s2=e4
cb5=_s
lb6=_s
if(!ShowDialog(dd 0 &controls)) ret

;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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
but id(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_COPY 0 0)
_s.getclip()
_s.findreplace("text" s1)
_s+ F";;{s2}"
_s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

#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_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
#27
Your code does not work their is a problem

s1 will always be "text"
s2 will always be description
#28
I just found out, thank you reminder   Big Grin

now code is ok

Macro Add autotext
Trigger CSAa     Help - how to add the trigger to the macro
Code:
Copy      Help
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 dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 150 210 "Dialog" "4"
;3 Edit 0x54030080 0x200 28 19 96 12 ""
;4 Edit 0x54030080 0x200 28 42 96 12 ""
;5 ComboBox 0x54230243 0x0 28 64 96 213 ""
;6 ListBox 0x54230101 0x200 28 84 96 90 ""
;1 Button 0x54030001 0x4 24 182 48 14 "OK"
;2 Button 0x54030000 0x4 80 182 48 14 "Cancel"
;7 Button 0x54020007 0x0 8 4 134 198 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4 5 6"
str e3 e4 cb5 lb6
e3="text"
e4="description"

cb5=_s
lb6=_s
if(!ShowDialog(dd 0 &controls)) ret

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
SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_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" 0 0
int w=wait(0 WA win("Text" "#32770"))
but id(6 w) ;;check box 'Multiline'
s.setwintext(id(3 w))
but id(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_COPY 0 0)
_s.getclip()
_s.findreplace("text" s1)
_s+ F";;{s2}"
_s.setclip
SendMessage(h SCI.SCI_PASTE 0 0)

#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_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
#29
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"


alot of this is absolutely wrong

str controls = "3 4 5 6"
str e3 e4 cb5 lb6
e3="text"
e4="description"
str s1 s2
s1=e3
s2=e4
cb5=_s
lb6=_s
if(!ShowDialog(dd 0 &controls)) ret
 
with this no matter what you enter in the dialog e3 will always be text and e4 will always be description

to get values of controls when the dialog closes you need to get them after ShowDialog returns
like so
Code:
Copy      Help
str controls = "3 4 5 6"
str e3 e4 cb5 lb6
e3="text"
e4="description"
cb5=_s
lb6=_s
if(!ShowDialog(dd 0 &controls)) ret
str s1 s2
s1=e3
s2=e4
#30
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. Sad

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


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 14 Guest(s)