C'est plus facile à faire en remplaçant l'EditorGadget par le ListViewGadget.
Sinon avec l'EditorGadget, il faut utiliser les apis.
J'ai mis les deux codes, ci-dessous.
ListViewGadget
Code : Tout sélectionner
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#Window_0
EndEnumeration
Enumeration FormGadget
#Tree_0
#Editor_0
#Splitter_0
#Btn_Quit
EndEnumeration
Declare ResizeGadgetsWindow_0()
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
TreeGadget(#Tree_0, 10, 15, 177, 340)
ListViewGadget(#Editor_0, 196, 15, 394, 340);EditorGadget(#Editor_0, 196, 15, 394, 340)
SplitterGadget(#Splitter_0, 10, 15, 580, 340, #Tree_0, #Editor_0, #PB_Splitter_Vertical)
SetGadgetState(#Splitter_0, 177)
ButtonGadget(#Btn_Quit, 485, 365, 100, 25, "Quitter")
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#Tree_0, 10, 15, 177, FormWindowHeight - 60)
ResizeGadget(#Editor_0, FormWindowWidth - 404, 15, 394, FormWindowHeight - 60)
ResizeGadget(#Splitter_0, 10, 15, FormWindowWidth - 20, FormWindowHeight - 60)
ResizeGadget(#Btn_Quit, GadgetWidth(#Splitter_0) - 95, GadgetHeight(#Splitter_0) - -25, 100, 25)
EndProcedure
;XIncludeFile "Splitter.pbf"
OpenWindow_0()
For ID = #Tree_0 To #Editor_0
For a = 0 To 10
AddGadgetItem(ID, -1, "Elément normal "+Str(a), 0, 0) ; si vous souhaitez ajouter une image, utilisez
AddGadgetItem(ID, -1, "Noeud "+Str(a), 0, 0) ; ImageID(x) comme 4ème paramètre
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-1", 0, 1) ; Ceux-là sont au premier sous-niveau
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-2", 0, 1)
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-3", 0, 1)
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-4", 0, 1)
AddGadgetItem(ID, -1, "Fichier "+Str(a), 0, 0) ; sous-niveau 0 à nouveau
Next
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #Btn_Quit
Break
Case #Tree_0
Select EventType()
Case #PB_EventType_Change
texte$= GetGadgetText(#Tree_0)
;Debug texte$
For i=0 To CountGadgetItems(#Editor_0) - 1
If texte$=GetGadgetItemText(#Editor_0,i)
SetGadgetState(#Editor_0, i)
Break
EndIf
Next i
EndSelect
EndSelect
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndSelect
ForEver
EditorGadget
Code : Tout sélectionner
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CompilerIf #PB_Compiler_Version < 500 Or (#PB_Compiler_Version >= 500 And Subsystem("Carbon"))
ImportC ""
GetControlProperty(ControlRef.L, PropertyCreator.L, PropertyTag.L, BufferSize.L, *ActualSize, *PropertyBuffer)
TXNSetSelection(TXNObject.L, StartOffset.L, EndOffset.L)
TXNShowSelection(TXNObject.L, ShowEnd.L)
EndImport
CompilerEndIf
CompilerEndIf
Procedure SelectEditorLine(EditorID.I, LineNumber.I)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected EndOfLine.GtkTextIter
Protected StartOfLine.GtkTextIter
Protected *TextBuffer.GtkTextBuffer
*TextBuffer = gtk_text_view_get_buffer_(GadgetID(EditorID))
gtk_text_buffer_get_iter_at_line_(*TextBuffer, @StartOfLine, LineNumber)
gtk_text_view_scroll_to_iter_(GadgetID(EditorID), StartOfLine, 0.0, #False, 0.0, 0.0)
EndOfLine = StartOfLine
gtk_text_iter_forward_to_line_end_(EndOfLine)
gtk_text_buffer_select_range_(*TextBuffer, StartOfLine, EndOfLine)
CompilerCase #PB_OS_MacOS
CompilerIf #PB_Compiler_Version < 470 Or (#PB_Compiler_Version >= 500 And Subsystem("Carbon"))
Protected EndOfLine.L
Protected StartOfLine.L
Protected TXNObject.L
If GetControlProperty(GadgetID(EditorID), $50555245, $54584F42, 4, 0, @TXNObject) = 0
StartOfLine = FindString(GetGadgetText(EditorID), GetGadgetItemText(EditorID, LineNumber)) - 1
EndOfLine = StartOfLine + Len(GetGadgetItemText(EditorID, LineNumber))
TXNSetSelection(TXNObject, StartOfLine, EndOfLine)
TXNShowSelection(TXNObject, #True)
EndIf
CompilerElse
Protected Range.NSRange
Range\location = FindString(GetGadgetText(EditorID), GetGadgetItemText(EditorID, LineNumber)) - 1
Range\length = Len(GetGadgetItemText(EditorID, LineNumber))
CocoaMessage(0, GadgetID(EditorID), "setSelectedRange:@", @Range)
CocoaMessage(0, GadgetID(EditorID), "scrollRangeToVisible:@", @Range)
CompilerEndIf
CompilerCase #PB_OS_Windows
Protected Selection.CHARRANGE
Protected StartOfLine.I
StartOfLine = SendMessage_(GadgetID(EditorID), #EM_LINEINDEX, LineNumber, 0)
Selection.CHARRANGE\cpMin = StartOfLine
Selection.CHARRANGE\cpMax = StartOfLine + Len(GetGadgetItemText(EditorID, LineNumber)) + 1
SendMessage_(GadgetID(EditorID), #EM_EXSETSEL, 0, @Selection)
CompilerEndSelect
EndProcedure
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#Window_0
EndEnumeration
Enumeration FormGadget
#Tree_0
#Editor_0
#Splitter_0
#Btn_Quit
EndEnumeration
Declare ResizeGadgetsWindow_0()
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
TreeGadget(#Tree_0, 10, 15, 177, 340)
EditorGadget(#Editor_0, 196, 15, 394, 340)
SplitterGadget(#Splitter_0, 10, 15, 580, 340, #Tree_0, #Editor_0, #PB_Splitter_Vertical)
SetGadgetState(#Splitter_0, 177)
ButtonGadget(#Btn_Quit, 485, 365, 100, 25, "Quitter")
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#Tree_0, 10, 15, 177, FormWindowHeight - 60)
ResizeGadget(#Editor_0, FormWindowWidth - 404, 15, 394, FormWindowHeight - 60)
ResizeGadget(#Splitter_0, 10, 15, FormWindowWidth - 20, FormWindowHeight - 60)
ResizeGadget(#Btn_Quit, GadgetWidth(#Splitter_0) - 95, GadgetHeight(#Splitter_0) - -25, 100, 25)
EndProcedure
;XIncludeFile "Splitter.pbf"
OpenWindow_0()
For ID = #Tree_0 To #Editor_0
For a = 0 To 10
AddGadgetItem(ID, -1, "Elément normal "+Str(a), 0, 0) ; si vous souhaitez ajouter une image, utilisez
AddGadgetItem(ID, -1, "Noeud "+Str(a), 0, 0) ; ImageID(x) comme 4ème paramètre
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-1", 0, 1) ; Ceux-là sont au premier sous-niveau
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-2", 0, 1)
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-3", 0, 1)
AddGadgetItem(ID, -1, "Sous-élément " + Str(a) + "-4", 0, 1)
AddGadgetItem(ID, -1, "Fichier "+Str(a), 0, 0) ; sous-niveau 0 à nouveau
Next
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case #Btn_Quit
Break
Case #Tree_0
Select EventType()
Case #PB_EventType_Change
texte$= GetGadgetText(#Tree_0)
;Debug texte$
For i=0 To CountGadgetItems(#Editor_0) - 1
If texte$=GetGadgetItemText(#Editor_0,i)
SelectEditorLine(#Editor_0, i)
Break
EndIf
Next i
EndSelect
EndSelect
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndSelect
ForEver
Mesa.