GoScintilla - 2.7 (Purebasic 4.5 onwards)

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by Tenaja »

Use the debugging tools to see where your bottleneck is; you may be duplicating commands.

I have opened a benchmark file with 100,000's of lines of code and lexed it in about 10-30 seconds (been too long to remember exactly) using a slow laptop and a lexing similar to the PB IDE. It did turn out slower than the PB IDE, but only a small amount. It was about 1/2 or maybe 2/3 the speed of Notepad++. Anybody using a file large enough to see the difference is kind of crazy.
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by StarBootics »

Hello everyone,

I have converted the srod's original code into a module. The source code can be downloaded from this link :
https://www.dropbox.com/s/7sp972ifdc34q ... e.zip?dl=0

Edit #1 : InitScintilla() for Windows Added
Edit #2 : Bug correction

Best regards
StarBootics
Last edited by StarBootics on Mon Mar 11, 2019 12:01 am, edited 3 times in total.
The Stone Age did not end due to a shortage of stones !
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by Zebuddi123 »

Hi Starbootics InitScintilla() missing from example code
Thanks Zebuddi. :)
malleo, caput, bang. Ego, comprehendunt in tempore
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by IdeasVacuum »

Hi Starbotics

Your GoScintilla Module - which version of GoScintilla is it based on? This forum post is about v2.7 but the most recent version, a bug fixer, is v3.1.

Edit: Only ASCII for Syntax Keywords? That sounds strange.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by StarBootics »

IdeasVacuum wrote:Hi Starbotics

Your GoScintilla Module - which version of GoScintilla is it based on? This forum post is about v2.7 but the most recent version, a bug fixer, is v3.1.

Edit: Only ASCII for Syntax Keywords? That sounds strange.
I think it's based on the 2.7 version but I'm not sure about that. Where is the download link for the version 3.1 ?

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by skywalk »

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
CDXbow
User
User
Posts: 97
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by CDXbow »

I want to try to build an app in Scintilla and I want to know what's the best approach. I have some GoScintilla examples that work and a few that don't. I noticed GoScintilla was last updated for PB 5.x. Does it still work properly in 6.20? Is it the best option? Are there alternatives? Syntax highlighting is important and the ability to handle different languages. Perhaps Scintilla is not the best way to go?
User avatar
CDXbow
User
User
Posts: 97
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by CDXbow »

I've jumped in using GoScintilla and things are going OK except I can't open a file. I can save, cut, copy and paste but the file open does not work properly. After selecting a file from the file dialog, a few aberrant characters appear in the Scintilla gadget. It keeps working. I feel it might be something to do with encoding, but I'm well out of depth here. Can anyone help?

Code: Select all

