Skip to content

Commit 5dd2701

Browse files
authored
Add files via upload
1 parent 98ead7a commit 5dd2701

25 files changed

Lines changed: 1067 additions & 0 deletions

FileIO.pb

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
;╔═══════════════════════════════════════════════════════════════════════════════╗
2+
;║ FileIO.pb - version 0.11-alpha ║
3+
;╟───────────────────────────────────────────────────────────────────────────────╢
4+
;║ Copyright 2021-2025 Duarte Mendes <duartenm@net.sapo.pt> ║
5+
;║ ║
6+
;║ Permission is hereby granted, free of charge, To any person obtaining a copy ║
7+
;║ of this software And associated documentation files (the "Software"), To deal ║
8+
;║ in the Software without restriction, including without limitation the rights ║
9+
;║ To use, copy, modify, merge, publish, distribute, sublicense, And/Or sell ║
10+
;║ copies of the Software, subject To the following conditions: ║
11+
;║ ║
12+
;║ The above copyright notice And this permission notice shall be included in ║
13+
;║ all copies Or substantial portions of the Software. ║
14+
;║ ║
15+
;║ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ║
16+
;║ EXPRESS Or IMPLIED, INCLUDING BUT Not LIMITED To THE WARRANTIES ║
17+
;║ OF MERCHANTABILITY, FITNESS For A PARTICULAR PURPOSE And NONINFRINGEMENT. ║
18+
;╟───────────────────────────────────────────────────────────────────────────────╢
19+
;║ > PURPOSE : ║
20+
;║ Handles File Operations (read/write) for program Notes.C . ║
21+
;║ ║
22+
;╚═══════════════════════════════════════════════════════════════════════════════╝
23+
24+
25+
;Update status bar after i/o operations
26+
Procedure UpdateStatusBar()
27+
Protected Text$ = "Note ID : " + Str(NoteID) + " | Filename : " + DatabaseFile$
28+
StatusBarText(0,0,Text$)
29+
Text$ = "Created : " + FormatDate("%dd/%mm/%yyyy", DateCreated) + " | Last modified : " + FormatDate("%dd/%mm/%yyyy", DateLast)
30+
StatusBarText(0,1,Text$)
31+
EndProcedure
32+
33+
34+
;Finds the records current/last position (NoteID)
35+
Procedure.l FindMyPosition()
36+
37+
Protected Text4Query$ = "Select NoteID FROM NotesDB"
38+
If DatabaseQuery(#MyDATABASE, Text4Query$)
39+
While NextDatabaseRow(#MyDATABASE)
40+
Protected c.l = GetDatabaseLong(#MyDATABASE, 0)
41+
Wend
42+
FinishDatabaseQuery(#MyDATABASE)
43+
ProcedureReturn c
44+
Else
45+
ProcedureReturn #False
46+
EndIf
47+
48+
EndProcedure
49+
50+
51+
; Save Tags "#" And "@" into database
52+
Procedure SaveTags(MyTextWithTags$)
53+
54+
; Find and saves Hashtags '#'
55+
Protected x.l = 0
56+
Repeat
57+
x = FindString(MyTextWithTags$,"#", x + 1)
58+
If x <> 0
59+
Protected ExtractedString$ = Mid(MyTextWithTags$, x, FindString(MyTextWithTags$, " ", x) - x)
60+
CheckDatabaseUpdate(#MyDATABASE, "INSERT INTO HashtagDB (NoteID, Hashtag) VALUES ('" + Str(NoteID) +"', '" + ExtractedString$ + "')")
61+
EndIf
62+
Until x = 0
63+
64+
; Find and saves Recipients '@'
65+
x = 0
66+
Repeat
67+
x = FindString(MyTextWithTags$,"@", x + 1)
68+
If x <> 0
69+
ExtractedString$ = Mid(MyTextWithTags$, x, FindString(MyTextWithTags$, " ", x) - x)
70+
CheckDatabaseUpdate(#MyDATABASE, "INSERT INTO RecipientDB (NoteID, Recipient) VALUES ('" + Str(NoteID) + "', '" + ExtractedString$ + "')")
71+
EndIf
72+
Until x = 0
73+
EndProcedure
74+
75+
76+
; Handles menu "Save"
77+
Procedure SaveMyFile()
78+
79+
Protected Text$ = GetScintillaAllText(Scintilla_0) ; Gets the content of Scintilla !
80+
DateLast = Date()
81+
82+
If DatabaseConnected = #True
83+
Protected Modified.b = ScintillaSendMessage(Scintilla_0, #SCI_GETMODIFY) ; Check if text was modified since last save
84+
85+
If Modified > 0
86+
If NoteID > 0
87+
;SQL insert
88+
Protected Text4Query$ = "UPDATE NotesDB SET Note = '" + Text$
89+
Text4Query$ +"', Format = '" + GetScintillaFormat(Scintilla_0) + "', DateLast = '" + Str(DateLast)
90+
Text4Query$ + "' WHERE NoteID = '" + Str(NoteID)+"'"
91+
CheckDatabaseUpdate(#MyDATABASE, Text4Query$)
92+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT) ;scintilla savepoint notification
93+
UpdateStatusBar()
94+
; -------------------------->>>>>>>>>>>>>>>>>>>>>>>>>> ToDo : Colocar a rotina de verificar os hashtags [LisIcon versus findstring(Text$)]
95+
Else
96+
DateCreated = Date()
97+
Text4Query$ = "INSERT INTO NotesDB (Note, Format, DateNew, DateLast) VALUES ('"
98+
Text4Query$ + Text$ + "', '" + GetScintillaFormat(Scintilla_0) + "', '" + Str(DateCreated) + "', '"+ Str(DateLast)+ "')"
99+
CheckDatabaseUpdate(#MyDatabase, Text4Query$) ; SQL command execute INSERT NEW
100+
NoteID = FindMyPosition()
101+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT) ;scintilla savepoint notification
102+
SaveTags(Text$)
103+
UpdateStatusBar()
104+
EndIf
105+
EndIf
106+
Else
107+
DatabaseFile$ = SaveFileRequester("New File","noname.sqlite", "sqlite DB (*.sqlite)|*.sqlite|All Files (*.*)|*.*",0)
108+
If DatabaseFile$<>""
109+
Protected Error.l = HandleMyError(CreateFile(#MyFile,DatabaseFile$),"File creation failure!",0)
110+
If Error = #False
111+
CloseFile(#MyFile)
112+
113+
Protected NewError.l = HandleMyError(OpenDatabase(#MyDATABASE, DatabaseFile$, "", "",#PB_Database_SQLite),"DataBase connection failure!",0)
114+
If NewError = #False
115+
; Creation of a new Tables
116+
CheckDatabaseUpdate(#MyDATABASE, "CREATE TABLE NotesDB (NoteID INTEGER PRIMARY KEY AUTOINCREMENT, Note CHAR, Format CHAR, DateNew INT, DateLast INT)")
117+
CheckDatabaseUpdate(#MyDATABASE, "CREATE TABLE HashtagDB (H_ID INTEGER PRIMARY KEY AUTOINCREMENT, NoteID INT, Hashtag CHAR)")
118+
CheckDatabaseUpdate(#MyDATABASE, "CREATE TABLE RecipientDB (R_ID INTEGER PRIMARY KEY AUTOINCREMENT, NoteID INT, Recipient CHAR)")
119+
120+
; Saves the current content, if any ...
121+
DateCreated = Date()
122+
Text4Query$ = "INSERT INTO NotesDB (Note, Format, DateNew, DateLast) VALUES ('"
123+
Text4Query$ + Text$ + "', '" + GetScintillaFormat(Scintilla_0) + "', '" + Str(DateCreated) + "', '"+ Str(DateLast)+ "')"
124+
CheckDatabaseUpdate(#MyDatabase, Text4Query$) ; SQL command execute INSERT NEW
125+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT) ;scintilla savepoint notification
126+
NoteID = 1
127+
128+
SaveTags(Text$)
129+
UpdateStatusBar()
130+
131+
DatabaseConnected=#True
132+
133+
MessageRequester("Success!", "File Saved sucessfully!", #PB_MessageRequester_Info)
134+
EndIf
135+
EndIf
136+
EndIf
137+
EndIf
138+
EndProcedure
139+
140+
;Routine for checking if text was modified and have the option to save it
141+
Procedure.b CheckModifiedAndSave()
142+
Protected Modified.b = ScintillaSendMessage(Scintilla_0, #SCI_GETMODIFY) ; Check if text was modified since last save
143+
144+
If Modified > 0 ; If modified from last save, ask question to save ...
145+
Protected Answer.l = MessageRequester("Question?","Save current Note ?", #PB_MessageRequester_Warning | #PB_MessageRequester_YesNoCancel)
146+
147+
Select Answer
148+
Case #PB_MessageRequester_Cancel
149+
ProcedureReturn #False ; Case CANCEL - the only option that remain the "as is" !
150+
Case #PB_MessageRequester_Yes
151+
SaveMyFile() ; Saves if YES
152+
ProcedureReturn #True
153+
Default ; Case #PB_MessageRequester_No
154+
ProcedureReturn #True
155+
EndSelect
156+
Else
157+
ProcedureReturn #True ; Case not modified
158+
EndIf
159+
EndProcedure
160+
161+
162+
; Handles menu Open
163+
Procedure OpenMyFile()
164+
165+
Static OldDatabaseFile$
166+
167+
If CheckModifiedAndSave() = #True ; LOAD operations
168+
DatabaseFile$ = OpenFileRequester("Open File","", "sqlite DB (*.sqlite)|*.sqlite|Todos (*.*)|*.*",0)
169+
170+
If DatabaseFile$ <> ""
171+
172+
If DatabaseConnected = #True
173+
HandleMyError(CloseDatabase(#MyDATABASE),"Error closing previous File!",1)
174+
EndIf
175+
176+
Protected Error.l = HandleMyError(OpenDatabase(#MyDATABASE, DatabaseFile$, "", "",#PB_Database_SQLite),"Error opening File!",0)
177+
178+
If Error = #False
179+
DatabaseConnected=#True
180+
OldDatabaseFile$ = DatabaseFile$ ; Keep records of previous file for reconnecting if necessary !
181+
ScintillaSendMessage(Scintilla_0, #SCI_SETREADONLY,0) ; Desprotect any text in Scintilla !
182+
ScintillaSendMessage(Scintilla_0, #SCI_CLEARALL)
183+
184+
If DatabaseQuery(#MyDATABASE, "SELECT * FROM NotesDB")
185+
While NextDatabaseRow(#MyDATABASE)
186+
Protected Text$ = GetDatabaseString(#MyDATABASE, 1)
187+
Protected Format$ = GetDatabaseString(#MyDATABASE,2)
188+
MyScintillaText(Scintilla_0, Text$, Format$, 1)
189+
NoteID = GetDatabaseLong(#MyDATABASE,0)
190+
DateCreated = GetDatabaseLong(#MyDATABASE,3)
191+
DateLast = GetDatabaseLong(#MyDATABASE,4)
192+
193+
Text$ = #CRLF$ + "NoteID [" + Str(NoteID) + "] - Created/Modified : " + FormatDate("%dd/%mm/%yyyy", DateCreated) + " - " + FormatDate("%dd/%mm/%yyyy", DateLast) + #CRLF$
194+
Format$ = "00"
195+
196+
Protected x.l = 3 ; 2 charaters are skiped = Chr(10) + Chr(13)
197+
For x = 3 To Len(Text$)
198+
Format$ + "6"
199+
Next x
200+
201+
MyScintillaText(Scintilla_0, Text$, Format$, 1)
202+
Wend
203+
FinishDatabaseQuery(#MyDATABASE)
204+
EndIf
205+
206+
207+
ContractFoldsScintilla(Scintilla_0)
208+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT)
209+
ScintillaSendMessage(Scintilla_0, #SCI_EMPTYUNDOBUFFER)
210+
ScintillaSendMessage(Scintilla_0, #SCI_SETREADONLY,1)
211+
UpdateStatusBar()
212+
213+
MessageRequester("Success!","File Loaded successfully!", #PB_MessageRequester_Info)
214+
Else
215+
If DatabaseConnected=#True
216+
HandleMyError(OpenDatabase(#MyDATABASE, OldDatabaseFile$, "", "",#PB_Database_SQLite),"Error loading previous File!",1) ;On error tries to reconnect to previous file ...
217+
EndIf
218+
EndIf
219+
EndIf
220+
EndIf
221+
EndProcedure
222+
223+
224+
; Handles Menu "New"
225+
Procedure NewNoteOrFile()
226+
ScintillaSendMessage(Scintilla_0, #SCI_SETREADONLY,0) ; Desprotect any text in Scintilla !
227+
228+
If CheckModifiedAndSave() = #True
229+
NoteID = 0
230+
ScintillaSendMessage(Scintilla_0, #SCI_CLEARALL)
231+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT) ;scintilla savepoint notification
232+
EndIf
233+
EndProcedure
234+
235+
236+
Procedure CloseMyFile()
237+
238+
If (DatabaseConnected = #True) And (CheckModifiedAndSave() = #True)
239+
HandleMyError(CloseDatabase(#MyDATABASE),"Error closing previous File!",1)
240+
DatabaseConnected = #False
241+
NoteID = 0
242+
DatabaseFile$ = ""
243+
DateCreated = Date()
244+
DateLast = Date()
245+
ScintillaSendMessage(Scintilla_0, #SCI_SETREADONLY,0) ; Desprotect any text in Scintilla !
246+
ScintillaSendMessage(Scintilla_0, #SCI_CLEARALL)
247+
ScintillaSendMessage(Scintilla_0, #SCI_EMPTYUNDOBUFFER)
248+
ScintillaSendMessage(Scintilla_0, #SCI_SETSAVEPOINT) ;scintilla savepoint notification
249+
UpdateStatusBar()
250+
EndIf
251+
EndProcedure
252+
253+
; IDE Options = PureBasic 6.21 (Windows - x64)
254+
; CursorPosition = 1
255+
; Folding = --
256+
; EnableXP

Geral.pbi

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
;╔═══════════════════════════════════════════════════════════════════════════════╗
2+
;║ Geral.pbi - version 0.11-alpha ║
3+
;╟───────────────────────────────────────────────────────────────────────────────╢
4+
;║ Copyright 2021-2025 Duarte Mendes <duartenm@net.sapo.pt> ║
5+
;║ ║
6+
;║ Permission is hereby granted, free of charge, To any person obtaining a copy ║
7+
;║ of this software And associated documentation files (the "Software"), To deal ║
8+
;║ in the Software without restriction, including without limitation the rights ║
9+
;║ To use, copy, modify, merge, publish, distribute, sublicense, And/Or sell ║
10+
;║ copies of the Software, subject To the following conditions: ║
11+
;║ ║
12+
;║ The above copyright notice And this permission notice shall be included in ║
13+
;║ all copies Or substantial portions of the Software. ║
14+
;║ ║
15+
;║ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ║
16+
;║ EXPRESS Or IMPLIED, INCLUDING BUT Not LIMITED To THE WARRANTIES ║
17+
;║ OF MERCHANTABILITY, FITNESS For A PARTICULAR PURPOSE And NONINFRINGEMENT. ║
18+
;╟───────────────────────────────────────────────────────────────────────────────╢
19+
;║ > PURPOSE : ║
20+
;║ General library with error handling and other routines that can be ║
21+
;║ usefull for any program. ║
22+
;╚═══════════════════════════════════════════════════════════════════════════════╝
23+
24+
25+
; Handles any SYSTEM error that occurs
26+
Procedure ErrorHandler()
27+
Protected ErrorMsg.s = "Error code:" + #TAB$ + Str(ErrorCode()) + #CRLF$
28+
ErrorMsg + "Error description:" + #TAB$ + ErrorMessage() + #CRLF$
29+
ErrorMsg + "Occured on line:" + #TAB$ + Str(ErrorLine()) + #CRLF$
30+
ErrorMsg + "Occured on file:" + #TAB$ + ErrorFile() + #CRLF$
31+
ErrorMsg + #CRLF$ + "The program will now EXIT !"
32+
Protected AnswerBox.l = MessageRequester("ERROR", ErrorMsg, #PB_MessageRequester_Ok!#PB_MessageRequester_Error)
33+
EndProcedure ; Program will always exit on ending the procedure ErrorHandler
34+
35+
36+
; Handles any I/O error that occurs
37+
Procedure HandleMyError (Result.l, ErrorMsg.s, Critical.l = 0) ; Optional 'Critical.l = 0' (= No, it can be choose either to proceed or not)
38+
If Result = 0
39+
If Critical = 0
40+
Protected AnswerBox.l = MessageRequester("ERROR", ErrorMsg + #CRLF$ + #CRLF$ + "Do you want to continue ?", #PB_MessageRequester_YesNo|#PB_MessageRequester_Error)
41+
If AnswerBox = #PB_MessageRequester_No
42+
End ; Ends program
43+
Else
44+
ProcedureReturn #True ;Returns a True value, signalizing that an Error happened but execution proceeded !
45+
EndIf
46+
Else
47+
AnswerBox.l = MessageRequester("Critical ERROR", ErrorMsg + #CRLF$ + #CRLF$ + "Critical Error !" + #CRLF$ + #CRLF$ + "Program will exit ...", #PB_MessageRequester_Ok|#PB_MessageRequester_Error)
48+
End
49+
EndIf
50+
EndIf
51+
ProcedureReturn #False ; Returns False value signalizing that an error didn't happened.
52+
EndProcedure
53+
54+
55+
; Handles DataBase operations check
56+
Procedure CheckDatabaseUpdate(Database, Query$)
57+
Protected Result = DatabaseUpdate(Database, Query$)
58+
If Result = 0
59+
Protected Erro$ = DatabaseError()
60+
MessageRequester("Error",Erro$,#PB_MessageRequester_Ok|#PB_MessageRequester_Error)
61+
EndIf
62+
ProcedureReturn Result
63+
EndProcedure
64+
65+
66+
;Disables deselection (state -1) in a ListIcon Gadget
67+
Procedure NoDeselection(MyGadget.l , ByDefault.l)
68+
If GetGadgetState(MyGadget) <0
69+
SetGadgetState(MyGadget,ByDefault)
70+
EndIf
71+
EndProcedure
72+
73+
; Searches for a text removing special characters before and after
74+
Procedure.s RemoveSpecialChars(MyText$)
75+
76+
Protected Char1.s{1} = MyText$ ; String of 1 character lenght for searching step by step
77+
78+
While (Char1 = Chr(10)) Or (Char1 = Chr(13)) Or (Char1 = " ") ;Removes end of lines characters in the begin.
79+
MyText$ = LTrim(MyText$, Chr(10)) ;#LF
80+
MyText$ = LTrim(MyText$, Chr(13)) ;#CR
81+
MyText$ = LTrim(MyText$) ; SPACE
82+
Char1 = MyText$
83+
Wend
84+
85+
If FindString(MyText$, Chr(10), 1) <> 0
86+
MyText$ = Mid(MyText$, 1,FindString(MyText$, Chr(10), 1) - 1) ; Only gets a text until end of line chr(10) : #LF
87+
EndIf
88+
89+
If FindString(MyText$, Chr(13), 1) <> 0
90+
MyText$ = Mid(MyText$, 1,FindString(MyText$, Chr(13), 1) - 1) ; Only gets a text until end of line chr(13) : #CR
91+
EndIf
92+
93+
If MyText$ ="" : MyText$ = "No Text!" : EndIf ; If not finds a end of line character chr(10) ou chr(13)
94+
95+
ProcedureReturn MyText$
96+
EndProcedure
97+
98+
99+
; IDE Options = PureBasic 6.21 (Windows - x64)
100+
; CursorPosition = 1
101+
; Folding = -
102+
; EnableXP

0 commit comments

Comments
 (0)