Page 1 of 1

Some "CodeHolder" in the Toolspanel of the IDE

Posted: Tue Mar 18, 2008 4:20 pm
by Franky
Hi people.

It would be handy to have just a little EditorGadget (Scintilla) in the toolspanel. Just to be able to copy some lines for example of Constant-Declarations in it. So I can write the specific Gadgets for it without forgetting one or always having to switch between the codes. Something like a "Notes"-Window. Shouldn´t be to hard to realise, should it?

I don´t know if this was requested before, because I don´t really know how to call it. So I searched for ToolsPanel and looked up the 2 last Pages of Features Requests and Wishlist.

Posted: Tue Mar 18, 2008 5:33 pm
by Trond
Sort of Tools -> Templates?

Posted: Tue Mar 18, 2008 6:20 pm
by Franky
You meant "ToolsPanel->Sort of Tools -> Code Templates"?

No, that´s not, what I want.

I meant more something like one of those PostIts you have around your screen

Image


IN the Screen.

I just build up my own little thing (it´s just a little bit changed from the original Code of TS-Soft, so not my work ;)):

Code: Select all

Define.s HighLightDLLPath = #PB_Compiler_Home + "Library SDK\Syntax Highlighting\SyntaxHilighting.dll"

If OpenLibrary(0, HighLightDLLPath) = #False : Debug "HL-DLL nicht gefunden" : End : EndIf
If InitScintilla("scintilla.dll") = #False : Debug "Scintilla-DLL nicht gefunden" : End : EndIf

Prototype SyntaxHighlight(*Buffer, len.l, callback.l, asm.l)
Global SyntaxHighlight.SyntaxHighlight = GetFunction(0, "SyntaxHighlight")

Enumeration; Gadgets
  #SciID
  #SciID2
  #Splitter
EndEnumeration

Enumeration; Syntax
  #SYNTAX_Text
  #SYNTAX_Keyword
  #SYNTAX_Comment
  #SYNTAX_Constant
  #SYNTAX_String
  #SYNTAX_Function
  #SYNTAX_Asm
  #SYNTAX_Operator
  #SYNTAX_Structure
  #SYNTAX_Number
  #SYNTAX_Pointer
  #SYNTAX_Separator
  #SYNTAX_Label
EndEnumeration

Define.l start_pos, Buffer, Editor

