Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass items in two combo boxes
#1
How to display the items in the list selection dialog directly to the combo box on the right, as shown in the picture below

The best way is that when I click on an item in the left combo box, the right combo box can directly display the items in it. Smile

This is a comprehensive example, I hope someone can finish it, thanks in advance



Macro Macro3
Code:
Copy      Help
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 334 188 "Add AutoText"
;14 Button 0x54032000 0x0 144 12 48 14 "Edit"
;3 ComboBox 0x54230641 0x0 11 8 120 173 ""
;4 ComboBox 0x54230641 0x0 204 8 120 172 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040801 "*" "" "" ""

str controls = "3 4"
str cb3 cb4
cb3=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,CB_SelectString(id(3 hDlg) "test")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 10 ;;Add
,DT_Ok hDlg
,case 14 ;;Edit
,_s.getwintext(id(3 hDlg))
,str ssss items=sub.gotoitemedit(_s)
,items.replacerx("\Q:sub.\E|\;" "     ")
,_i=ListDialog(items "Which item to Edit" "Select item")
,if(_i=0) ret
,mac+ _s
,int c=GetQmCodeEditor
,SendMessage(c SCI.SCI_GOTOLINE _i 0)
,ssss.getl(items _i-1)
,ssss.trim
,;int ii=findrx(ssss "\d" 0 1)
,int ii=findrx(ssss "Sub." 0 1)
,int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
,cp+ii
,SendMessage(c SCI.SCI_GOTOPOS cp 0)

ret 1


#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_s.getmacro(name 0)
str ss d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i])

ret d.trim

The following code sometimes does not match the data, Huh for example:

Autotext test
Trigger $t     Help - how to add the trigger to the macro
Code:
Copy      Help
/b/i/c/m
ata :sub.Sub2 ;;china
tes :sub.Sub1 ;;commnet
hel :"hello world" ;;hello world


#sub Sub1 m ;;tes    commnet
_s=
F
;english name
;english name2
PasteAutoInputDialog(_s)


#sub Sub2 m ;;ata    china
_s=
F
;china
PasteAutoInputDialog(_s)
​​​​​​​

 
Code:
Copy      Help
#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_s.getmacro(name 0)
str ss d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i])

ret d.trim


Attached Files Image(s)
   
#2
single left click left combo to select item. Double left click right combo to open and goto code. Edit button is not needed


Function Dialog_Edit_Autotext
Code:
Copy      Help
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 334 188 "Edit Existing AutoText"
;3 ComboBox 0x54230641 0x0 11 8 120 173 ""
;4 ComboBox 0x54230641 0x0 145 8 174 172 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4"
str cb3 cb4
cb3=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,CB_SelectString(id(3 hDlg) "test")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
int hcb2=id(4 hDlg) ;;combo box
sel wParam
,case IDOK
,case IDCANCEL
,case 10 ;;Add
,DT_Ok hDlg
,case CBN_SELENDOK<<16|3
,str cb1si
,_i=CB_SelectedItem(lParam cb1si)
,str cb2ii itemscb2=sub.gotoitemedit(cb1si)
,SendMessage(hcb2 CB_RESETCONTENT 0 0)
,itemscb2.findreplace(":sub." "     ")
,itemscb2.findreplace(";;" "     ")
,foreach cb2ii itemscb2
,,CB_Add(hcb2 cb2ii)    
,case CBN_DBLCLK<<16|4
,str cb2t
,_i=CB_SelectedItem(lParam cb2t)
,_s.getwintext(id(3 hDlg))
,mac+ _s
,int c=GetQmCodeEditor
,SendMessage(c SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(cb2t "Sub." 0 1)
,int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
,cp+ii
,SendMessage(c SCI.SCI_GOTOPOS cp 0)    
ret 1


#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_s.getmacro(name 0)
str ss d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i])

ret d.trim
#3
Wow, the effect is great. Tongue

But a single-line AutoText cannot match the data.  E.g
______________________________________
/b/i/c/m
ata Confusedub.Sub2 ;;china
tes Confusedub.Sub1 ;;commnet
hel :"hello world" ;;hello world
______________________________________

In addition, I need to change the items in the list to the following, is it possible?

ata   Sub2      china
tes   Sub1      commnet

To
2    ata      china
1    tes      commnet
#4
yes would need to change the pattern findrx searches for and would also need to adjust find replace code as well

"In addition, I need to change the items in the list to the following, is it possible?"
possible yes but i forsee a problem when autotext is only single line.
#5
I added a filter search function to the edit box in the combo box (This is very useful when there are a lot of items in the list), see the GIF below.

But The only problem now is that

the filtered results cannot be displayed in real time in the list of combo boxes.

I searched a lot in the forum, but I didn't find the answer. Is this impossible?

Macro Code+filter
Code:
Copy      Help
[size=large]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


ARRAY(str) aList=atn
IQmDropdown ddl
int inERS


