Menu

[327ada]: / Source / CodeInsList.pas  Maximize  Restore  History

Download this file

301 lines (260 with data), 9.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
{
This file is part of Dev-C++
Copyright (c) 2004 Bloodshed Software
Dev-C++ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Dev-C++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dev-C++; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit CodeInsList;
interface
uses
Windows, Classes;
type
PCodeIns = ^TCodeIns;
TCodeIns = record
Caption: String;
Line: String;
Desc: String;
Sep: integer;
end;
TCodeInsList = class(TObject)
private
fFile: String;
fList: TList;
procedure SetItem(index: integer; Value: PCodeIns);
function GetItem(index: integer): PCodeIns;
function GetCount: integer;
public
constructor Create;
destructor Destroy; override;
procedure LoadCode;
procedure SaveCode;
function AddItem(Value: PCodeIns): integer;
procedure AddItemByValues(const menutext, description, code: String; section: integer);
procedure Delete(index: integer);
procedure Clear;
property Items[index: integer]: PCodeins read GetItem write SetItem; default;
property Count: integer read GetCount;
end;
implementation
uses
SysUtils, IniFiles, devCFG, Utils, version, MultiLangSupport;
{ TCodeInsList }
constructor TCodeInsList.Create;
begin
inherited Create;
fList := TList.Create;
fFile := devDirs.Config + DEV_CODEINS_FILE;
end;
destructor TCodeInsList.Destroy;
var
I: integer;
begin
for I := 0 to fList.Count - 1 do
Dispose(PCodeIns(fList[I]));
fList.Free;
inherited Destroy;
end;
function TCodeInsList.AddItem(Value: PCodeIns): integer;
begin
result := fList.Add(Value);
end;
procedure TCodeInsList.AddItemByValues(const menutext, description, code: String; section: integer);
var
assembleditem: PCodeIns;
begin
new(assembleditem);
assembleditem^.Caption := menutext;
assembleditem^.Line := code;
assembleditem^.Desc := description;
assembleditem^.Sep := section;
fList.Add(assembleditem);
end;
procedure TCodeInsList.Clear;
var
I: integer;
begin
for I := 0 to fList.Count - 1 do
Dispose(PCodeIns(fList[I])); // Free pointed memory first!
fList.Clear;
end;
procedure TCodeInsList.Delete(index: integer);
begin
if (index < 0) or (index > fList.Count - 1) then
exit;
// Free pointed memory first!
Dispose(PCodeIns(fList[index]));
fList.Delete(index);
end;
function TCodeInsList.GetCount: integer;
begin
result := fList.Count;
end;
function TCodeInsList.GetItem(index: integer): PCodeIns;
begin
if (index < 0) or (index > fList.Count - 1) then
result := nil
else
result := PCodeIns(fList[index]);
end;
procedure TCodeInsList.SetItem(index: integer; Value: PCodeIns);
begin
fList[index] := Value;
end;
procedure TCodeInsList.LoadCode;
var
Item: PCodeIns;
tmp: TStringList;
I: integer;
begin
if devData.First then begin
// Win32
AddItemByValues('MessageBox', 'Win32 MessageBox', 'MessageBox(*|*,"Hello","Caption",MB_OK);', 1);
AddItemByValues('WinMain', 'Win32 Main Function',
'int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {' + #13#10 +
' WNDCLASSEX wc;' + #13#10 +
' HWND hwnd;' + #13#10 +
' MSG Msg;' + #13#10 +
'' + #13#10 +
' memset(&wc,0,sizeof(wc));' + #13#10 +
' wc.cbSize = sizeof(WNDCLASSEX);' + #13#10 +
' wc.lpfnWndProc = *|*; /* insert window procedure function here */' + #13#10 +
' wc.hInstance = hInstance;' + #13#10 +
' wc.hCursor = LoadCursor(NULL, IDC_ARROW);' + #13#10 +
' wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);' + #13#10 +
' wc.lpszClassName = "WindowClass";' + #13#10 +
' wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* use "A" as icon name when you want to use the project icon */' + #13#10
+
' wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* as above */' + #13#10 +
'' + #13#10 +
' if(!RegisterClassEx(&wc)) {' + #13#10 +
' MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);' + #13#10 +
' return 0;' + #13#10 +
' }' + #13#10 +
'' + #13#10 +
' hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,NULL,NULL,hInstance,NULL);' + #13#10
+
' if(hwnd == NULL) {' + #13#10 +
' MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);' + #13#10 +
' return 0;' + #13#10 +
' }' + #13#10 +
'' + #13#10 +
' while(GetMessage(&Msg, NULL, 0, 0) > 0) {' + #13#10 +
' TranslateMessage(&Msg);' + #13#10 +
' DispatchMessage(&Msg);' + #13#10 +
' }' + #13#10 +
' return Msg.wParam;' + #13#10 +
'}', 1);
AddItemByValues('Main Window Proc', 'Win32 Main Proc Function',
'LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {' + #13#10 +
' switch(Message) {' + #13#10 +
' case *|*: {' + #13#10 +
' break;' + #13#10 +
' }' + #13#10 +
' case WM_DESTROY: {' + #13#10 +
' PostQuitMessage(0);' + #13#10 +
' break;' + #13#10 +
' }' + #13#10 +
' default:' + #13#10 +
' return DefWindowProc(hwnd, Message, wParam, lParam);' + #13#10 +
' }' + #13#10 +
' return 0;' + #13#10 +
'}', 1);
AddItemByValues('Child Window Proc', 'Win32 Child Proc Function',
'BOOL CALLBACK ChildProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {' + #13#10 +
' switch(Message) {' + #13#10 +
' case *|*: {' + #13#10 +
' break;' + #13#10 +
' }' + #13#10 +
' default:' + #13#10 +
' return false;' + #13#10 +
' }' + #13#10 +
' return true;' + #13#10 +
'}', 1);
// Generic C
AddItemByValues('for()', 'for loop', 'for(*|*;;) {' + #13#10 + '}', 2);
AddItemByValues('while()', 'while loop', 'while(*|*) {' + #13#10 + '}', 2);
AddItemByValues('do-while()', 'do-while loop', 'do {' + #13#10 + '} while(*|*);', 2);
AddItemByValues('if()', 'if statement', 'if(*|*) {' + #13#10 + '}', 2);
AddItemByValues('switch()', 'switch statement', 'switch(*|*) {' + #13#10 + ' default:' + #13#10 + '}', 2);
// C++
AddItemByValues('Class', 'Class',
'class *|* {' + #13#10 +
' // Private section' + #13#10 +
' public:' + #13#10 +
' // Public Declarations' + #13#10 +
' protected:' + #13#10 +
' // Protected Declarations' + #13#10 +
'};', 2);
AddItemByValues('Class Header Template', 'Class',
'#ifndef SOMETHING_H' + #13#10 +
'#define SOMETHING_H' + #13#10#13#10 +
'class *|* {' + #13#10 +
' // Private section' + #13#10 +
' public:' + #13#10 +
' // Public Declarations' + #13#10 +
' protected:' + #13#10 +
' // Protected Declarations' + #13#10 +
'};' + #13#10 + #13#10 +
'#endif', 2);
// Preprocessor
AddItemByValues('#ifdef', 'Preprocessor if', '#ifdef *|*' + #13#10#13#10 + '#endif', 3);
AddItemByValues('#ifndef', 'Preprocessor !if', '#ifndef *|*' + #13#10#13#10 + '#endif', 3);
AddItemByValues('#ifdef/else', 'Preprocessor if-else', '#ifdef *|*' + #13#10#13#10 + '#elif' + #13#10#13#10 +
'#endif', 3);
AddItemByValues('#ifndef/else', 'Preprocessor !if-else', '#ifndef *|*' + #13#10#13#10 + '#elif' + #13#10#13#10 +
'#endif', 3);
// Save to disk as defaults
SaveCode;
end else if FileExists(fFile) then begin // no first time launch? load from disk
with TINIFile.Create(fFile) do try
tmp := TStringList.Create;
Clear;
try
ReadSections(tmp);
for I := 0 to tmp.Count - 1 do begin
new(Item);
Item^.Caption := StringReplace(tmp[I], '_', ' ', [rfReplaceAll]);
Item^.Desc := ReadString(tmp[I], 'Desc', '');
Item^.Line := StrtoCodeIns(ReadString(tmp[I], 'Line', ''));
Item^.Sep := ReadInteger(tmp[I], 'Sep', 0);
AddItem(Item);
end;
finally
tmp.free;
end;
finally
free;
end;
end;
end;
procedure TCodeInsList.SaveCode;
var
I: integer;
section: String;
item: PCodeIns;
begin
DeleteFile(fFile);
if fList.Count = 0 then
Exit;
with TINIFile.Create(fFile) do try
for I := 0 to pred(fList.Count) do begin
item := PCodeIns(fList[I]);
section := StringReplace(item^.Caption, ' ', '_', [rfReplaceAll]);
WriteString(section, 'Desc', item^.Desc);
WriteString(section, 'Line', CodeInstoStr(item^.Line));
WriteInteger(section, 'Sep', item^.Sep);
end;
finally
Free;
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.