#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-12-2019, 01:02 AM (This post was last modified: 04-12-2019, 01:04 AM by Kevin.)
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
04-12-2019, 01:07 AM (This post was last modified: 04-12-2019, 01:13 AM by win.)
I use Google Translate, I don't understand what you are describing, please forgive me.
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.
04-12-2019, 03:56 AM (This post was last modified: 04-12-2019, 03:59 AM by win.)
I have two new ideas.
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.
ret ;messages sel message ,caseWM_INITDIALOG ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseCBN_EDITCHANGE<<16|3 ,CB_AutoComplete lParam ,caseIDOK ,caseIDCANCEL ret1
;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]*))"04 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|400000"$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)
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" ,DT_SetAccelerators(hDlg "400 Az") ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseCBN_EDITCHANGE<<16|5 ,sub.CB_AutoComplete lParam ,caseIDOK ,caseIDCANCEL ,case10;;Add ,DT_Ok hDlg ,case13;;Multiline/Singlelin Autotext ,hidid(15 hDlg) ,hidid(16 hDlg) ,hidid(17 hDlg) ,case9;;Template for KeyAutoInputDialog ,hid-id(15 hDlg) ,hid-id(16 hDlg) ,hid-id(17 hDlg) ,case [15,400];;+ inp_name ,_s.getsel(00id(4 hDlg)) ,if _s.len ,,str s.from("$inp_" _s "$") ,,s.setsel(0id(4 hDlg)) ,else ,,mes"You must first select a word in the edit box" ,case16;;+ 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) ,actid(4 hDlg) ,paste aid_sel ,case17;;+ 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) ,actid(4 hDlg) ,paste aid_var 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
#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_SETEDITSEL0 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 04 aid_S) ,for i 0 aid_S.len ,,d.formata("%s[]" aid_S[0 i]) ret d.trim
04-17-2019, 01:59 AM (This post was last modified: 04-17-2019, 02:25 AM by win.)
Very beautiful, fully achieved the goal @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
04-17-2019, 08:02 AM (This post was last modified: 04-17-2019, 10:06 AM by win.)
I tried to add the code to the edit button
But there are three problems 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.
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" ,DT_SetAccelerators(hDlg "400 Az") ,caseWM_DESTROY ,caseWM_COMMANDgoto messages2 ret ;messages2 sel wParam ,caseCBN_EDITCHANGE<<16|5 ,sub.CB_AutoComplete lParam ,caseIDOK ,caseIDCANCEL ,case10;;Add ,DT_Ok hDlg ,case13;;Multiline/Singlelin Autotext ,hidid(15 hDlg) ,hidid(16 hDlg) ,hidid(17 hDlg) ,case9;;Template for KeyAutoInputDialog ,hid-id(15 hDlg) ,hid-id(16 hDlg) ,hid-id(17 hDlg) ,case [15,400];;+ inp_name ,_s.getsel(00id(4 hDlg)) ,if _s.len ,,str s.from("$inp_" _s "$") ,,s.setsel(0id(4 hDlg)) ,else ,,mes"You must first select a word in the edit box" ,case16;;+ 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) ,actid(4 hDlg) ,paste aid_sel ,case17;;+ 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) ,actid(4 hDlg) ,paste aid_var , ,case14;;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) 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
#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_SETEDITSEL0 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 04 aid_S) ,for i 0 aid_S.len ,,d.formata("%s[]" aid_S[0 i]) ret d.trim
04-18-2019, 03:43 AM (This post was last modified: 04-18-2019, 03:57 AM by win.)
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?
_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
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