Substitution

Post Reply
User avatar
rbytes
Posts: 1051
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Substitution

Post by rbytes » Sat Jul 01, 2017 12:40 am

This "Find and Replace" program saves a lot of time when you need to edit a program or other text file and make substitutions. I used a little browser trick to ensure that it would be easy to see the changes. Each time a substitution is made, all instances of it appear in a particular color. You can change your search parameters and repeat the substitution until it looks the way you want it to. This is a handy feature for renaming variables or interface objects.

When you are satisfied with the first substitution, you can make another. All instances of it will appear in a new color. Any previous changes will still be visible, but in their original color.

How is the colored text produced? I insert color tags into an HTML string surrounding each substitution, and use a browser to display the results.

Important! If you wish to make text changes manually, don't try to change text in the browser window! Press the Final button so that you get just the pure text to edit.

You can make up to 10 different substitutions. I could easily increase that maximum - but for this version I only defined ten web colors.

A lot of the screen's lower half is empty. That is because whenever you click the cursor into a field, the on-screen keyboard covers that area. If you use a Bluetooth keyboard, you can increase the height of the text fields and browser so that they fill the empty space.

Code: Select all

/*
Substitution 1.2
by rbytes
June 2017

1.2
clear field buttons for find and replace fields

1.1
Multiple substitutions

1.0
Searches a text file for all matches to a specific set of characters, 
word or phrase, and substitutes designated text.

Hint - when replacing words, be sure to leave a space
before and/or after the word to be searched for!
If replacing word-parts, take care that no matches will be found
that you don't want changed!

A saved file will have the same name as a loaded file, but with r added
to the extender. The original file will not be changed.

- This program is very effective in developing smart Basic programs. You
can easily change variable names, for example.

*/
SET BUTTONS CUSTOM
OPTION SPRITE POS CENTRAL
OPTION ANGLE DEGREES
SET TOOLBAR OFF
SET ORIENTATION LANDSCAPE
DIM carray$(11)
laun$=LAUNCHER$ ()
dev$=DEVICE_TYPE$()
lf$=CHR$(10)
GET SCREEN SIZE sw,sh
iostest=0
IF iostest THEN   ' iPhone 6 screen test. Adjust sw and sh for your screen size.
  sw=568
  sh=320
  dev$=""
ENDIF
rw=sw/1024!rh=sh/768
GRAPHICS
GRAPHICS CLEAR
srch$="Beatles"
repl$="Monkees"


' text string in which to search and replace

origin$="The Beatles were an English rock band formed in Liverpool in 1960. With members John Lennon, Paul McCartney, George Harrison and Ringo Starr, they became widely regarded as the foremost and most influential act of the rock era.  Rooted in skiffle, beat and 1950s rock and roll, the Beatles later experimented with several musical styles, ranging from pop ballads and Indian music to psychedelia and hard rock, often incorporating classical elements and unconventional recording techniques in innovative ways. Manager Brian Epstein moulded them into a professional act, and producer George Martin guided and developed their recordings, greatly expanding their popularity in the United Kingdom after their first hit, "&"""Love Me Do"""&", in late 1962. In 1963 their enormous popularity first emerged as "&"""Beatlemania"""&", and as the group's music grew in sophistication in subsequent years, led by primary songwriters Lennon and McCartney, they came to be perceived as an embodiment of the ideals shared by the counterculture of the 1960s. They acquired the nickname "&"""the Fab Four"""&" as Beatlemania grew in Britain, and by early 1964 became international stars, leading the "&"""British Invasion"""&" of the United States pop market. From 1965 onwards, the Beatles produced increasingly innovative recordings, including the albums Rubber Soul (1965), Revolver (1966), Sgt. Pepper's Lonely Hearts Club Band (1967), The Beatles (commonly known as the White Album, 1968) and Abbey Road (1969). After their break-up in 1970, they each enjoyed successful musical careers of varying lengths. "

