home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / eXpertDevelopmentKit / SOURCE / XDKEXPT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-26  |  6.4 KB  |  251 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 XDKExpt;
  10.  
  11. interface
  12.  
  13. uses
  14.   Windows, SysUtils, Classes, Graphics, Forms, Dialogs, Menus,
  15.   DsgnIntf, ExptIntf, EditIntf, FileIntf, ToolIntf, LibIntf;
  16.  
  17. type
  18.   TRepositoryExpertStyle = (esrForm,esrProject);
  19.  
  20. type
  21.   ExdkExpertError = class(Exception);
  22.   TxdkExpert = class;
  23.  
  24.   TxdkIExpert = class(TIExpert)
  25.   private
  26.     FOwner  : TxdkExpert;
  27.   public
  28.     function GetName: string; override;
  29.     function GetAuthor: string; override;
  30.     function GetComment: string; override;
  31.     function GetPage: string; override;
  32.     function GetGlyph: HICON; override;
  33.     function GetStyle: TExpertStyle; override;
  34.     function GetState: TExpertState; override;
  35.     function GetIDString: string; override;
  36.     function GetMenuText: string; override;
  37.     procedure Execute; override;
  38.   end;
  39.  
  40.   TxdkExpert = class(TComponent)
  41.   private
  42.     FIExpert   : TxdkIExpert;
  43.     FExpertName: string;
  44.     FAuthor    : string;
  45.     FComment   : string;
  46.     FPage      : string;
  47.     FGlyph     : TIcon;
  48.     FStyle     : TExpertStyle;
  49.     FState     : TExpertState;
  50.     FMenuText  : string;
  51.     FOnExecute : TNotifyEvent;
  52.   protected
  53.     property ExpertName:string read FExpertName write FExpertName;
  54.     property Author:string read FAuthor write FAuthor;
  55.     property Comment:string read FComment write FComment;
  56.     property Page:string read FPage write FPage;
  57.     property State:TExpertState read FState write FState default [esEnabled];
  58.     property MenuText:string read FMenuText write FMenuText;
  59.   public
  60.     constructor Create(AOwner: TComponent); override;
  61.     destructor Destroy; override;
  62.     procedure Loaded; override;
  63.   published
  64.     property OnExecute: TNotifyEvent read FOnExecute write FOnExecute;
  65.   end;
  66.  
  67.   TxdkStandardExpert = class(TxdkExpert)
  68.   public
  69.     constructor Create(AOwner: TComponent); override;
  70.   published
  71.     property ExpertName;
  72.     property State;
  73.     property MenuText;
  74.   end;
  75.  
  76.   TxdkRepositoryExpert = class(TxdkExpert)
  77.   private
  78.     FRStyle : TRepositoryExpertStyle;
  79.     procedure SetGlyph(Icon:TIcon); virtual;
  80.   public
  81.     constructor Create(AOwner: TComponent); override;
  82.     destructor Destroy; override;
  83.     procedure Loaded; override;
  84.   published
  85.     property ExpertName;
  86.     property Author;
  87.     property Comment;
  88.     property Page;
  89.     property Glyph:TIcon read FGlyph write SetGlyph;
  90.     property RStyle:TRepositoryExpertStyle read FRStyle write FRStyle default esrForm;
  91.   end;
  92.  
  93.  
  94. //====================================================================
  95. implementation
  96. //====================================================================
  97.  
  98. const
  99.   sInvalidExpertName = 'Expert name for %s can''t be empty!';
  100.   sInvalidMenuText = 'Menu text for %s can''t be empty!';
  101.  
  102. procedure Error(const S: string;ExpertComponent:TxdkExpert);
  103. begin
  104.   raise ExdkExpertError.Create(Format(S,[ExpertComponent.Name]));
  105. end;
  106.  
  107. //====================================================================
  108. // TxdkIExpert
  109. function TxdkIExpert.GetName: string;
  110. begin
  111.   Result:=FOwner.FExpertName
  112. end;
  113.  
  114. function TxdkIExpert.GetAuthor: string;
  115. begin
  116.   if FOwner.FAuthor<>'' then
  117.     Result:=FOwner.FAuthor
  118.   else
  119.     Result:='AuthorOf_'+FOwner.Name;
  120. end;
  121.  
  122. function TxdkIExpert.GetComment: string;
  123. begin
  124.   Result:=FOwner.FComment;
  125. end;
  126.  
  127. function TxdkIExpert.GetPage: string;
  128. begin
  129.   Result:=FOwner.FPage;
  130.   if Result=EmptyStr then
  131.   begin
  132.     if FOwner.FStyle=esForm then
  133.       Result:='Forms'
  134.     else
  135.       Result:='Projects';
  136.   end;    
  137. end;
  138.  
  139. function TxdkIExpert.GetGlyph: HICON;
  140. begin
  141.   if Assigned(FOwner) then
  142.     if (FOwner is TxdkRepositoryExpert) and Assigned(FOwner.FGlyph) then
  143.     begin
  144.       Result:=(FOwner as TxdkRepositoryExpert).FGlyph.Handle;
  145.       (FOwner as TxdkRepositoryExpert).FGlyph.ReleaseHandle;
  146.     end;  
  147. end;
  148.  
  149. function TxdkIExpert.GetStyle:TExpertStyle;
  150. begin
  151.   Result:=FOwner.FStyle;
  152. end;
  153.  
  154. function TxdkIExpert.GetState:TExpertState;
  155. begin
  156.   Result:=FOwner.FState;
  157. end;
  158.  
  159. function TxdkIExpert.GetIDString: string;
  160. begin
  161.   Result:=FOwner.ExpertName;
  162. end;
  163.  
  164. function TxdkIExpert.GetMenuText: string;
  165. begin
  166.   Result:=FOwner.FMenuText;
  167. end;
  168.  
  169. procedure TxdkIExpert.Execute;
  170. begin
  171.   if Assigned(FOwner) and Assigned(FOwner.FOnExecute) then
  172.     FOwner.OnExecute(FOwner);
  173. end;
  174.  
  175. //====================================================================
  176. // TxdkExpert
  177. constructor TxdkExpert.Create(AOwner: TComponent);
  178. begin
  179.   inherited Create(AOwner);
  180.   FIExpert:=TxdkIExpert.Create;
  181.   FIExpert.FOwner:=Self;
  182.   FState:=[esEnabled];
  183. end;
  184.  
  185. procedure TxdkExpert.Loaded;
  186. begin
  187.   inherited Loaded;
  188.   if not (csDesigning in ComponentState) then
  189.   begin
  190.     if FExpertName=EmptyStr then
  191.       Error(sInvalidExpertName,Self);
  192.     if FStyle=esStandard then
  193.       if FMenuText=EmptyStr then
  194.         Error(sInvalidMenuText,Self);
  195.  
  196.   //Add expert to IDE
  197.     DelphiIDE.AddExpert(FIExpert);
  198.   end;
  199. end;
  200.  
  201. destructor TxdkExpert.Destroy;
  202. begin
  203.   //Remove expert from IDE
  204.   if not (csDesigning in ComponentState) then
  205.     DelphiIDE.RemoveExpert(FIExpert);
  206.   FIExpert.Free;
  207.   inherited Destroy;
  208. end;
  209.  
  210. //=====================================================================
  211. // TxdkStandardExpert
  212. constructor TxdkStandardExpert.Create(AOwner: TComponent);
  213. begin
  214.   inherited Create(AOwner);
  215.   FStyle:=esStandard;
  216. end;
  217.  
  218. //=====================================================================
  219. // TxdkRepositoryExpert
  220. constructor TxdkRepositoryExpert.Create(AOwner: TComponent);
  221. begin
  222.   inherited Create(AOwner);
  223.   FGlyph:=TIcon.Create;
  224.   FRStyle:=esrForm;
  225.   FStyle:=esForm;
  226. end;
  227.  
  228. destructor TxdkRepositoryExpert.Destroy;
  229. begin
  230.   FGlyph.Free;
  231.   inherited Destroy;
  232. end;
  233.  
  234. procedure TxdkRepositoryExpert.Loaded;
  235. begin
  236.   inherited Loaded;
  237.   if FRStyle=esrForm then
  238.     FStyle:=esForm
  239.   else
  240.     FStyle:=esProject;
  241. end;
  242.  
  243. procedure TxdkRepositoryExpert.SetGlyph(Icon:TIcon);
  244. begin
  245.   FGlyph.Assign(Icon);
  246. end;
  247.  
  248. //=====================================================================
  249.  
  250. end.
  251.