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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
|
{
Double Commander
-------------------------------------------------------------------------
Change file properties dialog
Copyright (C) 2009-2015 Alexander Koblov (alexx2000@mail.ru)
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit fSetFileProperties;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls, Buttons,
uFileSourceSetFilePropertyOperation, DCBasicTypes, DateTimePicker;
type
{ TfrmSetFileProperties }
TfrmSetFileProperties = class(TForm)
Bevel2: TBevel;
Bevel1: TBevel;
btnCancel: TBitBtn;
btnCreationTime: TSpeedButton;
btnLastAccessTime: TSpeedButton;
btnLastWriteTime: TSpeedButton;
btnOK: TBitBtn;
cbExecGroup: TCheckBox;
cbExecOther: TCheckBox;
cbExecOwner: TCheckBox;
cbReadGroup: TCheckBox;
cbReadOther: TCheckBox;
cbReadOwner: TCheckBox;
cbSgid: TCheckBox;
cbSticky: TCheckBox;
cbSuid: TCheckBox;
cbWriteGroup: TCheckBox;
cbWriteOther: TCheckBox;
cbWriteOwner: TCheckBox;
chkArchive: TCheckBox;
chkCreationTime: TCheckBox;
chkHidden: TCheckBox;
chkLastAccessTime: TCheckBox;
chkLastWriteTime: TCheckBox;
chkReadOnly: TCheckBox;
chkRecursive: TCheckBox;
chkSystem: TCheckBox;
edtOctal: TEdit;
gbTimeSamp: TGroupBox;
gbWinAttributes: TGroupBox;
gbUnixAttributes: TGroupBox;
lblAttrBitsStr: TLabel;
lblAttrGroupStr: TLabel;
lblAttrInfo: TLabel;
lblModeInfo: TLabel;
lblAttrOtherStr: TLabel;
lblAttrOwnerStr: TLabel;
lblAttrText: TLabel;
lblAttrTextStr: TLabel;
lblExec: TLabel;
lblOctal: TLabel;
lblRead: TLabel;
lblWrite: TLabel;
DatesPanel: TPanel;
ChecksPanel: TPanel;
ZVCreationDateTime: TDateTimePicker;
ZVLastWriteDateTime: TDateTimePicker;
ZVLastAccessDateTime: TDateTimePicker;
procedure btnCreationTimeClick(Sender: TObject);
procedure btnLastAccessTimeClick(Sender: TObject);
procedure btnLastWriteTimeClick(Sender: TObject);
procedure SetOtherDateLikeThis(ReferenceZVDateTimePicker:TDateTimePicker);
procedure btnOKClick(Sender: TObject);
procedure cbChangeModeClick(Sender: TObject);
procedure chkChangeAttrClick(Sender: TObject);
procedure chkCreationTimeChange(Sender: TObject);
procedure chkLastAccessTimeChange(Sender: TObject);
procedure chkLastWriteTimeChange(Sender: TObject);
procedure edtOctalKeyPress(Sender: TObject; var Key: char);
procedure edtOctalKeyUp(Sender: TObject; var {%H-}Key: Word; {%H-}Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure ZVCreationDateTimeChange(Sender: TObject);
procedure ZVLastAccessDateTimeChange(Sender: TObject);
procedure ZVLastWriteDateTimeChange(Sender: TObject);
procedure ZVCreationDateTimeClick(Sender: TObject);
procedure ZVLastWriteDateTimeClick(Sender: TObject);
procedure ZVLastAccessDateTimeClick(Sender: TObject);
private
FOperation: TFileSourceSetFilePropertyOperation;
FChangeTriggersEnabled: Boolean;
procedure ShowMode(Mode: TFileAttrs);
procedure ShowAttr(Attr: TFileAttrs);
procedure UpdateAllowGrayed(AllowGrayed: Boolean);
function FormatUnixAttributesEx(iAttr: TFileAttrs): String;
function GetModeFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
function GetAttrFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
public
constructor Create(aOwner: TComponent; const aOperation: TFileSourceSetFilePropertyOperation); reintroduce;
end;
function ShowChangeFilePropertiesDialog(const aOperation: TFileSourceSetFilePropertyOperation): Boolean;
implementation
{$R *.lfm}
uses
LCLType, DCFileAttributes, DCStrUtils, uDCUtils, uFileProperty, uKeyboard;
function ShowChangeFilePropertiesDialog(const aOperation: TFileSourceSetFilePropertyOperation): Boolean;
begin
with TfrmSetFileProperties.Create(Application, aOperation) do
try
Result:= (ShowModal = mrOK);
finally
Free;
end;
end;
{ TfrmSetFileProperties }
procedure TfrmSetFileProperties.btnOKClick(Sender: TObject);
var
theNewProperties: TFileProperties;
begin
with FOperation do
begin
theNewProperties:= NewProperties;
if fpAttributes in SupportedProperties then
begin
if theNewProperties[fpAttributes] is TNtfsFileAttributesProperty then
IncludeAttributes:= GetAttrFromForm(ExcludeAttributes);
if theNewProperties[fpAttributes] is TUnixFileAttributesProperty then
IncludeAttributes:= GetModeFromForm(ExcludeAttributes);
// Nothing changed, clear new property
if (IncludeAttributes = 0) and (ExcludeAttributes = 0) then
begin
theNewProperties[fpAttributes].Free;
theNewProperties[fpAttributes]:= nil;
end;
end;
if chkCreationTime.Checked then
(theNewProperties[fpCreationTime] as TFileCreationDateTimeProperty).Value:= ZVCreationDateTime.DateTime
else
begin
theNewProperties[fpCreationTime].Free;
theNewProperties[fpCreationTime]:= nil;
end;
if chkLastWriteTime.Checked then
(theNewProperties[fpModificationTime] as TFileModificationDateTimeProperty).Value:= ZVLastWriteDateTime.DateTime
else
begin
theNewProperties[fpModificationTime].Free;
theNewProperties[fpModificationTime]:= nil;
end;
if chkLastAccessTime.Checked then
(theNewProperties[fpLastAccessTime] as TFileLastAccessDateTimeProperty).Value:= ZVLastAccessDateTime.DateTime
else
begin
theNewProperties[fpLastAccessTime].Free;
theNewProperties[fpLastAccessTime]:= nil;
end;
NewProperties:= theNewProperties;
Recursive:= chkRecursive.Checked;
end;
end;
procedure TfrmSetFileProperties.cbChangeModeClick(Sender: TObject);
var
AMode, ExcludeAttrs: TFileAttrs;
CheckBox: TCheckBox absolute Sender;
begin
if FChangeTriggersEnabled then
begin
FChangeTriggersEnabled := False;
if CheckBox.State = cbGrayed then
begin
edtOctal.Text:= EmptyStr;
lblAttrText.Caption:= EmptyStr;
end
else begin
AMode:= GetModeFromForm(ExcludeAttrs);
edtOctal.Text:= DecToOct(AMode);
lblAttrText.Caption:= FormatUnixAttributesEx(AMode);
end;
FChangeTriggersEnabled := True;
end;
end;
procedure TfrmSetFileProperties.chkChangeAttrClick(Sender: TObject);
begin
// Called after checking any windows-check
end;
procedure TfrmSetFileProperties.edtOctalKeyPress(Sender: TObject; var Key: char);
begin
if not ((Key in ['0'..'7']) or (Key = Chr(VK_BACK)) or (Key = Chr(VK_DELETE))) then
Key:= #0;
end;
procedure TfrmSetFileProperties.edtOctalKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
AMode: TFileAttrs;
begin
if FChangeTriggersEnabled then
begin
FChangeTriggersEnabled := False;
AMode:= OctToDec(edtOctal.Text);
lblAttrText.Caption:= FormatUnixAttributesEx(AMode);
ShowMode(AMode);
FChangeTriggersEnabled := True;
end;
end;
procedure TfrmSetFileProperties.FormCreate(Sender: TObject);
begin
end;
procedure TfrmSetFileProperties.ShowMode(Mode: TFileAttrs);
begin
cbReadOwner.Checked:= ((Mode and S_IRUSR) = S_IRUSR);
cbWriteOwner.Checked:= ((Mode and S_IWUSR) = S_IWUSR);
cbExecOwner.Checked:= ((Mode and S_IXUSR) = S_IXUSR);
cbReadGroup.Checked:= ((Mode and S_IRGRP) = S_IRGRP);
cbWriteGroup.Checked:= ((Mode and S_IWGRP) = S_IWGRP);
cbExecGroup.Checked:= ((Mode and S_IXGRP) = S_IXGRP);
cbReadOther.Checked:= ((Mode and S_IROTH) = S_IROTH);
cbWriteOther.Checked:= ((Mode and S_IWOTH) = S_IWOTH);
cbExecOther.Checked:= ((Mode and S_IXOTH) = S_IXOTH);
cbSuid.Checked:= ((Mode and S_ISUID) = S_ISUID);
cbSgid.Checked:= ((Mode and S_ISGID) = S_ISGID);
cbSticky.Checked:= ((Mode and S_ISVTX) = S_ISVTX);
end;
procedure TfrmSetFileProperties.ShowAttr(Attr: TFileAttrs);
begin
chkArchive.Checked:= ((Attr and FILE_ATTRIBUTE_ARCHIVE) <> 0);
chkReadOnly.Checked:= ((Attr and FILE_ATTRIBUTE_READONLY) <> 0);
chkHidden.Checked:= ((Attr and FILE_ATTRIBUTE_HIDDEN) <> 0);
chkSystem.Checked:= ((Attr and FILE_ATTRIBUTE_SYSTEM) <> 0);
end;
procedure TfrmSetFileProperties.UpdateAllowGrayed(AllowGrayed: Boolean);
var
Index: Integer;
begin
lblAttrInfo.Visible:= AllowGrayed;
for Index:= 0 to gbWinAttributes.ControlCount - 1 do
begin
if gbWinAttributes.Controls[Index] is TCheckBox then
TCheckBox(gbWinAttributes.Controls[Index]).AllowGrayed:= AllowGrayed;
end;
lblModeInfo.Visible:= AllowGrayed;
for Index:= 0 to gbUnixAttributes.ControlCount - 1 do
begin
if gbUnixAttributes.Controls[Index] is TCheckBox then
TCheckBox(gbUnixAttributes.Controls[Index]).AllowGrayed:= AllowGrayed;
end;
end;
function TfrmSetFileProperties.FormatUnixAttributesEx(iAttr: TFileAttrs): String;
begin
Result:= Copy(FormatUnixAttributes(iAttr), 2, MaxInt);
end;
function TfrmSetFileProperties.GetModeFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
begin
Result:= 0;
ExcludeAttrs:= 0;
case cbReadOwner.State of
cbChecked: Result:= (Result or S_IRUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IRUSR;
end;
case cbWriteOwner.State of
cbChecked: Result:= (Result or S_IWUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWUSR;
end;
case cbExecOwner.State of
cbChecked: Result:= (Result or S_IXUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXUSR;
end;
case cbReadGroup.State of
cbChecked: Result:= (Result or S_IRGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IRGRP;
end;
case cbWriteGroup.State of
cbChecked: Result:= (Result or S_IWGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWGRP;
end;
case cbExecGroup.State of
cbChecked: Result:= (Result or S_IXGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXGRP;
end;
case cbReadOther.State of
cbChecked: Result:= (Result or S_IROTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IROTH;
end;
case cbWriteOther.State of
cbChecked: Result:= (Result or S_IWOTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWOTH;
end;
case cbExecOther.State of
cbChecked: Result:= (Result or S_IXOTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXOTH;
end;
case cbSuid.State of
cbChecked: Result:= (Result or S_ISUID);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISUID;
end;
case cbSgid.State of
cbChecked: Result:= (Result or S_ISGID);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISGID;
end;
case cbSticky.State of
cbChecked: Result:= (Result or S_ISVTX);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISVTX;
end;
end;
function TfrmSetFileProperties.GetAttrFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
begin
Result:= 0;
ExcludeAttrs:= 0;
case chkArchive.State of
cbChecked: Result:= (Result or FILE_ATTRIBUTE_ARCHIVE);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or FILE_ATTRIBUTE_ARCHIVE;
end;
case chkReadOnly.State of
cbChecked: Result:= (Result or FILE_ATTRIBUTE_READONLY);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or FILE_ATTRIBUTE_READONLY;
end;
case chkHidden.State of
cbChecked: Result:= (Result or FILE_ATTRIBUTE_HIDDEN);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or FILE_ATTRIBUTE_HIDDEN;
end;
case chkSystem.State of
cbChecked: Result:= (Result or FILE_ATTRIBUTE_SYSTEM);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or FILE_ATTRIBUTE_SYSTEM;
end;
end;
constructor TfrmSetFileProperties.Create(aOwner: TComponent; const aOperation: TFileSourceSetFilePropertyOperation);
begin
inherited Create(aOwner);
FOperation:= aOperation;
FChangeTriggersEnabled:= True;
ZVCreationDateTime.DateTime:= NullDate;
ZVLastWriteDateTime.DateTime:= NullDate;
ZVLastAccessDateTime.DateTime:= NullDate;
// Enable only supported file properties
with FOperation do
begin
if fpAttributes in SupportedProperties then
begin
UpdateAllowGrayed((TargetFiles.Count > 1) or TargetFiles[0].IsDirectory);
if NewProperties[fpAttributes] is TNtfsFileAttributesProperty then
begin
if TargetFiles.Count = 1 then
ShowAttr((NewProperties[fpAttributes] as TNtfsFileAttributesProperty).Value);
gbWinAttributes.Show;
end;
if NewProperties[fpAttributes] is TUnixFileAttributesProperty then
begin
if TargetFiles.Count = 1 then
ShowMode((NewProperties[fpAttributes] as TUnixFileAttributesProperty).Value);
gbUnixAttributes.Show;
end;
end;
if (fpCreationTime in SupportedProperties) and Assigned(NewProperties[fpCreationTime]) then
begin
ZVCreationDateTime.DateTime:= (NewProperties[fpCreationTime] as TFileCreationDateTimeProperty).Value;
ZVCreationDateTime.Enabled:= True;
chkCreationTime.Enabled:= True;
btnCreationTime.Enabled:= True;
end;
if (fpModificationTime in SupportedProperties) and Assigned(NewProperties[fpModificationTime]) then
begin
ZVLastWriteDateTime.DateTime:= (NewProperties[fpModificationTime] as TFileModificationDateTimeProperty).Value;
ZVLastWriteDateTime.Enabled:= True;
chkLastWriteTime.Enabled:= True;
btnLastWriteTime.Enabled:= True;
end;
if (fpLastAccessTime in SupportedProperties) and Assigned(NewProperties[fpLastAccessTime]) then
begin
ZVLastAccessDateTime.DateTime:= (NewProperties[fpLastAccessTime] as TFileLastAccessDateTimeProperty).Value;
ZVLastAccessDateTime.Enabled:= True;
chkLastAccessTime.Enabled:= True;
btnLastAccessTime.Enabled:= True;
end;
end;
chkCreationTime.Checked:=False;
chkLastWriteTime.Checked:=False;
chkLastAccessTime.Checked:=False;
end;
procedure TfrmSetFileProperties.btnCreationTimeClick(Sender: TObject);
begin
ZVCreationDateTime.DateTime:= Now;
if not chkCreationTime.Checked then chkCreationTime.Checked:=TRUE;
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVCreationDateTime);
end;
procedure TfrmSetFileProperties.btnLastWriteTimeClick(Sender: TObject);
begin
ZVLastWriteDateTime.DateTime:= Now;
if not chkLastWriteTime.Checked then chkLastWriteTime.Checked:=TRUE;
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVLastWriteDateTime);
end;
procedure TfrmSetFileProperties.btnLastAccessTimeClick(Sender: TObject);
begin
ZVLastAccessDateTime.DateTime:= Now;
if not chkLastAccessTime.Checked then chkLastAccessTime.Checked:=TRUE;
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVLastAccessDateTime);
end;
procedure TfrmSetFileProperties.SetOtherDateLikeThis(ReferenceZVDateTimePicker:TDateTimePicker);
begin
if ReferenceZVDateTimePicker<>ZVCreationDateTime then
begin
ZVCreationDateTime.DateTime:=ReferenceZVDateTimePicker.DateTime;
chkCreationTime.Checked:=TRUE;
end;
if ReferenceZVDateTimePicker<>ZVLastWriteDateTime then
begin
ZVLastWriteDateTime.DateTime:=ReferenceZVDateTimePicker.DateTime;
chkLastWriteTime.Checked:=TRUE;
end;
if ReferenceZVDateTimePicker<>ZVLastAccessDateTime then
begin
ZVLastAccessDateTime.DateTime:=ReferenceZVDateTimePicker.DateTime;
chkLastAccessTime.Checked:=TRUE;
end;
ReferenceZVDateTimePicker.SetFocus;
end;
procedure TfrmSetFileProperties.chkCreationTimeChange(Sender: TObject);
begin
UpdateColor(ZVCreationDateTime, chkCreationTime.Checked);
if (chkCreationTime.Checked and Visible) then ZVCreationDateTime.SetFocus;
end;
procedure TfrmSetFileProperties.chkLastAccessTimeChange(Sender: TObject);
begin
UpdateColor(ZVLastAccessDateTime, chkLastAccessTime.Checked);
if (chkLastAccessTime.Checked and Visible) then ZVLastAccessDateTime.SetFocus;
end;
procedure TfrmSetFileProperties.chkLastWriteTimeChange(Sender: TObject);
begin
UpdateColor(ZVLastWriteDateTime, chkLastWriteTime.Checked);
if (chkLastWriteTime.Checked and Visible) then ZVLastWriteDateTime.SetFocus;
end;
procedure TfrmSetFileProperties.ZVCreationDateTimeChange(Sender: TObject);
begin
chkCreationTime.Checked:=True;
end;
procedure TfrmSetFileProperties.ZVLastAccessDateTimeChange(Sender: TObject);
begin
chkLastAccessTime.Checked:=True;
end;
procedure TfrmSetFileProperties.ZVLastWriteDateTimeChange(Sender: TObject);
begin
chkLastWriteTime.Checked:=True;
end;
procedure TfrmSetFileProperties.ZVCreationDateTimeClick(Sender: TObject);
begin
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVCreationDateTime);
end;
procedure TfrmSetFileProperties.ZVLastWriteDateTimeClick(Sender: TObject);
begin
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVLastWriteDateTime);
end;
procedure TfrmSetFileProperties.ZVLastAccessDateTimeClick(Sender: TObject);
begin
if ssCtrl in GetKeyShiftStateEx then SetOtherDateLikeThis(ZVLastAccessDateTime);
end;
end.
|