content$=origin$
GOSUB paintbutt
GOSUB colordef
FILL ALPHA 0
BUTTON "maintitle" TEXT "" AT 377*rw,9*rh SIZE 248*rw,32*rh
FILL ALPHA 1
FIELD "maintitle" TEXT "SUBSTITUTION" AT 414*rw,9*rh SIZE 234*rw,34*rh RO
FIELD "maintitle" FONT SIZE 24*rw
FIELD "maintitle" FONT COLOR 1,1,1
FIELD "maintitle" BACK ALPHA 0
DRAW COLOR 0,0,0
DRAW RECT 8*rw,48*rh TO sw-8*rw,322*rh
FIELD "title1" TEXT "Original" AT 10*rw,20*rh SIZE 120*rw,25*rh
FIELD "title1" FONT SIZE 18*rw
FIELD "title1" BACK COLOR .7,.7,1
FIELD "original" TEXT content$ AT 10*rw,50*rh SIZE sw-20*rw,270*rh ML
FIELD "original" FONT SIZE 18*rw
FIELD "corrected" TEXT "" AT 10*rw,50*rh SIZE sw-20*rw,270*rh ML
FIELD "corrected" FONT SIZE 18*rw
FIELD "corrected" HIDE
IF dev$="iPad" THEN
  html$="<H4>"&content$&"</H4>"
  bshift=0
ELSE
  html$="<H6>"&content$&"</H6>"
  bshift=5
ENDIF


' create interface buttons

FILL ALPHA 0
DRAW COLOR 1,1,1
SET BUTTONS FONT SIZE 22*rw
BUTTON "start" TEXT "START" AT 150*rw,bshift+680*rh SIZE 100*rw,50*rh
BUTTON "load" TEXT "LOAD" AT 270*rw,bshift+680*rh SIZE 100*rw,50*rh
BUTTON "run" TEXT "RUN" AT 390*rw,bshift+680*rh SIZE 100*rw,50*rh
BUTTON "final" TEXT "FINAL" AT 510*rw,bshift+680*rh SIZE 100*rw,50*rh
BUTTON "save" TEXT "SAVE" AT 630*rw,bshift+680*rh SIZE 100*rw,50*rh
BUTTON "stop" TEXT "STOP" AT 750*rw,bshift+680*rh SIZE 100*rw,50*rh
DRAW ALPHA 1
DRAW COLOR 0,0,0


' create 'search and replace' fields

FIELD "slabb" TEXT "" AT 40*rw,shfld+335*rh SIZE 160*rw,30*rw
FIELD "slabb" BACK COLOR 1,.6,1
FIELD "rlabb" TEXT "" AT shfld+555*rw,shfld+335*rh SIZE 135*rw,30*rw
FIELD "rlabb" BACK COLOR .4,1,1
FIELD "slab" TEXT " Find All Matches:" AT 40*rw,shfld+335*rh SIZE 155*rw,30*rw RO
FIELD "slab" FONT SIZE 18*rw
FIELD "slab" BACK ALPHA 0
FIELD "srch" TEXT srch$ AT 220*rw,shfld+335*rh SIZE 255*rw,30*rw
FIELD "srch" FONT SIZE 18*rw
FIELD "srch" BACK COLOR 1,.6,1
FIELD "rlab" TEXT " Substitute:" AT shfld+555*rw,shfld+335*rh SIZE 135*rw,30*rw RO
FIELD "rlab" FONT SIZE 18*rw
FIELD "rlab" BACK ALPHA 0
FIELD "repl" TEXT repl$ AT shfld+710*rw,shfld+335*rh SIZE 255*rw,30*rw
FIELD "repl" FONT SIZE 18*rw
FIELD "repl" BACK COLOR .4,1,1
set buttons font size 20*rw
BUTTON "clrfld1" TEXT CHR$(8855) AT 440*rw,332*rh
BUTTON "clrfld2" TEXT CHR$(8855) AT 930*rw,332*rh
field "warning" text "" at 410,450 size 200,60 ML RO
field "warning" hide


' main action loop

DO


' start button returns to original version of text

IF BUTTON_PRESSED ("start") THEN
  content$=origin$
  IF dev$="iPad" THEN
    html$="<H4>"&content$&"</H4>"
    bshift=0
  ELSE
    html$="<H6>"&content$&"</H6>"
    bshift=5
  ENDIF
  FIELD "title1" SHOW
  FIELD "original" SHOW
  FIELD "title2" HIDE
  FIELD "corrected" HIDE
  FIELD "title3" HIDE
  BROWSER "corrected" HIDE
  field "warning" hide
  colorflag=0
