;***************************************************** ;* Find & replace the texts in whole DB * ;***************************************************** ;*** Form window template *** defvar( moReplaceFormTemplate " \n FILE_TYPE=FORM_DEFN VERSION=2\n FORM\n FIXED\n PORT 60 0\n HEADER \"BATCH FIND & REPLACE v0.1\"\n TILE\n \n GRID moMainWindow\n FLOC 1 1\n FSIZE 40 10\n OPTIONS VLINES\n GHEAD TOP\n HEADSIZE 1\n ENDGHEAD\n ENDGRID\n \n FIELD moAddRow\n FLOC 49 1\n MENUBUTTON \"Add\" 10 3\n ENDFIELD\n \n FIELD moExecute\n FLOC 49 8\n MENUBUTTON \"Execute\" 10 3\n ENDFIELD\n \n ENDTILE\n ENDFORM\n " ) ;*** Initialize two columns (Find & Replace) *** procedure( moReplaceFormInitCols() let( ( moTempForm moTempCol) moTempForm = moReplaceForm moTempCol = make_formGridCol() moTempCol->fieldType = 'STRING moTempCol->colWidth = 20 moTempCol->align = 'left moTempCol->headText = "Find" axlFormGridInsertCol( moTempForm "moMainWindow" moTempCol) moTempCol->fieldType = 'STRING moTempCol->colWidth = 20 moTempCol->align = 'left moTempCol->headText = "Replace" axlFormGridInsertCol( moTempForm "moMainWindow" moTempCol) )) ;*** Initialize & add one row with default text ("") *** procedure( moReplaceFormInitRows() moTempForm = moReplaceForm axlFormGridInsertRows( moTempForm "moMainWindow" moRowsCnt 1) axlFormGridSetBatch( moTempForm "moMainWindow" 'moReplaceFormInitRowsCallBack nil) ) ;*** Call back function for moReplaceFormInitRows() *** procedure( moReplaceFormInitRowsCallBack( moTemp) let( ( moTempCell) moTempCell = axlFormGridNewCell() moTempCell->row = moRowsCnt moTempCell->col = 1 moTempCell->value = "" axlFormGridBatch( moTempCell) moTempCell->col = 2 axlFormGridBatch( moTempCell) moTempCell->value = nil )) ;*** Execute function (find & replace) *** procedure( moReplaceFormExecute( moRowNo) let( ( moTempCell moFind moReplace) moTempForm = moReplaceForm moTempCell = axlFormGridNewCell() axlSetFindFilter( ?enabled list( "noall" "text" "invisible") ?onButtons list( "noall" "text")) axlAddSelectAll() moAllTexts = axlGetSelSet() moTempCell->row = moRowNo moTempCell->col = 1 moFind = axlFormGridGetCell( moTempForm "moMainWindow" moTempCell)->value moTempCell->col = 2 moReplace = axlFormGridGetCell( moTempForm "moMainWindow" moTempCell)->value if( ( moFind == "" || moReplace == "" || strlen( moFind) < 3) ;filter for too short or unfiled inputs then printf( "Row %d ignored. Unfiled values or too short \"Find\" value (min. 3 char. required). \n" moRowNo) else foreach( moAllTexts axlGetSelSet() if( nindex( moAllTexts->text moFind) != nil then axlDBChangeText( moAllTexts pcreReplace( pcreCompile( moFind) moAllTexts->text moReplace 0)) ;main replace function ); end if ); end foreach ); end if axlClearSelSet() )) ;*** Start point of the main program section *** axlCmdRegister( "mo_bfr" 'mo_bfr ?cmdType "interactive" ?doneCmd nil ?cancelCmd nil) ;*** Main function *** defun( mo_bfr () moRowsCnt = 1 moReplaceForm = axlFormCreate( ( gensym) list( "form" moReplaceFormTemplate) nil 'moReplaceFormCallBack t ) moReplaceFormInitCols() moReplaceFormInitRows() axlFormGridEvents( moReplaceForm "moMainWindow" '( cellselect change)) axlFormGridUpdate( moReplaceForm "moMainWindow") axlFormDisplay( moReplaceForm) ;*** Add four more pre filled rows for( moLoop 1 4 moReplaceFormInitRows() axlFormGridUpdate( moReplaceForm "moMainWindow") moRowsCnt++ ) ;*** Call back function for moReplaceForm window *** defun( moReplaceFormCallBack (moReplaceFormRetVal) case( moReplaceFormRetVal->curField ( "moAddRow" if( moRowsCnt < 10 then moRowsCnt++ moReplaceFormInitRows() axlFormGridUpdate( moReplaceForm "moMainWindow") println( "Added new row") else println( "Max 10 rows per batch find & replace") ); end if ) ( "moExecute" for( moLoop 1 moRowsCnt moReplaceFormExecute( moLoop) ); end for ) ); end case ); end defun moReplaceFormCallBack ); end derun