home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d56 / RMCTL.ZIP / rmKeyBindingPropEdit.pas < prev    next >
Pascal/Delphi Source File  |  2001-06-22  |  3KB  |  140 lines

  1. {================================================================================
  2. Copyright (C) 1997-2001 Mills Enterprise
  3.  
  4. Unit     : rmKeyBindingPropEdit
  5. Purpose  : Component editor for the rmKeyBinding component.
  6. Date     : 05-03-2000
  7. Author   : Ryan J. Mills
  8. Version  : 1.80
  9. ================================================================================}
  10.  
  11. unit rmKeyBindingPropEdit;
  12.  
  13. interface
  14.  
  15. {$I CompilerDefines.INC}
  16.  
  17. {$ifdef BD6}
  18. uses
  19.   DesignIntf, DesignEditors, TypInfo;    
  20. {$else}
  21. uses
  22.   DsgnIntf, TypInfo;
  23. {$endif}
  24.  
  25.  
  26. type
  27.   TrmKeyBindingEditor = class(TComponentEditor)
  28.   private
  29.     procedure SaveToFile(Binary:boolean);
  30.     procedure LoadFromFile(Binary:Boolean);
  31.     procedure ClearData;
  32.     procedure EditBindings;
  33.   public
  34.     function GetVerb(index:integer):string; override;
  35.     function GetVerbCount:integer; override;
  36.     procedure ExecuteVerb(index:integer); override;
  37.   end;
  38.  
  39.  
  40. implementation
  41.  
  42. uses
  43.   rmKeyBindings, dialogs;
  44.  
  45. { TrmKeyBindingEditor }
  46.  
  47. procedure TrmKeyBindingEditor.ClearData;
  48. begin
  49.    if assigned(Component) then
  50.    begin
  51.       TrmKeyBindings(Component).ClearBindings;
  52.       designer.modified;
  53.    end;
  54. end;
  55.  
  56. procedure TrmKeyBindingEditor.EditBindings;
  57. begin
  58.    if assigned(Component) then
  59.    begin
  60.       if TrmKeyBindings(Component).EditBindings then
  61.       begin
  62.          TrmKeyBindings(Component).ApplyBindings;
  63.          designer.modified;
  64.       end;
  65.    end;
  66. end;
  67.  
  68. procedure TrmKeyBindingEditor.ExecuteVerb(index: integer);
  69. begin
  70.    case index of
  71.         0:EditBindings;
  72.         1:LoadFromFile(True);
  73.         2:LoadFromFile(False);
  74.         3:SaveToFile(True);
  75.         4:SaveToFile(False);
  76.         5:ClearData;
  77.    end;
  78. end;
  79.  
  80. function TrmKeyBindingEditor.GetVerb(index: integer): string;
  81. begin
  82.    case index of
  83.         0:result := 'Edit bindings...';
  84.         1:result := 'Load bindings from file (Binary)...';
  85.         2:result := 'Load bindings from file (Text)...';
  86.         3:result := 'Save bindings to file (Binary)...';
  87.         4:result := 'Save bindings to file (Text)...';
  88.         5:result := 'Clear bindings';
  89.    end;
  90. end;
  91.  
  92. function TrmKeyBindingEditor.GetVerbCount: integer;
  93. begin
  94.    result := 6;
  95. end;
  96.  
  97. procedure TrmKeyBindingEditor.LoadFromFile(Binary:Boolean);
  98. begin
  99.    if assigned(Component) then
  100.    begin
  101.       with TOpenDialog.create(nil) do
  102.       try
  103.          Title := 'Load file...';
  104.          Filter := 'All Files|*.*';
  105.          FilterIndex := 1;
  106.          if execute then
  107.          begin
  108.             TrmKeyBindings(Component).LoadBindingsFromFile(filename, Binary);
  109.             designer.modified;
  110.          end;
  111.       finally
  112.          free;
  113.       end
  114.    end;
  115. end;
  116.  
  117. procedure TrmKeyBindingEditor.SaveToFile(Binary:Boolean);
  118. begin
  119.    if assigned(Component) then
  120.    begin
  121.       if not assigned(TrmKeyBindings(Component).Actions) then
  122.       begin
  123.          ShowMessage('No actions are assigned');
  124.          exit;
  125.       end;
  126.       with TSaveDialog.create(nil) do
  127.       try
  128.          Title := 'Save to...';
  129.          Filter := 'All Files|*.*';
  130.          FilterIndex := 1;
  131.          if execute then
  132.             TrmKeyBindings(Component).SaveBindingsToFile(filename, Binary);
  133.       finally
  134.          free;
  135.       end
  136.    end;
  137. end;
  138.  
  139. end.
  140.