ENDIF


' run button finds and replaces text 

IF BUTTON_PRESSED ("run") then
  if colorflag<10 THEN
    if field_text$("corrected")<>"" then content$=field_text$("corrected")
    colorflag+=1
    hc$=carray$(colorflag)
    FIELD "title1" HIDE
    FIELD "original" HIDE
    FIELD "title2" HIDE
    FIELD "corrected" HIDE
    mark=0!mark2=0
    mark=INSTR(content$,srch$,mark+1)
    mark2=INSTR(html$,srch$,mark2+1)
    FIELD "title3" TEXT "Substituted" AT 10*rw,20*rh SIZE 130*rw,25*rh
    FIELD "title3" FONT SIZE 18*rw
    FIELD "title3" BACK COLOR 1,.7,.7
    FIELD "title3" SHOW
    BROWSER "corrected" URL "" AT 10*rw,50*rh SIZE sw-20*rw,270*rh
    BROWSER "corrected" SHOW

    LOOP:
    IF mark<>-1 AND mark2<>-1 THEN
      content$=LEFT$(content$,mark)&repl$&RIGHT$(content$,LEN(content$)-mark-LEN(srch$))
      html$=LEFT$(html$,mark2)&"<FONT COLOR="&hc$&">"&repl$&"</FONT>"&RIGHT$(html$,LEN(html$)-mark2-LEN(srch$))
      mark=INSTR(content$,srch$,mark+len(repl$)+1)
      mark2=INSTR(html$,srch$,mark2+len(repl$)+len(hc$)+13)  'mark 2 must add the length of the color tag!
      field "corrected" text content$
    ENDIF
    IF mark<>-1 AND mark2<>-1 THEN LOOP
    BROWSER "corrected" TEXT html$
  else
    warn$="Maximum substitutions! Press Start to start over."
    field "warning" text warn$
    field "warning" show
  endif
ENDIF


' accept button shows final result before saving

IF BUTTON_PRESSED ("final") THEN
  FIELD "title1" HIDE
  FIELD "original" HIDE
  FIELD "title3" HIDE
  BROWSER "corrected" HIDE
  FIELD "title2" TEXT "Completed" AT 10*rw,20*rh SIZE 120*rw,25*rh
  FIELD "title2" FONT SIZE 18*rw
  FIELD "title2" BACK COLOR .6,.9,.6
  FIELD "title2" SHOW
  FIELD "corrected" SHOW
ENDIF


' load button loads a new file
  
IF BUTTON_PRESSED("load") THEN
  GRAPHICS CLEAR
  DRAW COLOR 0,0,0
  DRAW ALPHA 1
  FILL ALPHA 1
  path$="/"
  ret$ = file_select$(360*rw,40*rh,310*rw,260*rh,1,path$)
  OPTION BASE 0
  PAGE "" SET
  PAGE "" SHOW
  PAGE "request" HIDE
  GRAPHICS CLEAR
  GOSUB paintbutt
  DRAW COLOR 0,0,0
  DRAW RECT 8*rw,48*rh TO sw-8*rw,322*rh
  IF ret$<>"" AND ret$<>"Cancel" THEN
    fname$=ret$
    IF FILE_EXISTS(fname$) THEN
      FILE fname$ SETPOS 0
      origin$=""
      IF dev$="iPad" THEN html$="<H4>" ELSE html$="<H6>"
      WHILE NOT FILE_END(fname$)
        FILE fname$ READLINE temp$
        origin$&=temp$&lf$
        html$&=temp$&"<br>"
      ENDWHILE
    ENDIF
  ENDIF
  content$=origin$
  IF dev$="iPad" THEN html$&="</H4>" ELSE html$&="</H6>"
  FIELD "original" TEXT content$
  FIELD "corrected" TEXT ""
ENDIF


' save button saves a corrected file
  
