home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / delphi / komprese / zip / DELZIP12.ZIP / DEMO1.ZIP / ADDUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1997-09-28  |  4KB  |  164 lines

  1. unit Addunit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, FileCtrl, ExtCtrls;
  8.  
  9. type
  10.   TAddForm = class(TForm)
  11.     Panel1: TPanel;
  12.     Panel2: TPanel;
  13.     Panel3: TPanel;
  14.     DriveComboBox1: TDriveComboBox;
  15.     FileListBox1: TFileListBox;
  16.     Panel4: TPanel;
  17.     DirectoryListBox1: TDirectoryListBox;
  18.     Panel5: TPanel;
  19.     AddFileBut: TButton;
  20.     RemoveBut: TButton;
  21.     OKBut: TButton;
  22.     CancelBut: TButton;
  23.     Panel6: TPanel;
  24.     SelectedList: TListBox;
  25.     Panel7: TPanel;
  26.     Label1: TLabel;
  27.     SortBut: TButton;
  28.     DirNameCB: TCheckBox;
  29.     RecurseCB: TCheckBox;
  30.     Bevel1: TBevel;
  31.     Panel8: TPanel;
  32.     SelectAllBut: TButton;
  33.     Label2: TLabel;
  34.     AddDirBut: TButton;
  35.     procedure OKButClick(Sender: TObject);
  36.     procedure CancelButClick(Sender: TObject);
  37.     procedure AddFileButClick(Sender: TObject);
  38.     procedure SortButClick(Sender: TObject);
  39.     procedure RemoveButClick(Sender: TObject);
  40.     procedure SelectAllButClick(Sender: TObject);
  41.     function  AppendSlash(const sDir : String): String;
  42.     procedure FormCreate(Sender: TObject);
  43.     procedure AddDirButClick(Sender: TObject);
  44.   private
  45.     { Private declarations }
  46.   public
  47.     { Public declarations }
  48.   end;
  49.  
  50. var
  51.   AddForm: TAddForm;
  52.   InMouseClick: Boolean;
  53.  
  54. implementation
  55.  
  56. uses mainunit;
  57.  
  58. {$R *.DFM}
  59.  
  60. procedure TAddForm.OKButClick(Sender: TObject);
  61. begin
  62.    MainUnit.Canceled:=False;
  63.    Close;
  64. end;
  65.  
  66. procedure TAddForm.CancelButClick(Sender: TObject);
  67. begin
  68.   Close;
  69. end;
  70.  
  71. procedure TAddForm.SortButClick(Sender: TObject);
  72. begin
  73.   SelectedList.Sorted:=True;
  74.   SortBut.Enabled:=False;  { list will remain sorted }
  75. end;
  76.  
  77. procedure TAddForm.RemoveButClick(Sender: TObject);
  78. var
  79.    i: Integer;
  80. begin
  81.    for i:=SelectedList.Items.Count-1 downto 0 do
  82.    begin
  83.       if SelectedList.Selected[i] then
  84.          SelectedList.Items.Delete(i);
  85.    end;
  86. end;
  87.  
  88. procedure TAddForm.SelectAllButClick(Sender: TObject);
  89. var
  90.    i: Integer;
  91. begin
  92.    for i := 0 to FileListBox1.Items.Count - 1 do
  93.       FileListBox1.Selected[i]:=True;
  94. end;
  95.  
  96. function TAddForm.AppendSlash(const sDir : String): String;
  97. begin
  98.   Result := sDir;
  99.   if (Length(sDir)>0) and (sDir[Length(sDir)]<>'\') then
  100.      Result := Result+'\';
  101. end;
  102.  
  103. procedure TAddForm.FormCreate(Sender: TObject);
  104. begin
  105.    DirNameCB.Checked:=False;
  106.    RecurseCB.Checked:=False;
  107.    InMouseClick:=False;
  108. end;
  109.  
  110. procedure TAddForm.AddDirButClick(Sender: TObject);
  111. var
  112.    i: Integer;
  113.    FullName: String;
  114. begin
  115.    MainUnit.Canceled:=True;  // default
  116.    for i := 0 to DirectoryListBox1.Items.Count - 1 do
  117.    begin
  118.       if DirectoryListBox1.Selected[i] then
  119.       begin
  120.          // Add this file if it isn't already in listbox
  121.          FullName:=AppendSlash(DirectoryListBox1.Directory);
  122.  
  123.          if SelectedList.Items.IndexOf(FullName) < 0 then
  124.             SelectedList.Items.Add(FullName);
  125.       { Never de-select dirnames from the DirectoryList! }
  126.       {  DirectoryListBox1.Selected[i]:=False; }
  127.       end;
  128.    end;
  129.    { Position the "SelectedList" listbox at the bottom }
  130.    with SelectedList do
  131.    begin
  132.       Selected[Items.Count-1]:=True;
  133.       Selected[Items.Count-1]:=False;
  134.    end;
  135. end;
  136.  
  137. procedure TAddForm.AddFileButClick(Sender: TObject);
  138. var
  139.    i: Integer;
  140.    FullName: String;
  141. begin
  142.    MainUnit.Canceled:=True;  // default
  143.    for i := 0 to FileListBox1.Items.Count - 1 do
  144.    begin
  145.       if FileListBox1.Selected[i] then
  146.       begin
  147.          // Add this file if it isn't already in listbox
  148.          FullName:=AppendSlash(DirectoryListBox1.Directory)
  149.                                  + FileListBox1.Items[i];
  150.          if SelectedList.Items.IndexOf(FullName) < 0 then
  151.             SelectedList.Items.Add(FullName);
  152.          FileListBox1.Selected[i]:=False;
  153.       end;
  154.    end;
  155.    { Position the "SelectedList" listbox at the bottom }
  156.    with SelectedList do
  157.    begin
  158.       Selected[Items.Count-1]:=True;
  159.       Selected[Items.Count-1]:=False;
  160.    end;
  161. end;
  162.  
  163. end.
  164.