home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / TABS / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1998-04-13  |  7KB  |  254 lines

  1. (* =========================================================== *(
  2. **  Main.Pas -- Tab control application                        **
  3. ** ........................................................... **
  4. **  This program inserts, removes, and converts tab controls   **
  5. **  in text files. For example, you can use Tabs to replace    **
  6. **  tabs in a .Pas file with blank spaces; or you can replace  **
  7. **  blanks with 8-column tabs (or any other column setting).   **
  8. **  The program can also convert an X-column-tabbed file to    **
  9. **  a Y-column-tabbed file--replacing 4-column tabs with 8-    **
  10. **  column tabs, for example.                                  **
  11. ** ........................................................... **
  12. **  WARNING: Although this program optionally saves a backup   **
  13. **  copy of processed files, you should run it only on a copy  **
  14. **  of sensitive source code and other text files.             **
  15. ** ........................................................... **
  16. **  Copyright (c) 1995,1998 by Tom Swan. All rights reserved.  **
  17. )* =========================================================== *)
  18.  
  19. unit Main;
  20.  
  21. interface
  22.  
  23. uses
  24.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  25.   Forms, Dialogs, Buttons, StdCtrls, ExtCtrls, Menus,
  26.   About, Options, TabsUnit;
  27.  
  28. type
  29.   TMainForm = class(TForm)
  30.     MainMenu1: TMainMenu;
  31.     FileMenu: TMenuItem;
  32.     FileOpen: TMenuItem;
  33.     N1: TMenuItem;
  34.     FileExit: TMenuItem;
  35.     OptionsMenu: TMenuItem;
  36.     OptionsSettings: TMenuItem;
  37.     OptionsReset: TMenuItem;
  38.     N2: TMenuItem;
  39.     OptionsSave: TMenuItem;
  40.     OptionsLoad: TMenuItem;
  41.     HelpMenu: TMenuItem;
  42.     HelpAbout: TMenuItem;
  43.     HelpHow: TMenuItem;
  44.     HelpSearch: TMenuItem;
  45.     HelpContents: TMenuItem;
  46.     N3: TMenuItem;
  47.     ToolbarPanel: TPanel;
  48.     ExitBitBtn: TBitBtn;
  49.     StatusPanel: TPanel;
  50.     OpenSB: TSpeedButton;
  51.     ExitSB: TSpeedButton;
  52.     OptionsSB: TSpeedButton;
  53.     SaveSB: TSpeedButton;
  54.     LoadSB: TSpeedButton;
  55.     InsertSB: TSpeedButton;
  56.     RemoveSB: TSpeedButton;
  57.     ConvertSB: TSpeedButton;
  58.     HelpSB: TSpeedButton;
  59.     TabPanel: TPanel;
  60.     TimePanel: TPanel;
  61.     KeyPanel: TPanel;
  62.     Timer1: TTimer;
  63.     OpenDialog1: TOpenDialog;
  64.     procedure FormCreate(Sender: TObject);
  65.     procedure FileExitClick(Sender: TObject);
  66.     procedure HelpAboutClick(Sender: TObject);
  67.     procedure Timer1Timer(Sender: TObject);
  68.     procedure HelpSBClick(Sender: TObject);
  69.     procedure OptionsSettingsClick(Sender: TObject);
  70.     procedure OptionsResetClick(Sender: TObject);
  71.     procedure OptionsSaveClick(Sender: TObject);
  72.     procedure OptionsLoadClick(Sender: TObject);
  73.     procedure FormActivate(Sender: TObject);
  74.     procedure FileOpenClick(Sender: TObject);
  75.     procedure InsertSBClick(Sender: TObject);
  76.     procedure RemoveSBClick(Sender: TObject);
  77.     procedure ConvertSBClick(Sender: TObject);
  78.   private
  79.     { Private declarations }
  80.     procedure UpdateStatusPanel;
  81.     procedure UpdateToolbar;
  82.   public
  83.     { Public declarations }
  84.   end;
  85.  
  86. var
  87.   MainForm: TMainForm;
  88.  
  89. implementation
  90.  
  91. {$R *.DFM}
  92.  
  93. const
  94.  
  95. {- Options dialog RadioGroup selections }
  96.   optInsert  = 0;
  97.   optRemove  = 1;
  98.   optConvert = 2;
  99.  
  100. {- Update status panel settings (tab settings only) }
  101. procedure TMainForm.UpdateStatusPanel;
  102. begin
  103.   with OptionsDialog do
  104.   TabPanel.Caption := Format('Tabs: In %d  Out %d',
  105.     [InTabEdit.Value, OutTabEdit.Value]);
  106. end;
  107.  
  108. {- Update toolbar button states }
  109. procedure TMainForm.UpdateToolbar;
  110. begin
  111.   case OptionsDialog.OperationRGroup.ItemIndex of
  112.     optInsert:
  113.       InsertSB.Down := True;
  114.     optRemove:
  115.       RemoveSB.Down := True;
  116.     optConvert:
  117.       ConvertSB.Down := True;
  118.   end;
  119. end;
  120.  
  121. {- Perform setups at form's creation }
  122. procedure TMainForm.FormCreate(Sender: TObject);
  123. begin
  124. {- Steal glyph from Exit BitBtn for toolbar }
  125.   ExitSB.Glyph := ExitBitBtn.Glyph;
  126. end;
  127.  
  128. {- Respond to File|Exit command }
  129. procedure TMainForm.FileExitClick(Sender: TObject);
  130. begin
  131.   Close;
  132. end;
  133.  
  134. {- Display About dialog }
  135. procedure TMainForm.HelpAboutClick(Sender: TObject);
  136. begin
  137.   AboutForm.ShowModal;
  138. end;
  139.  
  140. {- Update status panel time display }
  141. procedure TMainForm.Timer1Timer(Sender: TObject);
  142. begin
  143.   TimePanel.Caption := TimeToStr(Time);
  144. end;
  145.  
  146. {- Respond to Help command (not implemented) }
  147. procedure TMainForm.HelpSBClick(Sender: TObject);
  148. begin
  149.   ShowMessage('Sorry: Not Implemented!');
  150. end;
  151.  
  152. {- Display options dialog; update toolbar and status panel }
  153. procedure TMainForm.OptionsSettingsClick(Sender: TObject);
  154. begin
  155.   if OptionsDialog.ShowModal = mrOk then
  156.   begin
  157.     UpdateStatusPanel;
  158.     UpdateToolbar;
  159.   end;
  160. end;
  161.  
  162. {- Reset options dialog to default settings }
  163. procedure TMainForm.OptionsResetClick(Sender: TObject);
  164. begin
  165.   if Yes('Reset options to default settings?') then
  166.   begin
  167.     OptionsDialog.InitTabOptions;
  168.     UpdateStatusPanel;
  169.     UpdateToolbar;
  170.   end;
  171. end;
  172.  
  173. {- Save options dialog settings in .Ini file }
  174. procedure TMainForm.OptionsSaveClick(Sender: TObject);
  175. begin
  176.   OptionsDialog.SaveOptions;
  177. end;
  178.  
  179. {- Load options dialog settings from .Ini file }
  180. procedure TMainForm.OptionsLoadClick(Sender: TObject);
  181. begin
  182.   OptionsDialog.LoadOptions;
  183.   UpdateStatusPanel;
  184.   UpdateToolbar;
  185. end;
  186.  
  187. {- Perform setups on form's activation }
  188. procedure TMainForm.FormActivate(Sender: TObject);
  189. begin
  190. { Can't do this in OnCreate because Options dialog
  191.   object doesn't exist until after the main form is created. }
  192.   UpdateStatusPanel;
  193. end;
  194.  
  195. {- Respond to File|Open command; process tabs in file }
  196. procedure TMainForm.FileOpenClick(Sender: TObject);
  197. begin
  198.   if OpenDialog1.Execute then
  199.   with OptionsDialog, OpenDialog1 do
  200.   case OperationRGroup.ItemIndex of
  201.     optInsert:
  202.     begin
  203.       if Yes('Insert tabs into ' + FileName + '?') then
  204.         if ProcessTabs(FileName, True, BackupCheckbox.Checked) then
  205.           MessageDlg('Tabs inserted into ' + FileName,
  206.             mtInformation, [mbOk], 0);
  207.     end;
  208.     optRemove:
  209.     begin
  210.       if Yes('Remove tabs from ' + FileName + '?') then
  211.         if ProcessTabs(FileName, False, BackupCheckbox.Checked) then
  212.           MessageDlg('Tabs removed from ' + FileName,
  213.             mtInformation, [mbOk], 0);
  214.     end;
  215.     optConvert:
  216.     begin
  217.       if Yes('Convert tabs in ' + FileName + '?') then
  218.         if ProcessTabs(FileName, False, BackupCheckbox.Checked) then
  219.           if ProcessTabs(FileName, True, False) then
  220.             MessageDlg('Tabs converted in ' + FileName,
  221.               mtInformation, [mbOk], 0);
  222.     end;
  223.   end;
  224. end;
  225.  
  226. {- Clicked Insert button; update options dialog to match }
  227. procedure TMainForm.InsertSBClick(Sender: TObject);
  228. begin
  229.   OptionsDialog.OperationRGroup.ItemIndex := optInsert;
  230. end;
  231.  
  232. {- Clicked Remove button; update options dialog to match }
  233. procedure TMainForm.RemoveSBClick(Sender: TObject);
  234. begin
  235.   OptionsDialog.OperationRGroup.ItemIndex := optRemove;
  236. end;
  237.  
  238. {- Clicked Convert button; update options dialog to match }
  239. procedure TMainForm.ConvertSBClick(Sender: TObject);
  240. begin
  241.   OptionsDialog.OperationRGroup.ItemIndex := optConvert;
  242. end;
  243.  
  244. end.
  245.  
  246. (*
  247. // ==============================================================
  248. // Copyright (c) 1995 by Tom Swan. All rights reserved
  249. // Revision 1.00    Date: 2/24/1991
  250. // Revision 2.00    Date: 7/25/1995
  251. // - Converted to Delphi from Borland Pascal Turbo Vision
  252. *)
  253.  
  254.