IF BUTTON_PRESSED("save") THEN
  GRAPHICS CLEAR
  'path$="/My Utilities/Find and Replace/"
  DRAW COLOR 0,0,0
  DRAW ALPHA 1
  FILL ALPHA 1
  temp$=file_select$.fil$
  IF temp$<>"" THEN file_select$.fil$=temp$&"r"
  ret$ = file_select$(360*rw,40*rh,310*rw,260*rh,2,path$)
  FIELD "corrected" TEXT content$
  OPTION BASE 0
  PAGE "" SET
  PAGE "" SHOW
  PAGE "request" HIDE
  GRAPHICS CLEAR
  GOSUB paintbutt
  DRAW COLOR 0,0,0
  DRAW RECT 8*rw,48*rh TO sw-8*rw,322*rh
  IF ret$<>"" AND ret$<>"Cancel" THEN
    fname$=ret$
    IF FILE_EXISTS(fname$) THEN FILE fname$ DELETE
    FILE fname$ WRITELINE FIELD_TEXT$("corrected")
  ENDIF
ENDIF
  
  
' stop button quits the program
  
IF BUTTON_PRESSED("stop") THEN
  IF laun$="desktop" THEN
    IF FILE_EXISTS("/launch") THEN
      RUN "/-Launch.sb"
    ELSE
      EXIT
    ENDIF
  ENDIF
  END
ENDIF


' clrfld1 button clears the search field

IF BUTTON_PRESSED("clrfld1") THEN
srch$=""
field "srch" text srch$
field "srch" select 1
BUTTON "clrfld1" TEXT CHR$(8855) AT 440*rw,332*rh
endif


' clrfld2 button clears the substitution field

IF BUTTON_PRESSED("clrfld2") THEN
repl$=""
field "repl" text repl$
field "repl" select 1
BUTTON "clrfld2" TEXT CHR$(8855) AT 930*rw,332*rh
endif

' update 'search and replace' fields

IF FIELD_TEXT$("srch") <> srch$ THEN
  srch$=FIELD_TEXT$("srch")
ENDIF
IF FIELD_TEXT$("repl") <> repl$ THEN
  repl$=FIELD_TEXT$("repl")
ENDIF
IF FIELD_TEXT$("original")<>origin$ THEN
  origin$=FIELD_TEXT$("original")
ENDIF
IF content$<>FIELD_TEXT$("corrected") AND FIELD_TEXT$("corrected")<>"" THEN
  content$=FIELD_TEXT$("corrected")
ENDIF

SLOWDOWN
UNTIL 0


' create image within each button

paintbutt:
DRAW COLOR 1,1,1
DRAW ALPHA .7
SHADOW ON
DRAW IMAGE "Substitution/title.png" AT 377*rw,6*rh SCALE .92*rw,.7*rh
SHADOW OFF
'draw alpha 1
'button "maintitle" TEXT "" AT 377*rw,9*rh SIZE 248*rw,32*rh
DRAW ALPHA .8
png$="Substitution/button.png"
DRAW IMAGE png$ AT 150*rw,680*rh SCALE rw
DRAW IMAGE png$ AT 270*rw,680*rh SCALE rw
DRAW IMAGE png$ AT 390*rw,680*rh SCALE rw
DRAW IMAGE png$ AT 510*rw,680*rh SCALE rw
DRAW IMAGE png$ AT 630*rw,680*rh SCALE rw
DRAW IMAGE png$ AT 750*rw,680*rh SCALE rw
DRAW ALPHA 1
RETURN


' define colors for replacement text

colordef:
carray$(1)="red"
carray$(2)="limegreen"
carray$(3)="dodgerblue"
carray$(4)="darkturquoise"
carray$(5)="magenta"
carray$(6)="gold"
carray$(7)="orange"
carray$(8)="lime"
carray$(9)="peru"
carray$(10)="gold"
RETURN

'b'
' file browser/selector            Thanks to Henko for this file selector code
' returns selected file with path

DEF file_select$(xtop,ytop,wid,hgt,type,path$)
OPTION BASE 1
'type = 1 for load, 2 for save
PAGE "request" SET
PAGE "request" SHOW
PAGE "" HIDE
maxdim=500 ! SET LISTS CUSTOM
SET LISTS FONT SIZE 18*.rw
trans=0
DIM directs$(maxdim),FILES$(maxdim), combi$(2*maxdim)
FILL COLOR 1,1,1 ! DRAW COLOR 0,0,0
sw=.sw!sh=.sh!rw=.rw!rh=.rh
IF type=1 THEN
  fb$="Select file"&CHR$(10)&CHR$(10)&"Click OK to load it"&CHR$(10)&CHR$(10)&"Or RENAME or DELETE it"&CHR$(10)&CHR$(10)&"Click CANCEL to escape"
