Menu

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

Download this file

426 lines (365 with data), 12.7 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
{
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 FilePropertiesFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StrUtils, ExtCtrls, StdCtrls, SynEdit, utils,
SynEditTypes, FileCtrl, Menus;
type
TFilePropertiesForm = class(TForm)
lblFileName: TLabel;
lblProject: TLabel;
lblTotalLines: TLabel;
lblCodeLines: TLabel;
lblCommentLines: TLabel;
lblFileSize: TLabel;
lblEmptyLines: TLabel;
edProject: TEdit;
edFileSize: TEdit;
edTotalLines: TEdit;
edCodeLines: TEdit;
edCommentLines: TEdit;
edEmptyLines: TEdit;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel4: TBevel;
Bevel5: TBevel;
Bevel6: TBevel;
Bevel7: TBevel;
btnOK: TButton;
Bevel8: TBevel;
lblIncludes: TLabel;
edIncludes: TEdit;
cmbFiles: TComboBox;
lblAbsolute: TLabel;
lblRelative: TLabel;
edAbsolute: TEdit;
edRelative: TEdit;
Bevel9: TBevel;
lblTimeStamp: TLabel;
edTimestamp: TEdit;
PropertiesPop: TPopupMenu;
PropertiesCopy: TMenuItem;
N1: TMenuItem;
PropertiesSelAll: TMenuItem;
Bevel3: TBevel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnOKClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cmbFilesClick(Sender: TObject);
procedure PropertiesCopyClick(Sender: TObject);
procedure PropertiesSelAllClick(Sender: TObject);
private
fFileDate: integer;
fFileSize: integer;
fTotalLines: integer;
fCodeLines: integer;
fEmptyLines: integer;
fIncludeLines: integer;
fCommentLines: integer;
fFilename: String;
fEdit: TSynEdit;
procedure LoadText;
procedure RightAlign(window: TEdit);
procedure CalculateFile(const Filename: String);
procedure ShowPropsFor(const Filename: String);
procedure FillFiles;
public
procedure SetFile(const Filename: String);
end;
implementation
uses
SynEditHighlighter, main, MultiLangSupport, DataFrm, project, editor, devcfg;
{$R *.dfm}
{ TFilePropertiesForm }
procedure TFilePropertiesForm.CalculateFile(const Filename: String);
var
Attri: TSynHighlighterAttributes;
Current, Token: String;
I, J, hFile: integer;
begin
// Calculate size
hFile := FileOpen(Filename, fmOpenRead);
if hFile > 0 then begin
fFileDate := FileGetDate(hFile);
Inc(fFileSize, FileSeek(hFile, 0, 2));
FileClose(hFile);
end;
Inc(fTotalLines, fEdit.Lines.Count);
// iterate through all lines of file
for I := 0 to fEdit.Lines.Count - 1 do begin
Current := fEdit.Lines[I];
// locate first non-space char in line
J := 1;
while (J <= Length(Current)) and CharInSet(Current[J], [#9, #32]) do
Inc(J);
// take the token type of the first word of the line
if fEdit.GetHighlighterAttriAtRowCol(BufferCoord(J, I + 1), Token, Attri) then begin
// if it is preprocessor...
if SameStr(Attri.Name, 'Preprocessor') then begin
// check for includes
if StartsStr('#include', Token) or StartsStr('# include', Token) then
Inc(fIncludeLines);
// preprocessor directives are considered as code
Inc(fCodeLines);
end
// if it is a comment
else if SameStr(Attri.Name, 'Comment') then
Inc(fCommentLines)
// else it is code
else
Inc(fCodeLines);
end else // if we don't get a token type, this line is empty or contains only spaces
Inc(fEmptyLines);
end;
end;
procedure TFilePropertiesForm.FormCreate(Sender: TObject);
begin
LoadText;
fEdit := TSynEdit.Create(nil);
fEdit.Highlighter := dmMain.Cpp;
fFilename := '';
end;
procedure TFilePropertiesForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TFilePropertiesForm.btnOKClick(Sender: TObject);
begin
Close;
end;
procedure TFilePropertiesForm.LoadText;
begin
// Set interface font
Font.Name := devData.InterfaceFont;
Font.Size := devData.InterfaceFontSize;
PropertiesCopy.Caption := Lang[ID_ITEM_COPY];
PropertiesSelAll.Caption := Lang[ID_ITEM_SELECTALL];
Caption := Lang[ID_PROPS_PROPERTIES];
btnOK.Caption := Lang[ID_BTN_OK];
lblFileName.Caption := Lang[ID_PROPS_FILENAME] + ':';
lblProject.Caption := Lang[ID_PROPS_INPROJECT] + ':';
lblAbsolute.Caption := Lang[ID_PROPS_ABSOLUTE] + ':';
lblRelative.Caption := Lang[ID_PROPS_RELATIVE] + ':';
lblTotalLines.Caption := Lang[ID_PROPS_TOTAL] + ':';
lblCodeLines.Caption := Lang[ID_PROPS_CODE] + ':';
lblCommentLines.Caption := Lang[ID_PROPS_COMMENTS] + ':';
lblEmptyLines.Caption := Lang[ID_PROPS_EMPTY] + ':';
lblFileSize.Caption := Lang[ID_PROPS_FILESIZE] + ':';
lblIncludes.Caption := Lang[ID_PROPS_INCLUDES] + ':';
lblTimeStamp.Caption := Lang[ID_PROPS_TIMESTAMP] + ':';
RightAlign(edTotalLines);
RightAlign(edCodeLines);
RightAlign(edCommentLines);
RightAlign(edEmptyLines);
RightAlign(edFileSize);
RightAlign(edIncludes);
RightAlign(edTimestamp);
end;
procedure TFilePropertiesForm.RightAlign(window: TEdit);
var
currentstyle: dWord;
begin
currentstyle := GetWindowLong(window.Handle, GWL_STYLE);
SetWindowLong(window.Handle, GWL_STYLE, currentstyle or ES_RIGHT);
end;
procedure TFilePropertiesForm.FormDestroy(Sender: TObject);
begin
fEdit.Free;
end;
procedure TFilePropertiesForm.FormShow(Sender: TObject);
var
e: TEditor;
begin
if fFilename = '' then begin
e := MainForm.EditorList.GetEditor;
if Assigned(e) then
fFilename := e.FileName;
end;
FillFiles;
ShowPropsFor(fFilename);
end;
procedure TFilePropertiesForm.ShowPropsFor(const Filename: String);
var
I: integer;
loopfilename: String;
begin
fFileDate := 0;
fFileSize := 0;
fTotalLines := 0;
fFileSize := 0;
fFileDate := 0;
fCodeLines := 0;
fEmptyLines := 0;
fIncludeLines := 0;
fCommentLines := 0;
// Selected the project? Loop through files
if SameStr('.dev', ExtractFileExt(FileName)) then begin
// Loop through files
for I := 0 to cmbfiles.Items.Count - 1 do begin
// Get file name
if Assigned(cmbFiles.Items.Objects[I]) then begin // only count project files
loopfilename := String(cmbFiles.Items.Objects[I]);
if not SameStr('.dev', ExtractFileExt(loopfilename)) then begin
try
fEdit.Lines.LoadFromFile(loopfilename);
CalculateFile(loopfilename);
except
end;
end;
end;
end;
edProject.Text := '-';
edAbsolute.Text := MainForm.Project.FileName;
edRelative.Text := ExtractRelativePath(MainForm.Project.Directory, Filename);
if fFileDate = 0 then
edTimestamp.Text := '(Project file only) -'
else
edTimestamp.Text := '(Project file only) ' + FormatDateTime(FormatSettings.ShortDateFormat + ' hh:nn:ss',
FileDateToDateTime(fFileDate));
// Just show information about the selected file only
end else begin
// Get file properties
if FileExists(Filename) then
try
fEdit.Lines.LoadFromFile(Filename);
CalculateFile(FileName);
except
end;
// Check if it is in our project
if Assigned(MainForm.Project) and (MainForm.Project.Units.IndexOf(FileName) <> -1) then begin
edProject.Text := MainForm.Project.Name;
edRelative.Text := ExtractRelativePath(MainForm.Project.Directory, Filename)
end else begin
edProject.Text := '-';
edRelative.Text := '-';
end;
edAbsolute.Text := FileName;
if fFileDate = 0 then
edTimestamp.Text := '-'
else
edTimestamp.Text := FormatDateTime(FormatSettings.ShortDateFormat + ' hh:nn:ss', FileDateToDateTime(fFileDate));
end;
edTotalLines.Text := IntToStr(fTotalLines);
edCodeLines.Text := IntToStr(fCodeLines);
edEmptyLines.Text := IntToStr(fEmptyLines);
edIncludes.Text := IntToStr(fIncludeLines);
edCommentLines.Text := IntToStr(fCommentLines);
// Pretty print total file size
if fFileSize < 1024 then
edFileSize.Text := FloatToStrF(fFileSize, ffGeneral, 4, 1) + ' ' + Lang[ID_BYTES]
else if fFileSize < 1024 * 1024 then
edFileSize.Text := FloatToStrF(fFileSize / 1024, ffGeneral, 4, 1) + ' KiB'
else if fFileSize < 1024 * 1024 * 1024 then
edFileSize.Text := FloatToStrF((fFileSize / 1024) / 1024, ffGeneral, 4, 1) + ' MiB'
else
edFileSize.Text := FloatToStrF(((fFileSize / 1024) / 1024) / 1024, ffGeneral, 4, 1) + ' GiB';
end;
procedure TFilePropertiesForm.FillFiles;
var
I: integer;
e: TEditor;
FullFileName, ShortFileName: String;
begin
cmbFiles.Items.BeginUpdate;
cmbFiles.Clear;
// add all project files
if Assigned(MainForm.Project) then begin
// Add project file itself
FullFileName := MainForm.Project.FileName;
ShortFileName := ExtractFileName(FullFileName);
cmbFiles.Items.AddObject(ShortFileName, Pointer(FullFileName));
// Add files belonging to project
for I := 0 to MainForm.Project.Units.Count - 1 do begin
FullFileName := MainForm.Project.Units[I].FileName;
ShortFileName := ExtractFileName(FullFileName);
cmbFiles.Items.AddObject(ShortFileName, Pointer(FullFileName));
end;
end;
// add all open editor files not in project (they don't have that object)
for I := 0 to MainForm.EditorList.PageCount - 1 do begin
e := MainForm.EditorList[I];
if Assigned(e) and not e.InProject then begin
FullFileName := e.FileName;
ShortFileName := ExtractFileName(FullFileName);
cmbFiles.Items.AddObject(ShortFileName, Pointer(FullFileName));
end;
end;
// Highlight current file
I := cmbFiles.Items.IndexOf(ExtractFileName(fFilename));
if I = -1 then
I := cmbFiles.Items.IndexOf(fFilename);
cmbFiles.ItemIndex := I;
cmbFiles.Items.EndUpdate;
end;
procedure TFilePropertiesForm.cmbFilesClick(Sender: TObject);
begin
ShowPropsFor(String(cmbFiles.Items.Objects[cmbFiles.ItemIndex]));
end;
procedure TFilePropertiesForm.SetFile(const Filename: String);
begin
fFilename := Filename;
end;
procedure TFilePropertiesForm.PropertiesCopyClick(Sender: TObject);
begin
if edProject.Focused then
edProject.CopyToClipboard
else if edAbsolute.Focused then
edAbsolute.CopyToClipboard
else if edRelative.Focused then
edRelative.CopyToClipboard
else if edTotalLines.Focused then
edTotalLines.CopyToClipboard
else if edCodeLines.Focused then
edCodeLines.CopyToClipboard
else if edCommentLines.Focused then
edCommentLines.CopyToClipboard
else if edEmptyLines.Focused then
edEmptyLines.CopyToClipboard
else if edFileSize.Focused then
edFileSize.CopyToClipboard
else if edIncludes.Focused then
edIncludes.CopyToClipboard
else if edTimestamp.Focused then
edTimeStamp.CopyToClipboard;
end;
procedure TFilePropertiesForm.PropertiesSelAllClick(Sender: TObject);
begin
if edProject.Focused then
edProject.SelectAll
else if edAbsolute.Focused then
edAbsolute.SelectAll
else if edRelative.Focused then
edRelative.SelectAll
else if edTotalLines.Focused then
edTotalLines.SelectAll
else if edCodeLines.Focused then
edCodeLines.SelectAll
else if edCommentLines.Focused then
edCommentLines.SelectAll
else if edEmptyLines.Focused then
edEmptyLines.SelectAll
else if edFileSize.Focused then
edFileSize.SelectAll
else if edIncludes.Focused then
edIncludes.SelectAll
else if edTimestamp.Focused then
edTimeStamp.SelectAll;
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.