1{ Directory cleaning component configuration window 2 3 Copyright (C) 2007 Michael Van Canneyt michael@freepascal.org 4 5 This library is free software; you can redistribute it and/or modify it 6 under the terms of the GNU Library General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or (at your 8 option) any later version with the following modification: 9 10 As a special exception, the copyright holders of this library give you 11 permission to link this library with independent modules to produce an 12 executable, regardless of the license terms of these independent modules,and 13 to copy and distribute the resulting executable under terms of your choice, 14 provided that you also meet, for each linked independent module, the terms 15 and conditions of the license of that module. An independent module is a 16 module which is not derived from or based on this library. If you modify 17 this library, you may extend this exception to your version of the library, 18 but you are not obligated to do so. If you do not wish to do so, delete this 19 exception statement from your version. 20 21 This program is distributed in the hope that it will be useful, but WITHOUT 22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License 24 for more details. 25 26 You should have received a copy of the GNU Library General Public License 27 along with this library; if not, write to the Free Software Foundation, 28 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. 29} 30 31 32unit frmmain; 33 34{$mode objfpc}{$H+} 35 36interface 37 38uses 39 SysUtils, Forms, Controls, Dialogs, Menus, ActnList, ComCtrls, ExtCtrls, 40 RTTICtrls, StdCtrls, Buttons, dircleaner, LazFileUtils, LazUTF8; 41 42type 43 44 { TMainForm } 45 46 TMainForm = class(TForm) 47 AExecute: TAction; 48 ATest: TAction; 49 ADeleteItem: TAction; 50 ANewItem: TAction; 51 AQuit: TAction; 52 ASaveAs: TAction; 53 ASave: TAction; 54 AOpen: TAction; 55 ANew: TAction; 56 ALMain: TActionList; 57 ILMain: TImageList; 58 Label1: TLabel; 59 Label2: TLabel; 60 Label3: TLabel; 61 Label4: TLabel; 62 Label5: TLabel; 63 Label6: TLabel; 64 Label7: TLabel; 65 LEDailyAt: TLabel; 66 LSEHourlyAt: TLabel; 67 LSEFileActionMinCompressSize: TLabel; 68 LELocationName: TLabel; 69 LVFileActions: TListView; 70 LVLocations: TListView; 71 LVDirectories: TListView; 72 MIRun: TMenuItem; 73 MITest: TMenuItem; 74 MRun: TMenuItem; 75 MIDeleteItem: TMenuItem; 76 MINewItem: TMenuItem; 77 MItems: TMenuItem; 78 MIQuit: TMenuItem; 79 MISep1: TMenuItem; 80 MISaveAs: TMenuItem; 81 MISave: TMenuItem; 82 MIOpen: TMenuItem; 83 MNew: TMenuItem; 84 MFile: TMenuItem; 85 MMMain: TMainMenu; 86 ODConfig: TOpenDialog; 87 PFileAction: TPanel; 88 PLocation: TPanel; 89 PCConfig: TPageControl; 90 POptions: TPanel; 91 PDirectories: TPanel; 92 SBLocationPath: TSpeedButton; 93 SDConfig: TSaveDialog; 94 SDDir: TSelectDirectoryDialog; 95 SBDirPath: TSpeedButton; 96 CBDirEnabled: TTICheckBox; 97 CBDirRecurse: TTICheckBox; 98 CBStopOnError: TTICheckBox; 99 CBAllFileActions: TTICheckBox; 100 EDirName: TTIEdit; 101 EDirPath: TTIEdit; 102 ELocationName: TTIEdit; 103 ELocationBaseDir: TTIEdit; 104 CGLocationSubdirs: TTICheckGroup; 105 CBFileActionDelete: TTICheckBox; 106 CBFileActionCompress: TTICheckBox; 107 CBFileActionLocationName: TTIComboBox; 108 EFileActionName: TTIEdit; 109 EFileActionExtensions: TTIEdit; 110 SEFileActionMinCompressSize: TTISpinEdit; 111 CBLogAllFiles: TTICheckBox; 112 CGScheduleDays: TTICheckGroup; 113 EDailyAt: TTIEdit; 114 RGScheduleMode: TTIRadioGroup; 115 SEHourlyAt: TTISpinEdit; 116 TSScheduling: TTabSheet; 117 ToolButton1: TToolButton; 118 TBNewItem: TToolButton; 119 TBDeleteItem: TToolButton; 120 TSLocations: TTabSheet; 121 TSFileActions: TTabSheet; 122 TSOptions: TTabSheet; 123 TBMain: TToolBar; 124 TBQuit: TToolButton; 125 ToolButton2: TToolButton; 126 TBNew: TToolButton; 127 TBOpen: TToolButton; 128 TBSave: TToolButton; 129 procedure ADeleteItemExecute(Sender: TObject); 130 procedure ADeleteItemUpdate(Sender: TObject); 131 procedure AExecuteUpdate(Sender: TObject); 132 procedure ANewExecute(Sender: TObject); 133 procedure ANewItemExecute(Sender: TObject); 134 procedure AOpenExecute(Sender: TObject); 135 procedure AQuitExecute(Sender: TObject); 136 procedure ASaveAsExecute(Sender: TObject); 137 procedure ASaveExecute(Sender: TObject); 138 procedure ASaveUpdate(Sender: TObject); 139 procedure ATestExecute(Sender: TObject); 140 procedure ActionChanged(Sender: TObject); 141 procedure CBFileActionCompressChange(Sender: TObject); 142 procedure LocationSubdirsItemClick(Sender: TObject; Index: integer); 143 procedure DirectoryChanged(Sender: TObject); 144 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 145 procedure FormShow(Sender: TObject); 146 procedure LocationChanged(Sender: TObject); 147 procedure LVDirectoriesSelectItem(Sender: TObject; Item: TListItem; 148 Selected: Boolean); 149 procedure LVFileActionsSelectItem(Sender: TObject; Item: TListItem; 150 Selected: Boolean); 151 procedure LVLocationsSelectItem(Sender: TObject; Item: TListItem; 152 Selected: Boolean); 153 procedure OptionsChanged(Sender: TObject); 154 procedure PCConfigChange(Sender: TObject); 155 procedure SBDirPathClick(Sender: TObject); 156 procedure SBLocationPathClick(Sender: TObject); 157 procedure ScheduleModeChanged(Sender: TObject); 158 private 159 { private declarations } 160 FCleaner : TCleanDirs; 161 // For easy access 162 FLocations : TLocations; 163 FDirectories : TDirectories; 164 FFileActions : TFileActions; 165 // Currently shown 166 FLocation : TLocation; 167 FDirectory : TDirectory; 168 FFileAction : TFileAction; 169 // Tracking changes 170 FLocationChanged, 171 FDirectoryChanged, 172 FFileActionChanged, 173 FOptionChanged : Boolean; 174 procedure CheckScheduleMode; 175 procedure RunConfig(ACleaner: TCleanDirs; TestOnly: Boolean); 176 Procedure SaveCurrentRTTI; 177 procedure CheckInit; 178 procedure ClearChanged; 179 Function DataModified : Boolean; 180 procedure CheckCompressMinSize; 181 function CheckSave: Boolean; 182 procedure DeleteDirectory; 183 procedure DeleteFileAction; 184 procedure DeleteItem; 185 function DeleteListItem(LV: TListView): TListItem; 186 procedure DeleteLocation; 187 function HaveDirectory: Boolean; 188 function HaveFileAction: Boolean; 189 function HaveItem: Boolean; 190 function HaveLocation: Boolean; 191 procedure LoadFile(AFileName: String); 192 procedure NewConfig; 193 procedure NewItem; 194 procedure NewDirectory; 195 procedure NewFileAction; 196 procedure NewLocation; 197 function OpenFile: Boolean; 198 procedure RefreshDirectoryItem(LI: TListItem); 199 procedure RefreshFileActionItem(LI: TListItem); 200 procedure RefreshLocationItem(LI: TListItem); 201 function SaveData: Boolean; 202 function SaveDataAs: Boolean; 203 Function Selectdir(Current : String) : String; 204 procedure ShowDirectoryItem(LI: TListItem); 205 procedure ShowFileActionItem(LI: TListItem); 206 procedure ShowLocationItem(LI: TListItem); 207 procedure UpdateActionLocations(Loc: TLocations); 208 public 209 { public declarations } 210 Procedure ShowDiskCleaner(ACleaner : TCleanDirs); 211 Procedure ShowLocations(ALocations : TLocations); 212 Procedure ShowDirectories(ADirectories : TDirectories); 213 Procedure ShowFileActions(AFileActions : TFileActions); 214 end; 215 216var 217 MainForm: TMainForm; 218 219implementation 220 221{$R *.lfm} 222 223uses 224 frmLog, 225 typinfo; 226 227ResourceString 228 SYes = 'Yes'; 229 SNo = 'No'; 230 SSubdirExtension = 'Extension'; 231 SSubdirYear = 'Year'; 232 SSubdirMonth = 'Month'; 233 SSubdirDay = 'Day'; 234 SSubdirDate = 'Date'; 235 SSubdirHour = 'Hour'; 236 SSubdirMin = 'Min'; 237 SSubdirTime = 'Time'; 238 SDataChanged = 'The configuration has changed. Save changes ?'; 239 240 241Function BoolStr(B : Boolean) : String; 242 243begin 244 if B then 245 Result:=SYes 246 else 247 Result:=SNo; 248end; 249 250Function SubdirsToStr(S : TSubDirs) : String; 251 252 Procedure AddToResult(Const ToAdd: String); 253 254 begin 255 If (Result<>'') then 256 Result:=Result+','; 257 Result:=Result+ToAdd 258 259 end; 260 261Var 262 D : TSubDir; 263 A : String; 264 265begin 266 Result:=''; 267 For D:=Low(TSubDir) to High(TSubDir) do 268 If D in S then 269 begin 270 case D of 271 sdExtension : A:=SSubDirExtension; 272 sdYear : A:=SSubDirYear; 273 sdMonth : A:=SSubDirMonth; 274 sdDay : A:=SSubDirDay; 275 sdDate : A:=SSubDirDate; 276 sdHour : A:=SSubDirHour; 277 sdMin : A:=SSubDirMin; 278 sdTime : A:=SSubDirTime; 279 else 280 A:='?'; 281 end; 282 AddToResult(A); 283 end; 284end; 285 286{ TMainForm } 287 288procedure TMainForm.ANewExecute(Sender: TObject); 289begin 290 NewConfig; 291end; 292 293procedure TMainForm.ADeleteItemExecute(Sender: TObject); 294begin 295 DeleteItem; 296end; 297 298procedure TMainForm.ADeleteItemUpdate(Sender: TObject); 299begin 300 (Sender as Taction).Enabled:=HaveItem; 301end; 302 303procedure TMainForm.AExecuteUpdate(Sender: TObject); 304begin 305 (Sender as Taction).Enabled:=(FCleaner<>Nil) and (FFileActions.Count>0); 306end; 307 308procedure TMainForm.ANewItemExecute(Sender: TObject); 309begin 310 NewItem; 311end; 312 313procedure TMainForm.AOpenExecute(Sender: TObject); 314begin 315 OpenFile; 316end; 317 318procedure TMainForm.AQuitExecute(Sender: TObject); 319begin 320 Close; 321end; 322 323procedure TMainForm.ASaveAsExecute(Sender: TObject); 324begin 325 SaveDataAs; 326end; 327 328procedure TMainForm.ASaveExecute(Sender: TObject); 329begin 330 SaveData; 331end; 332 333procedure TMainForm.ASaveUpdate(Sender: TObject); 334begin 335 (Sender as Taction).Enabled:=DataModified; 336end; 337 338procedure TMainForm.ATestExecute(Sender: TObject); 339begin 340 RunConfig(FCleaner,(Sender=ATest)); 341end; 342 343procedure TMainForm.ActionChanged(Sender: TObject); 344begin 345 RefreshFileActionItem(LVFileActions.Selected); 346 FFileActionChanged:=True; 347end; 348 349 350procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); 351begin 352 CanClose:=CheckSave; 353end; 354 355procedure TMainForm.FormShow(Sender: TObject); 356begin 357 CheckInit; 358end; 359 360Function TMainForm.Selectdir(Current : String) : String; 361 362begin 363 With SDDir do 364 begin 365 If (Current<>'') then 366 InitialDir:=Current 367 else 368 InitialDir:=UserDir; 369 If Execute then 370 Result:=FileName 371 else 372 Result:=Current; 373 end; 374end; 375 376{ --------------------------------------------------------------------- 377 Config file management; 378 ---------------------------------------------------------------------} 379 380procedure TMainForm.NewConfig; 381 382begin 383 If Not CheckSave Then 384 Exit; 385 FreeAndNil(FCleaner); 386 ShowDiskCleaner(TCleanDirs.Create(Self)); 387end; 388 389procedure TMainForm.ShowDiskCleaner(ACleaner: TCleanDirs); 390begin 391 FCleaner:=ACleaner; 392 CBStopOnError.Link.TIObject:=FCleaner; 393 CBAllFileActions.Link.TIObject:=FCleaner; 394 CBLogAllFiles.Link.TIObject:=FCleaner; 395 RGScheduleMode.link.TIObject:=FCLeaner; 396 CGScheduleDays.link.TIObject:=FCLeaner; 397 EDailyAt.Link.TIObject:=FCleaner; 398 SEHourlyAt.Link.TIObject:=FCleaner; 399 ShowDirectories(FCleaner.Directories); 400 ShowLocations(FCleaner.Locations); 401 ShowFileActions(FCleaner.FileActions); 402 ClearChanged; 403end; 404 405Procedure TMainForm.ClearChanged; 406 407begin 408 FLocationChanged:=False; 409 FDirectoryChanged:=False; 410 FFileActionChanged:=False; 411 FOptionChanged:=False; 412end; 413 414procedure TMainForm.SaveCurrentRTTI; 415 416Var 417 C : TWinControl; 418 L : TPropertyLink; 419 420begin 421 C:=Self.ActiveControl; 422 If Assigned(C) then 423 begin 424 If IsPublishedProp(C,'Link') then 425 begin 426 L:=GetObjectProp(C,'Link',TPropertyLink) as TPropertyLink; 427 L.SaveToProperty; 428 end; 429 end; 430end; 431 432function TMainForm.DataModified: Boolean; 433begin 434 Result:=FOptionChanged 435 or FDirectoryChanged 436 or FFileActionChanged 437 or FLocationChanged; 438end; 439 440 441Function TMainForm.CheckSave : Boolean; // Return true if all OK, false if cancelled 442 443begin 444 SaveCurrentRTTI; 445 Result:=Not DataModified; 446 If Not Result then 447 begin 448 Result:=True; 449 case MessageDlg(SDataChanged,mtWarning,[mbYes,mbNo,mbCancel],0) of 450 mrYes : Result:=SaveData; 451 mrCancel : Result:=False; 452 end; 453 end; 454end; 455 456Function TMainForm.SaveData : Boolean; 457 458begin 459 If (FCleaner.ConfigFile<>'') then 460 begin 461 FCleaner.SaveToFile(FCleaner.ConfigFile); 462 ClearChanged; 463 end 464 else 465 Result:=SaveDataAs; 466end; 467 468Function TMainForm.SaveDataAs : Boolean; 469 470begin 471 With SDConfig do 472 begin 473 FileName:=FCleaner.ConfigFile; 474 Result:=Execute; 475 If Result then 476 begin 477 FCleaner.SaveToFile(FileName); 478 ClearChanged; 479 end; 480 end; 481end; 482 483Function TMainForm.OpenFile : Boolean; 484 485begin 486 Result:=CheckSave; 487 If Result then 488 With ODConfig do 489 begin 490 Result:=Execute; 491 If Result then 492 LoadFile(FileName); 493 end; 494end; 495 496procedure TMainForm.LoadFile(AFileName : String); 497 498Var 499 D : TCleanDirs; 500 501begin 502 D:=TCleanDirs.Create(Self); 503 Try 504 D.LoadFromFile(UTF8ToSys(AFileName)); 505 except 506 D.Free; 507 Raise; 508 end; 509 FreeAndNil(FCleaner); 510 ShowDiskCleaner(D); 511end; 512 513procedure TMainForm.CheckInit; 514 515begin 516 If (Application.ParamCount>0) and FileExistsUTF8(Application.Params[1]) then 517 LoadFile(Application.Params[1]) 518 else 519 NewConfig; 520end; 521 522procedure TMainForm.NewItem; 523 524Var 525 TS : TTabSheet; 526 527begin 528 SaveCurrentRTTI; 529 TS:=PCConfig.ActivePage; 530 If (TS=TSOptions) then 531 NewDirectory 532 else If (TS=TSLocations) then 533 NewLocation 534 else if (TS=TSFileActions) then 535 NewFileAction; 536end; 537 538procedure TMainForm.DeleteItem; 539 540Var 541 TS : TTabSheet; 542 543begin 544 TS:=PCConfig.ActivePage; 545 If (TS=TSOptions) then 546 DeleteDirectory 547 else If (TS=TSLocations) then 548 DeleteLocation 549 else if (TS=TSFileActions) then 550 DeleteFileAction; 551end; 552 553Function TMainForm.HaveItem : Boolean; 554 555Var 556 TS : TTabSheet; 557 558begin 559 Result:=False; 560 TS:=PCConfig.ActivePage; 561 If (TS=TSOptions) then 562 Result:=HaveDirectory 563 else If (TS=TSLocations) then 564 Result:=HaveLocation 565 else if (TS=TSFileActions) then 566 Result:=HaveFileAction 567end; 568 569procedure TMainForm.OptionsChanged(Sender: TObject); 570begin 571 FOptionChanged:=True; 572end; 573 574procedure TMainForm.PCConfigChange(Sender: TObject); 575begin 576 If (PCConfig.ActivePage=TSFileActions) and Assigned(FLocations) then 577 UpdateActionLocations(FLocations); 578end; 579 580procedure TMainForm.RunConfig(ACleaner : TCleanDirs; TestOnly : Boolean); 581 582Var 583 LO : Boolean; 584 F : TLogForm; 585 586begin 587 LO:=ACleaner.LogOnly; 588 try 589 ACleaner.LogOnly:=TestOnly; 590 F:=TLogForm.Create(Self); 591 try 592 F.Cleaner:=ACleaner; 593 F.ShowModal; 594 finally 595 F.Free; 596 end; 597 finally 598 ACleaner.LogOnly:=LO; 599 end; 600end; 601 602procedure TMainForm.ScheduleModeChanged(Sender: TObject); 603begin 604 CheckScheduleMode; 605 OptionsChanged(Sender); 606end; 607 608procedure TMainForm.CheckScheduleMode; 609 610Var 611 D : Boolean; 612 613 614begin 615 D:=(RGScheduleMode.ItemIndex=0); 616 EDailyAt.Enabled:=D; 617 SEHourlyAt.Enabled:=Not D; 618end; 619 620 621{ --------------------------------------------------------------------- 622 Directories 623 ---------------------------------------------------------------------} 624 625 626procedure TMainForm.ShowDirectories(ADirectories: TDirectories); 627 628Var 629 LI : TListItem; 630 D : TDirectory; 631 I : Integer; 632 633begin 634 FDirectories:=ADirectories; 635 With LVDirectories do 636 begin 637 BeginUpdate; 638 Try 639 Items.Clear; 640 For I:=0 to FDirectories.Count-1 do 641 begin 642 D:=FDirectories[i]; 643 LI:=LVDirectories.Items.Add; 644 LI.Data:=D; 645 RefreshDirectoryItem(LI); 646 end; 647 If (LVDirectories.Items.Count>0) then 648 ShowDirectoryItem(LVDirectories.Items[i]) 649 else 650 ShowDirectoryItem(Nil) 651 Finally 652 EndUpdate; 653 end; 654 end; 655end; 656 657 658procedure TMainForm.LVDirectoriesSelectItem(Sender: TObject; Item: TListItem; 659 Selected: Boolean); 660begin 661 If Selected then 662 ShowDirectoryItem(Item) 663 else 664 ShowDirectoryItem(Nil); 665end; 666 667 668 669procedure TMainForm.RefreshDirectoryItem(LI: TListItem); 670 671Var 672 D : TDirectory; 673 674begin 675 If Not Assigned(Li) then 676 Exit; 677 D:=TDirectory(LI.Data); 678 LI.Caption:=BoolStr(D.Enabled); 679 LI.SubItems.Clear; 680 LI.SubItems.Add(BoolStr(D.Recurse)); 681 LI.SubItems.Add(D.Name); 682 LI.SubItems.Add(D.Path); 683end; 684 685 686procedure TMainForm.ShowDirectoryItem(LI: TListItem); 687 688begin 689 If (LI=Nil) then 690 FDirectory:=Nil 691 else 692 FDirectory:=TDirectory(LI.Data); 693 EDirName.Link.TIObject:=FDirectory; 694 EDirPath.Link.TIObject:=FDirectory; 695 CBDirEnabled.Link.TIObject:=FDirectory; 696 CBDirRecurse.link.TIOBject:=FDirectory; 697end; 698 699 700procedure TMainForm.NewDirectory; 701 702Var 703 D : TDirectory; 704 LI : TListItem; 705 706begin 707 RefreshDirectoryItem(LVDirectories.Selected); 708 D:=FDirectories.AddDirectory; 709 LI:=LVDirectories.Items.Add; 710 LI.Data:=D; 711 LVDirectories.Selected:=LI; 712 RefreshDirectoryItem(LI); 713 ShowDirectoryItem(LI); 714 FDirectoryChanged:=True; 715end; 716 717 718Function TMainForm.DeleteListItem(LV : TListView) : TListItem; 719 720Var 721 LI : TListItem; 722 I : Integer; 723 724begin 725 Result:=Nil; 726 LI:=LV.Selected; 727 if (Li<>Nil) then 728 begin 729 I:=LI.Index; 730 LI.Free; 731 If (I>=LV.Items.Count) then 732 Dec(I); 733 If (i>=0) and (I<LV.Items.Count) then 734 Result:=LV.Items[I]; 735 end; 736end; 737 738procedure TMainForm.DeleteDirectory; 739 740begin 741 FreeAndNil(FDirectory); 742 ShowDirectoryItem(DeleteListItem(LVDirectories)); 743 FDirectoryChanged:=True; 744end; 745 746Function TMainForm.HaveDirectory : Boolean; 747 748begin 749 Result:=(FDirectory<>Nil); 750end; 751 752procedure TMainForm.DirectoryChanged(Sender: TObject); 753begin 754 RefreshDirectoryItem(LVDirectories.Selected); 755 FDirectoryChanged:=True; 756end; 757 758 759procedure TMainForm.SBDirPathClick(Sender: TObject); 760 761begin 762 If Assigned(FDirectory) then 763 begin 764 FDirectory.Path:=SelectDir(FDirectory.Path); 765 EDirPath.Link.LoadFromProperty; 766 end; 767end; 768 769{ --------------------------------------------------------------------- 770 Locations 771 ---------------------------------------------------------------------} 772 773procedure TMainForm.LVLocationsSelectItem(Sender: TObject; Item: TListItem; 774 Selected: Boolean); 775begin 776 If Selected then 777 ShowLocationItem(Item) 778 else 779 ShowLocationItem(Nil) 780end; 781 782procedure TMainForm.LocationChanged(Sender: TObject); 783begin 784 RefreshLocationItem(LVLocations.Selected); 785 FLocationChanged:=True; 786end; 787 788procedure TMainForm.LocationSubdirsItemClick(Sender: TObject; Index: integer); 789begin 790 LocationChanged(Sender); 791end; 792 793 794procedure TMainForm.SBLocationPathClick(Sender: TObject); 795begin 796 If Assigned(FLocation) then 797 begin 798 FLocation.BasePath:=SelectDir(FLocation.BasePath); 799 ELocationBaseDir.Link.LoadFromProperty; 800 end; 801end; 802 803 804procedure TMainForm.ShowLocations(ALocations: TLocations); 805 806Var 807 LI : TListItem; 808 L : TLocation; 809 I : Integer; 810 811begin 812 FLocations:=ALocations; 813 With LVLocations do 814 begin 815 BeginUpdate; 816 Try 817 Items.Clear; 818 For I:=0 to FLocations.Count-1 do 819 begin 820 L:=FLocations[i]; 821 LI:=LVLocations.Items.Add; 822 LI.Data:=L; 823 RefreshLocationItem(LI); 824 end; 825 If (LVLocations.Items.Count>0) then 826 ShowLocationItem(LVLocations.Items[i]) 827 else 828 ShowLocationItem(Nil) 829 Finally 830 EndUpdate; 831 end; 832 end; 833 UpdateActionLocations(ALocations); 834end; 835 836procedure TMainForm.RefreshLocationItem(LI: TListItem); 837 838Var 839 L : TLocation; 840 841begin 842 If Not Assigned(Li) then 843 Exit; 844 L:=TLocation(LI.Data); 845 LI.Caption:=L.Name; 846 LI.SubItems.Clear; 847 LI.SubItems.Add(L.BasePath); 848 LI.SubItems.Add(SubdirsToStr(L.SubDirs)); 849end; 850 851 852procedure TMainForm.ShowLocationItem(LI: TListItem); 853 854begin 855 If (LI=Nil) then 856 FLocation:=Nil 857 else 858 FLocation:=TLocation(LI.Data); 859 ELocationName.Link.TIObject:=FLocation; 860 ELocationBaseDir.Link.TIObject:=FLocation; 861 CGLocationSubdirs.Link.TIObject:=FLocation; 862end; 863 864procedure TMainForm.UpdateActionLocations(Loc : TLocations); 865 866Var 867 I,J : Integer; 868 869begin 870 With CBFileActionLocationName.Items do 871 begin 872 BeginUpdate; 873 Try 874 Clear; 875 For I:=0 to Loc.Count-1 do 876 begin 877 J:=Add(Loc[i].Name); 878 Objects[J]:=Loc[i]; 879 end; 880 Finally 881 EndUpdate; 882 end; 883 end; 884end; 885 886procedure TMainForm.NewLocation; 887 888Var 889 D : TLocation; 890 LI : TListItem; 891 892begin 893 RefreshLocationItem(LVLocations.Selected); 894 D:=FLocations.AddLocation; 895 LI:=LVLocations.Items.Add; 896 LI.Data:=D; 897 LVLocations.Selected:=LI; 898 RefreshLocationItem(LI); 899 ShowLocationItem(LI); 900 FLocationChanged:=True; 901end; 902 903procedure TMainForm.DeleteLocation; 904 905begin 906 FreeAndNil(FLocation); 907 ShowDirectoryItem(DeleteListItem(LVLocations)); 908end; 909 910Function TMainForm.HaveLocation : Boolean; 911 912begin 913 Result:=(FLocation<>Nil) 914end; 915 916{ --------------------------------------------------------------------- 917 FileActions 918 ---------------------------------------------------------------------} 919 920procedure TMainForm.LVFileActionsSelectItem(Sender: TObject; Item: TListItem; 921 Selected: Boolean); 922begin 923 If Selected then 924 ShowFileActionItem(Item) 925 else 926 ShowFileActionItem(Nil) 927end; 928 929procedure TMainForm.CBFileActionCompressChange(Sender: TObject); 930begin 931 ActionChanged(Sender); 932 CheckCompressMinSize; 933end; 934 935procedure TMainForm.ShowFileActions(AFileActions: TFileActions); 936 937Var 938 LI : TListItem; 939 A : TFileAction; 940 I : Integer; 941 942begin 943 FFileActions:=AFileActions; 944 With LVFileActions do 945 begin 946 BeginUpdate; 947 Try 948 Items.Clear; 949 For I:=0 to FFileActions.Count-1 do 950 begin 951 A:=FFileActions[i]; 952 LI:=LVFileActions.Items.Add; 953 LI.Data:=A; 954 RefreshFileActionItem(LI); 955 end; 956 If (LVFileActions.Items.Count>0) then 957 ShowFileActionItem(LVFileActions.Items[i]) 958 else 959 ShowFileActionItem(Nil) 960 Finally 961 EndUpdate; 962 end; 963 end; 964end; 965 966procedure TMainForm.RefreshFileActionItem(LI: TListItem); 967 968Var 969 A : TFileAction; 970 971begin 972 If Not Assigned(Li) then 973 Exit; 974 A:=TFileAction(LI.Data); 975 LI.Caption:=A.Name; 976 LI.SubItems.Clear; 977 LI.SubItems.Add(A.Extensions); 978 LI.SubItems.Add(A.LocationName); 979 LI.SubItems.Add(BoolStr(A.Delete)); 980 LI.SubItems.Add(BoolStr(A.Compress)); 981 LI.SubItems.Add(IntToStr(A.MinCompressSize)); 982 LI.SubItems.Add(BoolStr(A.CaseSensitive)); 983end; 984 985 986procedure TMainForm.ShowFileActionItem(LI: TListItem); 987 988begin 989 If (LI=Nil) then 990 FFileAction:=Nil 991 else 992 FFileAction:=TFileAction(LI.Data); 993 EFileActionName.Link.TIObject:=FFileAction; 994 EFileActionExtensions.Link.TIObject:=FFileAction; 995 CBFileActionLocationName.Link.TIObject:=FFileAction; 996 // Bug in control: the items list is cleared !! 997// UpdateActionLocations(FLocations); 998 CBFileActionDelete.Link.TIObject:=FFileAction; 999 CBFileActionCompress.Link.TIObject:=FFileAction; 1000 SEFileActionMinCompressSize.Link.TIObject:=FFileAction; 1001 CheckCompressMinSize; 1002end; 1003 1004procedure TMainForm.CheckCompressMinSize; 1005 1006begin 1007 With SEFileActionMinCompressSize do 1008 begin 1009 Enabled:=CBFileActionCompress.State=cbChecked; 1010 If Not enabled then 1011 SEFileActionMinCompressSize.Value:=0; 1012 LSEFileActionMinCompressSize.Enabled:=Enabled; 1013 end; 1014end; 1015 1016procedure TMainForm.NewFileAction; 1017 1018Var 1019 D : TFileAction; 1020 LI : TListItem; 1021 1022begin 1023 RefreshFileActionItem(LVFileActions.Selected); 1024 D:=FFileActions.AddFileAction; 1025 LI:=LVFileActions.Items.Add; 1026 LI.Data:=D; 1027 LVFileActions.Selected:=LI; 1028 RefreshFileActionItem(LI); 1029 ShowFileActionItem(LI); 1030 FFileActionChanged:=True; 1031end; 1032 1033procedure TMainForm.DeleteFileAction; 1034 1035begin 1036 FreeAndNil(FFileAction); 1037 ShowDirectoryItem(DeleteListItem(LVFileActions)); 1038 FFileActionChanged:=True; 1039end; 1040 1041Function TMainForm.HaveFileAction : Boolean; 1042 1043begin 1044 Result:=(FFileAction<>Nil) 1045end; 1046 1047end. 1048 1049