IDE An idea to organize yourself better in large code files

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

IDE An idea to organize yourself better in large code files

Post by Josepho »

Inspired on a lot of text editors it would be cool if you would be able to indentify faster what are the procedures you are visualizing on every moment in the procedure explorer.

Check the image to understand what im talking about
Image

This should be an easy upgrade to the ide that would be a huge advance from my point of view, what do you think?

edit: Damn i think i chosed the wrong forum section my bad
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: IDE An idea to organize yourself better in large code fi

Post by skywalk »

This is the tool I modified from kiffi.
I assign the action to [Ctrl+Q] for "query procedure"?

Code: Select all

; kiffi, https://www.purebasic.fr/german/viewtopic.php?f=8&t=28267
; GetProcedureName
; REV: 190606, skywalk
;      Modified to catch similarly named Procedures in ListBox.
;      Ex. ShowIt() and ShowIt2().
; REV: 190607, skywalk
;      Attempt to read process memory instead of temp file.
;      Ex. ShowIt() and ShowIt2().
;#################################################################
; Tool arguments: "%TEMPFILE"
;#################################################################
EnableExplicit
#SP$ = Chr(32)
#TAB$ = Chr(9)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
  #EOL$ = #CRLF$
CompilerDefault
  #EOL$ = #LF$
