; ********** ; Bloc notes ; **********
Enumeration #Window_0 #Editor_1 #tree #Etiq_1 #Etiq_rubrique #Etiq_note #Bouton_rubrique #Bouton_note #Bouton_crubr #Bouton_cnote #Bouton_sauve #Bouton_quit EndEnumeration
Define.l Event, EventWindow, EventGadget
Procedure F_tree() If OpenFile(0,"./tree.conf") While Eof(o) =0 Numero.s = ReadString(0) Niveau.s = ReadString(0) Nom$ = ReadString(0) AddGadgetItem(#tree,Val(Numero), Nom$, 0, Val(Niveau)) Wend CloseFile(0) EndIf EndProcedure Procedure sauve_tree() If OpenFile(0,"./tree.conf") TruncateFile(0) For i = 0 To CountGadgetItems(#tree) - 1 Niveau.l = GetGadgetItemAttribute(#tree, i, #PB_Tree_SubLevel) Nom$ = GetGadgetItemText(#tree, i) WriteStringN(0,Str(i)) WriteStringN(0,Str(Niveau)) WriteStringN(0,Nom$) Next EndIf CloseFile(0) EndProcedure Procedure Sauver_note() Numero = GetGadgetState(#tree) Nom$ = GetGadgetItemText(#tree, Numero) designation$ = ReplaceString(Nom$," ","_") If OpenFile(0,"./" + designation$) TruncateFile(0) For i = 0 To CountGadgetItems(#Editor_1) - 1 WriteStringN(0,GetGadgetItemText(#Editor_1,i)) Next EndIf CloseFile(0) EndProcedure Procedure aff_note() ClearGadgetItems(#Editor_1) Numero = GetGadgetState(#tree) Niveau = GetGadgetItemAttribute(#tree, Numero, #PB_Tree_SubLevel) If Niveau <> 0 Nom$ = GetGadgetItemText(#tree, Numero) designation$ = ReplaceString(Nom$," ","_") If OpenFile(0,"./" + designation$) i = 0 While Eof(0) =0 text$ = ReadString(0) SetGadgetItemText(#Editor_1,i,text$ + Chr(10)) i=i+1 Wend CloseFile(0) EndIf EndIf EndProcedure Procedure Open_Window_0() If OpenWindow(#Window_0,234,21,1100,660,"Bloc notes") EditorGadget(#Editor_1,235,2,860,617) TreeGadget(#tree,2,2,230,400) TextGadget(#Etiq_1,4,625,1088,25,"",#PB_Text_Border) ButtonGadget(#Bouton_rubrique,2,410,230,25,"Nouvelle rubrique") StringGadget(#Etiq_rubrique,2,440,200,25,"") ButtonGadget(#Bouton_crubr,205,440,25,25,"") ButtonGadget(#Bouton_note,2,470,230,25,"Nouvelle note") StringGadget(#Etiq_note,2,500,200,25,"") ButtonGadget(#Bouton_cnote,205,500,25,25,"") ButtonGadget(#Bouton_sauve,2,530,230,25,"Sauver note") ButtonGadget(#Bouton_quit,2,590,230,25,"Quitter") EndIf EndProcedure
Open_Window_0()
HideGadget(#Etiq_rubrique,1) HideGadget(#Bouton_crubr,1) HideGadget(#Etiq_note,1) HideGadget(#Bouton_cnote,1) HideGadget(#Editor_1,1) F_tree()
Repeat Event = WaitWindowEvent() Select Event
Case #PB_Event_Gadget If EventGadget() = #Bouton_rubrique SetGadgetText(#Etiq_1,"") HideGadget(#Etiq_rubrique,0) HideGadget(#Bouton_crubr,0) EndIf If EventGadget() = #Bouton_crubr SetGadgetText(#Etiq_1,"") AddGadgetItem(#tree, -1, GetGadgetText(#Etiq_rubrique), 0, 0) sauve_tree() HideGadget(#Etiq_rubrique,1) HideGadget(#Bouton_crubr,1) EndIf If EventGadget() = #Bouton_note SetGadgetText(#Etiq_1,"") HideGadget(#Etiq_note,0) HideGadget(#Bouton_cnote,0) EndIf If EventGadget() = #Bouton_cnote SetGadgetText(#Etiq_1,"") Numero = GetGadgetState(#tree) If Numero = -1 SetGadgetText(#Etiq_1,"Sélectionner ou créer une rubrique") Else AddGadgetItem(#tree,Numero +1, GetGadgetText(#Etiq_note), 0, 1) EndIf sauve_tree() HideGadget(#Etiq_note,1) HideGadget(#Bouton_cnote,1) EndIf If EventGadget() = #tree Numero = GetGadgetState(#tree) Niveau = GetGadgetItemAttribute(#tree, Numero, #PB_Tree_SubLevel) If Niveau = 0 HideGadget(#Editor_1,1) Else HideGadget(#Editor_1,0) EndIf aff_note() EndIf If EventGadget() = #Bouton_sauve Sauver_note() EndIf If EventGadget() = #Bouton_quit End EndIf Case #PB_Event_CloseWindow End
EndSelect ForEver
|