ELSE
  fb$="Select or name file"&CHR$(10)&CHR$(10)&"Click OK to save it"&CHR$(10)&CHR$(10)&"Or RENAME or DELETE it"&CHR$(10)&CHR$(10)&"Click CANCEL to escape"
ENDIF
IF xtop+wid>sw-10 THEN xtop=sw-wid-10 ! xbot=xtop+wid
IF ytop+hgt>sh-10 THEN ytop=sh-hgt-10 ! ybot=ytop+hgt*1.6
/*FIELD "stats" TEXT "" AT 50*.rw,480*.rh SIZE 140*.rw,100*.rh RO ML
FIELD "stats" FONT SIZE 20*.rw
FIELD "stats" SHOW*/
SPRITE "fbrow" SCAN xtop-2,ytop-2,wid+4,hgt+4
DRAW SIZE 3 !FILL RECT xtop,ytop TO xbot,ybot*.8
DRAW RECT xtop,ytop TO xbot,ybot*.8
DRAW LINE xtop,ytop*6 TO xbot,ytop*6
DRAW FONT SIZE 22*.rw
DRAW COLOR 0,0,0
DRAW TEXT title$ AT sw*.18,ytop+sh*.116
DRAW TEXT title2$ AT sw*.18,ytop+sh*.166
DRAW TEXT title3$ AT sw*.18,ytop+sh*.216
FIELD "namer" TEXT "" AT xtop+wid*.05,ytop+hgt*1 SIZE wid*.87,hgt*.18
FIELD "namer" FONT SIZE 20*.rw
FIELD "namer" FONT NAME "Arial-BoldMT"
IF fil$="" THEN fil$=.backfil$
FIELD "namer" TEXT fil$
procnam$=fil$
FIELD "feedback" TEXT fb$ AT xtop*.4,ytop*1.6 SIZE sw*.16+2,sh*.396 RO ML
FIELD "feedback" FONT COLOR 0,0,0
DRAW RECT xtop*.4-2,ytop*1.6-2 TO xtop*.4+sw*.16+3,ytop+hgt*.35+sh*.31
FIELD "feedback" FONT SIZE 20*.rw
FIELD "filter" TEXT "filter" AT xtop*2.005,ytop+hgt*.08 SIZE sw*.216,sh*.05
FIELD "filter" FONT SIZE 20*.rw
BUTTON "cancel" title "CANCEL" AT xtop*2,ytop+hgt*.8 SIZE sw*.1,sh*.07
BUTTON "ok" title "OK" AT xtop*2,ytop+hgt*1.05 SIZE sw*.1,sh*.07
BUTTON "back" title "BACK" AT xtop*2,ytop+hgt*.55 SIZE sw*.1,sh*.07
BUTTON "root" title "ROOT" AT xtop*2,ytop+hgt*.3 SIZE sw*.1,sh*.07
BUTTON "+dir" title "+ DIR" AT xtop*2.34,ytop+hgt*1.05 SIZE sw*.1,sh*.07
BUTTON "-dir" title "- DIR" AT xtop*2.34,ytop+hgt*.8 SIZE sw*.1,sh*.07
BUTTON "rename" title "RENAME" AT xtop*2.34,ytop+hgt*.3 SIZE sw*.1,sh*.07
BUTTON "del" title "DELETE" AT xtop*2.34,ytop+hgt*.55 SIZE sw*.1,sh*.07
BUTTON "import" TEXT "IMPORT" AT xtop*.06,ytop+hgt*.4 SIZE sw*.1,sh*.07
BUTTON "export" TEXT "EXPORT" AT xtop*.06,ytop+hgt*.65 SIZE sw*.1,sh*.07
DRAW ALPHA 1
FILL ALPHA 0
BUTTON "clrfld" TEXT CHR$(8855) AT xtop*1.77,ytop+hgt*1.02
DRAW ALPHA 1
FILL ALPHA 1
IF type=2 THEN
  filter$=""