CompilerEndSelect
Global.s FilePath$
Procedure.s RemoveLeadingWhitespaceFromString(InString$)
  While Left(InString$, 1) = #SP$ Or Left(InString$, 1) = #TAB$
    InString$ = LTrim(InString$, #SP$)
    InString$ = LTrim(InString$, #TAB$)
  Wend
  ProcedureReturn InString$
EndProcedure
Procedure.s GetScintillaText()
  ; sicro, http://www.purebasic.fr/german/viewtopic.php?p=324916#p324916
  Protected.s r$
  Protected File, BOM
  FilePath$ = ProgramParameter(0); %TEMPFILE (file also exists if code is not saved)
  File = ReadFile(#PB_Any, FilePath$, #PB_File_SharedRead)
  If IsFile(File)
    BOM = ReadStringFormat(File)  ; Skip BOM if present
    r$ = ReadString(File, #PB_File_IgnoreEOL); | BOM)
    CloseFile(File)
    If FindString(FilePath$, "\Temp\", 1, #PB_String_NoCase)
      ; Only delete temp file, in case user enters wrong path in Tool options.
      DeleteFile(FilePath$)
    EndIf
  EndIf
  ProcedureReturn r$
EndProcedure
Procedure.i ct_hpID_from_hW(hW.i)
  ;         ct_pID_from_hW
  Protected.i pID, hpID
  If GetWindowThreadProcessId_(hW, @pID)
    hpID = OpenProcess_(#PROCESS_ALL_ACCESS, 0, pID)
  EndIf
  ProcedureReturn hpID
EndProcedure
Procedure.s ct_sci_GetText(hSci.i, hpid.i)
  ; REV:  180218, skywalk
  ; USE:  Get all text in current tab of editor.
  Protected.i ri, Length, Length2, Format
  Protected.i *mSci, *mtxt
  Protected.s txt$
  If hSci And hpid
    Select SendMessage_(hSci, #SCI_GETCODEPAGE, 0, 0)
    Case 0
      Format = #PB_Ascii
    Case 2, 65001
      Format = #PB_UTF8
    EndSelect
    MessageRequester("Format", Str(Format))
    Length = SendMessage_(hSci, #SCI_GETTEXT, 0, 0) + SizeOf(Character)
    MessageRequester("Length", Str(Length))
    MessageRequester("hpid", Str(hpid))
    *mtxt = AllocateMemory(Length+32)
    If *mtxt
      *mSci = VirtualAllocEx_(hpid, 0, Length, #MEM_RESERVE | #MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
      MessageRequester("*mSci", Str(*mSci))
      If *mSci
        SendMessage_(hSci, #SCI_GETTEXT, 0, *mSci)
        ri = ReadProcessMemory_(hpid, *mSci, *mtxt, Length - SizeOf(Character), @Length2)
        MessageRequester("readprocessmemory", Str(ri))
        MessageRequester("length2", Str(length2))
        txt$ = PeekS(*mtxt, Length2, #PB_Ascii)
        Delay(30)
        VirtualFreeEx_(hpid, *mSci, Length, #MEM_RELEASE)
      EndIf
      MessageRequester("txt$", txt$)
      FreeMemory(*mtxt)
    EndIf
  EndIf
  ProcedureReturn txt$
EndProcedure
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Procedure EnumChildProc(hWnd, *lParam)
    Protected.i Count, i, Size, searchfull
    Protected.s Buffer, Buffer2
    Protected CName.s{128}
    GetClassName_(hWnd, @CName, 128)
    If CName = "ListBox"
      Count = SendMessage_(hWnd, #LB_GETCOUNT, #Null, #Null)
      For i = Count - 1 To 0 Step -1  ; Search bottom up to help search alphabetically.
        Size   = SendMessage_(hWnd, #LB_GETTEXTLEN, i, #Null)
        Buffer = Space(Size + 64)
        If SendMessage_(hWnd, #LB_GETTEXT, i, @Buffer)
          If searchfull = 0
            ; Check if parameters are shown in listview
            If FindString(Buffer, "(")
              searchfull = 1
            Else
              searchfull = -1
            EndIf
          EndIf
          If searchfull = 1
            If PeekS(*lParam) = Buffer
              SendMessage_(hWnd, #LB_SETCURSEL, i, #Null)
              ProcedureReturn 0
            EndIf
          Else
            Buffer2 = Trim(StringField(PeekS(*lParam), 1, "("))
            ;MessageRequester("In EnumChildProc", Buffer + " = " + Buffer2)
            If Buffer2 = Buffer
              SendMessage_(hWnd, #LB_SETCURSEL, i, #Null)
              ProcedureReturn 0
            EndIf
          EndIf
        EndIf
      Next i
    EndIf
    ProcedureReturn 1
  EndProcedure
CompilerEndIf
CompilerIf 0
  Procedure ShowIt2(Line$)
    ; Dummy procedure with nearly same name.
    ; Cursor here did not not select correct Procedure in ListBox.
  EndProcedure
CompilerEndIf
Procedure ShowIt(Line$)
  Protected.i hwnd, i
  Protected.s s$
  CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    hwnd = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))
    i    = FindString(Line$, " ")
    If i = 0
      i = FindString(Line$, #TAB$)
    EndIf
    Line$ = Mid(Line$, i + 1)
    Line$ = RemoveLeadingWhitespaceFromString(Line$)
    ;MessageRequester("SHOWIT", Line$)
    EnumChildWindows_(hWnd, @EnumChildProc(), @Line$)
  CompilerDefault
    ;Linux / Mac?
    MessageRequester("You are here:", Line$)
  CompilerEndSelect
EndProcedure
;-{ START
Define.i i
Define.i CursorLine = Val(StringField(GetEnvironmentVariable("PB_TOOL_Cursor"), 1, "x"))
Define.s ScintillaText$, Line$
If 1
  ScintillaText$ = GetScintillaText()
Else  ;TBD; Get the text from current opened file instead of TEMPFILE.
  Define.i hSci = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
  Define.i hIDE = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))
  Define.i hpid = ct_hpid_from_hW(hSci)
  If hSci And hpid
    ScintillaText$ = ct_sci_GetText(hSci, hpid)
    CloseHandle_(hpid)
  EndIf
EndIf
If ScintillaText$ <> #Empty$
  For i = CursorLine To 1 Step - 1
    Line$ = RemoveLeadingWhitespaceFromString(StringField(ScintillaText$, i, #EOL$))
    ;;MessageRequester("BEFORE SHOWIT", Line$)
    ; Allow EndProcedure to trigger search.
    ;If Left(LCase(Line$), Len("endprocedure")) = "endprocedure"
    ;  Break
    ;EndIf
    If Left(LCase(Line$), Len("procedure")) = "procedure"
      If Left(LCase(Line$), Len("procedurereturn")) <> "procedurereturn"
        ShowIt(Line$)
        Break
      EndIf
    EndIf
  Next i
EndIf
;-} STOP
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: IDE An idea to organize yourself better in large code fi

Post by BarryG »

+1

But this was requested 11 years ago -> viewtopic.php?f=3&t=41215

And this from 12 years ago -> viewtopic.php?f=3&t=38088

So I don't hold much hope that it'll ever happen.
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: IDE An idea to organize yourself better in large code fi

Post by Tenaja »

BarryG wrote:+1

But this was requested 11 years ago -> viewtopic.php?f=3&t=41215

And this from 12 years ago -> viewtopic.php?f=3&t=38088

So I don't hold much hope that it'll ever happen.
Although with the IDE now open source, there is a possibiilty of one of us (i.e. you) adding it...
:mrgreen:
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: IDE An idea to organize yourself better in large code fi

Post by oreopa »

Tenaja wrote:...one of us (i.e. you)...
:lol:

Made my morning... ;)
Proud supporter of PB! * Musician * C64/6502 Freak
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: IDE An idea to organize yourself better in large code fi

Post by BarryG »

Tenaja wrote:Although with the IDE now open source, there is a possibiilty of one of us (i.e. you) adding it
As I keep saying: I would if I knew how to use github (or whatever it is). We need a tutorial.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: IDE An idea to organize yourself better in large code fi

Post by Michael Vogel »

BarryG wrote:+1

But this was requested 11 years ago -> viewtopic.php?f=3&t=41215

And this from 12 years ago -> viewtopic.php?f=3&t=38088

So I don't hold much hope that it'll ever happen.
How time flies... :lol:

Caching the line numbers of all procedure (and macro) headers would also allow to speed up cursor movement in the IDE when procedures are collapsed.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: IDE An idea to organize yourself better in large code fi

Post by infratec »

BarryG wrote:As I keep saying: I would if I knew how to use github (or whatever it is). We need a tutorial.
You don't need github.

Download the source as zip file.
Make the changes.

Remember which files you changed and upload these files as change and start a pull request.

If the last line is to complicated, show the modified files here in the forum and someone will check them in.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: IDE An idea to organize yourself better in large code fi

Post by BarryG »

infratec wrote:Download the source as zip file.
Make the changes.
Remember which files you changed and upload these files as change and start a pull request.
Sounds easy enough, then. I'll give it a play and see.

[Edit] Not so easy after all. The "make" command is not recognized, so I assume I have to install something else? Looks like UnixTools-4-Win.zip, and VisualStudio C++ 2013 Community Edition, and the Windows Platform SDK? Really? All three? That's a lot of software just to edit the IDE. The IDE is written in PureBasic as far as I knew, so I should just be able to edit it using PureBasic as well?
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

Re: IDE An idea to organize yourself better in large code files

Post by Josepho »

Hope you dont get angry if i bump this topic, maybe now that @fred is working on new releases for PB could include this, it would really help a lot the development and it has become somehow an standard for a lot of IDEs since a lot of time
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: IDE An idea to organize yourself better in large code files

Post by davido »

+1
DE AA EB
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: IDE An idea to organize yourself better in large code files

Post by zikitrake »

I would love to see something as native to the editor the great job @RSBasic did with Multicolor Procedure List:
  • Changing color to each procedure
  • Tracking the active procedure (making it visible in the list and/or changing the font to Bold)
  • ...
A marvel that should be in every PB user's home. :D
Post Reply