[Gambas-devel] find your sub easier

Benoit Minisini gambas at ...1...
Sun Aug 1 20:23:15 CEST 2004


On Sunday 01 August 2004 19:30, you wrote:
> Dear Mr.Minisini:

Hi,

>
> I found it is difficult to find a sub or function while writing
> Gambas program. I make some change to list the sub or function
> under the class in tvwproject. by select the sub or function,
> edtEditor automatically goto the function. I don't know what you
> think about this idea. it is not nearly pefect because I don't
> want to work to much on it untill you told me that'a good idea.

But you can already list the subs and functions directly in the editor. Do you 
want to do that also in the project window ? The problem is that files 
displayed in the project window are loaded only when the user want to edit 
them. So they will be seen only when the file is opened.

>
> I try to post it on maillist, somehow it is not working.(or it may
> take a while), so I send a email to you.

Yes, sometimes the mailing-list is slow. But don't worry, I will get it :-)

> here is the changelog.
>
>
>
> * Wed Jul 31 2004 yizhou <yizhou at ...143...> 0.95-104
>
> All the modification below is to make developer can browe
> function or sub of a class
> and by click on the function or sub, the current focus will goto
> the start of the function
> or class. even if Gambas can fold cold in edit window, this
> function will still be useful.
> ---------------------------------------------------------------------------
>-------- - add sub RefreshchildList in class FEditor
>
> PRIVATE SUB RefreshchildList(sText AS String)
>   DIM Linearray AS NEW String[]
>   DIM isStatic AS Integer
>   DIM isPublic AS Integer
>   DIM isSub AS Integer
>   DIM lines AS String
>   DIM ChildName AS String
>   DIM NamePos AS Integer
>   DIM lineses AS String
>   DIM LineNumber AS Integer
>   DIM iLine AS Integer
>   Linearray=Split(sText,"\n")
>
>   FOR EACH lineses IN Linearray
>     LineNumber=LineNumber+1
>     isStatic=0
>     isPublic=0
>     isSub=0
>     lines=lineses
>     IF lines="END" THEN
>       'MESSAGE(ChildName)
>       fmain.AddMethod(ChildName,Path,iLine)
>     END IF
>     IF Left(lines,7)="STATIC " THEN
>       isStatic=1
>       lines=Right(lines,Len(lines)-7)
>     ENDIF
>     IF Left(lines,7)="PUBLIC " THEN
>       isPublic=1
>       lines=Right(lines,Len(lines)-7)
>     ENDIF
>     IF Left(lines,8)="PRIVATE " THEN
>       isPublic=0
>       lines=Right(lines,Len(lines)-8)
>     ENDIF
>     IF Left(lines,4)="SUB " THEN
>       isSub=1
>       lines=Right(lines,Len(lines)-4)
>     ENDIF
>     IF Left(lines,9)="FUNCTION " THEN
>       isSub=2
>       lines=Right(lines,Len(lines)-9)
>     ENDIF
>     IF isSub>0 THEN
>       NamePos=Instr(lines,"(")
>       IF NamePos=0 THEN NamePos=Instr(lines," ")
>       ChildName=Left(lines,NamePos-1)
>       'To show the detail of function then use next line
>       'ChildName=lines
>       iLine=LineNumber
>     ENDIF
>     'message( isstatic+ispublic+issub)
>
>
>   NEXT
> END
>

The CreateMenu() function in FEditor does almost the same thing. So I think 
they must be factorized.

> ---------------------------------------------------------------------------
>----------- - add function AddMethod in class FMain
>
> PUBLIC FUNCTION AddMethod(ChildName AS String,Name AS String,iLine
> AS Integer) AS String
>
>   IF NOT tvwproject.Exist(CStr(iLine) & "@" & Name) THEN
> tvwproject.Add(CStr(iLine) & "@" &
> Name,ChildName,Picture["img/16/method.png"],Name)
>   tvwproject.Current.Expanded=TRUE
> END
>
> ---------------------------------------------------------------------------
>-----------
>
> - Change sub tvwProject_Activate in class FMain
>
> PUBLIC SUB tvwProject_Activate()
> DIM pos AS Integer
> DIM iLine AS Integer
> DIM iLineString AS String
>   IF tvwProject.Key THEN
>     IF CanEdit(tvwProject.Key) THEN
>       pos=Instr(tvwProject.Key,"@")
>       IF pos=0 THEN
>         iLine=0
>         iLineString=tvwProject.Key
>       ELSE
>         iLineString=Left(tvwProject.Key,pos-1)
>         iLine=CInt(iLineString)
>         iLineString=Right(tvwProject.Key,Len(tvwProject.Key)-pos)
>
>       ENDIF
>       Project.OpenFile(iLineString,iLine)
>     ENDIF
>   ENDIF
>
> END
>
> ---------------------------------------------------------------------------
>-------------------
>
> - Change sub Modify in class FEditor
>
> PUBLIC SUB Modify(OPTIONAL bReset AS Boolean)
>
>   IF Project.ReadOnly THEN RETURN
>   IF $bModify <> bReset THEN RETURN
>
>   $bModify = NOT bReset
>   DrawTitle
>   RefreshChildList(edtEditor.Text)
> END
>

Browsing the source code to find function each time the file is modified is a 
huge job: this function is called each time you enter a character!

You must do it less often, for example, each time a whole line is modified, 
i.e. each time the cursor line change AND the file has been modified.

> ---------------------------------------------------------------------------
>-------------------
>
> - Change sub Goto in class FEditor
>
> PUBLIC SUB Goto(iLine AS Integer, OPTIONAL iColumn AS Integer =
> -1)
>
>   DIM PosEndOfTheLine AS Integer
>   DIM PosStartOfTheLine AS Integer
>   edtEditor.Line = iLine
>   edtEditor.Column=0
>   PosEndOfTheLine=edtEditor.Pos
>   edtEditor.Line = iLine-1
>   PosStartOfTheLine=edtEditor.Pos
>
>   IF iColumn >= 0 THEN
>     edtEditor.Column = iColumn
>   ELSE
>     edtEditor.Column=0
>     edtEditor.Select(PosStartOfTheLine,PosEndOfTheLine-PosStartOfTheLine-1)
>   ENDIF
>
> END
>

Why do you want to select the entire line when you are going to a line ?

> ---------------------------------------------------------------------------
>----------------------- - Change property of tvwProject.sort to Ture
>
> waiting for your reply
> best regards
>
> Yizhou He
>
> Research Technician (Xiong Lab)
> Lineberger Comprehensive Cancer Center
> University of North Carolina at Chapel Hill
> Chapel Hill, NC 27599-7295
> Tel: (919)-962-2143

Don't be upset by my questions. I want to be sure of what you want to do 
exactly, and I must ensure that it don't break anything in the IDE.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list