home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / SRC / OPENFILE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  3.6 KB  |  113 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 2.1                                                    }
  5. {    Copyright (C) 1997-1998 Li-Hsin Huang                                 }
  6. {                                                                          }
  7. {    This program is free software; you can redistribute it and/or modify  }
  8. {    it under the terms of the GNU General Public License as published by  }
  9. {    the Free Software Foundation; either version 2 of the License, or     }
  10. {    (at your option) any later version.                                   }
  11. {                                                                          }
  12. {    This program is distributed in the hope that it will be useful,       }
  13. {    but WITHOUT ANY WARRANTY; without even the implied warranty of        }
  14. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         }
  15. {    GNU General Public License for more details.                          }
  16. {                                                                          }
  17. {    You should have received a copy of the GNU General Public License     }
  18. {    along with this program; if not, write to the Free Software           }
  19. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             }
  20. {                                                                          }
  21. {**************************************************************************}
  22.  
  23. unit Openfile;
  24.  
  25. interface
  26.  
  27. uses Classes, Forms, Controls, Buttons, StdCtrls, Dialogs;
  28.  
  29. type
  30.   TOpenFileDlg = class(TForm)
  31.     OKBtn: TBitBtn;
  32.     CancelBtn: TBitBtn;
  33.     Combo: TComboBox;
  34.     Label1: TLabel;
  35.     Listbox: TListBox;
  36.     OpenDialog: TOpenDialog;
  37.     procedure OKBtnClick(Sender: TObject);
  38.     procedure FormCreate(Sender: TObject);
  39.     procedure FormDestroy(Sender: TObject);
  40.     procedure ComboDblClick(Sender: TObject);
  41.     procedure ListboxClick(Sender: TObject);
  42.     procedure ListboxDblClick(Sender: TObject);
  43.   private
  44.     { Private declarations }
  45.     Changed : Boolean;
  46.   public
  47.     { Public declarations }
  48.     class function Execute : string;
  49.   end;
  50.  
  51.  
  52. implementation
  53.  
  54. {$R *.DFM}
  55.  
  56. uses Settings, Start, MiscUtil, Menus, SysUtils;
  57.  
  58. var
  59.   OpenFileDlg: TOpenFileDlg;
  60.  
  61. procedure TOpenFileDlg.OKBtnClick(Sender: TObject);
  62. begin
  63.   Changed := AddHistory(Combo) or Changed;
  64. end;
  65.  
  66. procedure TOpenFileDlg.FormCreate(Sender: TObject);
  67. var
  68.   i: Integer;
  69.   item : TMenuItem;
  70. begin
  71.   ini.ReadStrings('OpenFileWith', Combo.Items);
  72.   if Combo.Items.Count > 0 then Combo.Text := Combo.Items[0];
  73.   ini.ReadSection('File Viewers', Listbox.Items);
  74. end;
  75.  
  76. class function TOpenFileDlg.Execute : string;
  77. begin
  78.   OpenFileDlg := TOpenFileDlg.Create(Application);
  79.   try
  80.     if OpenFileDlg.ShowModal = mrOK then
  81.       Result := OpenFileDlg.Combo.Text
  82.     else Result := '';
  83.   finally
  84.     OpenFileDlg.Free;
  85.     OpenFileDlg := nil;
  86.   end;
  87. end;
  88.  
  89. procedure TOpenFileDlg.FormDestroy(Sender: TObject);
  90. begin
  91.   if Changed then
  92.     ini.RewriteSectionStrings('OpenFileWith', Combo.Items);
  93. end;
  94.  
  95. procedure TOpenFileDlg.ComboDblClick(Sender: TObject);
  96. begin
  97.   if OpenDialog.Execute then
  98.     Combo.Text := Lowercase(OpenDialog.Filename);
  99. end;
  100.  
  101. procedure TOpenFileDlg.ListboxClick(Sender: TObject);
  102. begin
  103.   with Listbox do
  104.   Combo.Text := ini.ReadString('File Viewers', Items[ItemIndex], '');
  105. end;
  106.  
  107. procedure TOpenFileDlg.ListboxDblClick(Sender: TObject);
  108. begin
  109.   OKBtn.Click;
  110. end;
  111.  
  112. end.
  113.