-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUFrmDefinition.pas
180 lines (152 loc) · 4.33 KB
/
UFrmDefinition.pas
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
unit UFrmDefinition;
interface
uses Vcl.Forms, Vcl.Buttons, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls,
System.Classes,
//
UConfig;
type
TFrmDefinition = class(TForm)
LbName: TLabel;
EdName: TEdit;
LbSource: TLabel;
EdSource: TEdit;
LbDestination: TLabel;
EdDestination: TEdit;
LbInclusions: TLabel;
LbExclusions: TLabel;
EdInclusions: TMemo;
EdExclusions: TMemo;
CkRecursive: TCheckBox;
CkDelete: TCheckBox;
BtnOK: TButton;
BtnCancel: TButton;
BottomLine: TBevel;
BtnSourceFolder: TSpeedButton;
BtnDestinationFolder: TSpeedButton;
BtnHelp: TSpeedButton;
CkHiddenFiles: TCheckBox;
Label1: TLabel;
procedure FormShow(Sender: TObject);
procedure BtnOKClick(Sender: TObject);
procedure BtnSourceFolderClick(Sender: TObject);
procedure BtnDestinationFolderClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure EdMasksKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure EdMasksKeyPress(Sender: TObject; var Key: Char);
procedure BtnHelpClick(Sender: TObject);
procedure CkDeleteClick(Sender: TObject);
private
Edit: Boolean;
Def: TDefinition;
LastKeyIsMasksIdent: Boolean;
end;
var
FrmDefinition: TFrmDefinition;
function DoEditDefinition(Edit: Boolean; var Def: TDefinition): Boolean;
implementation
{$R *.dfm}
uses System.SysUtils, Vcl.Dialogs, System.UITypes, Vcl.FileCtrl,
UFrmMasksAutoComplete, UCommon;
function DoEditDefinition;
begin
FrmDefinition := TFrmDefinition.Create(Application);
FrmDefinition.Edit := Edit;
FrmDefinition.Def := Def;
Result := FrmDefinition.ShowModal = mrOk;
if Result then Def := FrmDefinition.Def;
FrmDefinition.Free;
end;
procedure TFrmDefinition.FormCreate(Sender: TObject);
begin
Width := Width+8; //fix theme behavior
EnableEditDirectoryAutoComplete(EdSource);
EnableEditDirectoryAutoComplete(EdDestination);
end;
procedure TFrmDefinition.FormShow(Sender: TObject);
begin
if Edit then
begin
Caption := 'Edit Definition';
EdName.Text := Def.Name;
EdSource.Text := Def.Source;
EdDestination.Text := Def.Destination;
EdInclusions.Text := Def.Inclusions;
EdExclusions.Text := Def.Exclusions;
CkHiddenFiles.Checked := Def.HiddenFiles;
CkRecursive.Checked := Def.Recursive;
CkDelete.Checked := Def.Delete;
end;
end;
procedure TFrmDefinition.BtnOKClick(Sender: TObject);
procedure ValidateEdit(Ed: TEdit; const Name: string);
begin
Ed.Text := Trim(Ed.Text);
if Ed.Text = string.Empty then
begin
MessageDlg(Name+' is empty', mtError, [mbOK], 0);
Ed.SetFocus;
Abort;
end;
end;
begin
ValidateEdit(EdName, 'Name');
ValidateEdit(EdSource, 'Source');
ValidateEdit(EdDestination, 'Destination');
//
if not Edit then
begin
Def := TDefinition.Create;
Config.Definitions.Add(Def);
end;
Def.Name := EdName.Text;
Def.Source := EdSource.Text;
Def.Destination := EdDestination.Text;
Def.Inclusions := EdInclusions.Text;
Def.Exclusions := EdExclusions.Text;
Def.HiddenFiles := CkHiddenFiles.Checked;
Def.Recursive := CkRecursive.Checked;
Def.Delete := CkDelete.Checked;
ModalResult := mrOk;
end;
procedure TFrmDefinition.BtnSourceFolderClick(Sender: TObject);
var
Dir: string;
begin
Dir := EdSource.Text;
if SelectDirectory('Source folder:', string.Empty, Dir) then
EdSource.Text := Dir;
end;
procedure TFrmDefinition.BtnDestinationFolderClick(Sender: TObject);
var
Dir: string;
begin
Dir := EdDestination.Text;
if SelectDirectory('Destination folder:', string.Empty, Dir) then
EdDestination.Text := Dir;
end;
procedure TFrmDefinition.EdMasksKeyPress(Sender: TObject; var Key: Char);
begin
if Key=':' then
LastKeyIsMasksIdent := True;
end;
procedure TFrmDefinition.EdMasksKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if LastKeyIsMasksIdent then
begin
LastKeyIsMasksIdent := False;
DoMasksAutoComplete(TMemo(Sender));
end;
end;
procedure TFrmDefinition.BtnHelpClick(Sender: TObject);
begin
ShowMasksHelp;
end;
procedure TFrmDefinition.CkDeleteClick(Sender: TObject);
begin
if CkDelete.Focused and CkDelete.Checked then
MessageDlg(
'Warning! This option will erase all files and folders on the destination'+
' that don''t match the items of the synchronization.', mtWarning, [mbOK], 0);
end;
end.