Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | Unit renunit; |
2 | (************************************************************************ |
||
3 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht, |
||
4 | Eric W. Engler and Chris Vleghert. |
||
5 | |||
6 | This file is part of TZipMaster Version 1.9. |
||
7 | |||
8 | TZipMaster is free software: you can redistribute it and/or modify |
||
9 | it under the terms of the GNU Lesser General Public License as published by |
||
10 | the Free Software Foundation, either version 3 of the License, or |
||
11 | (at your option) any later version. |
||
12 | |||
13 | TZipMaster is distributed in the hope that it will be useful, |
||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | GNU Lesser General Public License for more details. |
||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public License |
||
19 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
20 | |||
21 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
22 | updates: http://www.delphizip.org |
||
23 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
24 | ************************************************************************) |
||
25 | |||
26 | |||
27 | Interface |
||
28 | |||
29 | Uses |
||
30 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
||
31 | StdCtrls, ExtCtrls, Buttons, ZipMstr19, Grids, SortGrid; |
||
32 | |||
33 | Type |
||
34 | TRenForm = Class(TForm) |
||
35 | OkBitBtn: TBitBtn; |
||
36 | CancelBitBtn: TBitBtn; |
||
37 | Label1: TLabel; |
||
38 | Label2: TLabel; |
||
39 | Label3: TLabel; |
||
40 | Label4: TLabel; |
||
41 | Panel1: TPanel; |
||
42 | OldCombo: TComboBox; |
||
43 | NewEdit: TEdit; |
||
44 | DTEdit: TEdit; |
||
45 | AddBtn: TButton; |
||
46 | RemoveBtn: TButton; |
||
47 | DTAllBtn: TButton; |
||
48 | |||
49 | Procedure FormShow(Sender: TObject); |
||
50 | Procedure FormCreate(Sender: TObject); |
||
51 | Procedure FormDestroy(Sender: TObject); |
||
52 | Procedure AddBtnClick(Sender: TObject); |
||
53 | Procedure DTAllBtnClick(Sender: TObject); |
||
54 | Procedure OkBitBtnClick(Sender: TObject); |
||
55 | Procedure OldComboClick(Sender: TObject); |
||
56 | Procedure RemoveBtnClick(Sender: TObject); |
||
57 | Procedure CancelBitBtnClick(Sender: TObject); |
||
58 | Procedure SelectedGridGetCellFormat(Sender: TObject; Col, Row: Integer; |
||
59 | State: TGridDrawState; Var FormatOptions: TFormatOptions); |
||
60 | |||
61 | PRIVATE { Private declarations } |
||
62 | Procedure ClearZipRenList; |
||
63 | |||
64 | PUBLIC { Public declarations } |
||
65 | ZipRenameList: TList; |
||
66 | SelectedGrid: TSortGrid; |
||
67 | GDateTime: Integer; |
||
68 | End; |
||
69 | |||
70 | Var |
||
71 | RenForm: TRenForm; |
||
72 | |||
73 | Implementation |
||
74 | |||
75 | Uses mainunit, msgunit; |
||
76 | {$R *.DFM} |
||
77 | |||
78 | Procedure TRenForm.FormShow(Sender: TObject); |
||
79 | Var |
||
80 | i: Integer; |
||
81 | Begin |
||
82 | GDateTime := 0; |
||
83 | SelectedGrid.RowCount := 2; |
||
84 | SelectedGrid.Rows[1].Clear(); |
||
85 | RenForm.Caption := 'Rename items in zip archive: ' + ExtractFileName |
||
86 | (MainForm.ZipMaster1.ZipFileName); |
||
87 | OldCombo.Clear(); |
||
88 | ClearZipRenList(); |
||
89 | For i := 1 To MainForm.ZipMaster1.Count Do |
||
90 | Begin |
||
91 | With MainForm.ZipMaster1[i - 1] Do |
||
92 | Begin |
||
93 | OldCombo.Items.Add(FileName); |
||
94 | End; |
||
95 | End; |
||
96 | End; |
||
97 | |||
98 | Procedure TRenForm.AddBtnClick(Sender: TObject); |
||
99 | Var |
||
100 | AddItem: String; |
||
101 | RenRec: PZMRenameRec; |
||
102 | Begin |
||
103 | AddItem := OldCombo.Text; |
||
104 | If (AddItem <> NewEdit.Text) Or (DTEdit.Text <> '') Then |
||
105 | Begin |
||
106 | If (Length(AddItem) > 0) And (Length(NewEdit.Text) > 0) Then |
||
107 | Begin |
||
108 | If (SelectedGrid.RowCount > 2) Or ((SelectedGrid.RowCount = 2) And |
||
109 | (SelectedGrid.Cells[0, 1] <> '')) Then |
||
110 | SelectedGrid.RowCount := SelectedGrid.RowCount + 1; |
||
111 | New(RenRec); |
||
112 | RenRec^.Source := AddItem; |
||
113 | RenRec^.Dest := NewEdit.Text; |
||
114 | Try |
||
115 | If DTEdit.Text <> '' Then |
||
116 | RenRec^.DateTime := DateTimeToFileDate(StrToDateTime(DTEdit.Text)); |
||
117 | Except |
||
118 | Else |
||
119 | Dispose(RenRec); |
||
120 | Raise ; |
||
121 | End; |
||
122 | ZipRenameList.Add(RenRec); |
||
123 | SelectedGrid.Cells[0, SelectedGrid.RowCount - 1] := AddItem; |
||
124 | SelectedGrid.Cells[1, SelectedGrid.RowCount - 1] := NewEdit.Text; |
||
125 | SelectedGrid.Cells[2, SelectedGrid.RowCount - 1] := DTEdit.Text; |
||
126 | End; |
||
127 | OldCombo.Text := ''; |
||
128 | NewEdit.Text := ''; |
||
129 | DTEdit.Text := ''; |
||
130 | End; |
||
131 | End; |
||
132 | |||
133 | Procedure TRenForm.FormCreate(Sender: TObject); |
||
134 | Begin |
||
135 | ZipRenameList := TList.Create(); |
||
136 | SelectedGrid := TSortGrid.create(self); |
||
137 | SelectedGrid.Parent := self; |
||
138 | SelectedGrid.Left := 16; |
||
139 | SelectedGrid.Top := 16; |
||
140 | SelectedGrid.Width := 417; |
||
141 | SelectedGrid.Height := 93; |
||
142 | SelectedGrid.Color := clSilver; |
||
143 | SelectedGrid.ColCount := 3; |
||
144 | SelectedGrid.DefaultColWidth := 198; |
||
145 | SelectedGrid.DefaultRowHeight := 16; |
||
146 | SelectedGrid.FixedCols := 0; |
||
147 | SelectedGrid.RowCount := 2; |
||
148 | SelectedGrid.Font.Color := clWindowText; |
||
149 | SelectedGrid.Font.Height := -11; |
||
150 | SelectedGrid.Font.Name := 'Arial'; |
||
151 | SelectedGrid.Font.Style := []; |
||
152 | SelectedGrid.Options := [goFixedVertLine, goFixedHorzLine, goRangeSelect, goColSizing, goRowSelect]; |
||
153 | SelectedGrid.ParentFont := False; |
||
154 | SelectedGrid.ParentShowHint := False; |
||
155 | SelectedGrid.ShowHint := False; |
||
156 | SelectedGrid.TabOrder := 0; |
||
157 | SelectedGrid.CaseSensitive := False; |
||
158 | SelectedGrid.AlignmentHorz := taLeftJustify; |
||
159 | SelectedGrid.AlignmentVert := taTopJustify; |
||
160 | SelectedGrid.ProportionalScrollBars := True; |
||
161 | SelectedGrid.ExtendedKeys := False; |
||
162 | SelectedGrid.SortOnClick := True; |
||
163 | SelectedGrid.FooterFont.Color := clWindowText; |
||
164 | SelectedGrid.FooterFont.Height := -11; |
||
165 | SelectedGrid.FooterFont.Name := 'MS Sans Serif'; |
||
166 | SelectedGrid.FooterFont.Style := []; |
||
167 | SelectedGrid.ColWidths[0] := 154; |
||
168 | SelectedGrid.ColWidths[1] := 160; |
||
169 | SelectedGrid.ColWidths[2] := 96; |
||
170 | SelectedGrid.Cells[0, 0] := 'Old name'; |
||
171 | SelectedGrid.Cells[1, 0] := 'New name'; |
||
172 | SelectedGrid.Cells[2, 0] := 'Date/Time'; |
||
173 | End; |
||
174 | |||
175 | Procedure TRenForm.FormDestroy(Sender: TObject); |
||
176 | Begin |
||
177 | ClearZipRenList(); |
||
178 | ZipRenameList.Free(); |
||
179 | End; |
||
180 | |||
181 | Procedure TRenForm.ClearZipRenList(); |
||
182 | Var |
||
183 | i: Integer; |
||
184 | RenRec: PZMRenameRec; |
||
185 | Begin |
||
186 | For i := 0 To ZipRenameList.Count - 1 Do |
||
187 | Begin |
||
188 | RenRec := ZipRenameList.Items[i]; |
||
189 | Dispose(RenRec); |
||
190 | End; |
||
191 | ZipRenameList.Clear(); |
||
192 | End; |
||
193 | |||
194 | Procedure TRenForm.RemoveBtnClick(Sender: TObject); |
||
195 | Var |
||
196 | i, j: Integer; |
||
197 | RenRec: PZMRenameRec; |
||
198 | Begin |
||
199 | j := SelectedGrid.Selection.Top; |
||
200 | For i := SelectedGrid.Selection.Bottom Downto j Do |
||
201 | Begin |
||
202 | If SelectedGrid.Cells[0, i] <> '' Then |
||
203 | Begin |
||
204 | RenRec := ZipRenameList.Items[i - 1]; |
||
205 | ZipRenameList.Delete(i - 1); |
||
206 | Dispose(RenRec); |
||
207 | SelectedGrid.Rows[i].Clear(); |
||
208 | If i <> 1 Then |
||
209 | SelectedGrid.DeleteRow(i); |
||
210 | End; |
||
211 | End; |
||
212 | End; |
||
213 | |||
214 | Procedure TRenForm.CancelBitBtnClick(Sender: TObject); |
||
215 | Begin |
||
216 | Hide(); |
||
217 | End; |
||
218 | |||
219 | Procedure TRenForm.OkBitBtnClick(Sender: TObject); |
||
220 | Var |
||
221 | RenameErr: Integer; |
||
222 | Begin |
||
223 | AddBtnClick(Sender); |
||
224 | |||
225 | MsgForm.Memo1.Clear(); |
||
226 | MsgForm.Show(); |
||
227 | { Put this message into the message form's memo } |
||
228 | MainForm.ZipMaster1Message(Self, 0, |
||
229 | 'Begin renaming entries in: ' + MainForm.ZipMaster1.ZipFileName); |
||
230 | |||
231 | RenameErr := MainForm.ZipMaster1.Rename(ZipRenameList, GDateTime); |
||
232 | If RenameErr <> 0 Then |
||
233 | ShowMessage('Error ' + IntToStr(RenameErr) + |
||
234 | ' occured in rename zip specification(s)'); |
||
235 | MsgForm.Hide(); |
||
236 | Hide(); |
||
237 | End; |
||
238 | |||
239 | Procedure TRenForm.OldComboClick(Sender: TObject); |
||
240 | Begin |
||
241 | NewEdit.Text := OldCombo.Items.Strings[OldCombo.ItemIndex]; |
||
242 | NewEdit.SetFocus(); |
||
243 | NewEdit.SelStart := Length(NewEdit.Text); |
||
244 | End; |
||
245 | |||
246 | Procedure TRenForm.SelectedGridGetCellFormat |
||
247 | (Sender: TObject; Col, Row: Integer; State: TGridDrawState; |
||
248 | Var FormatOptions: TFormatOptions); |
||
249 | Begin |
||
250 | If Row = 0 Then |
||
251 | Begin |
||
252 | FormatOptions.AlignmentHorz := taCenter; |
||
253 | FormatOptions.Font.Style := FormatOptions.Font.Style + [fsBold]; |
||
254 | FormatOptions.Font.Color := clBlue; |
||
255 | End; |
||
256 | End; |
||
257 | |||
258 | Procedure TRenForm.DTAllBtnClick(Sender: TObject); |
||
259 | Begin |
||
260 | If DTEdit.Text <> '' Then |
||
261 | GDateTime := DateTimeToFileDate(StrToDateTime(DTEdit.Text)) |
||
262 | Else |
||
263 | GDateTime := 0; |
||
264 | End; |
||
265 | |||
266 | End. |