Procedure.s GetSpecialFolder(CSIDL.l)
  Protected *itemid.ITEMIDLIST
  Protected location.s = Space(#MAX_PATH)

  If SHGetSpecialFolderLocation_ (0, CSIDL, @*itemid) = #NOERROR
    If SHGetPathFromIDList_(*itemid, @location)
      If Right(location, 1) <> "\" : location + "\" : EndIf
      ProcedureReturn location
    EndIf
  EndIf
EndProcedure

Procedure SHCallback(pos, len, id)
  Shared start_pos,Buffer, Editor

  ScintillaSendMessage(Editor, #SCI_STARTSTYLING, (pos - Buffer) + start_pos, $1F)
  ScintillaSendMessage(Editor, #SCI_SETSTYLING, len, id)
EndProcedure

Procedure ScintillaCallBack(EditorGadget.l, *scinotify.SCNotification)
  Protected line_number.l
  Protected txtr.TEXTRANGE
  Protected end_pos.l
  Shared start_pos, Buffer, Editor
 
  Editor = EditorGadget
  If *scinotify\nmhdr\code = #SCN_STYLENEEDED
    line_number = ScintillaSendMessage(EditorGadget, #SCI_LINEFROMPOSITION, ScintillaSendMessage(EditorGadget, #SCI_GETENDSTYLED))
    start_pos = ScintillaSendMessage(EditorGadget, #SCI_POSITIONFROMLINE, line_number)
    end_pos     = *scinotify\Position

    txtr\chrg\cpMin = start_pos
    txtr\chrg\cpMax = end_pos
    txtr\lpstrText  = AllocateMemory(end_pos - start_pos + 1)
    Buffer          = txtr\lpstrText

    ScintillaSendMessage(EditorGadget, #SCI_GETTEXTRANGE, 0, txtr)
    SyntaxHighlight(Buffer, end_pos - start_pos, @SHCallback(), #False)

    FreeMemory(Buffer)
  EndIf
EndProcedure

Procedure CreatePBSourceView()
Protected temp.s
    ScintillaSendMessage(#SciID, #SCI_SETLEXER, #SCLEX_CONTAINER)

    OpenPreferences(GetSpecialFolder(#CSIDL_APPDATA) + "PureBasic\PureBasic.prefs")
    PreferenceGroup("Editor")
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE,#STYLE_DEFAULT, $000000)
    ScintillaSendMessage(#SciID, #SCI_STYLESETBACK, #STYLE_DEFAULT, ReadPreferenceLong("BackgroundColor", $FFFFFF))
    temp = ReadPreferenceString("EditorFontName", "Courier New")
    ScintillaSendMessage(#SciID, #SCI_STYLESETFONT, #STYLE_DEFAULT, @temp)
    ScintillaSendMessage(#SciID, #SCI_STYLESETSIZE, #STYLE_DEFAULT, ReadPreferenceLong("EditorFontSize", 10))
    ScintillaSendMessage(#SciID, #SCI_STYLECLEARALL)

    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Text, ReadPreferenceLong("NormalTextColor", 0))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Keyword, ReadPreferenceLong("BasicKeywordColor", $9D030D))
    ScintillaSendMessage(#SciID, #SCI_STYLESETBOLD, #SYNTAX_Keyword, #True)
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Comment, ReadPreferenceLong("CommentColor", $6F884A))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Constant, ReadPreferenceLong("ConstantColor", $0B46AE))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_String, ReadPreferenceLong("StringColor", $413C33))
    ScintillaSendMessage(#SciID, #SCI_STYLESETITALIC, #SYNTAX_String, #True)
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Function, ReadPreferenceLong("PureKeywordColor", $EF303D))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Asm, ReadPreferenceLong("ASMKeywordColor", $400080))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Operator,  ReadPreferenceLong("OperatorColor", $0000FF))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Structure, ReadPreferenceLong("StructureColor", $0548B4))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Number, ReadPreferenceLong("NumberColor", $0000FF))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Pointer,  ReadPreferenceLong("PointerColor", $0507B4))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Separator,  ReadPreferenceLong("SeparatorColor", $000000))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #SYNTAX_Label,  ReadPreferenceLong("LabelColor", $804000))
    ScintillaSendMessage(#SciID, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
    ScintillaSendMessage(#SciID, #SCI_SETMARGINWIDTHN, 0, 10)
    ScintillaSendMessage(#SciID, #SCI_STYLESETBACK, #STYLE_LINENUMBER, ReadPreferenceLong("LineNumberBackColor", GetSysColor_(15)))
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #STYLE_LINENUMBER, ReadPreferenceLong("LineNumberColor", 0))
    ScintillaSendMessage(#SciID, #SCI_SETMARGINWIDTHN, 1, 5)
    ClosePreferences()
EndProcedure

If OpenWindow(0,800,200,100,100,"NoteIT!",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
   SetWindowState(0,#WS_EX_TOOLWINDOW)
   StickyWindow(0,1)
       CreateGadgetList(WindowID(0))
          ScintillaGadget(0,0,0,100,100,@ScintillaCallBack())
          CreatePBSourceView()
         Repeat 
          event=WaitWindowEvent()
          If event=#PB_Event_SizeWindow
                 ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
          EndIf
         Until event=#PB_Event_CloseWindow
EndIf
A simple Editorgadget to have things in view, nothing more.

The advantage to have it IN the IDE would bei, that it wouldn´t be in front when the PB-IDE is not active.

Even that Line-Counting-Thing is not needet.