Procedure OpenTextFile()
  file$ = OpenFileRequester("Open file", "", "HTML Files (*.html)|*.html|JavaScript Files (*.js)|*.js|CSS Files (*.css)|*.css|Text Files (*.txt)|*.txt|All Files (*.*)|*.*", 0)
  If file$
    If ReadFile(0, file$)
      fileSize = Lof(0)
      *buffer = AllocateMemory(fileSize)
      If *buffer
        ReadData(0, *buffer, fileSize)
        fileContent$ = PeekS(*buffer, fileSize, #PB_UTF8)
        FreeMemory(*buffer)
        ScintillaSendMessage(#ScintillaGadget, #SCI_SETTEXT, 0, @fileContent$)
        currentFile$ = file$
      EndIf
      CloseFile(0)
    Else
      MessageRequester("Error", "Failed to open the file.", #PB_MessageRequester_Ok)
    EndIf
  EndIf
EndProcedure
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by wombats »

CDXbow wrote: Sun Feb 23, 2025 7:19 am I've jumped in using GoScintilla and things are going OK except I can't open a file. I can save, cut, copy and paste but the file open does not work properly. After selecting a file from the file dialog, a few aberrant characters appear in the Scintilla gadget. It keeps working. I feel it might be something to do with encoding, but I'm well out of depth here. Can anyone help?
How about this?

Code: Select all

EnableExplicit

Procedure OpenTextFile()
  Protected file$, format, fileContent$, buffer
  file$ = OpenFileRequester("Open file", "", "HTML Files (*.html)|*.html|JavaScript Files (*.js)|*.js|CSS Files (*.css)|*.css|Text Files (*.txt)|*.txt|All Files (*.*)|*.*", 0)
  If file$
    If ReadFile(0, file$)
      format = ReadStringFormat(0)
      While Eof(0) = 0
        fileContent$ + ReadString(0, format)
      Wend
      buffer = AllocateMemory(StringByteLength(fileContent$, format) + 1)
      If buffer 
        PokeS(buffer, fileContent$, -1, format)
        ScintillaSendMessage(0, #SCI_SETTEXT, 0, buffer)
        FreeMemory(buffer)
      EndIf
      CloseFile(0)
    Else
      MessageRequester("Error", "Failed to open the file.", #PB_MessageRequester_Ok)
    EndIf
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ScintillaGadget(0, 5, 5, 320, 80, 0)
  
  OpenTextFile()
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
User avatar
CDXbow
User
User
Posts: 97
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by CDXbow »

Thanks Wombat, I gave it a try but it didn't work. No errors, just nothing happened. I have found a solution, which was based of Azjio code in his scintilla notepad. I had previously used the insert date and time code of his to make an insert file procedure. This I had working, so I did this

Code: Select all

Procedure OpenTextFile()
  ; Clear the Scintilla gadget
  ScintillaSendMessage(1, #SCI_CLEARALL, 0, 0)
  ; Move the cursor to the top of the page
  ScintillaSendMessage(1, #SCI_GOTOPOS, 0, 0)
  ; Use InsertFile() to select and insert a file
  InsertFile()
EndProcedure
It is not an elegant solution but works. Now you may ask yourself, why didn't CD use Azjio file open code? It is very complex, did my head in and after reading the first 300 lines I fell asleep without significant understanding. Simple folks like me need simple solutions.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by AZJIO »

CDXbow wrote: Sun Feb 23, 2025 10:54 amIt is not an elegant solution but works. Now you may ask yourself, why didn't CD use Azjio file open code? It is very complex, did my head in and after reading the first 300 lines I fell asleep without significant understanding. Simple folks like me need simple solutions.
Here's a simplified version, or rather a middle ground between the simplest and the most complex in Scintilla. This code is different in that it can open UTF files without BOM

Code: Select all

EnableExplicit
 
Global g_Format
 
; https://www.purebasic.fr/english/viewtopic.php?p=478874
XIncludeFile "AutoDetectTextEncoding_Trim.pbi"
 
; Чтение файла в гаджет
Procedure.s OpenFileToGadget(FilePath$)
    Protected length, oFile, bytes, *mem, Text$
    oFile = ReadFile(#PB_Any, FilePath$)
    If oFile
        g_Format = ReadStringFormat(oFile)
        length = Lof(oFile)
        *mem = AllocateMemory(length)
        If *mem
            bytes = ReadData(oFile, *mem, length)
            If bytes
                If g_Format = #PB_Ascii
                    g_Format = dte::detectTextEncodingInBuffer(*mem, bytes, 0)
                    If g_Format = #PB_Ascii
                        Text$ = PeekS(*mem, bytes, #PB_Ascii)
                    Else
                        Text$ = PeekS(*mem, bytes, #PB_UTF8) ; если UTF8 без BOM
                    EndIf
                Else
                    ; тут не уверен, PeekS() поддерживает #PB_Unicode,
                    ; а ReadStringFormat() может дать #PB_UTF16BE, #PB_UTF32, #PB_UTF32BE
                    ; хотя эти форматы не популярны скорее не встретятся, и надо сделать на них игнор
                    Text$ = PeekS(*mem, bytes, g_Format)
                EndIf
            EndIf
                FreeMemory(*mem)
        EndIf
        CloseFile(oFile)
    EndIf
    ProcedureReturn Text$
EndProcedure
 
Define FilePath$ = "C:\2023.01\1.txt"
Debug OpenFileToGadget(FilePath$)
User avatar
CDXbow
User
User
Posts: 97
Joined: Mon Aug 12, 2019 5:32 am
Location: Oz

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by CDXbow »

Thank you very much Azjio, I appreciate it. I haven't got time to try it now, but I will this evening and report back.

ADDED - It works. Again, many thanks.
Post Reply