string StartDir[255]="" string blocks_footer[] = " Enter-Goto Del-Remove Escape-Cancel " integer blocks_buf=0 integer yb,ye,xb,xe,y,x,row,cpos,xoff string bt[1] integer bti string filename[255],qfilename[255],o_fn[255] string ss[255] string blocksgn[26]="abcdefghijklmnopqrstuvwxyz" integer currbi=1 integer old_id integer m,lt255,cl string ln[255] string bi[1]="" string tag[1] string b_fn[255],a_fn[255] integer b_line,b_numlines,a_numlines string proc BlocksFilesStr() if Query(SaveState)==_LOCAL_ if StartDir=="" StartDir=CurrDir() endif return(StartDir + "tseblock.dat") endif return(LoadDir() + "tseblock.dat") end proc get_blocksgn() string _bi[1] GotoLine(1) while (1) if isLower(GetText(3,1)) _bi=GetText(3,1) blocksgn[Asc(_bi)-96]=Upper(_bi) else KillLine() endif if not Down() break endif endwhile end proc set_blocksgn() currbi=0 GotoLine(1) while (1) if isLower(GetText(3,1)) bi=GetText(3,1) blocksgn[Asc(bi)-96]=Upper(bi) if currbi==0 currbi=Asc(bi)-96 endif else KillLine() endif if not Down() break endif endwhile if currbi==0 currbi=1 endif end integer proc GotoBlocksBuffer() if blocks_buf==0 if CreateBuffer("*Blocks List*", _SYSTEM_, blocks_buf, _FORCE_NAME_) if NumLines() == 0 LoadBuffer(BlocksFilesStr()) set_blocksgn() endif endif else GotoBufferId(blocks_buf) get_blocksgn() endif return(blocks_buf) end proc myDelBlock() old_id=GetBufferId() if GotoBlocksBuffer() //delete blank line GotoLine(1) while (1) if isLower(GetText(3,1)) if not Down() break endif else KillLine() endif endwhile //sort PushBlock() MarkColumn(1,3,NumLines(),3) ExecMacro("sort") GotoLine(1) if Find(bi,"lg")<>0 KillLine() //delete line which contain bi blocksgn[Asc(bi)-96]=bi endif PopBlock() endif GotoBufferId(old_id) end proc myAddBlock() old_id=GetBufferId() qfilename=QuotePath(CurrFilename()) if SubStr(qfilename,1,1)<>'"' qfilename='"'+qfilename+'"' endif if GotoBlocksBuffer() //~[A] filename.ext lineNo: content //BLOCKS a|l|k yb ye xb xe y x row cpos xoff "fullpathfilename.ext" filename=Format(LeftStr(SplitPath(qfilename,_NAME_|_EXT_),16):-16) m=1 AddLine("~["+bi+"] "+filename+" "+Format(y:8)+": ", blocks_buf) EndLine() EditFile(qfilename) PushPosition() GotoLine(y) cl=CurrLineLen() if cl0 j=CurrPos() j=j+10 ss=GetText(j,255) j=StrFind('"',ss) if j>0 k=StrFind('"',ss,'',2) if k>0 qfilename=Substr(ss,j,k-j+1) bt=GetToken(ss, ' ', 1) case bt when 'a' bti=_INCLUSIVE_ when 'A' bti=_NONINCLUSIVE_ when 'l' bti=_LINE_ when 'k' bti=_COLUMN_ endcase yb =Val(GetToken(ss, ' ', 2)) ye =Val(GetToken(ss, ' ', 3)) xb =Val(GetToken(ss, ' ', 4)) xe =Val(GetToken(ss, ' ', 5)) y =Val(GetToken(ss, ' ', 6)) x =Val(GetToken(ss, ' ', 7)) row =Val(GetToken(ss, ' ', 8)) cpos=Val(GetToken(ss, ' ', 9)) xoff=Val(GetToken(ss, ' ', 10)) //refresh current line content BegLine() KillToEol() filename=Format(LeftStr(SplitPath(qfilename,_NAME_|_EXT_),16):-16) m=1 if qfilename==o_fn tag="~" else tag=" " endif InsertText(tag+"["+bi+"] "+filename+" "+Format(y:8)+": ",_INSERT_) EditFile(qfilename) PushPosition() GotoLine(y) cl=CurrLineLen() if cl Up() Down() PageUp() PageDown() BegFile() EndFile() bi=GetText(3,1) KillLine() blocksgn[Asc(bi)-96]=bi SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) EndProcess(True) EndProcess(False) end proc ListHook() Enable(ListKeys,_EXCLUSIVE_) end proc myManageBlock() integer line o_fn=QuotePath(CurrFileName()) if SubStr(o_fn,1,1)<>'"' o_fn='"'+o_fn+'"' endif old_id = GetBufferId() line=CurrLine() if not GotoBlocksBuffer() // or NumLines() == 0 GotoBufferId(old_id) return() endif if NumLines()>0 //refresh all line content BegFile() while (1) bi=GetText(3,1) get_qfilename_and_info() if not Down() break endif endwhile bi=Chr(96+currbi) //sort and locate to line contain bi PushBlock() MarkColumn(1,3,NumLines(),3) ExecMacro("sort") GotoLine(1) lFind(bi,"lg") PopBlock() ListFooter(blocks_footer) else ListFooter("") bi="" endif Hook(_LIST_STARTUP_, ListHook) Set(X1,1) Set(Y1,1) if List("["+bi+"] Blocks - "+Str(line), Query(ScreenCols)) UnHook(ListHook) if NumLines()>0 if myGotoBlock() GotoBufferId(old_id) else GotoBufferId(old_id) endif else GotoBufferId(old_id) endif else UnHook(ListHook) GotoBufferId(old_id) endif end proc myNewBlock() integer i old_id=GetBufferId() GotoBlocksBuffer() GotoBufferId(old_id) if not(isBlockMarked() and isCursorInBlock()) return() endif case isCursorInBlock() when _INCLUSIVE_ bt='a' when _NONINCLUSIVE_ bt='A' when _LINE_ bt='l' when _COLUMN_ bt='k' endcase yb=Query(BlockBegLine) ye=Query(BlockEndLine) xb=Query(BlockBegCol) xe=Query(BlockEndCol) y=CurrLine() x=CurrCol() row=CurrRow() cpos=CurrPos() xoff=CurrXoffset() i=0 while (1) if isLower(blocksgn[currbi]) bi=blocksgn[currbi] myAddBlock() SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) break endif currbi=currbi+1 if currbi>26 currbi=1 endif i=i+1 if i>=26 bi=Lower(blocksgn[currbi]) myDelBlock() myAddBlock() SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) break endif endwhile end proc myPrevBlock() integer i,f old_id=GetBufferId() GotoBlocksBuffer() GotoBufferId(old_id) i=0 while (1) currbi=currbi-1 if currbi<1 currbi=26 endif i=i+1 if i>26 break endif if isUpper(blocksgn[currbi]) bi=Lower(blocksgn[currbi]) old_id=GetBufferId() GotoBufferId(blocks_buf) PushBlock() MarkColumn(1,3,NumLines(),3) ExecMacro("sort") GotoLine(1) f=Find(bi,"lg") PopBlock() if f myGotoBlock() endif GotoBufferId(old_id) break endif endwhile end proc myNextBlock() integer i,f old_id=GetBufferId() GotoBlocksBuffer() GotoBufferId(old_id) i=0 while (1) currbi=currbi+1 if currbi>26 currbi=1 endif i=i+1 if i>26 break endif if isUpper(blocksgn[currbi]) bi=Lower(blocksgn[currbi]) old_id=GetBufferId() GotoBufferId(blocks_buf) PushBlock() MarkColumn(1,3,NumLines(),3) ExecMacro("sort") GotoLine(1) f=Find(bi,"lg") PopBlock() if f myGotoBlock() endif GotoBufferId(old_id) break endif endwhile end proc myOutInBlock() string oldcurrext[32] integer j oldcurrext=CurrExt() j=MsgBox("","Do you want to export / import marker block groups? (select YES to export / NO to import)",_YES_NO_CANCEL_) if j==1 //export if not Ask("Please enter the file name to save the exported marker block group (No .ext is required):",filename,18) return() endif old_id=GetBufferId() if GotoBlocksBuffer() SaveAs(QuotePath(filename+oldcurrext),_DEFAULT_) GotoBufferId(old_id) EditFile(QuotePath(filename+oldcurrext)) //make sure read new content from disk QuitFile() EditFile(QuotePath(filename+oldcurrext)) else Warn("There are currently no marker block groups that can be exported") endif return() else if j==2 //import if not Ask("Please enter the file name to be read by the import marker block group (need to add .ext):",filename,9) return() endif j=EditFile(QuotePath(filename)) if j==0 Warn("Open "+QuotePath(filename)+" failure!") return() endif QuitFile() old_id=GetBufferId() GotoBlocksBuffer() LoadBuffer(QuotePath(filename)) set_blocksgn() GotoBufferId(old_id) PushKey() endif endif end proc mySaveBlock() integer k old_id=GetBufferId() GotoBlocksBuffer() GotoBufferId(old_id) if not(isBlockMarked() and isCursorInBlock()) return() endif while (1) Message("Save Block [A..Z]:") k=LoByte(GetKey(_LOWERCASE_KBD_)) if k==27 UpdateDisplay(_STATUSLINE_REFRESH_) return() endif if 97<=k and k<=122 break endif endwhile UpdateDisplay(_STATUSLINE_REFRESH_) case isCursorInBlock() when _INCLUSIVE_ bt='a' when _NONINCLUSIVE_ bt='A' when _LINE_ bt='l' when _COLUMN_ bt='k' endcase yb=Query(BlockBegLine) ye=Query(BlockEndLine) xb=Query(BlockBegCol) xe=Query(BlockEndCol) y=CurrLine() x=CurrCol() row=CurrRow() cpos=CurrPos() xoff=CurrXoffset() currbi=k-96 if isLower(blocksgn[currbi]) bi=blocksgn[currbi] myAddBlock() SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) else bi=Lower(blocksgn[currbi]) myDelBlock() myAddBlock() SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) endif end proc myLoadBlock() integer k,f old_id=GetBufferId() GotoBlocksBuffer() GotoBufferId(old_id) while (1) Message("Load Block [A..Z]:") k=LoByte(GetKey(_LOWERCASE_KBD_)) if k==27 UpdateDisplay(_STATUSLINE_REFRESH_) return() endif if 97<=k and k<=122 break endif endwhile UpdateDisplay(_STATUSLINE_REFRESH_) currbi=k-96 bi=Chr(k) if isUpper(blocksgn[currbi]) old_id=GetBufferId() GotoBufferId(blocks_buf) PushBlock() MarkColumn(1,3,NumLines(),3) ExecMacro("sort") GotoLine(1) f=Find(bi,"lg") PopBlock() if f myGotoBlock() endif GotoBufferId(old_id) // else // Message("Block ["+bi+"] no exsits") endif end proc OnAbandonEditor() if blocksgn=="abcdefghijklmnopqrstuvwxyz" return() endif if GotoBlocksBuffer() SaveAs(BlocksFilesStr(),_OVERWRITE_ | _DONT_PROMPT_) endif end proc AdjustBlock() integer j,k,n PushPosition() if GotoBlocksBuffer() BegFile() while (1) bi=GetText(3,1) //~[A] filename.ext lineNo: content //BLOCKS a|l|k yb ye xb xe y x row cpos xoff "fullpathfilename.ext" // 1 2 3 4 5 6 7 8 9 10 BegLine() if lFind(" //BLOCKS ","c")>0 j=CurrPos() j=j+10 ss=GetText(j,255) j=StrFind('"',ss) if j>0 k=StrFind('"',ss,'',2) if k>0 qfilename=Substr(ss,j,k-j+1) if a_fn==qfilename bt=GetToken(ss, ' ', 1) case bt when 'a' bti=_INCLUSIVE_ when 'A' bti=_NONINCLUSIVE_ when 'l' bti=_LINE_ when 'k' bti=_COLUMN_ endcase yb =Val(GetToken(ss, ' ', 2)) ye =Val(GetToken(ss, ' ', 3)) xb =Val(GetToken(ss, ' ', 4)) xe =Val(GetToken(ss, ' ', 5)) y =Val(GetToken(ss, ' ', 6)) x =Val(GetToken(ss, ' ', 7)) row =Val(GetToken(ss, ' ', 8)) cpos=Val(GetToken(ss, ' ', 9)) xoff=Val(GetToken(ss, ' ', 10)) if a_numlines>b_numlines n=a_numlines-b_numlines //insert n line if b_line0 return() endif b_fn=QuotePath(CurrFilename()) if SubStr(b_fn,1,1)<>'"' b_fn='"'+b_fn+'"' endif b_line=CurrLine() b_numlines=NumLines() end proc AfterCommand() if QueryEditState()<>0 return() endif a_fn=QuotePath(CurrFilename()) if SubStr(a_fn,1,1)<>'"' a_fn='"'+a_fn+'"' endif a_numlines=NumLines() if b_fn<>a_fn return() endif if b_numlines==a_numlines return() endif AdjustBlock() end keydef BlocksKeys myNewBlock() myPrevBlock() myNextBlock() myManageBlock() myOutInBlock() mySaveBlock() myLoadBlock() end proc WhenLoaded() Enable(BlocksKeys) Hook(_ON_ABANDON_EDITOR_,OnAbandonEditor) Hook(_BEFORE_COMMAND_,BeforeCommand) Hook(_AFTER_COMMAND_,AfterCommand) end proc main() MsgBox("---------- Blocks -------------"+Chr(13)+ "New Block "+Chr(13)+ "Prev Block "+Chr(13)+ "Prev Block "+Chr(13)+ "Next Block "+Chr(13)+ "Manage Block "+Chr(13)+ "Out/In Block "+Chr(13)+ "Save Block ... "+Chr(13)+ "Load Block ... ") //255 characters totaly return() end