ELSE
  filter$=""
ENDIF
filter2$=""
fil$=""
fil_lab1: DIR$=""
fil_lab2: 
IF DIR$>"" THEN path$=path$ & "/" & DIR$ & "/"
fil_lab21:
DIR path$ LIST DIRS directs$,n1
DIR path$ LIST FILES FILES$,n2
fil_lab3:
IF n1 THEN
  FOR i=1 TO n1 ! combi$(i)="DIR: " & directs$(i) ! NEXT i
  END IF
fil_lab4:
ntot=n1
IF n2 THEN
  FOR i=1 TO n2
    IF filter$="" OR filter$="filter" OR INSTR(FILES$(i),filter$)>=0 OR (type=1 AND INSTR(FILES$(i),filter2$)>=0) THEN
      ntot+=1 ! combi$(ntot)=FILES$(i)
      END IF
    NEXT i
  END IF
IF ntot=0 THEN ! ntot=1 ! combi$(1)="" ! END IF
DIM temp$(ntot)
FOR i=1 TO ntot ! temp$(i)=combi$(i) ! NEXT i
LIST "fsel" TEXT temp$ AT xtop+2,sh*.07 SIZE xbot-xtop-3,hgt*.9
DRAW SIZE 3 ! DRAW LINE xtop,ytop+hgt*.95 TO xbot,ytop+hgt*.95
.path$=path$ ! .fil$=fil$
fil_lab5:
IF BUTTON_PRESSED("-dir") THEN
  dirop=1
  fb$="Select directory"&CHR$(10)&CHR$(10)&"Click OK to delete it"&CHR$(10)&CHR$(10)&"Click CANCEL to escape"
  FIELD "feedback" TEXT fb$
ENDIF
IF BUTTON_PRESSED("+dir") THEN
  dirop=2
  fb$="Enter name of new directory"&CHR$(10)&CHR$(10)&"Click OK to create it"&CHR$(10)&CHR$(10)&"Click CANCEL to escape"
  FIELD "feedback" TEXT fb$
ENDIF
IF BUTTON_PRESSED("cancel") THEN
  ret$="" ! GOTO fil_lab6
END IF
IF BUTTON_PRESSED("clrfld") THEN FIELD "namer" TEXT ""
IF BUTTON_PRESSED("del") THEN
  'if file not yet selected, ask user to select one.
  checksel=LIST_SELECTED("fsel")
  IF checksel=-1 THEN
    fb$="You must first select a file to delete."
    GOTO skipremove
  ENDIF
