Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 12:21 AM
(This post was last modified: 01-17-2021, 12:57 AM by macman.)
hello everyone,
The following code can locate an entry in the Autotext File
However, after sorting the list items[M3 Line7], the positioning function fails
Is there a better solution to this problem? Any suggestions are welcome. Thanks in advance
In addition,
the cursor is at the beginning of a line, but why the result is not 1?[M3 Line49]
How to move the cursor to the back of the dot.? E.g: hw ub.Sub3
Macro M3
Trigger A1
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
;a.sort ;;After sorting, it is unable to locate accurately
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
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
,int hcb3=id(3 hDlg)
,str cb3t
,_i=CB_SelectedItem(hcb3 cb3t)
,mes cb3t
,mac+ "A1"
,int h=GetQmCodeEditor
,mes _i
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,
,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
,mes cp ;;Why the result is not 1
,
,case IDCANCEL
ret 1
Autotext A1
Trigger $t
/b/i/c/p3
fw :sub.Sub9
cp :sub.Sub7
es :sub.Sub5
hw :sub.Sub3
ba :sub.Sub2
abc :sub.Sub1
#sub Sub1 m
mes 1
#sub Sub2 m
mes 2
#sub Sub3 m
mes 3
#sub Sub5 m
mes 5
#sub Sub7 m
mes 7
#sub Sub9 m
mes 9
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-17-2021, 12:43 AM
(This post was last modified: 01-17-2021, 12:50 AM by Kevin.)
,mes cp ;;Why the result is not 1?
because it returns the character position of the line in the entire text of A1.
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 12:53 AM
(This post was last modified: 01-17-2021, 12:56 AM by macman.)
oh,
why, cp+9 The cursor Can't move behind the dot?
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-17-2021, 12:56 AM
(This post was last modified: 01-17-2021, 01:24 AM by Kevin.)
cp= position in qm editor
cp+9 means position + 9 more characters
the reason it fails after sorting is because the line positions of the text have changed
so easy fix
need to find the position again
this works with sorting
Macro M3
Trigger A1
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
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
,int hcb3=id(3 hDlg)
,str cb3t
,_i=CB_SelectedItem(hcb3 cb3t)
,out cb3t
,mac+ "A1"
,_s.getmacro("A1" 0)
,int cp1=findrx(_s cb3t)
,out cp1
,int h=GetQmCodeEditor
,SendMessage(h SCI.SCI_GOTOPOS cp1 0)
,case IDCANCEL
ret 1
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 01:25 AM
(This post was last modified: 01-17-2021, 01:26 AM by macman.)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
mes cp
SendMessage(h SCI.SCI_SETSEL cp cp+9)
It can move to the back of the dot, but it's unstable
Posts: 1,338
Threads: 61
Joined: Jul 2006
all of your code under case ID_OK should be moved. it isn't needed there as can do the same after the dialog closes
this is where it should be
Macro M3
Trigger A1
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
out cb3
_s.getmacro("A1" 0)
int cp=findrx(_s cb3)
out cp
mac+ "A1"
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_GOTOPOS cp 0)
SendMessage(h SCI.SCI_SETSEL cp cp+9)
#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
Posts: 125
Threads: 20
Joined: Jan 2021
I added code on line 10 to remove useless characters, and now the location is invalid
Macro M4
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
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
,int hcb3=id(3 hDlg)
,str cb3t
,_i=CB_SelectedItem(hcb3 cb3t)
,out cb3t
,mac+ "A1"
,_s.getmacro("A1" 0)
,int cp1=findrx(_s cb3t)
,out cp1
,int h=GetQmCodeEditor
,SendMessage(h SCI.SCI_GOTOPOS cp1 0)
,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
,out cp
,case IDCANCEL
ret 1
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-17-2021, 02:35 AM
(This post was last modified: 01-17-2021, 02:37 AM by Kevin.)
If it was me, I wouldn't do that.
But if you must this will work with the example.
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
out cb3
int cp1=findrx(_s cb3 0 1)
out cp1
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
out cp
#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
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 02:47 AM
(This post was last modified: 01-17-2021, 02:54 AM by macman.)
In many cases, the cursor cannot be displayed
This is a final example:
Autotext A1 comment added
The ;; was removed from the M4 Line11
In many cases, the cursor cannot be displayed
Macro M4
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.replacerx(";;" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
out cb3
int cp1=findrx(_s cb3 0 1)
out cp1
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
out cp
#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
Autotext A1
Trigger $t
/b/i/c/p3
fw :sub.Sub9 ;;test9
cp :sub.Sub7 ;;test
es :sub.Sub5 ;;test2
hw :sub.Sub3
ba :sub.Sub2 ;;test0
abc :sub.Sub1 ;;test5
#sub Sub1 m
mes 1
#sub Sub2 m
mes 2
#sub Sub3 m
mes 3
#sub Sub5 m
mes 5
#sub Sub7 m
mes 7
#sub Sub9 m
mes 9
Posts: 1,338
Threads: 61
Joined: Jul 2006
try this
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
out cb3
int cp1=findrx(_s cb3 0 1)
out cp1
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_SETEMPTYSELECTION cp1 0)
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
;int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentposition
;out cp
#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
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 03:30 AM
(This post was last modified: 01-17-2021, 03:35 AM by macman.)
still many cases, the cursor cannot be displayed
1.Line11 added a line of code
2.Autotext A1 added comment
Posts: 1,338
Threads: 61
Joined: Jul 2006
sorry got busy for a few
the more you keep changing the string that is in combo box the more difficult it will be to find in qm editor.
try this
Macro M4
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.replacerx(";;" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
cb3.trim
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
out cb3
cb3.replacerx("\s+(\w+)" " ;;${1}" 4)
out cb3
int cp1=findrx(_s cb3 0 1)
out cp1
int h=GetQmCodeEditor
SendMessage(h SCI.SCI_CLEARSELECTIONS 0 0)
0.1
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos: begin of the line
out cp
#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
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 03:52 AM
(This post was last modified: 01-17-2021, 03:52 AM by macman.)
Instability, sometimes success, sometimes failure The cursor is not displayed
Posts: 1,338
Threads: 61
Joined: Jul 2006
don't know what to tell you works every time for me
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 03:56 AM
(This post was last modified: 01-17-2021, 03:57 AM by macman.)
act h
With the above code added, the test is now successful
Thank you very much for your help. It took you too much time
Posts: 1,338
Threads: 61
Joined: Jul 2006
here is 1 more piece of code to add
will move cursor to the subname so you can then press F2 to then move to the subfunction code for that autotext.
Macro M4
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.replacerx(";;" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3"
str cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
cb3.trim
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
cb3.replacerx("\s+(\w+)" " ;;${1}" 4)
int cp1=findrx(_s cb3 0 1)
int h=GetQmCodeEditor
act h
int ii=findrx(cb3 "sub." 0 1)
if ii!=-1
,cp1=cp1+ii+5
out cp1
act h
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos
out cp
#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
Posts: 125
Threads: 20
Joined: Jan 2021
@ Kevin
If the comment is a double byte character test failure
Posts: 1,338
Threads: 61
Joined: Jul 2006
post autotext comment where it fails.
I tried with 5 different double byte characters and worked for me
Posts: 125
Threads: 20
Joined: Jan 2021
test below
Autotext A1
Trigger $t
/b/i/c/p3
fw :sub.Sub9 ;;中文
cp :sub.Sub7 ;;test,.
es :sub.Sub5 ;;test2
hw :sub.Sub3
ba :sub.Sub2 ;;test0
abc :sub.Sub1 ;;test5
#sub Sub1 m
mes 1
#sub Sub2 m
mes 2
#sub Sub3 m
mes 3
#sub Sub5 m
mes 5
#sub Sub7 m
mes 7
#sub Sub9 m
mes 9
Posts: 125
Threads: 20
Joined: Jan 2021
I added a grid control to the code
Can achieve the same effect as combo box?
Double click an element in the grid to open the corresponding entry in the autotext
The visual effect of the grid is very good
Macro Macro8-ok
str pattern="(?:.*\:sub\..*)"
_s.getmacro("A1" 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort
for i 0 a.len
,d.formata("%s[]" a[0 i])
d.replacerx(":sub.Sub" " ") ;;Delete useless characters
d.replacerx(";;" " ") ;;Delete useless characters
d.trim
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 154 "Dialog" "4"
;3 ComboBox 0x54230641 0x0 8 8 96 122 ""
;4 QM_Grid 0x56031041 0x200 108 8 110 120 "0x0,0,0,0x0,0x0[]Abbr,30%,,[]#,20%,,[]Comment,50%,,"
;1 Button 0x54030001 0x4 112 136 48 14 "OK"
;2 Button 0x54030000 0x4 168 136 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040B01 "*" "" "" ""
str controls = "3 4"
str cb3 qmg4x
cb3=d
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
TO_CBGetItem(cb3)
cb3.trim
mac+ "A1"
_s.getmacro("A1" 0)
cb3.replacerx("\s+" " :sub.Sub" 4)
cb3.replacerx("\s+(\w+)" " ;;${1}" 4)
int cp1=findrx(_s cb3 0 1)
int h=GetQmCodeEditor
act h
int ii=findrx(cb3 "sub." 0 1)
if ii!=-1
,cp1=cp1+ii+5
out cp1
act h
SendMessage(h SCI.SCI_GOTOPOS cp1 0)
int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0) ;;currentpos
out cp
#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
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-17-2021, 03:05 PM
(This post was last modified: 01-18-2021, 01:17 AM by Kevin.)
I have a grid example somewhere just don't have time to find it now. I have already done all this work before with autotext.
here is the older project not with sorted list but has an edit control with interactive list filtering
this gets all autotext files and put them in list .
will post later grid example of this
Function Dialog_Edit_Autotext
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 196 192 48 14 "Sort" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,itemslb2.findreplace(":sub." " ")
,itemslb2.findreplace(";;" " ")
,itemslb2.findreplace(":" " ")
,foreach lb2ii itemslb2
,,LB_Add(hlb2 lb2ii)
,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb2t)
,int lb6ic=LB_GetCount(lParam)
,if(lb6ic<>lb6lc)
,,ARRAY(str) b=itemslb2
,,for i 0 b.len
,,,if(StrCompare(b[i] lb2t)=0)
,,,,_i=i
,,,,break
,LB_SelectedItem(id(4 hDlg) _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(lb2t "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg) _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2)
,s=a
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
ret 1
#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d
#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)
#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)
ret R
#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)
ret R
#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd
#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items
Posts: 125
Threads: 20
Joined: Jan 2021
01-17-2021, 10:32 PM
(This post was last modified: 01-17-2021, 11:15 PM by macman.)
@ Kevin
Thank you for sharing. This is a very good case
The above code Line249-275 is repeatedly defined
Posts: 1,338
Threads: 61
Joined: Jul 2006
yes the whole sub function getAtItem is not needed. Cannot remember why I have it there. I removed it from code above
Posts: 125
Threads: 20
Joined: Jan 2021
01-18-2021, 01:38 AM
(This post was last modified: 01-18-2021, 01:54 AM by macman.)
Sometimes, if I select an item from the lb6 list box and press enter, the QM software crashes and I can't reproduce it right now
I didn't use the mouse during the operation:
1.type letters in E3 edit box, press enter to select the searched item, Use the arrow keys to select items
2.press tab twice, continue to type letters in E5 editbox, Use the arrow keys to select items
3.press enter, (In some cases, QM crashes)
In addition,
#19 Published AutoText files
Unable to locate the item with double byte characters 中文
Sometimes After the dialog box is closed
AutoText triggers are disabled, Cannot be enabled automatically, only manually
Posts: 1,338
Threads: 61
Joined: Jul 2006
I cannot reproduce crashing
I tested this with double byte characters as comments and as actual text and on win10 and win7 finds them all
Posts: 125
Threads: 20
Joined: Jan 2021
01-29-2021, 11:19 AM
(This post was last modified: 01-30-2021, 12:49 AM by macman.)
@ Kevin
#21 Code:
After pressing the sort button, it will add an empty line. See Gif Demo:
Posts: 1,338
Threads: 61
Joined: Jul 2006
Yes it does forgot to put the trim line in
find
,;;code: Write the sort result to the original file
add new line above
Posts: 125
Threads: 20
Joined: Jan 2021
01-30-2021, 05:12 AM
(This post was last modified: 01-30-2021, 05:20 AM by macman.)
@kevin
Thanks for your help!
I changed the code:
line 88: replacing the extra characters, It looks more concise
line 146: adding multi condition sorting
Now:
Double click on the AutoText entry and the location failed
In addition, automatically press F2 to locate the sub function. Is there a more stable solution?
Macro Dialog_Edit_Autotext_mod
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 196 192 48 14 "Sort" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." " ")
,;itemslb2.findreplace(";;" " ")
,;itemslb2.findreplace(":" " ")
,itemslb2.replacerx(":sub.Sub\d+\s;;" " ") ;;Replace extra characters
,foreach lb2ii itemslb2
,,LB_Add(hlb2 lb2ii)
,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb2t)
,int lb6ic=LB_GetCount(lParam)
,if(lb6ic<>lb6lc)
,,ARRAY(str) b=itemslb2
,,for i 0 b.len
,,,if(StrCompare(b[i] lb2t)=0)
,,,,_i=i
,,,,break
,LB_SelectedItem(id(4 hDlg) _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(lb2t "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg) _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2)
,s=a
,s.rtrim
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
ret 1
#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort(2 sub.Callback_q_sort) ;;add Multi condition sorting
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d
#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)
,
#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)
#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)
ret R
#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)
ret R
#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd
#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items
Posts: 125
Threads: 20
Joined: Jan 2021
01-31-2021, 01:54 AM
(This post was last modified: 01-31-2021, 01:56 AM by macman.)
@ Kevin
solved the problem with one line of code
Line 96:
but% id(7 hDlg) ;;Sort autotext
Is this method stable? need to add waiting time? For example, when there are many strings?
Now only F2 is left to navigate to the subfunction
Macro Dialog_Edit_Autotext_mod2
out
str- sItems
str- sdItems
sub.DisableEnableAutoText(1 "" sItems sdItems)
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 214 "Edit Existing AutoText"
;3 Edit 0x54030080 0x200 9 8 120 14 ""
;4 ListBox 0x54230101 0x200 9 22 120 157 ""
;5 Edit 0x54030080 0x200 145 8 174 14 ""
;6 ListBox 0x54330101 0x200 145 22 174 157 ""
;7 Button 0x54032000 0x0 196 192 48 14 "Sort" "Sort Autotext function in qm"
;1 Button 0x54030001 0x4 116 216 48 14 "OK"
;2 Button 0x54030000 0x4 168 216 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
str controls = "3 4 5 6"
str e3 lb4 e5 lb6
lb4=sItems
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
str- itemslb2
int- lb6lc
str- sItems
int i
str- sdItems
sel message
,case WM_INITDIALOG
,SetWindowSubclass((id(3 hDlg)) &sub.EditSubclassProc 3 0)
,SetWindowSubclass((id(5 hDlg)) &sub.EditSubclassProc 5 0)
,SetWindowSubclass(id(6 hDlg) &sub.ListBoxSubclassProc 6 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_TIMER
,sel wParam
,,case 1
,,KillTimer hDlg wParam
,,int hlb=id(4 hDlg)
,,SendMessage hlb LB_RESETCONTENT 0 0
,,str s3 sEdit3.getwintext(id(3 hDlg))
,,foreach s3 sItems
,,,if(sEdit3.len and find(s3 sEdit3 0 1)<0) continue
,,,LB_Add hlb s3
,,int count=LB_GetCount(hlb)
,,if count=1;; auto select list item if only 1 item is left when searching
,,,SendMessage hDlg WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hlb) hlb
,,case 2
,,KillTimer hDlg wParam
,,int hlb2a=id(6 hDlg)
,,SendMessage hlb2a LB_RESETCONTENT 0 0
,,str s5 sEdit5.getwintext(id(5 hDlg))
,,foreach s5 itemslb2
,,,if(sEdit5.len and find(s5 sEdit5 0 1)<0) continue
,,,LB_Add hlb2a s5
,,int count2=LB_GetCount(hlb2a)
,,if count2=1
,,,LB_SelectItem(hlb2a 0)
ret
;messages2
int h=GetQmCodeEditor
int hlb2=id(6 hDlg) ;;list box 2
sel wParam
,case IDOK
,sub.DisableEnableAutoText(2 sdItems)
,case IDCANCEL
,sub.DisableEnableAutoText(3 sdItems)
,case EN_CHANGE<<16|3
,SetTimer hDlg 1 100 0
,case EN_CHANGE<<16|5
,SetTimer hDlg 2 100 0
,case LBN_SELCHANGE<<16|4
,str lb1si
,_i=LB_SelectedItem(lParam lb1si)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb1si)
,str lb2ii
,itemslb2=sub.gotoitemedit(lb1si)
,SendMessage(hlb2 LB_RESETCONTENT 0 0)
,;itemslb2.findreplace(":sub." " ")
,;itemslb2.findreplace(";;" " ")
,;itemslb2.findreplace(":" " ")
,itemslb2.replacerx(":sub.Sub\d+\s;;" " ") ;;Replace extra characters
,foreach lb2ii itemslb2
,,LB_Add(hlb2 lb2ii)
,lb6lc=LB_GetCount(hlb2)
,case LBN_DBLCLK<<16|4
,_i=LB_SelectedItem(lParam _s)
,mac+ _s
,case LBN_DBLCLK<<16|6
,but% id(7 hDlg) ;;Sort autotext
,str lb2t
,_i=LB_SelectedItem(lParam lb2t)
,if(_i=-1)
,,LB_SelectItem(lParam 0)
,,_i=LB_SelectedItem(lParam lb2t)
,int lb6ic=LB_GetCount(lParam)
,if(lb6ic<>lb6lc)
,,ARRAY(str) b=itemslb2
,,for i 0 b.len
,,,if(StrCompare(b[i] lb2t)=0)
,,,,_i=i
,,,,break
,LB_SelectedItem(id(4 hDlg) _s)
,mac+ _s
,act h
,SendMessage(h SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(lb2t "sub." 0 1)
,if ii!=-1
,,int cp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,,cp+ii
,,SendMessage(h SCI.SCI_GOTOPOS cp 0)
,sub.FlashCodeLine(_i+1 h)
,clo hDlg
,case 7 ;;Sort autotext in qm not dialog
,int sep
,LB_SelectedItem(id(4 hDlg) _s)
,str s=sub.getAutotextItem(_s sep)
,ARRAY(str) a=s
,a.sort(2 sub.Callback_q_sort)
,s=a
,s.rtrim
,;;code: Write the sort result to the original file
,mac+ _s
,h=GetQmCodeEditor
,act h
,SendMessage(h SCI.SCI_GOTOLINE 1 0)
,int ssp=SendMessage(h SCI.SCI_GETCURRENTPOS 0 0)
,SendMessage(h SCI.SCI_SETSEL ssp sep)
,s.setclip
,SendMessage(h SCI.SCI_PASTE 0 0)
ret 1
#sub gotoitemedit
function~ ~name
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0)
str d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
a.sort(2 sub.Callback_q_sort) ;;add Multi condition sorting
for i 0 a.len
,d.formata("%s[]" a[0 i].trim)
ret d
#sub Callback_q_sort
function# param str&a str&b
str s.gett(a -1 ":") ;str ss.gett(b -1 ":")
if(StrCompare(s ss)=0)
,ret StrCompare(a+findcr(a ';')+1 b+findcr(b ';')+1 1)
else
,ret StrCompare(a b 1)
,
#sub FlashCodeLine
function line hce
if(!hce) hce=GetQmCodeEditor
act hce
int indicator=19
SendMessage(hce SCI.SCI_SETINDICATORCURRENT indicator 0)
SendMessage(hce SCI.SCI_INDICSETALPHA indicator 100)
SendMessage(hce SCI.SCI_INDICSETFORE indicator 0x00FF00)
SendMessage(hce SCI.SCI_INDICSETSTYLE indicator SCI.INDIC_STRAIGHTBOX)
SendMessage(hce SCI.SCI_INDICSETUNDER indicator TRUE)
int lsp=SendMessage(hce SCI.SCI_POSITIONFROMLINE line 0)
int lep=SendMessage(hce SCI.SCI_GETLINEENDPOSITION line 0)
rep 4
,SendMessage(hce SCI.SCI_INDICATORFILLRANGE lsp lep-lsp)
,0.25
,SendMessage(hce SCI.SCI_INDICATORCLEARRANGE lsp lep-lsp)
,0.25
SendMessage(hce SCI.SCI_SETINDICATORCURRENT 0 0)
#sub EditSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
int Phwnd= GetParent(hwnd)
;OutWinMsg message wParam lParam
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_CHAR
,sel(wParam) case VK_RETURN ret 0
,case WM_KEYDOWN
,sel wParam ;;virtual key code
,,case VK_RETURN
,,;on enter in the edit box select the item in the list box
,,sel uIdSubclass
,,,case 3
,,,SendMessage Phwnd WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(id(4 Phwnd)) id(4 Phwnd)
,,,case 5
,,,SendMessage Phwnd WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(id(6 Phwnd)) id(6 Phwnd)
,,ret
,,case [VK_DOWN,VK_UP,VK_PRIOR,VK_NEXT]
,,;relay these keys to the listbox and not to the edit box
,,sel uIdSubclass
,,,case 3
,,,SendMessage id(4 Phwnd) message wParam lParam
,,,case 5
,,,SendMessage id(6 Phwnd) message wParam lParam
,,ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.EditSubclassProc uIdSubclass)
ret R
#sub ListBoxSubclassProc
function# hwnd message wParam lParam uIdSubclass dwRefData
sel message
,case WM_GETDLGCODE
,sel(wParam) case VK_RETURN ret DLGC_WANTALLKEYS ;;send WM_KEYDOWN instead of closing the dialog
,case WM_KEYDOWN
,sel(wParam) case VK_RETURN SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|uIdSubclass hwnd; ret
int R=DefSubclassProc(hwnd message wParam lParam)
sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.ListBoxSubclassProc uIdSubclass)
ret R
#sub DisableEnableAutoText
function mode [str'dati] [str&atItems] [str&atditems]
QMITEM q; int i
ARRAY(str) atn atd
rep
,i=qmitem(-i 1|16 &q 1)
,if(i=0) break
,if q.itype=4
,,atn[]=q.name
,,sel mode
,,,case 1 ;;disable
,,,if(dis(q.name)) atd[]=q.name
,,,else dis+ q.name
,,,case else ;;enable
,,,int fdat=findw(dati q.name 0 "[]")
,,,if fdat = -1
,,,,dis- q.name
if(mode <>1) ret
atItems=atn
atditems=atd
#sub getAutotextItem
function~ ~name &sep
str pattern="(?m)^(.+\s\:.+)"
_s.getmacro(name 0);
ARRAY(CHARRANGE) a; int i
findrx(_s pattern 0 4 a)
str items t
for i 0 a.len
,int offset(a[0 i].cpMin) length(a[0 i].cpMax-a[0 i].cpMin)
,t.get(_s offset length)
,items.formata("%s[]" t.trim)
,sep=offset+length
ret items
Posts: 125
Threads: 20
Joined: Jan 2021
01-31-2021, 09:06 AM
(This post was last modified: 01-31-2021, 12:25 PM by macman.)
@ Kevin
Sorting items function, in some cases
Some sub functions are deleted, It's because there are characters of AutoText in the sub function. Thanks @kevin
Autotext1
The test was successful
Autotext Autotext1
Trigger $t
/b/i/c/m
cbc :sub.Sub7 ;;1test
cbc :sub.Sub6 ;;2test
ax :sub.Sub5 ;;1test
ax :sub.Sub4 ;;3aest
ax :sub.Sub3 ;;2test
ax :sub.Sub2 ;;4test
zbc :sub.Sub1 ;;test1
#sub Sub1 m ;;zbc test1
mes 1
#sub Sub2 m ;;ax 4test
mes 2
#sub Sub3 m ;;ax 2test
mes 3
#sub Sub4 m ;;ax 3test
mes 4
#sub Sub5 m ;;ax 1test
mes 5
#sub Sub6 m ;;cbc 2test
mes 6
#sub Sub7 m ;;cbc 1test
mes 7
|