[All] Small notepad
Posted: Wed Aug 07, 2002 2:47 pm
Code updated for 5.20+
Restored from previous forum. Originally posted by fweil.
Hello,
Reading many messages about difficulties concerning text/string gadgets, with multilines, end of line characters issues on one side, threads, etc on the other, and because I was collecting information with replies ... I just wrote this small example of a multilined string gadget as a base of Notepad like program. It is small and does not process anything except loading a text file content in the text box. It works and it is easy to enhance for text modifications, with a menu for load, new, save features etc ...
The only last issue you may notice if you want to use it is the string size limitation (actually to 64KB but should change ...).
If you find any bug to correct or good feature to add, share on the forum.
Hope this will help.
Rgrds
Francois Weil
14, rue Douer
F64100 Bayonne
Restored from previous forum. Originally posted by fweil.
Hello,
Reading many messages about difficulties concerning text/string gadgets, with multilines, end of line characters issues on one side, threads, etc on the other, and because I was collecting information with replies ... I just wrote this small example of a multilined string gadget as a base of Notepad like program. It is small and does not process anything except loading a text file content in the text box. It works and it is easy to enhance for text modifications, with a menu for load, new, save features etc ...
The only last issue you may notice if you want to use it is the string size limitation (actually to 64KB but should change ...).
If you find any bug to correct or good feature to add, share on the forum.
Hope this will help.
Rgrds
Code: Select all
;===========================================
; Small notepad skeleton for PureBasic community
;
Global gWindowMode,gThreadID, gServiceMessage.s
Procedure ServiceMessage(void)
Repeat
If gServiceMessage <> ""
If gWindowMode
StatusBarText(99,0, gServiceMessage, 0)
Else
MessageRequester("Alert", gServiceMessage, 0)
EndIf
gServiceMessage = ""
EndIf
Delay(5)
ForEver
EndProcedure
;
;
;
Global gFileName.s,gFile2String.s
gWindowMode = #False
gFile2String = ""
gFileName = OpenFileRequester("Select a file", "C:\*.*", "", 0)
gThreadID = CreateThread(@ServiceMessage(), 0)
If gFileName <> ""
If ReadFile(0, gFileName)
Repeat
gFile2String + ReadString(0) + #CRLF$
Until Eof(0)
CloseFile(0)
If OpenWindow(0, 100, 100, 500,400,"PureBasic NotePad",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
gWindowMode = #True
CreateStatusBar(99, WindowID(0))
AddStatusBarField(90)
gTextbox = EditorGadget(0, 2, 2, 496, 366)
SetGadgetText(0,gFile2String)
gServiceMessage = "File : " + FileName + " selected"
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
Else
gServiceMessage = "Could not open a window"
EndIf
Else
gServiceMessage = "File is not accessible or does not exist"
EndIf
Else
gServiceMessage = "No file selected"
EndIf
Repeat
Until gServiceMessage = ""
End
;===========================================
14, rue Douer
F64100 Bayonne