j'ai corrigé la procédure de recherche / remplacer.
pour effectuer la recherche.
Code : Tout sélectionner
; Scintilla : Search Replace Exemple
EnableExplicit
Enumeration
#Mainform
#Editor
#StringFindForm
#StringFind
#StringFindCheck
#StringReplace
#Btn_StringFindNext
#Btn_StringFindReplace
#Btn_StringFindEnd
#Kbd_CtrlF ;Shortcut Find / replace
#Kbd_F3 ;Shortcut Next string
#Kbd_Return
#LexerState_Error
EndEnumeration
Define.l Event, WEvent, MEvent, GEvent, TEvent
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Global StringFind.s, StringReplace.s
;Indentation
Global SciPos.l, SciLine.l, SciCol.l, SciIndent.l
; Set Text
Procedure ScintillaSetText(Gadget.l, Buffer.s)
ScintillaSendMessage(Gadget, #SCI_SETTEXT, 0, @Buffer)
EndProcedure
; Get Text
Procedure.s ScintillaGetText(Gadget.l)
Protected SciLength.i, *MemoryID, Buffer.s
SciLength = ScintillaSendMessage(Gadget, #SCI_GETLENGTH)+1
*MemoryID = AllocateMemory(SciLength)
If *MemoryID
ScintillaSendMessage(Gadget, #SCI_GETTEXT, SciLength, *MemoryID)
Buffer=PeekS(*MemoryID)
FreeMemory(*MemoryID)
EndIf
ProcedureReturn(Buffer)
EndProcedure
; Find String
Procedure ScintillaStringFind(StringFind.s)
Protected Current.l, start.l, Anchor.l, Result.i
If StringFind <> ""
Current = ScintillaSendMessage(#Editor, #SCI_GETCURRENTPOS)
ScintillaSendMessage(#Editor, #SCI_SETANCHOR, Current)
ScintillaSendMessage(#Editor, #SCI_SEARCHANCHOR)
Start = ScintillaSendMessage(#Editor, #SCI_SEARCHNEXT, 0, @StringFind)
If Start<> -1
anchor = ScintillaSendMessage(#Editor, #SCI_GETANCHOR)
ScintillaSendMessage(#Editor, #SCI_SETSEL, start, anchor)
Else
Result = MessageRequester("Find string", "No more matching."+#CRLF$+
"Do you Want to Continue the search from the beginning",
#PB_MessageRequester_YesNo)
If Result = #PB_MessageRequester_Yes
ScintillaSendMessage(#Editor, #SCI_GOTOLINE, 0, 0)
ScintillaStringFind(StringFind)
Else
EndIf
EndIf
EndIf
EndProcedure
; Find Replace string
Procedure ScintillaStringReplace(StringFind.s, StringReplace.s)
Protected StringSel.s
;Storing the selected word
ScintillaSendMessage(#Editor, #SCI_COPY)
StringSel=GetClipboardText()
If LCase(StringSel)=LCase(StringFind)
SetClipboardText(StringReplace)
ScintillaSendMessage(#Editor, #SCI_PASTE)
;Find the next occurrence
ScintillaStringFind(StringFind)
EndIf
EndProcedure
; Show find/replace string dialog
Procedure Open_StringFindForm()
If OpenWindow(#StringFindForm,0,0,455,195,"Find/Replace",#PB_Window_Tool|#PB_Window_WindowCentered,WindowID(#Mainform))
TextGadget(#PB_Any,30,21,85,20,"Find")
ComboBoxGadget(#StringFind,130,18,310,23,#PB_ComboBox_Editable)
CheckBoxGadget(#StringFindCheck,15,60,105,20,"Replace by")
ComboBoxGadget(#StringReplace,130,59,310,23,#PB_ComboBox_Editable)
ButtonGadget(#Btn_StringFindNext,20,150,125,20,"Next String")
ButtonGadget(#Btn_StringFindReplace,160,150,80,20,"Replace")
ButtonGadget(#Btn_StringFindEnd,360,150,80,20,"Close")
DisableGadget(#StringReplace, #True)
DisableGadget(#Btn_StringFindReplace, #True)
SetActiveGadget(#StringFind)
AddKeyboardShortcut(#StringFindForm, #PB_Shortcut_Return, #Kbd_Return) ;Find String
EndIf
EndProcedure
; Scintilla Callback
;
; CallBack To receive the events of Scintilla gadget
; scinotify * pointer to a structure containing the information on the event:
; See the bottom of this page http://www.scintilla.org/ScintillaDoc.html
;
; -Knowing the current cursor position and correctly position
; after having press the Enter key
Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
; Enter key is used
If *scinotify\ch=13
;New line: Cursor on the indentation of the previous line.
ScintillaSendMessage(Gadget, #SCI_SETLINEINDENTATION, SciLIne+1, SciIndent)
If SciIndent=0
SciPos=SciPos+2
EndIf
ScintillaSendMessage(Gadget, #SCI_GOTOPOS, SciPos+SciIndent)
EndIf
;Position in the chain scintilla
SciPos = ScintillaSendMessage(Gadget, #SCI_GETANCHOR)
;Line from position
SciLine = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, SciPos)
;Column from position
SciCol = ScintillaSendMessage(Gadget, #SCI_GETCOLUMN, SciPos)
;Determination de l'indentation
SciIndent = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, SciLine)
EndProcedure
;Init scintilla properties (minimalist)
Procedure ScintillaSetProperties(Gadget)
ScintillaSendMessage(Gadget, #SCI_SETLEXER, 0); No lexer
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT, #STYLE_DEFAULT,@"Arial") ;Police
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12) ;Size
ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, RGB(245, 245, 220));Line Active BackColor
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, #True) ;Cursor Yes
ScintillaSendMessage(gadget, #SCI_SETCARETWIDTH, 3) ;Cursor Size
ScintillaSendMessage(Gadget, #SCI_SETUSETABS, #False) ;User tabs replace by space
ScintillaSendMessage(Gadget, #SCI_SETINDENT, 8) ; Number spaces
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #LexerState_Error, RGB(255, 0, 0))
EndProcedure
;Mainform
Procedure Open_MainForm()
OpenWindow(#Mainform, 0, 0, 800, 600, "Recherche", WindowStyle)
ScintillaGadget(#Editor, 10, 10, 780, 580, @ScintillaCallBack())
ScintillaSetProperties(#Editor)
;Init Shortcut
RemoveKeyboardShortcut(#Mainform, #PB_Shortcut_Tab)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_F|#PB_Shortcut_Control, #Kbd_CtrlF)
AddKeyboardShortcut(#Mainform, #PB_Shortcut_F3, #Kbd_F3)
SetActiveGadget(#Editor)
EndProcedure
Procedure Start()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
InitScintilla()
CompilerEndIf
Open_MainForm()
ScintillaSetText(#Editor, "éventuel"+#CRLF$+"élève"+#CRLF$+"bientôt")
;Goto line 0
ScintillaSendMessage(#Editor, #SCI_GOTOLINE, 0, 0)
ScintillaSendMessage(#Editor, #SCI_SETSELFORE,RGB(255, 0, 0),0)
EndProcedure
start()
Repeat
Event = WaitWindowEvent(10)
WEvent = EventWindow()
MEvent = EventMenu()
GEvent = EventGadget()
TEvent = EventType()
Select Event
Case #PB_Event_Menu
Select MEvent
Case #Kbd_CtrlF
Open_StringFindForm()
Case #Kbd_F3
ScintillaStringFind(StringFind)
Case #Kbd_Return
Select WEvent
Case #StringFindForm
ScintillaStringFind(StringFind)
EndSelect
EndSelect
Case #PB_Event_Gadget
Select GEvent
Case #StringFindCheck
If GetGadgetState(#StringFindCheck)=#PB_Checkbox_Checked
DisableGadget(#StringReplace, #False)
DisableGadget(#Btn_StringFindReplace, #False)
Else
DisableGadget(#StringReplace, #True)
DisableGadget(#Btn_StringFindReplace, #True)
EndIf
Case #StringFind
StringFind=GetGadgetText(#StringFind)
Case #StringReplace
StringReplace=GetGadgetText(#StringReplace)
Case #Btn_StringFindEnd
CloseWindow(#StringFindForm)
Case #Btn_StringFindNext
ScintillaStringFind(GetGadgetText(#StringFind))
Case #Btn_StringFindReplace
ScintillaStringReplace(StringFind, StringReplace)
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver