home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto06 / delphi10 / ufmgr15.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-10-22  |  33.9 KB  |  957 lines

  1. unit Ufmgr15;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl,
  8.    DRWSUtl1, DRWSUtl3;
  9.  
  10. type
  11.   TCCFileMgrForm = class(TForm)
  12.     Panel1: TPanel;
  13.     Panel2: TPanel;
  14.     BitBtn1: TBitBtn;
  15.     Panel3: TPanel;
  16.     Label1: TLabel;
  17.     BitBtn2: TBitBtn;
  18.     BitBtn3: TBitBtn;
  19.     BitBtn4: TBitBtn;
  20.     BitBtn5: TBitBtn;
  21.     BitBtn6: TBitBtn;
  22.     BitBtn7: TBitBtn;
  23.     OpenDialog1: TOpenDialog;
  24.     BitBtn8: TBitBtn;
  25.     BitBtn9: TBitBtn;
  26.     OpenDialog2: TOpenDialog;
  27.     BitBtn10: TBitBtn;
  28.     Panel4: TPanel;
  29.     Panel5: TPanel;
  30.     Panel6: TPanel;
  31.     Panel7: TPanel;
  32.     Label2: TLabel;
  33.     Label3: TLabel;
  34.     Label4: TLabel;
  35.     procedure FormResize(Sender: TObject);
  36.     procedure FormCreate(Sender: TObject);
  37.     procedure BitBtn7Click(Sender: TObject);
  38.     procedure BitBtn1Click(Sender: TObject);
  39.     procedure BitBtn2Click(Sender: TObject);
  40.     procedure BitBtn3Click(Sender: TObject);
  41.     procedure BitBtn4Click(Sender: TObject);
  42.     procedure BitBtn5Click(Sender: TObject);
  43.     procedure FormPaint(Sender: TObject);
  44.     procedure BitBtn8Click(Sender: TObject);
  45.     procedure BitBtn9Click(Sender: TObject);
  46.     procedure BitBtn6Click(Sender: TObject);
  47.     procedure BitBtn1DragDrop(Sender, Source: TObject; X, Y: Integer);
  48.     procedure BitBtn1DragOver(Sender, Source: TObject; X, Y: Integer;
  49.       State: TDragState; var Accept: Boolean);
  50.     procedure BitBtn2DragDrop(Sender, Source: TObject; X, Y: Integer);
  51.     procedure BitBtn3DragDrop(Sender, Source: TObject; X, Y: Integer);
  52.     procedure BitBtn4DragDrop(Sender, Source: TObject; X, Y: Integer);
  53.     procedure BitBtn10Click(Sender: TObject);
  54.     procedure FormDestroy(Sender: TObject);
  55.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  56.       Shift: TShiftState);
  57.     procedure BitBtn9KeyDown(Sender: TObject; var Key: Word;
  58.       Shift: TShiftState);
  59.     procedure Label2Click(Sender: TObject);
  60.     procedure Label3Click(Sender: TObject);
  61.     procedure Label4Click(Sender: TObject);
  62.   private
  63.     { Private declarations }
  64.   public
  65.     { Public declarations }
  66.     DirectoryListBox1 : TDirectoryListBox;
  67.     FileListBox1 : TIconFileListBox;
  68.     ScrollBox1 : TFileIconPanelScrollbox;
  69.   end;
  70. var
  71.   CCFileMgrForm      : TCCFileMgrForm;
  72.   CurrentView        : Integer;  { This holds the current view setting      }
  73.  
  74. implementation
  75.  
  76. {$R *.DFM}
  77.  
  78. uses DDDFUnit,  { Include custom directory selection form }
  79.      CfmpfUn;   { Include custom options dialog           }
  80.  
  81. { Set up the resize to replace the icon buttons }
  82. procedure TCCFileMgrForm.FormResize(Sender: TObject);
  83. begin
  84.   { Send in the panel and global buttons list }
  85.   SpacePanelButtons( Panel2 );
  86. end;
  87.  
  88. { Delphi wrote this; use it to set everything up }
  89. procedure TCCFileMgrForm.FormCreate(Sender: TObject);
  90. var TheIconPanel : TFileIconPanel;
  91.     CurrentPath : String;
  92. begin
  93.   { Create the directory list box }
  94.   DirectoryListBox1 := TDirectoryListBox.Create( Panel1 );
  95.   DirectoryListBox1.Parent := Panel1;
  96.   DirectoryListBox1.Visible := true;
  97.   DirectoryListbox1.Top := 17;
  98.   DirectoryListbox1.Left := 0;
  99.   DirectoryListbox1.Height := Panel1.Height - 32;
  100.   DirectoryListbox1.Width := 0;
  101.   { Create the file list box }
  102.   FileListBox1 := TIconFileListBox.Create( Panel1 );
  103.   FileListBox1.Parent := Panel1;
  104.   FileListbox1.Top := 17;
  105.   FileListbox1.Left := 146;
  106.   FileListbox1.Height := Panel1.Height - 32;
  107.   FileListbox1.Width := 0;
  108.   FileListBox1.Visible := true;
  109.   FileListBox1.ShowGlyphs := true;
  110.   FileListBox1.MultiSelect := true;
  111.   FileListBox1.DragMode := dmAutomatic;
  112.   { Set intercomponent interactions }
  113.   DirectoryListBox1.FileList := FileListbox1;
  114.   DirectoryListBox1.DirLabel := Label1;
  115.   { Create the scrollbox }
  116.   ScrollBox1 := TFileIconPanelScrollBox.Create( Panel1 );
  117.   ScrollBox1.Parent := Panel1;
  118.   ScrollBox1.align := alClient;
  119.   ScrollBox1.Left := 0;
  120.   ScrollBox1.Top := 0;
  121.   ScrollBox1.Width := Panel1.Width - 32;
  122.   ScrollBox1.Height := Panel1.Height - 32;
  123.   ScrollBox1.IconsNeedRefreshing := false;
  124.   ScrollBox1.TheStoredHandle := Self.Handle;
  125.   ScrollBox1.TheParentForm := Self;
  126.   { Get the current directory with 0 parameter }
  127.   GetDir( 0 , CurrentPath );
  128.   { Set the display caption }
  129.   Label1.Caption := CurrentPath;
  130.   { Add a trailing \ if not root }
  131.   CurrentPath := ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentPath );
  132.   { Get the icons display using scrollbox1 }
  133.   ScrollBox1.GetIconsForEntireDirectory( CurrentPath );
  134.   { Set the Icon View as default }
  135.   CurrentView := 1;
  136.   { Start the FIP IOManager }
  137.   if not assigned( TheIOManager ) then
  138.   begin
  139.     TheIOManager := TIOManager.Create( Self );
  140.     TheIOManager.Parent := Self;
  141.     TheIOManager.InitLocks;
  142.   end;
  143.   { Load the special cursor to toggle the LOCK keys }
  144.   Screen.Cursors[ 6 ] := LoadCursor( hInstance , 'KEYSET' );
  145.   Panel5.Cursor := 6;
  146.   Panel6.Cursor := 6;
  147.   Panel7.Cursor := 6;
  148.   Label2.Visible := TheIOManager.IsCapsLockDown;
  149.   Label3.Visible := TheIOManager.IsNumLockDown;
  150.   Label4.Visible := TheIOManager.IsScrollLockDown;
  151. end;
  152.  
  153. { Delphi wrote this; use it to close the application }
  154. procedure TCCFileMgrForm.BitBtn7Click(Sender: TObject);
  155. begin
  156.   Close;
  157. end;
  158.  
  159. { Delphi wrote this use it to perform a copy on all selected files }
  160. procedure TCCFileMgrForm.BitBtn1Click(Sender: TObject);
  161. var ThePosition  : Integer;       { Loop counter   }
  162.     CurrentName ,                 { Holds work name}
  163.     TheOldString : String;        { Holds Dir      }
  164.     finished     : Boolean;       { Loop control   }
  165.     WorkingDir   : String;        { Holds mod wd   }
  166.     TargetDir    : String;        { target of op   }
  167.     TheResult    : Integer;       { Modal res hold }
  168. begin
  169.   { Get current directory and save it for later }
  170.   GetDir( 0 , TheOldString );
  171.   { Check for need to add trailing \ }
  172.   WorkingDir := TheOldString;
  173.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  174.   { Display the Windows-based directory input form }
  175.   TheResult := DestDDForm.ShowModal;
  176.   { If not cancelled do the copy }
  177.   if TheResult = mrOK then
  178.   begin
  179.     { Get the target directory with \ OK }
  180.     TargetDir := DestDDForm.GetTargetDirectory;
  181.     { Show the hourglass to indicate waiting }
  182.     Screen.Cursor := crHourGlass;
  183.     { Setup to get all selections }
  184.     ThePosition := 1;
  185.     finished := false;
  186.     while not finished do
  187.     begin
  188.       { Call generic file getting routine based on current view}
  189.       case CurrentView of
  190.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  191.              ThePosition );
  192.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  193.              ThePosition );
  194.       end;
  195.       { If returns blank string out of selections so exit }
  196.       if CurrentName = '' then finished := true else
  197.       begin
  198.         { If a directory signal error }
  199.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  200.         begin
  201.           if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  202.            +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  203.           begin
  204.             ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  205.              TargetDir );
  206.           end;
  207.         end
  208.         else
  209.         begin
  210.           Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  211.         end;
  212.       end;
  213.     end;
  214.     { Reset to normal cursor }
  215.     Screen.Cursor := crDefault;
  216.   end;
  217.   { Reset to the original directory }
  218.   ChDir( TheOldString );
  219. end;
  220.  
  221. { Delphi wrote this, use it to move files which are selected }
  222. procedure TCCFileMgrForm.BitBtn2Click(Sender: TObject);
  223. var ThePosition  : Integer;       { Loop counter   }
  224.     CurrentName ,                 { Holds work name}
  225.     TheOldString : String;        { Holds Dir      }
  226.     finished     : Boolean;       { Loop control   }
  227.     WorkingDir   : String;        { Holds mod wd   }
  228.     TargetDir    : String;        { target of op   }
  229.     TheResult    : Integer;       { Modal res hold }
  230. begin
  231.   { Get current directory and save it for later }
  232.   GetDir( 0 , TheOldString );
  233.   { Check for need to add trailing \ }
  234.   WorkingDir := TheOldString;
  235.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  236.   { Display the Windows-based directory input form }
  237.   TheResult := DestDDForm.ShowModal;
  238.   { If not cancelled do the copy }
  239.   if TheResult = mrOK then
  240.   begin
  241.     { Get the target directory with \ OK }
  242.     TargetDir := DestDDForm.GetTargetDirectory;
  243.     { Show the hourglass to indicate waiting }
  244.     Screen.Cursor := crHourGlass;
  245.     { Set up to get all current selections }
  246.     ThePosition := 1;
  247.     finished := false;
  248.     while not finished do
  249.     begin
  250.       { Call generic file getting routine based on current view}
  251.       case CurrentView of
  252.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  253.              ThePosition );
  254.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  255.              ThePosition );
  256.       end;
  257.       { If returns blank string then out of selections }
  258.       if CurrentName = '' then finished := true else
  259.       begin
  260.         { If a directory signal error }
  261.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  262.         begin
  263.           if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  264.            '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  265.             ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  266.              TargetDir );
  267.         end
  268.         else
  269.         begin
  270.           Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  271.         end;
  272.       end;
  273.       { Reset to normal cursor }
  274.       Screen.Cursor := crDefault;
  275.     end;
  276.   end;
  277.   { Reset to the original directory }
  278.   ChDir( TheOldString );
  279.   if CurrentView = 1 then { Reset icon display if in view }
  280.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  281. end;
  282.  
  283. { Delphi wrote this, use it to delete files which are selected }
  284. procedure TCCFileMgrForm.BitBtn3Click(Sender: TObject);
  285. var ThePosition  : Integer;       { Loop counter   }
  286.     CurrentName ,                 { Holds work name}
  287.     TheOldString : String;        { Holds Dir      }
  288.     finished     : Boolean;       { Loop control   }
  289.     WorkingDir   : String;        { Holds mod wd   }
  290. begin
  291.   { Get current directory and save it for later }
  292.   GetDir( 0 , TheOldString );
  293.   { Check for need to add trailing \ }
  294.   WorkingDir := TheOldString;
  295.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  296.   { Set up to do loop for selected files }
  297.   ThePosition := 1;
  298.   finished := false;
  299.   while not finished do
  300.   begin
  301.     { Call generic file getting routine based on current view}
  302.     case CurrentView of
  303.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  304.            ThePosition );
  305.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  306.            ThePosition );
  307.     end;
  308.     { if returns blank string out of selections }
  309.     if CurrentName = '' then finished := true else
  310.     begin
  311.       { If its a directory signal error }
  312.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  313.       begin
  314.         if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation,
  315.          mbYesNoCancel , 0 ) = mrYes then
  316.         begin
  317.           ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  318.           Scrollbox1.TheFWB.RemoveDirectory( Currentname );
  319.         end;
  320.       end
  321.       else
  322.       begin
  323.         { Otherwise get confirmation message and if OKed delete file }
  324.         if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  325.          mbYesNoCancel , 0 ) = mrYes then
  326.         begin
  327.           ScrollBox1.TheFWB.DeleteTheFile( Currentname );
  328.         end;
  329.       end;
  330.     end;
  331.   end;
  332.   if CurrentView = 1 then { Reset icon display if in view }
  333.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  334. end;
  335.  
  336. { Delphi wrote this; use it to rename selected files }
  337. procedure TCCFileMgrForm.BitBtn4Click(Sender: TObject);
  338. var ThePosition  : Integer;       { Loop counter   }
  339.     CurrentName ,                 { Holds work name}
  340.     TheOldString : String;        { Holds Dir      }
  341.     finished     : Boolean;       { Loop control   }
  342.     WorkingDir   : String;        { Holds mod wd   }
  343. begin
  344.   { Get current directory for later }
  345.   GetDir( 0 , TheOldString );
  346.   { Check for need to add trailing \ }
  347.   WorkingDir := TheOldString;
  348.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  349.   { Set up to do loop for selected files }
  350.   ThePosition := 1;
  351.   finished := false;
  352.   while not finished do
  353.   begin
  354.     { Call generic file getting routine based on current view}
  355.     case CurrentView of
  356.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  357.            ThePosition );
  358.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  359.            ThePosition );
  360.     end;
  361.     { If returns blank string then out of selections }
  362.     if CurrentName = '' then finished := true else
  363.     begin
  364.       { Otherwise set up the opendialog with filename and caption }
  365.       OpenDialog1.Filename := ExtractFilename( CurrentName );
  366.       { Use this to prevent error from changing directories }
  367.       OpenDialog1.Options := [ofNoChangeDir];
  368.       OpenDialog1.Title := 'Rename File';
  369.       { If not cancelled then do rename or signal error }
  370.       if OpenDialog1.Execute then
  371.       begin
  372.         ScrollBox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  373.       end;
  374.     end;
  375.   end;
  376.   if CurrentView = 1 then { Reset icon display if in view }
  377.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  378. end;
  379.  
  380. { Delphi wrote this; use it to make a new directory under current one }
  381. procedure TCCFileMgrForm.BitBtn5Click(Sender: TObject);
  382. begin
  383.   { Set up the dialog to get the new directory name }
  384.   OpenDialog2.FileName := '*.*';
  385.   OpenDialog2.Title := 'Enter Directory Name';
  386.   if OpenDialog1.Execute then
  387.   begin
  388.     { If not cancelled make new directory }
  389.     Scrollbox1.TheFWB.CreateNewDirectory( OpenDialog1.Filename );
  390.   end;
  391.   if CurrentView = 1 then { Reset icon display if in view }
  392.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  393. end;
  394.  
  395. { Delphi wrote this; use it to handle refreshing the scrollbox }
  396. procedure TCCFileMgrForm.FormPaint(Sender: TObject);
  397. var CurrentDirectory : String; { Get current dir }
  398. begin
  399.   { If updated, do refresh }
  400.   if ScrollBox1.IconsNeedRefreshing then
  401.   begin
  402.     Scrollbox1.ClearTheFIPs;
  403.     ScrollBox1.IconsNeedRefreshing := false;
  404.     GetDir( 0 , CurrentDirectory );
  405.     { Force trailing backslash }
  406.     CurrentDirectory := ScrollBox1.TheFWB.ForceTrailingBackSlash(
  407.      CurrentDirectory );
  408.     { Set the label to the new directory }
  409.     Label1.Caption := UpperCase( CurrentDirectory );
  410.     { Do the update }
  411.     ScrollBox1.GetIconsForEntireDirectory( CurrentDirectory );
  412.   end;
  413. end;
  414.  
  415. { Delphi wrote this; use it to reset the current view Icons/List }
  416. procedure TCCFileMgrForm.BitBtn8Click(Sender: TObject);
  417. var TheOldString : String; { Use to get current directory }
  418. begin
  419.   { Reset currentview }
  420.   if CurrentView = 1 then CurrentView := 2 else
  421.    CurrentView := 1;
  422.   { either show the windows boxes or the scrollbox }
  423.   case CurrentView of
  424.     1 : begin
  425.           { Make the listboxes invisible by changing align and width }
  426.           FileListBox1.Visible := false;
  427.           FileListBox1.Align := alNone;
  428.           FileListBox1.Width := 0;
  429.           DirectoryListBox1.Visible := false;
  430.           DirectoryListBox1.align := alNone;
  431.           DirectoryListBox1.Width := 0;
  432.           { Keep them from getting mouse clicks }
  433.           FileListBox1.Enabled := false;
  434.           DirectoryListBox1.Enabled := false;
  435.           { Have the scrollbox get mouse and be seen  by resetting align/wid}
  436.           Scrollbox1.align := alClient;
  437.           Scrollbox1.width := Panel1.Width - 32;
  438.           ScrollBox1.Enabled := true;
  439.           { Tell the scrollbox to repaint itself just in case }
  440.           ScrollBox1.Update;
  441.         end;
  442.     2 : begin
  443.           { Make the listboxes visible by resetting align and width}
  444.           FileListBox1.Visible := true;
  445.           DirectoryListBox1.Visible := true;
  446.           DirectoryListBox1.width := 145;
  447.           DirectoryListBox1.align := alLeft;
  448.           FileListBox1.align := alClient;
  449.           FileListBox1.Width := Panel1.Width - 32 - DirectoryListBox1.Width;
  450.           { Have them getting mouse clicks }
  451.           FileListBox1.Enabled := true;
  452.           DirectoryListBox1.Enabled := true;
  453.           { Have the scrollbox not get mouse and not be seen via align/width}
  454.           ScrollBox1.Enabled := false;
  455.           ScrollBox1.Visible := false;
  456.           ScrollBox1.align := alNone;
  457.           ScrollBox1.Width := 0;
  458.         end;
  459.   end;
  460.   Invalidate;
  461. end;
  462.  
  463. { Delphi wrote this; use it to do a file search display }
  464. procedure TCCFileMgrForm.BitBtn9Click(Sender: TObject);
  465. var CurrentDirectory : String; { Holds current directory }
  466. begin
  467.   { Set up and run the search dialog }
  468.   OpenDialog2.FileName := '*.*';
  469.   { if not cancelled do the search }
  470.   if OpenDialog2.Execute then
  471.   begin
  472.     { Get current directory }
  473.     GetDir( 0 , CurrentDirectory );
  474.     { Force trailing backslash }
  475.     CurrentDirectory :=
  476.      ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentDirectory );
  477.     { display recursive search results }
  478.     GlobalAbortFlag := false;
  479.     Scrollbox1.DisplayRecursiveSearchResults(
  480.      CurrentDirectory + OpenDialog2.Filename );
  481.     Label1.Caption := 'Search Results for ' + CurrentDirectory +
  482.      OpenDialog2.FileName;
  483.   end;
  484. end;
  485.  
  486. { Delphi wrote this; use it to set a file's properties }
  487. procedure TCCFileMgrForm.BitBtn6Click(Sender: TObject);
  488. var ThePosition  : Integer;       { Loop counter   }
  489.     CurrentName ,                 { Holds work name}
  490.     TheOldString : String;        { Holds Dir      }
  491.     finished     : Boolean;       { Loop control   }
  492.     WorkingDir   : String;        { Holds mod wd   }
  493. begin
  494.   { Get current directory for later }
  495.   GetDir( 0 , TheOldString );
  496.   ThePosition := 1;
  497.   { Check for need to add trailing \ }
  498.   Workingdir := TheOldString;
  499.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  500.   { Call generic file getting routine based on current view}
  501.   case CurrentView of
  502.     1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  503.          ThePosition );
  504.     2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  505.          ThePosition );
  506.   end;
  507.   { If nothing selected then abort (gets ..!) }
  508.   if CurrentName = '' then
  509.   begin
  510.     MessageDlg( 'No File Selected!' , mtError , [mbOK] , 0 );
  511.     exit;
  512.   end
  513.   else
  514.   begin
  515.     { Otherwise set up the properties form and show it }
  516.     CCFMPropsForm.WorkingFileName := CurrentName;
  517.     CCFMPropsForm.ThePosition := ThePosition;
  518.     CCFMPropsForm.BitBtn4.Enabled := true;
  519.     CCFMPropsForm.Initialize;
  520.     CCFMPropsForm.ShowModal;
  521.   end;
  522.   if CurrentView = 1 then { Reset icon display if in view }
  523.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  524. end;
  525.  
  526. { Delphi wrote this; use it to drag and drop files for copying }
  527. procedure TCCFileMgrForm.BitBtn1DragDrop(Sender, Source: TObject; X,
  528.   Y: Integer);
  529. var CurrentName ,                 { Holds work name}
  530.     WorkingDir ,
  531.     TheOldString : String;        { Holds Dir      }
  532.     TargetDir    : String;        { target of op   }
  533.     TheResult    : Integer;       { Modal res hold }
  534.     Counter_1    : Integer;
  535. begin
  536.   { Make sure source is indeed a FileIconPanel }
  537.   if Source is TIconFileListbox then
  538.   begin
  539.     with Source as TIconFileListBox do
  540.     begin
  541.      { Get current directory and save it for later }
  542.      GetDir( 0 , TheOldString );
  543.      WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  544.      { Display the Windows-based directory input form }
  545.      TheResult := DestDDForm.ShowModal;
  546.      { If not cancelled do the copy }
  547.      if TheResult = mrOK then
  548.      begin
  549.        for Counter_1 := 1 to Items.Count do
  550.        begin
  551.          if Selected[ Counter_1 - 1 ] then
  552.          begin
  553.             CurrentName := WorkingDIr + Items[ Counter_1 - 1 ];
  554.             { Get the target directory with \ OK }
  555.             TargetDir := DestDDForm.GetTargetDirectory;
  556.             { If a directory signal and do recursive operation }
  557.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  558.             begin
  559.               if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  560.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  561.               begin
  562.                 ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  563.                  TargetDir );
  564.               end;
  565.             end
  566.             else
  567.             begin
  568.               { Do the copy }
  569.               Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  570.             end;
  571.             { Reset to the original directory }
  572.             ChDir( TheOldString );
  573.           end;
  574.         end;
  575.       end;
  576.     end;
  577.     FileListBox1.Update;
  578.     exit;
  579.   end;
  580.   if TheIOManager.WasSHIFTPressed then
  581.   begin
  582.     BitBtn1Click( Source );
  583.     exit;
  584.   end;
  585.   with Source as TFileIconPanel do
  586.   begin
  587.     { Get current directory and save it for later }
  588.     GetDir( 0 , TheOldString );
  589.     { Display the Windows-based directory input form }
  590.     TheResult := DestDDForm.ShowModal;
  591.     { If not cancelled do the copy }
  592.     if TheResult = mrOK then
  593.     begin
  594.       CurrentName := FTheName;
  595.       { Get the target directory with \ OK }
  596.       TargetDir := DestDDForm.GetTargetDirectory;
  597.       { If a directory signal and do recursive operation }
  598.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  599.       begin
  600.         if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  601.          +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  602.         begin
  603.           ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  604.            TargetDir );
  605.         end;
  606.       end
  607.       else
  608.       begin
  609.         { Do the copy }
  610.         Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  611.       end;
  612.       { Reset to the original directory }
  613.       ChDir( TheOldString );
  614.     end;
  615.   end;
  616. end;
  617.  
  618. { Delphi wrote this; use it to generically OK DnD from FIPs }
  619. procedure TCCFileMgrForm.BitBtn1DragOver(Sender, Source: TObject; X,
  620.   Y: Integer; State: TDragState; var Accept: Boolean);
  621. begin
  622.   { Only accept from FileIconPanel components }
  623.   if ( Source is TFileIconPanel ) or
  624.      ( Source is TIconFileListBox ) then Accept := true else Accept := false;
  625. end;
  626.  
  627. { Delphi wrote this; use it to accept Drag and Drop moving }
  628. procedure TCCFileMgrForm.BitBtn2DragDrop(Sender, Source: TObject; X,
  629.   Y: Integer);
  630. var CurrentName ,                 { Holds work name}
  631.     WorkingDir ,
  632.     TheOldString : String;        { Holds Dir      }
  633.     TargetDir    : String;        { target of op   }
  634.     TheResult       : Integer;    { Modal res hold }
  635.     Counter_1   : Integer;
  636. begin
  637.   { Make sure source is indeed a FileIconPanel }
  638.   if Source is TIconFileListbox then
  639.   begin
  640.     with Source as TIconFileListBox do
  641.     begin
  642.       { Get current directory and save it for later }
  643.       GetDir( 0 , TheOldString );
  644.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  645.       { Display the Windows-based directory input form }
  646.       TheResult := DestDDForm.ShowModal;
  647.       for Counter_1 := 1 to Items.Count do
  648.       begin
  649.         if Selected[ Counter_1 - 1 ] then
  650.         begin
  651.           { If not cancelled do the copy }
  652.           if TheResult = mrOK then
  653.           begin
  654.             CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  655.             { Get the target directory with \ OK }
  656.             TargetDir := DestDDForm.GetTargetDirectory;
  657.             { If a directory signal and do recursive operation }
  658.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  659.             begin
  660.               if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir
  661.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  662.               begin
  663.                 ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  664.                  TargetDir );
  665.               end;
  666.             end
  667.             else
  668.             begin
  669.               { Do the copy }
  670.               Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  671.             end;
  672.             { Reset to the original directory }
  673.             ChDir( TheOldString );
  674.           end;
  675.         end;
  676.       end;
  677.     end;
  678.     FileListBox1.Update;
  679.     exit;
  680.   end;
  681.   if TheIOManager.WasSHIFTPressed then
  682.   begin
  683.     BitBtn2Click( Source );
  684.     exit;
  685.   end;
  686.   with Source as TFileIconPanel do
  687.   begin
  688.     { Get current directory and save it for later }
  689.     GetDir( 0 , TheOldString );
  690.     { Display the Windows-based directory input form }
  691.     TheResult := DestDDForm.ShowModal;
  692.     { If not cancelled do the copy }
  693.     if TheResult = mrOK then
  694.     begin
  695.       { Get the target directory with \ OK }
  696.       TargetDir := DestDDForm.GetTargetDirectory;
  697.       { If Copyfile returns false an error occurred }
  698.       CurrentName := FTheName;
  699.       { If a directory signal and do recursion }
  700.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  701.       begin
  702.         if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  703.          '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  704.           ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  705.            TargetDir );
  706.       end
  707.       else
  708.       begin  { Do the move }
  709.         Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  710.         ChDir( TheOldString );
  711.       end;
  712.       { Refresh display }
  713.       ScrollBox1.Update;
  714.     end;
  715.   end;
  716. end;
  717.  
  718. { Delphi wrote this; use it to do drag and drop deletes }
  719. procedure TCCFileMgrForm.BitBtn3DragDrop(Sender, Source: TObject; X,
  720.   Y: Integer);
  721. var WorkingDir ,
  722.     CurrentName : String;  { Holds work name}
  723.     Counter_1   : Integer;
  724. begin
  725.   { Make sure source is indeed a FileIconPanel }
  726.   if Source is TIconFileListbox then
  727.   begin
  728.     with Source as TIconFileListBox do
  729.     begin
  730.       GetDir( 0 , WorkingDir );
  731.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  732.       for Counter_1 := 1 to Items.Count do
  733.       begin
  734.         if Selected[ Counter_1 - 1 ] then
  735.         begin
  736.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  737.           { If a directory signal and do recursive operation }
  738.           if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  739.           begin
  740.             if MessageDlg( 'Delete Directory ' + CurrentName +'?',
  741.              mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  742.             begin
  743.               ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  744.               Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  745.             end;
  746.           end
  747.           else
  748.           begin
  749.             if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  750.              mbYesNoCancel , 0 ) = mrYes then
  751.             begin
  752.               Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  753.             end;
  754.           end;
  755.         end;
  756.       end;
  757.     end;
  758.     FileListBox1.Update;
  759.     exit;
  760.   end;
  761.   if TheIOManager.WasSHIFTPressed then
  762.   begin
  763.     BitBtn3Click( Source );
  764.     exit;
  765.   end;
  766.   with Source as TFileIconPanel do
  767.   begin
  768.     CurrentName := FTheName;
  769.     { If its a directory signal and do recursive delete }
  770.     if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  771.     begin
  772.       if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation ,
  773.        mbYesNoCancel , 0 ) = mrYes then
  774.       begin
  775.         Scrollbox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  776.         Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  777.       end;
  778.     end
  779.     else
  780.     begin
  781.       { Otherwise get confirmation message and if OKed delete file }
  782.       if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  783.        mbYesNoCancel , 0 ) = mrYes then
  784.       begin
  785.         Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  786.       end;
  787.     end;
  788.     { Refresh Display }
  789.     Scrollbox1.Update;
  790.   end;
  791. end;
  792.  
  793. { Delphi wrote this; use it to do drag and drop renames }
  794. procedure TCCFileMgrForm.BitBtn4DragDrop(Sender, Source: TObject; X,
  795.   Y: Integer);
  796. var WorkingDir ,
  797.     CurrentName : String;  { Holds work name}
  798.     Counter_1   : Integer;
  799. begin
  800.   { Make sure source is indeed a FileIconPanel }
  801.   if Source is TIconFileListbox then
  802.   begin
  803.     with Source as TIconFileListBox do
  804.     begin
  805.       GetDir( 0 , WorkingDir );
  806.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  807.       for Counter_1 := 1 to Items.Count do
  808.       begin
  809.         if Selected[ Counter_1 - 1 ] then
  810.         begin
  811.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  812.           { Otherwise set up the opendialog with filename and caption }
  813.           OpenDialog2.Filename := ExtractFilename( CurrentName );
  814.           { Use this to prevent error from changing directories }
  815.           OpenDialog2.Options := [ofNoChangeDir];
  816.           OpenDialog2.Title := 'Rename File';
  817.           { If not cancelled then do rename or signal error }
  818.           if OpenDialog2.Execute then
  819.           begin
  820.             Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  821.           end;
  822.         end;
  823.       end;
  824.     end;
  825.     FileListBox1.Update;
  826.     exit;
  827.   end;
  828.   if TheIOManager.WasSHIFTPressed then
  829.   begin
  830.     BitBtn4Click( Source );
  831.     exit;
  832.   end;
  833.   with Source as TFileIconPanel do
  834.   begin
  835.     CurrentName := FTheName;
  836.     { If a directory signal error }
  837.     { Otherwise set up the opendialog with filename and caption }
  838.     OpenDialog2.Filename := ExtractFilename( CurrentName );
  839.     { Use this to prevent error from changing directories }
  840.     OpenDialog2.Options := [ofNoChangeDir];
  841.     OpenDialog2.Title := 'Rename File';
  842.     { If not cancelled then do rename or signal error }
  843.     if OpenDialog2.Execute then
  844.     begin
  845.       Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  846.     end;
  847.     { Refresh the display }
  848.     ScrollBox1.Update;
  849.   end;
  850. end;
  851.  
  852. procedure TCCFileMgrForm.BitBtn10Click(Sender: TObject);
  853. var TheCCFMForm : TCCFileMgrForm;
  854. begin
  855.   TheCCFMForm := TCCFileMgrForm.Create( Application );
  856.   TheCCFMForm.Show;
  857. end;
  858.  
  859. procedure TCCFileMgrForm.FormDestroy(Sender: TObject);
  860. begin
  861.   { Release the IO Manager }
  862.   if assigned( TheIOManager) then
  863.   begin
  864.     TheIOManager.Free;
  865.     TheIOManager := nil;
  866.   end;
  867. end;
  868.  
  869. procedure TCCFileMgrForm.FormKeyDown(Sender: TObject; var Key: Word;
  870.   Shift: TShiftState);
  871. var S_lock , N_Lock , C_lock : Boolean;
  872. begin
  873.   case Key of
  874.     VK_Capital : begin
  875.                    TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  876.                    C_Lock := not C_Lock;
  877.                    TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  878.                    Label2.Visible := C_Lock;
  879.                  end;
  880.     VK_End : begin
  881.                 ScrollBox1.VertScrollbar.Position :=
  882.                  ScrollBox1.VertScrollbar.Range;
  883.                 ScrollBox1.HorzScrollbar.Position :=
  884.                  ScrollBox1.HorzScrollBar.Range;
  885.              end;
  886.     VK_Home : begin
  887.                 ScrollBox1.VertScrollbar.Position := 0;
  888.                 ScrollBox1.HorzScrollbar.Position := 0;
  889.               end;
  890.     VK_F1 : TheIOManager.OnF1Pressed( Sender , Key , Shift );
  891.     VK_F2 : TheIOManager.OnF2Pressed( Sender , Key , Shift );
  892.     VK_F3 : TheIOManager.OnF3Pressed( Sender , Key , Shift );
  893.     VK_F4 : TheIOManager.OnF4Pressed( Sender , Key , Shift );
  894.     VK_F5 : TheIOManager.OnF5Pressed( Sender , Key , Shift );
  895.     VK_F6 : TheIOManager.OnF6Pressed( Sender , Key , Shift );
  896.     VK_F7 : TheIOManager.OnF7Pressed( Sender , Key , Shift );
  897.     VK_F8 : TheIOManager.OnF8Pressed( Sender , Key , Shift );
  898.     VK_F9 : TheIOManager.OnF9Pressed( Sender , Key , Shift );
  899.     VK_F10 : TheIOManager.OnF10Pressed( Sender , Key , Shift );
  900.     VK_F11 : TheIOManager.OnF11Pressed( Sender , Key , Shift );
  901.     VK_F12 : TheIOManager.OnF12Pressed( Sender , Key , Shift );
  902.     VK_Numlock : Begin
  903.                    TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  904.                    N_Lock := not N_Lock;
  905.                    TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  906.                    Label3.Visible := N_Lock;
  907.                  end;
  908.     VK_Scroll : Begin
  909.                    TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  910.                    S_Lock := not S_Lock;
  911.                    TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  912.                    Label4.Visible := S_Lock;
  913.                 end;
  914.   end;
  915. end;
  916.  
  917. procedure TCCFileMgrForm.BitBtn9KeyDown(Sender: TObject; var Key: Word;
  918.   Shift: TShiftState);
  919. begin
  920.   case Key of
  921.     VK_CANCEL : begin
  922.                   if MessageDlg( 'Control Break Pressed! Abort Search?',
  923.                    mtConfirmation,mbYesNoCancel,0) = mrYes
  924.                     then GlobalAbortFlag := true;
  925.                 end;
  926.   end;
  927. end;
  928.  
  929. procedure TCCFileMgrForm.Label2Click(Sender: TObject);
  930. var C_Lock , N_Lock , S_Lock : Boolean;
  931. begin
  932.   TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  933.   C_Lock := not C_Lock;
  934.   TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  935.   Label2.Visible := C_Lock;
  936. end;
  937.  
  938. procedure TCCFileMgrForm.Label3Click(Sender: TObject);
  939. var C_Lock , N_Lock , S_Lock : Boolean;
  940. begin
  941.   TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  942.   N_Lock := not N_Lock;
  943.   TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  944.   Label3.Visible := N_Lock;
  945. end;
  946.  
  947. procedure TCCFileMgrForm.Label4Click(Sender: TObject);
  948. var C_Lock , N_Lock , S_Lock : Boolean;
  949. begin
  950.   TheIOManager.ReadLocks( C_lock , N_Lock , S_Lock );
  951.   S_Lock := not S_Lock;
  952.   TheIOManager.SetLocks( C_Lock , N_Lock , S_Lock );
  953.   Label4.Visible := S_Lock;
  954. end;
  955.  
  956. end.
  957.