str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 188 "Edit Existing AutoText"
;3 ComboBox 0x54230641 0x0 11 8 120 173 ""
;4 ComboBox 0x54230641 0x0 145 8 174 172 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4"
str cb3 cb4
cb3=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,CB_SelectString(id(3 hDlg) "test")
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
int hcb2=id(4 hDlg) ;;combo box
sel wParam
,case IDOK
,case IDCANCEL
,case 10 ;;Add
,DT_Ok hDlg
,case CBN_SELENDOK<<16|3
,str cb1si
,_i=CB_SelectedItem(lParam cb1si)
,str cb2ii itemscb2=sub.gotoitemedit(cb1si)
,SendMessage(hcb2 CB_RESETCONTENT 0 0)
,itemscb2.findreplace(":sub." "     ")
,itemscb2.findreplace(";;" "     ")
,foreach cb2ii itemscb2
,,CB_Add(hcb2 cb2ii)
,case CBN_DBLCLK<<16|4
,str cb2t
,_i=CB_SelectedItem(lParam cb2t)
,_s.getwintext(id(3 hDlg))
,mac+ _s
,int c=GetQmCodeEditor
,SendMessage(c SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(cb2t "Sub." 0 1)
,int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
,cp+ii
,SendMessage(c SCI.SCI_GOTOPOS cp 0)
,
,case CBN_EDITCHANGE<<16|3 sub.OnTextChanged lParam
,
ret 1


#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_s.getmacro(name 0)
str ss d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i])

ret d.trim


#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret

if(ShowDropdownList(x i 0 1 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(i+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1
inERS=0[/size]



possible yes but i forsee a problem when autotext is only single line.

When a single line of text, the front number shows 0
Idea

There is a problem now

When I press the esc key, the dialog will close.

I want to implement:
A. when I press the esc key,
empty the contents of the edit box in the upper left corner, and the cursor is positioned in the edit box.

B. When I press the esc key twice,
close the window.

How to achieve?


Attached Files Image(s)
   
#6
Current code, there are two questions: (Below is an animated GIF demo and related code)

1. After the highlight code is displayed, the cursor position is at the end, and F2 cannot be used directly.

2. If there is a single-line AutoText, the positioning is not accurate.
_____________________________________________________________________

I have a feature request:

When I press the  mouse right click on the AutoText, I can execute it instead of opening it.

For example, when I right click on sub.sub3, the Notepad program will open.


Autotext test
Trigger $t     Help - how to add the trigger to the macro

Code:
Copy      Help
[size=large]/b/i/c/m
ata :sub.Sub2 ;;china
tes :sub.Sub1 ;;commnet
te :"hello" ;;heloo
te :sub.Sub3 ;;run notepad

#sub Sub1 m ;;tes    commnet
_s=
F
;english name
;english name2
PasteAutoInputDialog(_s)


#sub Sub2 m ;;ata    china
_s=
F
;china
PasteAutoInputDialog(_s)


#sub Sub3 m ;;te    run notepad

run "notepad"[/size]


Macro Code+filter
Code:
Copy      Help
[size=large]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


ARRAY(str) aList=atn
IQmDropdown ddl
int inERS


str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 334 188 "Edit Existing AutoText"
;3 ComboBox 0x54230641 0x0 11 8 120 173 ""
;4 ComboBox 0x54230641 0x0 145 8 174 172 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3 4"
str cb3 cb4
cb3=_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,CB_SelectString(id(3 hDlg) "test")
,
,case WM_DESTROY
,
,case WM_COMMAND goto messages2
ret
;messages2
int hcb2=id(4 hDlg) ;;combo box
sel wParam
,case IDOK
,
,case IDCANCEL
,
,case CBN_SELENDOK<<16|3
,str cb1si
,_i=CB_SelectedItem(lParam cb1si)
,str cb2ii itemscb2=sub.gotoitemedit(cb1si)
,SendMessage(hcb2 CB_RESETCONTENT 0 0)
,itemscb2.findreplace(":sub." "     ")
,itemscb2.findreplace(";;" "     ")
,foreach cb2ii itemscb2
,,CB_Add(hcb2 cb2ii)
,
,case CBN_DBLCLK<<16|4
,str cb2t
,_i=CB_SelectedItem(lParam cb2t)
,_s.getwintext(id(3 hDlg))
,mac+ _s
,int c=GetQmCodeEditor
,SendMessage(c SCI.SCI_GOTOLINE _i+1 0)
,int ii=findrx(cb2t "Sub." 0 1)
,int cp=SendMessage(c SCI.SCI_GETCURRENTPOS 0 0)
,cp+ii
,SendMessage(c SCI.SCI_GOTOPOS cp 0)
,
,SendMessage(c SCI.SCI_SETSELBACK 0 0x00FF00)
,'SE
,
,case CBN_EDITCHANGE<<16|3 sub.OnTextChanged lParam
,
ret 1


#sub gotoitemedit
function~ ~name

str pattern="(?:.*\:sub\..*)"

_s.getmacro(name 0)
str ss d
int i
ARRAY(str) a
findrx(_s pattern 0 4 a)
for i 0 a.len
,d.formata("%s[]" a[0 i])

ret d.trim


#sub OnTextChanged v
function hEdit

if(inERS) ret
if(ddl) ddl.Close; ddl=0

str s.getwintext(hEdit)
if(!s.len) ret

ICsv x._create
x.AddRow1(0 "")
int i
for i 0 aList.len
,if(find(aList[i] s 0 1)<0) continue
,x.AddRow1(-1 aList[i])
if(!x.RowCount) ret

if(ShowDropdownList(x i 0 1 hEdit 0 0 0 ddl)&QMDDRET_SELOK=0) ret
s=x.Cell(i+1 0)

inERS=1
EditReplaceSel hEdit 0 s 1
inERS=0[/size]


Attached Files Image(s)
   


Forum Jump:


Users browsing this thread: 1 Guest(s)