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
|
Unit frmprops;
{$mode objfpc}
Interface
uses glib,gdk,gtk,sysutils;
Const
NrTableLines = 8;
CheckBoxLineStart = 5;
Type
TFilePropertiesDialog = Record
Window : PgtkDialog;
Table : PGtkTable;
OkButton : PGtkButton;
Labels : Array[0..1,0..NrTableLines] of PGtkLabel;
CheckBoxes : Array[CheckBoxLineStart..NrTableLines] of PgtkCheckButton;
end;
PFilePropertiesDialog = ^TFilePropertiesDialog;
Function NewFilePropertiesDialog(FileName : String) : PFilePropertiesDialog;
Procedure ShowFilePropertiesDialog(Dialog : PFilePropertiesDialog);
Implementation
uses Futils;
Const
SPropsTitle : PChar = 'File properties';
SOk : PChar = ' OK ';
SFile = ' File.';
LabelTexts : Array[0..NrTableLines] of Pchar = (
'Name',
'Directory',
'Type',
'Size',
'Date',
'Attributes',
'',
'',
''
);
CheckBoxTexts : Array[CheckBoxLineStart..NrTableLines] of Pchar = (
'Read-only',
'Archive',
'Hidden',
'System'
);
procedure DestroyPropDialog(Widget : PGtkWidget; Dlg : PFilePropertiesDialog);cdecl;
begin
Dispose(Dlg);
end;
Function NewFilePropertiesDialog(FileName : String) : PFilePropertiesDialog;
Const
CheckAttrs : Array [CheckBoxLineStart..NrTableLines] of Integer
= (faReadOnly,faArchive,faHidden,faSysFile);
Var
Info : TSearchRec;
I : Longint;
begin
Result:=New(PFilePropertiesDialog);
With Result^ do
begin
Window:=PgtkDialog(gtk_dialog_new);
gtk_window_set_title(PgtkWindow(Window),SPropsTitle);
gtk_window_set_modal(PgtkWindow(Window),True);
gtk_window_set_policy(PgtkWindow(Window),0,0,0);
gtk_window_set_position(PGtkWindow(Window),GTK_WIN_POS_CENTER);
OkButton:=PGtkButton(gtk_button_new_with_label(SOK));
gtk_box_pack_start(PgtkBox(Window^.action_area),PGtkWidget(Okbutton),False,False,5);
gtk_window_set_focus(PGtkWindow(Window),PGtkWidget(OkButton));
gtk_widget_show(PGtkWidget(OkButton));
Table:=PgtkTable(gtk_table_new(NrTableLines+1,2,TRUE));
gtk_box_pack_start(PGtkBox(Window^.vbox),PGtkWidget(Table),True,True,10);
For I:=0 to NrTableLines do
begin
Labels[0,i]:=PGtkLabel(gtk_label_new(LabelTexts[i]));
gtk_label_set_justify(Labels[0,I],GTK_JUSTIFY_RIGHT);
gtk_table_attach_defaults(Table,PgtkWidget(Labels[0,I]),0,1,I,I+1);
end;
For I:=0 to CheckboxLineStart-1 do
begin
Labels[1,i]:=PGtkLabel(gtk_label_new(''));
gtk_label_set_justify(Labels[1,I],GTK_JUSTIFY_LEFT);
gtk_table_attach_defaults(Table,PgtkWidget(Labels[1,I]),1,2,I,I+1);
end;
For I:=CheckboxLineStart to NrTableLines do
begin
checkBoxes[i]:=PgtkCheckButton(gtk_check_button_new_with_label(CheckBoxTexts[I]));
gtk_widget_set_state(PGtKWidget(CheckBoxes[i]),GTK_STATE_INSENSITIVE);
gtk_table_attach_defaults(Table,PgtkWidget(CheckBoxes[i]),1,2,I,I+1);
end;
gtk_label_set_text(Labels[1,0],PChar(ExtractFileName(FileName)));
gtk_label_set_text(Labels[1,1],PChar(ExtractFilePath(FileName)));
gtk_label_set_text(Labels[1,2],PChar(ExtractFileExt(FileName)+SFile));
If FindFirst(FileName,faAnyFile,Info)=0 Then
begin
gtk_label_set_text(Labels[1,3],PChar(FileSizeToString(Info.Size)));
gtk_label_set_text(Labels[1,4],PChar(DateTimeToStr(FileDateToDateTime(Info.Time))));
For I:=CheckboxLineStart to NrTableLines do
If (CheckAttrs[i] and Info.Attr)=CheckAttrs[i] then
gtk_toggle_button_set_active(PgtkToggleButton(CheckBoxes[I]),True);
FindClose(Info);
end;
gtk_signal_connect(PGtkObject(Window),'destroy',
TGTKSignalFunc(@DestroyPropDialog),Result);
gtk_signal_connect_object(PgtkObject(OKButton),'clicked',
GTK_SIGNAL_FUNC(@gtk_widget_destroy),
PGTKOBJECT(Window));
end;
end;
Procedure ShowFilePropertiesDialog(Dialog : PFilePropertiesDialog);
begin
gtk_widget_show_all(PgtkWidget(Dialog^.Window));
end;
end.
|