fil$=temp$(checksel)
fb$="Are you sure you wish to delete the file """&fil$&""" ? If yes, press OK. If no, press Cancel. A deleted file cannot be recovered!"
deleter=1
skipremove:
FIELD "feedback" TEXT fb$
BEEP
BEEP
ENDIF

IF BUTTON_PRESSED("rename") THEN
'if not yet selected, ask user to select a file.
  checksel=LIST_SELECTED("fsel")
  IF checksel=-1 THEN
    fb$="You must first select a file to rename."
    GOTO skiprename
  ENDIF
fil$=temp$(checksel)
fb$="Are you sure you wish to rename the file """&fil$&""" ? If yes, enter the new name and press OK. If no, press Cancel."
FIELD "feedback" TEXT fb$
renamer=1
skiprename:
FIELD "feedback" TEXT fb$
BEEP
ENDIF
IF BUTTON_PRESSED("import") THEN
  impo=1!GOTO fil_lab6
ENDIF
IF BUTTON_PRESSED("export") THEN
  'if not yet selected, ask user to select a file.
  checksel=LIST_SELECTED("fsel")
  IF checksel=-1 THEN
    ret$=path$&procnam$
  ELSE
    ret$=path$ & fil$
  ENDIF
  expo=1!GOTO fil_lab6
ENDIF
IF BUTTON_PRESSED("ok") THEN
  IF RIGHT$(path$,1)<>"/" THEN path$&="/"
  IF FIELD_TEXT$("namer")<>"" THEN fil$=FIELD_TEXT$("namer")
  IF dirop=2 AND fil$<>"" THEN
    DIR path$&fil$ CREATE
    FIELD "namer" TEXT ""
    dirop=0
    GOTO fil_lab21
  ENDIF
  IF dirop=1 AND fil$<>"" THEN
    DIR path$&fil$ DELETE
    FIELD "namer" TEXT ""
    dirop=0
    GOTO fil_lab21
  ENDIF
  IF deleter THEN
    FILE path$&fil$ DELETE
    deleter=0
    ret$=""
    GOTO fil_lab21
  ENDIF
  IF renamer THEN
    FILE path$&combi$(sel) RENAME path$&fil$
    renamer=0
    ret$=""
    GOTO fil_lab21
  ENDIF
  IF fil$>"" THEN
    IF path$ > "" THEN
     ret$=path$ & fil$
    ELSE
     ret$ = fil$
    END IF
    GOTO fil_lab6
  END IF
END IF

IF filter$<>filterhold$ THEN
'IF FIELD_CHANGED("filter") THEN
  filter$=FIELD_TEXT$("filter")
  'filterhold$=FIELD_TEXT$ ("filter")
  GOTO fil_lab4
END IF
  filterhold$=FIELD_TEXT$ ("filter")
IF FIELD_CHANGED("namer") THEN
  fil$=FIELD_TEXT$("namer")
  LIST "fsel" SELECT -1
  GOTO fil_lab4
ENDIF
IF BUTTON_PRESSED("back") THEN 
  'IF path$<>"Listful/" THEN
    IF RIGHT$(path$,1)="/" THEN path$=LEFT$(path$,LEN(path$)-1)
    FOR k=LEN(path$) TO 1 STEP -1
      IF MID$(path$,k,1)="/" THEN BREAK
      NEXT k
    IF k THEN ! path$=LEFT$(path$,k) ! GOTO fil_lab21 ! END IF
  'ENDIF
END IF
IF BUTTON_PRESSED("root") THEN
  path$="/" ! DIR$=""
  GOTO fil_lab21
END IF
IF BUTTON_PRESSED("quit") THEN
  IF .laun$="desktop" THEN EXIT
  IF .laun$="basic" THEN END
ENDIF
IF BUTTON_PRESSED("debug") THEN DEBUG PAUSE
sel=LIST_SELECTED("fsel")
IF sel>0 THEN
  IF sel>n1 THEN
     IF NOT trans THEN FIELD "namer" TEXT combi$(sel)
     trans=1
     IF FIELD_CHANGED ("namer") THEN trans=0
     IF sel<>tempsel THEN trans=0
     IF FIELD_TEXT$("namer")="" THEN
        fil$=combi$(sel)
     ELSE
        'FIELD "namer" TEXT combi$(sel)
        fil$=FIELD_TEXT$("namer")
     ENDIF
     tempsel=sel
     /*IF RIGHT$(fil$,4)=".gif" OR RIGHT$(fil$,4)=".GIF" OR RIGHT$(fil$,4)=".jpg" OR RIGHT$(fil$,4)=".JPG" OR RIGHT$(fil$,4)=".png" OR RIGHT$(fil$,4)="PNG" THEN
       IF RIGHT$(path$,1)="/" THEN
         sep$=""
       ELSE
         sep$="/"
       ENDIF
       SPRITE "pvimage" LOAD path$&sep$&fil$
       GET SPRITE "pvimage" SIZE imw,imh
       SPRITE "pvimage" AT 500*rw,560*rh+adjh SCALE .24*rw*MIN(2048/imw,1536/imh)
       IF NOT prepped THEN
         SPRITE "pvimage" SHOW
         SPRITE "pvimage" DELAY 1
         SPRITE "pvimage" LOOP
         prepped=1
       ENDIF
     ELSE
       SPRITE "pvimage" HIDE
     ENDIF
     stats$="Width:  "&imw&CHR$(10)&"Height: "&imh&CHR$(10)&INT(FILE_SIZE (path$&sep$&fil$)/1000)&" kb"
     FIELD "stats" TEXT stats$*/
     GOTO fil_lab5
    ELSE
    IF dirop<>1 THEN
      DIR$=directs$(sel) ! GOTO fil_lab2
    ELSE
      FIELD "namer" TEXT MID$(combi$(sel),6,45)
    ENDIF
    END IF
  END IF
  SLOWDOWN
GOTO fil_lab5

fil_lab6:
BUTTON "cancel" DELETE ! BUTTON "ok" DELETE ! BUTTON "clrfld" DELETE
BUTTON "rename" DELETE ! BUTTON "del" DELETE ! BUTTON "root" DELETE
BUTTON "back" DELETE ! BUTTON "+dir" DELETE ! BUTTON "-dir" DELETE
BUTTON "import" DELETE ! BUTTON "export" DELETE
FIELD "namer" DELETE ! LIST "fsel" DELETE
FIELD "filter" DELETE 
SPRITE "fbrow" AT xtop-2,ytop-2 ! SPRITE "fbrow" STAMP
SPRITE "fbrow" DELETE ! FIELD "feedback" DELETE
DRAW SIZE 1
IF impo THEN RETURN rets
IF expo THEN RETURN ret$
GRAPHICS CLEAR .7, .7, .7
IF type =2 AND ret$<>"" THEN
  DRAW FONT SIZE 40
  DRAW TEXT "SAVING" AT sw/2-TEXT_WIDTH("SAVING")/2, sh/2
  PAUSE 1
ENDIF
.path$=path$
RETURN ret$
END DEF
''
Attachments
title.png
Attachment 1 - title background
title.png (123.94 KiB) Viewed 144 times
button.png
Attachment 2 - button background
button.png (38.82 KiB) Viewed 144 times
IMG_2217.PNG
The original (example) file
IMG_2217.PNG (1.72 MiB) Viewed 148 times
IMG_2218.PNG
All instances of Beatles changed to Monkees
IMG_2218.PNG (1.71 MiB) Viewed 149 times
IMG_2219.PNG
You can make final edits on the Final screen
IMG_2219.PNG (1.72 MiB) Viewed 149 times
IMG_2220.PNG
Notice that there are some unintended changes!
IMG_2220.PNG (1.71 MiB) Viewed 149 times
IMG_2222.PNG
Here is a third substitution
IMG_2222.PNG (1.71 MiB) Viewed 149 times
IMG_2223.PNG
All substitutions can be edited on the Final screen
IMG_2223.PNG (1.72 MiB) Viewed 149 times
Last edited by rbytes on Sat Jul 01, 2017 4:50 pm, edited 1 time in total.
####### Living the colorful life #######

User avatar
rbytes
Posts: 1051
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Substitution 1.2

Post by rbytes » Sat Jul 01, 2017 4:49 pm

I re-posted the code this morning. Had to do a bug fix on the code that updates the browser text for each substitution. :roll:

I made a small improvement. There are now clear buttons in the find and substitute fields. When you press one, it clears the field and positions the cursor ready for a new entry.

The program is now named Substitution 1.2.
Attachments
IMG_2225.PNG
IMG_2225.PNG (1.71 MiB) Viewed 120 times
####### Living the colorful life #######

User avatar
Henko
Posts: 603
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone 5S, iPad air 2, Windows PC's
Location: Netherlands
Flag: Netherlands

Re: Substitution

Post by Henko » Sun Jul 02, 2017 7:17 am

Thanks Richard,
You filled a missing feature in the SB editor.
A nice (and common) feature would be that replacement could be done on a individual basis, by stepping through all replacement and push a "replace" or "next" button.
I will use it when taking up programming again some time.

User avatar
rbytes
Posts: 1051
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 6
iPad 2
Dell Inspiron laptop
Location: Canada
Flag: Canada
Contact:

Re: Substitution

Post by rbytes » Sun Jul 02, 2017 2:15 pm

Thanks, Henk. Good idea. I will add that to the next version. 8-)
####### Living the colorful life #######

Erg2
Posts: 11
Joined: Sat Dec 10, 2016 8:58 pm
My devices: ipad2
Flag: Australia

Re: Substitution

Post by Erg2 » Sat Jul 15, 2017 6:38 am

Very well done rybtes, love it👍!! And as Henko suggested, ....step by step on a individual basis..... would make it even better

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest