Mini text editor

Share your advanced PureBasic knowledge/code with the community.
threedslider
Enthusiast
Enthusiast
Posts: 610
Joined: Sat Feb 12, 2022 7:15 pm

Mini text editor

Post by threedslider »

Here a small text editor, hope you enjoy from it :mrgreen:

The code :

Code: Select all

; =========================
; Mini text editor
; =========================

If OpenWindow(0, 100, 100, 600, 400, "Mini text editor", #PB_Window_SystemMenu)

  ; Zone de texte
  EditorGadget(0, 10, 10, 580, 320)

  ; Boutons
  ButtonGadget(1, 10, 340, 90, 30, "Open")
  ButtonGadget(2, 110, 340, 90, 30, "Save")
  ButtonGadget(3, 500, 340, 90, 30, "Quit")

  Repeat
    Event = WaitWindowEvent()

    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()

          ; Ouvrir un fichier
          Case 1
            FileName$ = OpenFileRequester("Open the file", "", "Text file (*.txt)|*.txt", 0)
            If FileName$
              If ReadFile(0, FileName$)
                Text$ = ""
                While Eof(0) = 0
                  Text$ + ReadString(0) + Chr(10)
                Wend
                CloseFile(0)
                SetGadgetText(0, Text$)
              EndIf
            EndIf

          ; Enregistrer un fichier
          Case 2
            FileName$ = SaveFileRequester("Save the file", "", "Text file (*.txt)|*.txt", 0)
            If FileName$
              If CreateFile(0, FileName$)
                WriteString(0, GetGadgetText(0))
                CloseFile(0)
              EndIf
            EndIf

          ; Quitter
          Case 3
            End
        EndSelect

      Case #PB_Event_CloseWindow
        End
    EndSelect

  ForEver
EndIf
Happy coding !