04-04-2019, 05:26 AM (This post was last modified: 04-04-2019, 05:27 AM by Kevin.)
let's assume that checkbox has been assigned id 8 by the dialog editor
when show dialog returns the variable for that control will be either
"1" if checked, "0" if unchecked
in the example below the variable is c8Ope
04-04-2019, 05:38 AM (This post was last modified: 04-04-2019, 05:41 AM by win.)
I saw in the code that there are subfunctions that locate the insertion point.
I think if I position the insertion point to the front of the second line, is it simpler and more stable? Because I want to add the phrase, always at the top, how to modify the code? I tried to modify the code but always got an error
_________________________________________________________________________________________
My understanding of the smart dialog is not very deep, welcome to release the code of the smart dialog
By the way, change the insertion point to the second line begin
The above code works better than the previous code.
Double-click the AutoText list item to continue executing the code. I think I can only use the event handling of the smart dialog, but I don't know where to add the event.
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) if(c8Ope=0) ,men33285 _hwndqm ;;Close active item ,men33013 _hwndqm ;;Close Qm Window
#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 , mac+ name
h=GetQmCodeEditor SendMessage(h SCI.SCI_GOTOLINE10)
#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
Three feature requests:
1. Edit box defaults to focus
2. The first AutoText project defaults to focus
3. Press the alt key to set the checkbox status.
Using the tree directory, I feel it may be more troublesome. I have an idea now, it might be simpler to implement.
by default,
The list box shows all AutoText items.
Combo box displays all AutoText folders
When I select an AutoText folder, the AutoText file in it is displayed in the list box.
here is the dialog
the checkbox is toggle by alt+y change to whatever you like(cannot be just alt)
edit 3 is now focused when dialog opens
double left in the list box launches the autotext code insertion
out str s.getsel ;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
#sub DlgProc v function# hDlg message wParam lParam
sel message ,caseWM_INITDIALOG ,DT_SetAccelerators(hDlg "400 Ay");; alt+y change to something else if you dont like (alt cannot be used by itself) ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseIDOK ,caseIDCANCEL ,case400 ,but*id(8 hDlg);;toggle checkbox ,caseLBN_DBLCLK<<16|6 ,str name ,_i=LB_SelectedItem(lParam &name) ,str s1 s2 c8 ,DT_GetControl(hDlg 3 s1) ,DT_GetControl(hDlg 4 s2) ;,2.code:Open selected Autotext ,mac+ name ;;;;3.code: find insertion point ,int h ,sub.InsertionPoint(name 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 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) ,DT_GetControl(hDlg 8 c8) ,if(c8=0) ,,men33285 _hwndqm ;;Close active item ,,men33013 _hwndqm ;;Close Qm Window ret1 #sub InsertionPoint function~name int&h mac+ name
h=GetQmCodeEditor SendMessage(h SCI.SCI_GOTOLINE10)
#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
04-04-2019, 08:42 AM (This post was last modified: 04-04-2019, 08:54 AM by win.)
Help when you are convenient, don't want to delay your energy
I just tested the code and When I click the OK button nothing happened.
Can't set two focus points?
Currently, the edit box gets the focus,
I hope that the top AutoText name is also focus
Double-click the item name of the AutoText to successfully add it, but clicking the OK button is a failure.
In addition, I want to double-click the name of the AutoText, the dialog box will automatically close, and then the screen will display a two-second prompt: Acronym: *** has been added successfully,
out str s.getsel ;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 controls ="3 4 5 6 8" str e3 e4 cb5 lb6 c8Ope
e3="Text"
e4="Description"
cb5=_s
lb6=_s if(!ShowDialog(dd &sub.DlgProc&controls))ret str s1 s2
s1=e3
s2=e4 ;2.code:Open selected Autotext ;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: 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) if(c8Ope=0) ,men33285 _hwndqm ;;Close active item ,men33013 _hwndqm ;;Close Qm Window OnScreenDisplayF"Acronym: {s1} has been added successfully"2
#sub DlgProc function# hDlg message wParam lParam
sel message ,caseWM_INITDIALOG ,DT_SetAccelerators(hDlg "400 Ay");; alt+y change to something else if you dont like (alt cannot be used by itself) ,SendMessageid(6 hDlg)LB_SETCURSEL00 ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseIDOK ,caseIDCANCEL ,case400 ,but*id(8 hDlg);;toggle checkbox ,caseLBN_DBLCLK<<16|6 ,DT_Ok hDlg ret1 #sub InsertionPoint function~name int&h mac+ name
h=GetQmCodeEditor SendMessage(h SCI.SCI_GOTOLINE10)
#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
04-04-2019, 04:30 PM (This post was last modified: 04-04-2019, 04:43 PM by win.)
@kevin
Thanks, it’s great
Currently only one function is not implemented.
By default, the list box displays all AutoText, and the combo box displays all the folders (for containing AutoText) When I select one of the folders, the list box can be displayed item inside (If there is no AutoText in the folder, it will be empty)
I will always give feedback on this feature (ctrl+alt+shift+A add autotext). When it is very stable, I hope more people can use it to facilitate work and study.
04-08-2019, 05:07 AM (This post was last modified: 04-08-2019, 05:30 AM by Kevin.)
your idea is indeed not simpler but will make it more complicated. Let qm figure out subfunction numbers it does it automatically already. We can however get rid of the text dialog.
I created a new dialog
looks like this
has multiline edit control for autotext statements. can be either normal or multiline autotext or can use it for making a template for keyAutoInput
still can can be launched by ctrl+shift+alt+a
will check if active window has selection and paste it into
multiline edit in dialog
template just needs the template code nothing else no leading space
Dear Mr. $inp_Customer$,
thank you for contacting us. The price is $$inp_Price$. Let's meet next $inp_Day$.
Myfile is here "$inp_Filepath$"
Thanks and best regards,
$set_CaretHere$
pcname is $var_pcname$
$var_ShortDate$
the dialog will add the remaining code needed to create the autotext for the template
here try this out
Function Add_AutoText_Dialog_New
Trigger CSAa
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" ;2 Button 0x54030000 0x4 304 184 48 14 "Cancel" ;END DIALOG ;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
sel message ,caseWM_INITDIALOG ,SendMessageid(3 hDlg)EM_SETCUEBANNERTRUE@"Enter Text" ,SendMessageid(4 hDlg)EM_SETCUEBANNERTRUE@"Enter Statements" ,SendMessageid(12 hDlg)EM_SETCUEBANNERTRUE@"Enter Comment" ,SendMessageid(5 hDlg)CB_SETCUEBANNER0@"Select Autotext file to add text to" ,;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET|TVGN_FIRSTVISIBLE q.htvi ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseIDOK ,caseIDCANCEL ,case10;;Add ,DT_Ok hDlg ,case13;;Multiline/Singlelin Autotext ,ifbut(id(13 hDlg)) ,,but-id(9 hDlg) ,case9;;Template for KeyAutoInputDialog ,ifbut(id(9 hDlg)) ,,but-id(13 hDlg) ret1
#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
04-08-2019, 06:59 AM (This post was last modified: 04-08-2019, 09:56 AM by win.)
very good!!!
Your dialog box is very refined. I just found out that I found the error. Please see Figure 1 below.
In addition:
1. I still want to increase the Open AutoText checkbox, but use the hotkey to achieve, Press ctrl+Enter to perform the addition and open the AutoText
2. By default, the first AutoText file is selected,
3. When no acronym is entered, the default output is Text. When no comment is entered, the default output: Description
4. When Template for keyAutoInputDialog is selected, the +inp name button will appear on the left, click on it to generate a field, for example: $inp_***$
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" ;14 Button 0x54012003 0x4 224 161 106 10 "Open Autotext (Ctrl+Enter)" "After adding, open the AutoText, or press the hotkey directly: Ctrl+Enter" ;15 Button 0x54032000 0x0 6 68 48 14 "+ inp name" ;2 Button 0x54030000 0x4 304 184 48 14 "Cancel" ;END DIALOG ;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""
sel message ,caseWM_INITDIALOG ,SendMessageid(3 hDlg)EM_SETCUEBANNERTRUE@"Enter Text" ,SendMessageid(4 hDlg)EM_SETCUEBANNERTRUE@"Enter Statements" ,SendMessageid(12 hDlg)EM_SETCUEBANNERTRUE@"Enter Comment" ,SendMessageid(5 hDlg)CB_SETCUEBANNER0@"Select Autotext file to add text to" ,;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET|TVGN_FIRSTVISIBLE q.htvi ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseIDOK ,caseIDCANCEL ,case10;;Add ,DT_Ok hDlg ,case13;;Multiline/Singlelin Autotext ,ifbut(id(13 hDlg)) ,,but-id(9 hDlg) ,case9;;Template for KeyAutoInputDialog ,ifbut(id(9 hDlg)) ,,but-id(13 hDlg) ret1
#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
sel message ,caseWM_INITDIALOG ,SendMessageid(3 hDlg)EM_SETCUEBANNERTRUE@"Enter Text" ,SendMessageid(4 hDlg)EM_SETCUEBANNERTRUE@"Enter Statements" ,SendMessageid(12 hDlg)EM_SETCUEBANNERTRUE@"Enter Comment" ,SendMessageid(5 hDlg)CB_SETCUEBANNER0@"Select Autotext file to add text to" ,;SendMessage id(2202 _hwndqm) TVM_SELECTITEM TVGN_CARET|TVGN_FIRSTVISIBLE q.htvi ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseIDOK ,caseIDCANCEL ,case10;;Add ,DT_Ok hDlg ,case13;;Multiline/Singlelin Autotext ,ifbut(id(13 hDlg)) ,,but-id(9 hDlg) ,case9;;Template for KeyAutoInputDialog ,ifbut(id(9 hDlg)) ,,but-id(13 hDlg) ret1
#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
I have an idea, the default comment, shows the first three words of the statement
04-09-2019, 04:36 AM (This post was last modified: 04-09-2019, 04:38 AM by Kevin.)
"I just found out that I found the error. Please see Figure 1 below."
is not an error its by design
was intended to make autotext template for pasting into other functions not to run KeyAutoInputDialog from auto text
"I have an idea, the default comment, shows the first three words of the statement"
not a good idea what if first line is blank or /b/i/c/m or / or any other number of things. Just making more work trying to parse text when don't need to.
04-09-2019, 12:52 PM (This post was last modified: 04-09-2019, 01:02 PM by Kevin.)
Again please read and understand what i said. The code was not designed to do what your trying to do. Its is not a bug or an error. Your simply trying to do something that the code was not designed to do and expecting different results.
no time to redo the code right now sorry. Maybe in about 12 hours.