Sources PureBasic

Sources PureBasicConsultez toutes les sources
Nombre d'auteurs : 41, nombre de sources : 88, dernière mise à jour : 13 août 2011
Sommaire→ScintillaExécutez ce programme, et copiez un code XML dans la fenêtre qui s'affiche, la coloration syntaxique définie ci dessous devrait s'appliquer à votre texte.
EnableExplicit
InitScintilla("SciLexer") ; use a version with lexer, not the scintilla.dll!
Procedure SetScintillaProperties(id)
ScintillaSendMessage(id, #SCI_SETLEXER,#SCLEX_XML)
; # Default
ScintillaSendMessage(id, #SCI_STYLESETFORE, #STYLE_DEFAULT, #Black)
ScintillaSendMessage(id, #SCI_STYLESETBACK, #STYLE_DEFAULT, #White)
ScintillaSendMessage(id, #SCI_STYLECLEARALL)
; # Tags
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_TAG, RGB($00, $00, 80))
; # Unknown Tags
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_TAGUNKNOWN, RGB($00, $00, $80))
; # Attributes
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_ATTRIBUTE, RGB($00, $80, $80))
; # Unknown Attributes
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_ATTRIBUTEUNKNOWN, RGB($00, $80, $80))
; # Numbers
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_NUMBER, #Red)
; # Double quoted strings
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_DOUBLESTRING, RGB(120, 120, 120))
; # Single quoted strings
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_SINGLESTRING, RGB(120, 120, 120))
; # Other inside tag
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_OTHER, RGB($80, $00, $80))
; # Comment
ScintillaSendMessage(id, #SCI_STYLESETFORE, #SCE_H_COMMENT, RGB($80, $00, $80))
; ...
; #define SCE_H_ENTITY 10
; #define SCE_H_TAGEND 11
; #define SCE_H_XMLSTART 12
; #define SCE_H_XMLEND 13
; #define SCE_H_SCRIPT 14
; #define SCE_H_ASP 15
; #define SCE_H_ASPAT 16
; #define SCE_H_CDATA 17
; #define SCE_H_QUESTION 18
; #define SCE_H_VALUE 19
; #define SCE_H_XCCOMMENT 20
EndProcedure
OpenWindow(0, #PB_Ignore, #PB_Ignore, 800, 600, "XML", #PB_Window_SystemMenu)
RemoveKeyboardShortcut(0, #PB_Shortcut_Tab)
ScintillaGadget(0, 5, 5, 790, 590, 0)
SetScintillaProperties(0)
While WaitWindowEvent() <> #PB_Event_CloseWindow : WendCe code montre comment utiliser la bibliothèque scintilla.
;===========================================;
; ;
; Scintilla example ;
; ;
;===========================================;
Global KeyWordUp.s, KeyWordDown.s, KeyWordNone.s
KeyWordUp = "Repeat If Procedure"
KeyWordDown = "ForEver EndIf EndProcedure"
KeyWordNone = "Else"
Enumeration 0
#LexerState_Space
#LexerState_Comment
#LexerState_NonKeyword
#LexerState_Keyword
#LexerState_FoldKeyword
#LexerState_Constant
#LexerState_String
#LexerState_FoldKeywordUp
#LexerState_FoldKeywordDown
EndEnumeration
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
InitScintilla("Scintilla.dll")
CompilerEndIf
Procedure SCI_GetLineEndPosition(gadget, line)
ProcedureReturn ScintillaSendMessage(gadget,#SCI_GETLINEENDPOSITION,line)
EndProcedure
Procedure SCI_LineFromPosition(gadget, Pos)
ProcedureReturn ScintillaSendMessage(gadget,#SCI_LINEFROMPOSITION,Pos)
EndProcedure
Procedure KeyWordIs(key.s)
Protected n
If key=""
ProcedureReturn -1
EndIf
For n=1 To CountString(KeyWordUp, " ") + 1
If LCase(StringField(KeyWordUp, n, " ")) = LCase(key)
ProcedureReturn #LexerState_FoldKeywordUp
EndIf
Next n
For n=1 To CountString(KeyWordDown, " ") + 1
If LCase(StringField(KeyWordDown, n, " ")) = LCase(key)
ProcedureReturn #LexerState_FoldKeywordDown
EndIf
Next n
For n=1 To CountString(KeyWordNone, " ") + 1
If LCase(StringField(KeyWordNone, n, " ")) = LCase(key)
ProcedureReturn #LexerState_Keyword
EndIf
Next n
ProcedureReturn -1
EndProcedure
Procedure Highlight(sciptr.l, endpos.l)
Protected level = #SC_FOLDLEVELBASE, Char.l, keyword.s, state.i, linenumber.l
Protected thislevel.l = level
Protected nextlevel.l = level
Protected CurrentPos.l = 0, endlinepos.l, startkeyword
Protected currentline.l = 0
endpos = SCI_GetLineEndPosition(sciptr, SCI_LineFromPosition(sciptr, endpos))
ScintillaSendMessage(sciptr, #SCI_STARTSTYLING, CurrentPos, $1F | #INDICS_MASK)
While CurrentPos <= endpos
Char = ScintillaSendMessage(sciptr, #SCI_GETCHARAT, CurrentPos)
Select Char
Case 10
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, 1, #LexerState_NonKeyword)
ScintillaSendMessage(sciptr, #SCI_SETFOLDLEVEL, linenumber , thislevel)
thislevel = nextlevel
linenumber + 1
Case 'a' To 'z', 'A' To 'Z'
endlinepos = SCI_GetLineEndPosition(sciptr, SCI_LineFromPosition(sciptr, currentpos))
keyword = Chr(char)
While currentpos < endlinepos
currentpos + 1
char = ScintillaSendMessage(sciptr, #SCI_GETCHARAT, currentpos)
If Not ((char >= 'a' And char <= 'z') Or (char >= 'A' And char <= 'Z') Or char = '_'Or (char >= '0' And char <= '9'))
currentpos-1
Break
EndIf
keyword + Chr(char)
Wend
Select KeyWordIs(keyword)
Case #LexerState_FoldKeywordUp
state = #LexerState_Keyword
thislevel | #SC_FOLDLEVELHEADERFLAG
nextlevel + 1
Case #LexerState_FoldKeywordDown
state = #LexerState_Keyword
nextlevel - 1
If nextlevel < #SC_FOLDLEVELBASE
nextlevel = #SC_FOLDLEVELBASE
EndIf
Case #LexerState_Keyword
state = #LexerState_Keyword
Default
state = #LexerState_NonKeyword
EndSelect
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, Len(keyword), state)
Case '"'
endlinepos = SCI_GetLineEndPosition(sciptr, SCI_LineFromPosition(sciptr, currentpos))
startkeyword = 1
While currentpos < endlinepos
currentpos + 1
startkeyword + 1
If ScintillaSendMessage(sciptr, #SCI_GETCHARAT, currentpos) = '"'
Break
EndIf
Wend
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, startkeyword, #LexerState_String)
Case ';'
endlinepos = SCI_GetLineEndPosition(sciptr, SCI_LineFromPosition(sciptr, currentpos))
startkeyword = 1
While currentpos < endlinepos
currentpos + 1
startkeyword + 1
Wend
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, startkeyword, #LexerState_Comment)
Case 9, ' '
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, 1, #LexerState_Space)
Case '#'
endlinepos = SCI_GetLineEndPosition(sciptr, SCI_LineFromPosition(sciptr, currentpos))
startkeyword = 1
While currentpos < endlinepos
currentpos + 1
char = ScintillaSendMessage(sciptr, #SCI_GETCHARAT, currentpos)
If Not ((char >= 'a' And char <= 'z') Or (char >= 'A' And char <= 'Z') Or char = '_' Or (char >= '0' And char <= '9'))
currentpos-1
Break
EndIf
startkeyword + 1
Wend
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, startkeyword, #LexerState_Constant)
Default
ScintillaSendMessage(sciptr, #SCI_SETSTYLING, 1, #LexerState_NonKeyword)
EndSelect
currentpos+1
Wend
EndProcedure
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
Case #SCN_STYLENEEDED
Highlight(Gadget, *scinotify\position)
Case #SCN_MARGINCLICK
ScintillaSendMessage(Gadget, #SCI_TOGGLEFOLD, ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, *scinotify\Position))
EndSelect
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "Scintilla exemple", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
If UseGadgetList(WindowID(0))
ScintillaGadget(0, 0, 0, 800, 600, @ScintillaCallBack())
; Choose a lexer
ScintillaSendMessage(0, #SCI_SETLEXER, #SCLEX_CONTAINER, 0)
; Set default font
ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, @"Courier New")
ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12)
ScintillaSendMessage(0, #SCI_STYLECLEARALL)
; Set caret line colour
ScintillaSendMessage(0, #SCI_SETCARETLINEBACK, $eeeeff)
ScintillaSendMessage(0, #SCI_SETCARETLINEVISIBLE, #True)
; Set styles for custom lexer
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Comment, $bb00)
ScintillaSendMessage(0, #SCI_STYLESETITALIC, #LexerState_Comment, 1)
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_NonKeyword, 0)
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Keyword, RGB(0, 102, 102))
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_Constant, RGB(169, 64, 147))
ScintillaSendMessage(0, #SCI_STYLESETFORE, #LexerState_String, RGB(255, 139, 37))
; Margins
ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
ScintillaSendMessage(0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 0, 50)
ScintillaSendMessage(0, #SCI_SETMARGINWIDTHN, 2, 20)
ScintillaSendMessage(0, #SCI_SETMARGINSENSITIVEN, 2, #True)
; Choose folding icons
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_CIRCLEMINUS)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER, #SC_MARK_CIRCLEPLUS)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB, #SC_MARK_VLINE)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL, #SC_MARK_LCORNERCURVE)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND, #SC_MARK_CIRCLEPLUSCONNECTED)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID, #SC_MARK_CIRCLEMINUSCONNECTED)
ScintillaSendMessage(0, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERMIDTAIL, #SC_MARK_TCORNERCURVE)
; Choose folding icon colours
ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, $FFFFFF)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, 0)
ScintillaSendMessage(0, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, $FFFFFF)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, 0)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, 0)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERSUB, 0)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERTAIL, 0)
ScintillaSendMessage(0, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERMIDTAIL, 0)
txt.s = "procedure test()"+#LF$
txt.s + " #test = "+ Chr(34)+ "chaine 1"+ Chr(34)+#LF$
txt.s + " If #test = 24"+#LF$
txt.s + " ;test "+#LF$
txt.s + " Else"+#LF$
txt.s + ""+#LF$
txt.s + " EndIf"+#LF$
txt.s + "EndProcedure"+#LF$
ScintillaSendMessage(0, #SCI_SETTEXT, #Null, @txt)
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
EndC'est une version minimaliste, elle permet surtout de montrer les bases pour créer son propre éditeur.
EnableExplicit
Enumeration
#File
#Mainform
#MainMenu
#New
#Open
#Save
#SaveAs
#Quit
#Editor
#StatusBar
EndEnumeration
Global StyleWindows.l=#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget
Global SciPos.l, SciLine.l, SciCol.l, SciIndent.l, SciFile.s, SciText.s
Global Result.l, FileLenght.l, *MemoryID.l
;Initialisation de la DLL Scintilla.
;Attention : SciLexer.dll doit etre present dans le meme dossier que votre programme
;ou bien dans un dossier dont vous aurez indiqué le chemin.
If Not InitScintilla("SciLexer.dll")
MessageRequester("Information", "SciLexer.dll doit etre present dans le meme dossier que votre programme")
End
EndIf
;CallBack qui recevra les evenements emis par le gadget Scintilla
;*scinotify pointe vers une structure comportant les informations sur l'évènement:
;Voir le bas de cette page http://www.scintilla.org/ScintillaDoc.html
;
;Cette procedure va permettre de connaitre la position courante du curseur
;et de se positionner correctement apres avoir actionner la touche Entrée
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
;La touche Entrée est utilisée
If *scinotify\ch=13
;Mise en place dans la nouvelle ligne de l'indentation de la ligne précédente
ScintillaSendMessage(Gadget, #SCI_SETLINEINDENTATION, SciLIne+1, SciIndent)
;Positionnement du curseur d'edition sur la nouvelle ligne
;Si pas d'indentation alors on ajoute 2 (ça fait bricolage mais je n'ai pas trouvé mieux)
If SciIndent=0
SciPos=SciPos+2
EndIf
;Positionnement du curseur
ScintillaSendMessage(Gadget, #SCI_GOTOPOS, SciPos+SciIndent)
EndIf
;Determination de la position à l'intérieur de la chaine scintilla
SciPos = ScintillaSendMessage(Gadget, #SCI_GETANCHOR)
;Determination de la ligne en cours
SciLine = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, SciPos)
;Determination de la colonne en cours
SciCol = ScintillaSendMessage(Gadget, #SCI_GETCOLUMN, SciPos)
;Determination de l'indentation
SciIndent = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, SciLine)
;Affichage du numéro de ligne/colonne dans la barre de status
StatusBarText(#StatusBar,0,"Line : " +Str(SciLine+1)+ " Col : "+Str(SciCol+1), #PB_StatusBar_Center)
EndProcedure
Procedure SetScintillaProperties(Gadget)
;Chargement du dictionnaire HTML
ScintillaSendMessage(Gadget, #SCI_SETLEXER, #SCLEX_HTML)
;Style par defaut du gadget scintilla
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, #Black)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, $EAFEFE)
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT,#STYLE_DEFAULT,@"Verdana")
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12)
;ScintillaSendMessage(gadget, #SCI_CLEARALL)
;Affichage de la colone de numérotation des lignes
ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER) ;
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, 40)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, $D4D4D4)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, #Yellow)
;Margin Mask Folder
ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 2, 15)
;Affichage et couleur de la ligne active
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, #True)
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, $C4FBFA)
;Les tabulations sont remplacées par des espaces
ScintillaSendMessage(Gadget, #SCI_SETUSETABS, #False)
;Nombre d'espaces pour une tabulation
ScintillaSendMessage(Gadget, #SCI_SETINDENT, 4)
;Affichage du guide d'indentation et affectatoin d'une couleur
ScintillaSendMessage(Gadget, #SCI_SETINDENTATIONGUIDES, #SC_IV_LOOKFORWARD)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_INDENTGUIDE, #Red)
;coloration syntaxique (Prefixe #SCE_H pour les attribut du lexer HTML)
;Texte par defaut
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_DEFAULT, #Black)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_DEFAULT, $EAFEFE)
;Balises HTML
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_TAG, #Red)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_TAG, $EAFEFE)
;Balises inconnues
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_TAGUNKNOWN, $949494)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_TAGUNKNOWN, $EAFEFE)
;Attributs
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_ATTRIBUTE, #Blue)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_ATTRIBUTE, $EAFEFE)
;Attributs inconnus
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_ATTRIBUTEUNKNOWN, $505000)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_ATTRIBUTEUNKNOWN, $EAFEFE)
;Chiffres
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_NUMBER, #Red)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_NUMBER, $EAFEFE)
;Texte entres guillemets
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_DOUBLESTRING, $787878)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_DOUBLESTRING, $EAFEFE)
;Textes entres simples quotes
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_SINGLESTRING, $787878)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_SINGLESTRING, $EAFEFE)
;Autres balises
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_OTHER, $AE0050)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_OTHER, $EAFEFE)
;Commentaires
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_H_COMMENT, #Green)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_H_COMMENT, $EAFEFE)
EndProcedure
;Affichage de la fenetre principale de l'application
Procedure MainFormShow()
OpenWindow(#MainForm, 0, 0, 800, 600, "HTML Editor", StyleWindows)
;Evite le scintillement du Scintilla gadget lors du redimentionnement de la fenetre
SmartWindowRefresh(#Mainform, #True)
;Menu de l'application
CreateMenu(#mainmenu,WindowID(#MainForm))
MenuTitle("Fichier")
MenuItem(#New,"Nouveau")
MenuItem(#Open,"Ouvrir")
MenuItem(#Save,"Enregistre")
MenuItem(#SaveAs,"Enregistrer Sous")
MenuBar()
MenuItem(#Quit,"Quitter")
;@ScintillaCallBack() correspond à l'adresse de la procédure
;qui recevra les évènements émis par le contrôle.
ScintillaGadget(#Editor, 10, 40, 790, 590, @ScintillaCallBack())
CreateStatusBar(#StatusBar,WindowID(#Mainform))
AddStatusBarField(150)
AddStatusBarField(450)
RemoveKeyboardShortcut(#Mainform, #PB_Shortcut_Tab)
;Affectation des touches de racourcis à aucun évènement menu
;tant qu'elles ne servent à rien afin d'éviter l'insertion des caracteres spéciaux
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_B, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_G, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_E, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_R, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_O, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_P, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_Q, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_S, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_F, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_H, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_K, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_W, 0)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_N, 0)
StatusBarText(#StatusBar,1,"Nouveau document")
SetActiveGadget(#editor)
EndProcedure
;Redimensionnement de la fenetre principale
Procedure MainFormResize()
ResizeGadget(#Editor, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-30, WindowHeight(#Mainform)-100)
EndProcedure
;Nouveau document
Procedure NewFile()
ScintillaSendMessage(#Editor, #SCI_SETTEXT, 0, @"")
StatusBarText(#StatusBar,1,"Nouveau document")
EndProcedure
;Ouverture d'un fichier
Procedure LoadFile()
SciFile=OpenFileRequester("Ouvrir un fichier", "", "html (*.html)|*.html|All files (*.*)|*.*", 0)
If SciFile
StatusBarText(#StatusBar,1,SciFile)
If ReadFile(#File, SciFile)
FileLenght = Lof(#file)
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ReadData(#File, *MemoryID, FileLenght)
ScintillaSendMessage(#Editor, #SCI_SETTEXT, 0, *MemoryID)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
EndIf
EndProcedure
;Sauvegarde d'un fichier sous
Procedure SaveFileAs()
SciFile=OpenFileRequester("Sauvegarder un fichier sous", "", "html (*.html)|*.html|All files (*.*)|*.*", 0)
If SciFile
StatusBarText(#StatusBar,1,SciFile)
If CreateFile(#File, SciFile)
FileLenght = ScintillaSendMessage(#Editor, #SCI_GETLENGTH)+1
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ScintillaSendMessage(#Editor, #SCI_GETTEXT, FileLenght, *MemoryID)
WriteData(#File, *MemoryID, FileLenght)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
EndIf
EndProcedure
;Sauvegarde d'un fichier
Procedure SaveFile()
If SciFile<>""
If CreateFile(#File, SciFile)
FileLenght = ScintillaSendMessage(#Editor, #SCI_GETLENGTH)+1
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ScintillaSendMessage(#Editor, #SCI_GETTEXT, FileLenght, *MemoryID)
WriteData(#File, *MemoryID, FileLenght)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
Else
SaveFileAs()
EndIf
EndProcedure
;Debut du traitement
MainFormShow()
SetScintillaProperties(#Editor)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case #new
NewFile()
Case #Open
LoadFile()
Case #Save
SaveFile()
Case #SaveAs
SaveFileAs()
Case #Quit
End
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
Case #PB_Event_SizeWindow
MainFormResize()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver


