home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / eXpertDevelopmentKit / SOURCE / XDKNOTIF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-26  |  7.7 KB  |  173 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       eXpert Development Kit                          }
  4. {                                                       }
  5. {       Copyright (c) 1996,97 Sergey Orlik              }
  6. {       - product manager of Borland Russia             }
  7. {                                                       }
  8. {*******************************************************}
  9. unit XDKNotif;
  10.  
  11. interface
  12. uses
  13.   Windows, SysUtils, Classes, Graphics, Forms, 
  14.   DsgnIntf, ExptIntf, EditIntf, FileIntf, ToolIntf, LibIntf;
  15.  
  16. type
  17.   TxdkFileEventWCancel = procedure (Sender:TObject; const FileName:string; var Cancel:boolean) of object;
  18.   TxdkFileEvent  = procedure (Sender:TObject; const FileName:string) of object;
  19.   TxdkEventEvent = procedure (Sender:TObject; var Cancel:boolean) of object;
  20.  
  21.   TxdkAddInNotifier = class;
  22.  
  23.   TxdkINotifier = class(TIAddInNotifier)
  24.   private
  25.     FNotifier : TxdkAddInNotifier;
  26.   public
  27.     constructor Create(ANotifier:TxdkAddInNotifier);
  28.     procedure FileNotification(NotifyCode: TFileNotification;
  29.       const FileName: string; var Cancel: Boolean); override;
  30.     procedure EventNotification(NotifyCode: TEventNotification;
  31.       var Cancel: Boolean); override;
  32.   end;
  33.  
  34.   TxdkAddInNotifier = class(TComponent)
  35.   private
  36.     FINotifier           : TxdkINotifier;
  37.     FOnFileOpening       : TxdkFileEventWCancel;
  38.     FOnFileOpened        : TxdkFileEvent;
  39.     FOnFileClosing       : TxdkFileEventWCancel;
  40.     FOnProjectOpening    : TxdkFileEventWCancel;
  41.     FOnProjectOpened     : TxdkFileEvent;
  42.     FOnProjectClosing    : TxdkFileEventWCancel;
  43.     FOnAddedToProject    : TxdkFileEventWCancel;
  44.     FOnRemovedFromProject: TxdkFileEventWCancel;
  45.     FOnDefaultDesktopLoad: TxdkFileEvent;
  46.     FOnDefaultDesktopSave: TxdkFileEvent;
  47.     FOnProjectDesktopLoad: TxdkFileEvent;
  48.     FOnProjectDesktopSave: TxdkFileEvent;
  49.     FOnPackageInstalled  : TxdkFileEvent;
  50.     FOnPackageUnInstalled: TxdkFileEvent;
  51.     FOnBeforeCompile     : TxdkEventEvent;
  52.     FOnAfterCompile      : TxdkEventEvent;
  53.   public
  54.     constructor Create(AOwner:TComponent); override;
  55.     destructor Destroy; override;
  56.     procedure Loaded; override;
  57.   published
  58.     property OnFileOpening: TxdkFileEventWCancel read FOnFileOpening write FOnFileOpening;
  59.     property OnFileOpened: TxdkFileEvent read FOnFileOpened write FOnFileOpened;
  60.     property OnFileClosing: TxdkFileEventWCancel read FOnFileClosing write FOnFileClosing;
  61.     property OnProjectOpening: TxdkFileEventWCancel read FOnProjectOpening write FOnProjectOpening;
  62.     property OnProjectOpened: TxdkFileEvent read FOnProjectOpened write FOnProjectOpened;
  63.     property OnProjectClosing: TxdkFileEventWCancel read FOnProjectClosing write FOnProjectClosing;
  64.     property OnAddedToProject: TxdkFileEventWCancel read FOnAddedToProject write FOnAddedToProject;
  65.     property OnRemovedFromProject: TxdkFileEventWCancel read FOnRemovedFromProject write FOnRemovedFromProject;
  66.     property OnDefaultDesktopLoad: TxdkFileEvent read FOnDefaultDesktopLoad write FOnDefaultDesktopLoad;
  67.     property OnDefaultDesktopSave: TxdkFileEvent read FOnDefaultDesktopSave write FOnDefaultDesktopSave;
  68.     property OnProjectDesktopLoad: TxdkFileEvent read FOnProjectDesktopLoad write FOnProjectDesktopLoad;
  69.     property OnProjectDesktopSave: TxdkFileEvent read FOnProjectDesktopSave write FOnProjectDesktopSave;
  70.     property OnPackageInstalled: TxdkFileEvent read FOnPackageInstalled write FOnPackageInstalled;
  71.     property OnPackageUnInstalled: TxdkFileEvent read FOnPackageUnInstalled write FOnPackageUnInstalled;
  72.     property OnBeforeCompile: TxdkEventEvent read FOnBeforeCompile write FOnBeforeCompile;
  73.     property OnAfterCompile: TxdkEventEvent read FOnAfterCompile write FOnAfterCompile;
  74.   end;
  75.  
  76. { *** will be implemented in next version ***
  77.   TxdkProjectNotifier = class(TComponent)
  78.  
  79.   end;
  80.  
  81.   TxdkModuleNotifier = class(TComponent)
  82.  
  83.   end;
  84. }
  85.  
  86. //================================================================
  87. implementation
  88. //================================================================
  89. // TxdkINotifier
  90.  
  91. constructor TxdkINotifier.Create(ANotifier:TxdkAddInNotifier);
  92. begin
  93.   inherited Create;
  94.   FNotifier:=ANotifier;
  95. end;
  96.  
  97. procedure TxdkINotifier.FileNotification(NotifyCode: TFileNotification;
  98.   const FileName: string; var Cancel: Boolean);
  99. begin
  100.   case NotifyCode of
  101.     fnFileOpening       : if Assigned(FNotifier.FOnFileOpening) then
  102.                             FNotifier.FOnFileOpening(FNotifier,FileName,Cancel);
  103.     fnFileOpened        : if Assigned(FNotifier.FOnFileOpened) then
  104.                             FNotifier.FOnFileOpened(FNotifier,FileName);
  105.     fnFileClosing       : if Assigned(FNotifier.FOnFileClosing) then
  106.                             FNotifier.FOnFileClosing(FNotifier,FileName,Cancel);
  107.     fnProjectOpening    : if Assigned(FNotifier.FOnProjectOpening) then
  108.                             FNotifier.FOnProjectOpening(FNotifier,FileName,Cancel);
  109.     fnProjectOpened     : if Assigned(FNotifier.FOnProjectOpened) then
  110.                             FNotifier.FOnProjectOpened(FNotifier,FileName);
  111.     fnProjectClosing    : if Assigned(FNotifier.FOnProjectClosing) then
  112.                             FNotifier.FOnProjectClosing(FNotifier,FileName,Cancel);
  113.     fnAddedToProject    : if Assigned(FNotifier.FOnAddedToProject) then
  114.                             FNotifier.FOnAddedToProject(FNotifier,FileName,Cancel);
  115.     fnRemovedFromProject: if Assigned(FNotifier.FOnRemovedFromProject) then
  116.                             FNotifier.FOnRemovedFromProject(FNotifier,FileName,Cancel);
  117.     fnDefaultDesktopLoad: if Assigned(FNotifier.FOnDefaultDesktopLoad) then
  118.                             FNotifier.FOnDefaultDesktopLoad(FNotifier,FileName);
  119.     fnDefaultDesktopSave: if Assigned(FNotifier.FOnDefaultDesktopSave) then
  120.                             FNotifier.FOnDefaultDesktopSave(FNotifier,FileName);
  121.     fnProjectDesktopLoad: if Assigned(FNotifier.FOnProjectDesktopLoad) then
  122.                             FNotifier.FOnProjectDesktopLoad(FNotifier,FileName);
  123.     fnprojectDesktopSave: if Assigned(FNotifier.FOnProjectDesktopLoad) then
  124.                             FNotifier.FOnProjectDesktopLoad(FNotifier,FileName);
  125.     fnPackageInstalled  : if Assigned(FNotifier.FOnPackageInstalled) then
  126.                             FNotifier.FOnPackageInstalled(FNotifier,FileName);
  127.     fnPackageUninstalled: if Assigned(FNotifier.FOnPackageUnInstalled) then
  128.                             FNotifier.FOnPackageUnInstalled(FNotifier,FileName);
  129.   end;
  130. end;
  131.  
  132. procedure TxdkINotifier.EventNotification(NotifyCode: TEventNotification;
  133.   var Cancel: Boolean);
  134. begin
  135.   case NotifyCode of
  136.     enBeforeCompile     : if Assigned(FNotifier.FOnBeforeCompile) then
  137.                             FNotifier.FOnBeforeCompile(FNotifier,Cancel);
  138.     enAfterCompile      : if Assigned(FNotifier.FOnAfterCompile) then
  139.                             FNotifier.FOnAfterCompile(FNotifier,Cancel);
  140.   end;
  141. end;
  142.  
  143. //================================================================
  144. // TxdkAddInNotifier
  145.  
  146. constructor TxdkAddInNotifier.Create(AOwner:TComponent);
  147. begin
  148.   inherited Create(AOwner);
  149.   if not (csDesigning in ComponentState) then
  150.     FINotifier:=TxdkINotifier.Create(Self);
  151. end;
  152.  
  153. destructor TxdkAddInNotifier.Destroy;
  154. begin
  155.   if not (csDesigning in ComponentState) then
  156.   begin
  157.     ToolServices.RemoveNotifier(FINotifier);
  158.     FINotifier.Free;
  159.   end;
  160.   inherited Destroy;
  161. end;
  162.  
  163. procedure TxdkAddInNotifier.Loaded;
  164. begin
  165.   inherited Loaded;
  166.   if not (csDesigning in ComponentState) then
  167.     ToolServices.AddNotifierEx(FINotifier)
  168. end;
  169.  
  170. //================================================================
  171.  
  172. end.
  173.