Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some operations of QM_Grid control
#1
Hi,

First of all, I would like to thank the QM developers. QM is very powerful and easy to understand. It is the best programming language I have ever seen

It took me less than an hour to create a file renaming program, This was impossible before. I'm not a professional programming developer
I encountered the following problems: 
My English expression is very poor. Watch the following pictures to demonstrate it more clearly
[Image: 1677808477]

Bug1: Drag and drop files to the grid, Bug no column 2
Add: 1.Prevent repeated addition; 2.Add from the last blank line

Bug2: Prefix Added repeatedly
Bug3: Suffix Added repeatedly

Add: matching text highlighting

Bug4: Match case does not work
Add: Support regular expressions

Sorry, I forgot a function in the presentation:
After deleting the text in the edit box, the second column in the grid will restore the original text

Thanks in advance for any suggestions and help
david

Macro Rener
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x8 0 0 408 160 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 0 0 292 160 "0x5,0,0,0x2,0x0[]Original Filename,60%,7,[]New Filename,40%,,"
;4 Edit 0x54030080 0x200 328 8 72 12 ""
;5 Edit 0x54030080 0x204 328 28 72 13 ""
;16 Edit 0x54030080 0x204 328 48 72 13 ""
;6 Static 0x54000000 0x0 301 9 48 13 "Prefix"
;7 Static 0x54000000 0x0 301 29 48 13 "Suffix"
;15 Static 0x54000000 0x4 301 49 48 13 "Ext"
;10 Button 0x54012003 0x0 354 76 48 10 "Regexp"
;13 Edit 0x54030080 0x204 328 89 72 13 ""
;14 Edit 0x54030080 0x204 328 108 72 13 ""
;11 Static 0x54000000 0x4 301 90 48 13 "Find"
;12 Static 0x54000000 0x4 301 110 48 12 "Replace"
;17 Button 0x54012003 0x4 301 76 48 10 "Match case"
;1 Button 0x54030001 0x4 300 140 48 14 "Run"
;2 Button 0x54030000 0x4 352 140 48 14 "Cancel"
;8 Button 0x54020007 0x0 296 0 108 66 ""
;9 Button 0x54020007 0x0 296 68 108 58 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3 4 5 16 10 13 14 17"
str qmg3x e4 e5 e16 c10Reg e13 e14 c17Mat

ARRAY(str) a
GetFilesInFolder a "$desktop$\Test"
;out a
for _i 0 a.len
,str fn.getfilename(a[_i] 1)
,_s.addline(F"{a[_i]},{fn}")
;out _s
qmg3x=_s

if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

DlgGrid g.Init(hDlg 3)
str nfn

sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(id(3 hDlg) hDlg 16)
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s=di.files
,,ARRAY(str) as=s
,,for _i 0 as.len
,,,fn.getfilename(as[_i] 1)
,,,_s.addline(F"{as[_i]},{fn}")
,,;out _s
,,str s_; int i_=g.RowsCountGet-1
,,;Bug1: Drag and drop files to the grid, Bug no column 2
,,;Add: 1.Prevent repeated addition; 2.Add from the last blank line
,,foreach s_ _s
,,,g.RowAddSetMS(i_ s_ 1)
,,,i_+1
,,ret DT_Ret(hDlg 1)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,for _i 0 g.RowsCountGet
,,fn=g.CellGet(_i 0)
,,nfn=g.CellGet(_i 1)
,,ren* fn nfn
,
,case IDCANCEL
,
,;Bug2: Added repeatedly
,case EN_CHANGE<<16|4 ;;Prefix
,str e4s.getwintext(id(4 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 1)
,,_s-F"{e4s}"
,,g.CellSet(_i 1 _s)
,
,;Bug3: Added repeatedly
,case EN_CHANGE<<16|5 ;;Suffix
,str e5s.getwintext(id(5 hDlg))
,str fn ex
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 1)
,,fn.getfilename(_s)
,,ex.GetFilenameExt(_s)
,,_s.from(fn e5s "." ex)
,,g.CellSet(_i 1 _s)
,
,case EN_CHANGE<<16|16 ;;Ext
,str e16s.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 1)
,,fn.getfilename(_s)
,,_s.from(fn "." e16s)
,,g.CellSet(_i 1 _s)
,
,;Add: matching text highlighting
,case EN_CHANGE<<16|13 ;;Find
,str e13s.getwintext(id(13 hDlg))
,
,;Bug4: Match case does not work
,;Add: Support regular expressions
,case EN_CHANGE<<16|14 ;;Replace
,e13s.getwintext(id(13 hDlg))
,str e14s.getwintext(id(14 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 1)
,,if(c17Mat) _s.findreplace(e13s e14s)
,,else _s.findreplace(e13s e14s 1)
,,g.CellSet(_i 1 _s)

ret 1


Attached Files
.zip   Test Files.zip (Size: 1.09 KB / Downloads: 81)
#2
Bug1: Drag and drop files to the grid, Bug no column 2
Resolved!
 
Code:
Copy      Help
,sel wParam
,,case 3 ;;drop
,,str s=di.files
,,ARRAY(str) as=s
,,str s1 s2
,,for _i 0 as.len
,,,fn.getfilename(as[_i] 1)
,,,s1.addline(F"{as[_i]}" 1)
,,,s2.addline(F"{fn}" 1)
,,int i_=g.RowsCountGet
,,int n=numlines(s1)
,,str ss1 ss2
,,for _i 0 n
,,,ss1.getl(s1 _i)
,,,ss2.getl(s2 _i)
,,,TO_LvAdd g.hwnd i_ 0 0 ss1 ss2
,,,i_+1
,,ret DT_Ret(hDlg 1)

It may be more appropriate to use g.RowAddSetMS function, but I don't know how to use it


Bug2: Prefix Added repeatedly
Bug3: Suffix Added repeatedly

Resolved!
 
Code:
Copy      Help
,case EN_CHANGE<<16|4 ;;Prefix
,str Pre.getwintext(id(4 hDlg))
,str Suf.getwintext(id(5 hDlg))
,str Ex.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 0)
,,fn.getfilename(_s)
,,if(empty(Ex)) Ex.GetFilenameExt(_s)
,,_s.from(Pre fn Suf "." Ex)
,,g.CellSet(_i 1 _s)
,
,case EN_CHANGE<<16|5 ;;Suffix
,Pre.getwintext(id(4 hDlg))
,Suf.getwintext(id(5 hDlg))
,Ex.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 0)
,,fn.getfilename(_s)
,,if(empty(Ex)) Ex.GetFilenameExt(_s)
,,_s.from(Pre fn Suf "." Ex)
,,g.CellSet(_i 1 _s)
,
,case EN_CHANGE<<16|16 ;;Ext
,Ex.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 1)
,,fn.getfilename(_s)
,,_s.from(fn "." Ex)
,,g.CellSet(_i 1 _s)
#3
Now there is only one last problem that has not been solved. There is a function I need in the find and replacement panel of QM (as shown in the figure below). Where can I find the code of this function?
[Image: 1677827049]

Bug4: Match case does not work
Resolved!

Code:
Copy      Help
,case EN_CHANGE<<16|14 ;;Replace
,str fi.getwintext(id(13 hDlg))
,str re.getwintext(id(14 hDlg))
,Pre.getwintext(id(4 hDlg))
,Suf.getwintext(id(5 hDlg))
,Ex.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 0)
,,fn.getfilename(_s)
,,if(empty(Ex)) Ex.GetFilenameExt(_s)
,,_s.from(Pre fn Suf "." Ex)
,,
,,if(but(id(17 hDlg))) _s.findreplace(fi re)
,,else _s.findreplace(fi re 1)
,,g.CellSet(_i 1 _s)

Add: Support regular expressions

There is only the last question. I don't understand regular expressions

It seems that the problem has been solved, but it may not be complete Smile


Code:
Copy      Help
,case EN_CHANGE<<16|14 ;;Replace
,str fi.getwintext(id(13 hDlg))
,str re.getwintext(id(14 hDlg))
,Pre.getwintext(id(4 hDlg))
,Suf.getwintext(id(5 hDlg))
,Ex.getwintext(id(16 hDlg))
,for _i 0 g.RowsCountGet
,,_s=g.CellGet(_i 0)
,,fn.getfilename(_s)
,,if(empty(Ex)) Ex.GetFilenameExt(_s)
,,_s.from(Pre fn Suf "." Ex)
,,
,,if(but(id(10 hDlg)) and but(id(17 hDlg)))
,,,_s.replacerx(fi re)
,,
,,if(but(id(10 hDlg)) and !but(id(17 hDlg)))
,,,_s.replacerx(fi re 1)
,,,
,,if(but(id(17 hDlg)) and !but(id(10 hDlg)))
,,,_s.findreplace(fi re)
,,else
,,,_s.findreplace(fi re 1)
,,g.CellSet(_i 1 _s)

The text in the rule needs to be escaped. If someone can improve it, thank you in advance


Forum Jump:


Users browsing this thread: 1 Guest(s)