default.MouseDown: Function MouseDown(X As Integer, Y As Integer) As Boolean quit End Function default.EnableMenuItems: Sub EnableMenuItems() filenew.enabled=true fileprefs.enabled=true appleAbout.enabled=true helpcontents.enabled=true helplinks.enabled=true End Sub default.Timer1.Action: Sub Action() dim newwindow as search self.backdrop=Nil self.left=-900 newwindow=new search newwindow.top=60 newwindow.left=60 newwindow.visible=true newwindow.show self.backdrop=Nil End Sub prefs.Open: Sub Open() dim x as integer gbfont.deleteAllRows big5font.deleteAllRows japfont.deleteAllRows x=0 while x"asedict" then stuff=stuff+outputlist.cell(i,0)+delim+outputlist.cell(i,1)+delim+outputlist.cell(i,2)+chr(13) else parser=replaceall(outputlist.cell(i,2),"; ","/") stuff=stuff+outputlist.cell(i,0)+" ["+outputlist.cell(i,1)+"] /"+parser+"/"+chr(13) end end next if stuff<>"" then //get rid of the last carriage return: stuff=left(stuff,len(stuff)-1) end return stuff End Function search.finddict: Function finddict() As Boolean dim dicname as string dim f as folderItem if big5.value=true then dicname="cedict.b5 Chinese" elseif gb.value=true then dicname="cedict.gb Chinese" else dicname="edict Japanese" end msgBox "Please locate the "+dicname+" dictionary file." f=getopenfolderitem("text/plain") if f<>Nil and f.exists<>false then if big5.value=true then cedictbig5=f.absolutePath elseif gb.value=true then cedictgb=f.absolutePath else edict=f.absolutePath end if writeprefs()<>false then return true else return false end else return false end End Function search.checkword: Function checkword(source as string,target as string) As boolean //looks for whole words in a given source string from the EDICT or CEDICT dictionary dim x as integer dim y,z as string x=inStr(source,target) if x=0 then return false else y=mid(source,x-1,1) z=mid(source,x+len(target),1) if (y=" " or y="/") and (z=" " or z="/" or z=",") then return true else return false end end End Function search.Activate: Sub Activate() Dim c as Clipboard dim tex as string if outputlist.textsize<>outputsize then outputlist.textsize=outputsize end if autopaste="true" then c=New Clipboard If c <> Nil then If c.TextAvailable then tex=c.text if len(tex)>50 then tex=left(tex,50) end searchdata.text=tex searchdata.sellength=len(searchdata.text) End if c.close End if end if backdrops="false" then me.backdrop=Nil else if gb.value=true then me.backdrop=gbpic elseif jp.value=true then me.backdrop=jppic else me.backdrop=big5pic end end if entsremain="true" then emptyout.visible=true else emptyout.visible=false end End Sub search.EnableMenuItems: Sub EnableMenuItems() if windowcount<6 then filenew.enabled=true end appleAbout.enabled=true fileclose.enabled=true if outputlist.listcount>0 then fileexport.enabled=true end fileprefs.enabled=true editCopi.enabled=true editCopyAs.enabled=true astab.enabled=true ascomma.enabled=true asslash.enabled=true asspace.enabled=true asreturn.enabled=true asedict.enabled=true asuser.enabled=true helpcontents.enabled=true helplinks.enabled=true End Sub search.Open: Sub Open() dim prefs,test, newp as folderitem dim prefstext as textinputStream dim textprefs as string dim newprefs as textoutputStream dim check,diccheck as FolderItem check=GetFolderItem("") version="1.0" gb.value=true outputlist.enabledrag=true //Read the preferences or create them //Look for the two primary dictionary files prefs=preferencesFolder.child("Fool's Lexicon Prefs") if prefs.exists then if readprefs("All")="false" then msgBox "Error reading preferences." end else newp=preferencesFolder.child("Fool's Lexicon Prefs") newprefs=newp.createtextFile newp.maccreator="FoLL" newp.mactype="pref" newprefs.writeLine "Fool's Lexicon "+version+". This file stores the paths to dictionaries and other configuration settings." newprefs.close if writeprefs()=false then msgBox "Error writing preferences." end end //Handle Defaults from Prefs if defdict="Japanese" then jp.value=true gb.value=false big5.value=false elseif defdict="Chinese GB" then jp.value=false gb.value=true big5.value=false else jp.value=false gb.value=false big5.value=true end if backdrops="true" then mywell.image=gbpic mywell.image=big5pic mywell.image=jppic if defdict="Japanese" then me.backdrop=jppic elseif defdict="Chinese GB" then me.backdrop=gbpic else me.backdrop=big5pic end else me.backdrop=Nil end outputlist.textsize=outputsize uncheckall if copyformat="asuser" then asuser.checked=true elseif copyformat="ascomma" then ascomma.checked=true elseif copyformat="asreturn" then asreturn.checked=true elseif copyformat="asslash" then asslash.checked=true elseif copyformat="asedict" then asedict.checked=true elseif copyformat="asspace" then asspace.checked=true else astab.checked=true copyformat="astab" end //*******BEGIN LOOKING FOR DICTIONARIES******** test=getfolderItem(cedictbig5) if cedictbig5="" or test=Nil or test.exists=false then //check to see if the dictionary is in the app directory diccheck=check.child("cedict.b5") if diccheck.exists then cedictbig5=diccheck.absolutePath else msgBox "Please locate the CEDICT big5 file" test=getopenFolderItem("text/plain") if test=Nil or test.exists=false then msgbox "You have not chosen a dictionary text file for traditional characters. You will not be able to look up words using that dictionary until you do so." else cedictbig5=test.absolutePath end end end test=getfolderItem(cedictgb) if cedictgb="" or test=Nil or test.exists=false then //check to see if the dictionary is in the app directory diccheck=check.child("cedict.gb") if diccheck.exists then cedictgb=diccheck.absolutePath else msgBox "Please locate the CEDICT GB file" test=getopenFolderItem("text/plain") if test=Nil or test.exists=false then msgbox "You have not chosen a dictionary text file for simplified characters. You will not be able to look up words using that dictionary until you do so." else cedictgb=test.absolutePath end end end test=getfolderItem(edict) if edict="" or test=Nil or test.exists=false then //check to see if the dictionary is in the app directory diccheck=check.child("edict") if diccheck.exists then edict=diccheck.absolutePath else msgBox "Please locate the EDICT Japanese dictionary file" test=getopenFolderItem("text/plain") if test=Nil or test.exists=false then msgbox "You have not chosen a dictionary text file for Japanese. You will not be able to look up words using that dictionary until you do so." else edict=test.absolutePath end end end if writeprefs()=false then msgBox "There was an error saving the preferences." end if defdict<>"Japanese" then outputlist.heading(0)="Hanzi" outputlist.heading(1)="Pinyin" outputlist.heading(2)="English Definitions" if instr(defdict,"gb")<>0 then searchdata.textfont=c2font else searchdata.textfont=c1font end else searchdata.textfont=jfont outputlist.heading(0)="Kanji" outputlist.heading(1)="Kana" outputlist.heading(2)="English Definitions" end wholeword.value=true onlyterm.value=false End Sub search.searchdata.LostFocus: Sub LostFocus() whofocus="n" End Sub search.searchdata.GotFocus: Sub GotFocus() whofocus="sd" End Sub search.PushButton1.Action: Sub Action() dim target,dict as string dim dictfi as folderItem dim dicttext as textinputStream dim x,y as integer dim z as double dim theline,hanzi,pinyin,def as string z=ticks target=searchdata.text if target="" then beep return end if big5.value=true then dict=cedictbig5 outputlist.textfont=c1font outputlist.heading(0)="Hanzi" outputlist.heading(1)="Pinyin" elseif gb.value=true then dict=cedictgb outputlist.textfont=c2font outputlist.heading(0)="Hanzi" outputlist.heading(1)="Pinyin" else dict=edict outputlist.textfont=jfont outputlist.heading(0)="Kanji" outputlist.heading(1)="Kana" end dictfi=getfolderItem(dict) if dictfi=Nil or dictfi.exists=false then msgBox "Can't open the dictionary. File invalid or not found." if finddict()=false then beep end else dicttext=dictfi.openastextFile theline=dicttext.readline if instr(theline,"EDICT")=0 then msgBox "The file you have designated as the dictionary does not appear to be a valid dictionary file." if finddict()=false then beep end return end x=0 if entsremain<>"true" then outputlist.deleteAllRows end 'chasin.visible=true while theline<>"" x=x+1 if x>200000 then exit //check for infinite loop end theline=dicttext.readline //Cedict starts on line two. if (wholeword.value=false and onlyterm.value=false and instr(theline,target)<>0) then hanzi=left(theline,instr(theline,chr(32))-1) pinyin=mid(theline,instr(theline,chr(32))+2,(instr(theline,"]"))-(instr(theline,chr(32))+2)) def=mid(theline,instr(theline,"/")+1) def=replaceall(def,"/","; ") def=left(def,(len(def))-2) def=uppercase(left(def,1))+mid(def,2) outputlist.addrow(hanzi) outputlist.cell(outputlist.listcount-1,1)=pinyin outputlist.cell(outputlist.listcount-1,2)=def if outputlist.listcount>19999 then beep msgBox "More than 20000 entries were found." entrycount.text="Entries Listed: "+str(outputlist.listcount) dicttext.close return end elseif (wholeword.value=true and onlyterm.value=false and checkword(theline,target)=true) then hanzi=left(theline,instr(theline,chr(32))-1) pinyin=mid(theline,instr(theline,chr(32))+2,(instr(theline,"]"))-(instr(theline,chr(32))+2)) def=mid(theline,instr(theline,"/")+1) def=replaceall(def,"/","; ") def=left(def,(len(def))-2) def=uppercase(left(def,1))+mid(def,2) outputlist.addrow(hanzi) outputlist.cell(outputlist.listcount-1,1)=pinyin outputlist.cell(outputlist.listcount-1,2)=def if outputlist.listcount>19999 then beep msgBox "More than 20000 entries were found." entrycount.text="Entries Listed: "+str(outputlist.listcount) dicttext.close return end elseif (onlyterm.value=true and instr(theline,"/"+target+"/")<>0) then hanzi=left(theline,instr(theline,chr(32))-1) pinyin=mid(theline,instr(theline,chr(32))+2,(instr(theline,"]"))-(instr(theline,chr(32))+2)) def=mid(theline,instr(theline,"/")+1) def=replaceall(def,"/","; ") def=left(def,(len(def))-2) def=uppercase(left(def,1))+mid(def,2) outputlist.addrow(hanzi) outputlist.cell(outputlist.listcount-1,1)=pinyin outputlist.cell(outputlist.listcount-1,2)=def if outputlist.listcount>19999 then beep msgBox "More than 20000 entries were found." entrycount.text="Entries Listed: "+str(outputlist.listcount) dicttext.close return end end wend 'chasin.visible=false dicttext.close entrycount.text="Entries Listed: "+str(outputlist.listcount) z=(ticks-z)/60 timetaken.text="Time Taken: "+left(str(z),4)+" Seconds" end End Sub search.outputlist.LostFocus: Sub LostFocus() whofocus="n" End Sub search.outputlist.GotFocus: Sub GotFocus() whofocus="ol" End Sub search.outputlist.KeyDown: Function KeyDown(Key As String) As Boolean dim x as integer if key=chr(8) then if allowdelete="true" then if outputlist.selcount=1 then outputlist.removeRow(outputlist.listindex) else for x=outputlist.listcount-1 downto 0 if outputlist.selected(x) then outputlist.removerow(x) end next end outputlist.listindex=-1 entrycount.text="Entries Listed: "+str(outputlist.listcount) end end End Function search.big5.Action: Sub Action() searchdata.text="" searchdata.textfont=c1font if me.value<>true then if backdrops="true" then self.backdrop=big5pic end me.value=true gb.value=false jp.value=false end End Sub search.gb.Action: Sub Action() searchdata.text="" searchdata.textfont=c2font if me.value<>true then if backdrops="true" then self.backdrop=gbpic end me.value=true big5.value=false jp.value=false end End Sub search.jp.Action: Sub Action() searchdata.text="" searchdata.textfont=jfont if me.value<>true then if backdrops="true" then self.backdrop=jppic end me.value=true gb.value=false big5.value=false end End Sub search.emptyout.Action: Sub Action() outputlist.deleteAllRows End Sub search.wholeword.Action: Sub Action() if me.value=false then onlyterm.value=false end End Sub search.onlyterm.Action: Sub Action() if me.value=true then wholeword.value=true end End Sub globals.readprefs: Function readprefs(variablename as string) As string dim prefs as folderItem dim prefstext as textinputStream dim textprefs as string prefs=preferencesFolder.child("Fool's Lexicon Prefs") prefstext=prefs.openastextFile if variablename="All" then textprefs=prefstext.readall cedictbig5=nthfield((nthField(textprefs,chr(13),2)),"=",2) cedictgb=nthfield((nthField(textprefs,chr(13),3)),"=",2) edict=nthfield((nthField(textprefs,chr(13),4)),"=",2) c1font=nthfield((nthField(textprefs,chr(13),5)),"=",2) c2font=nthfield((nthField(textprefs,chr(13),6)),"=",2) jfont=nthfield((nthField(textprefs,chr(13),7)),"=",2) defdict=nthfield((nthField(textprefs,chr(13),8)),"=",2) autopaste=nthfield((nthField(textprefs,chr(13),9)),"=",2) backdrops=nthfield((nthField(textprefs,chr(13),10)),"=",2) entsremain=nthfield((nthField(textprefs,chr(13),11)),"=",2) allowdelete=nthfield((nthField(textprefs,chr(13),12)),"=",2) userdef=nthfield((nthField(textprefs,chr(13),13)),"=",2) outputsize=val(nthfield((nthField(textprefs,chr(13),14)),"=",2)) return "true" end prefstext.close End Function globals.writeprefs: Function writeprefs() As boolean dim pre as folderItem dim prout as textoutputStream pre=preferencesFolder.child("Fool's Lexicon Prefs") if pre=Nil or pre.exists=false then return false end //check for missing variables if cedictbig5="" then cedictbig5="?" end if cedictgb="" then cedictgb="?" end if c1font="" then c1font="Taipei" end if c2font="" then c2font="Beijing" end if jfont="" then jfont="Osaka" end if defdict="" then defdict="Japanese" end if autopaste="" then autopaste="false" end if backdrops="" then backdrops="true" end if entsremain="" then entsremain="false" end if allowdelete="" then allowdelete="false" end if userdef="" then userdef="*" end if outputsize<>9 and outputsize<>10 and outputsize<>12 and outputsize<>14 and outputsize<>18 and outputsize<>24 then outputsize=12 end prout=pre.createtextFile prout.writeLine "Fool's Lexicon "+version+". This file stores the paths to dictionaries and other configuration settings." prout.writeline "Path to Big5 Dictionary="+cedictbig5 prout.writeLine "Path to GB Dictionary="+cedictgb prout.writeLine "Path to Japanese Dictionary="+edict prout.writeLine "Font for Big5 Display="+c1font prout.writeLine "Font for GB Display="+c2font prout.writeLine "Font for Japanese Display="+jfont prout.writeLine "Default Dictionary="+defdict prout.writeLine "Auto Paste Feature="+autopaste prout.writeLine "Backdrop Visibility="+backdrops prout.writeLine "Entries Remain For Multiple Searches="+entsremain prout.writeLine "Allow Deleting from the List="+allowdelete prout.writeLine "User Defined Copy Delimiter="+userdef prout.writeLine "Output Window Text Size="+str(outputsize) prout.close pre.maccreator="FoLL" pre.mactype="pref" return true End Function globals.boolstr: Function boolstr(zabool as boolean) As string if zabool=true then return "true" else return "false" end End Function globals.strbool: Function strbool(zastr as string) As boolean if zastr="true" then return true else return false end End Function About.BevelButton1.Action: Sub Action() showURL "http://www.foolsworkshop.com/feedback.html" End Sub About.PushButton1.Action: Sub Action() self.close End Sub About.BevelButton2.Action: Sub Action() showURL "http://www.csse.monash.edu.au/~jwb/j_edict.html" End Sub About.BevelButton3.Action: Sub Action() showURL "http://www.mandarintools.com/cedict.html" End Sub About.BevelButton4.Action: Sub Action() showURL "http://www.foolsworkshop.com/" End Sub About.BevelButton5.Action: Sub Action() showURL "http://www.gnu.org/copyleft/gpl.html" End Sub