home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / OPENFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  4KB  |  117 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 1.0                                                    }
  5. {    Copyright (C) 1997  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.   private
  43.     { Private declarations }
  44.     Changed : Boolean;
  45.   public
  46.     { Public declarations }
  47.     class function Execute : string;
  48.   end;
  49.  
  50.  
  51. implementation
  52.  
  53. {$R *.DFM}
  54.  
  55. uses Settings, Start, MiscUtil, Menus, SysUtils;
  56.  
  57. var
  58.   OpenFileDlg: TOpenFileDlg;
  59.  
  60. procedure TOpenFileDlg.OKBtnClick(Sender: TObject);
  61. begin
  62.   Changed := AddHistory(Combo) or Changed;
  63. end;
  64.  
  65. procedure TOpenFileDlg.FormCreate(Sender: TObject);
  66. var
  67.   i: Integer;
  68.   item : TMenuItem;
  69. begin
  70.   Listbox.ItemHeight := LineHeight;
  71.  
  72.   ini.ReadStrings('OpenFileWith', Combo.Items);
  73.   if Combo.Items.Count > 0 then Combo.Text := Combo.Items[0];
  74.  
  75.   item := StartMenu.Find('Open', True);
  76.   if item <> nil then with item do
  77.     for i := 0 to Count-1 do
  78.       Listbox.Items.AddObject(Items[i].Caption, Items[i]);
  79. end;
  80.  
  81. class function TOpenFileDlg.Execute : string;
  82. begin
  83.   OpenFileDlg := TOpenFileDlg.Create(Application);
  84.   try
  85.     if OpenFileDlg.ShowModal = mrOK then
  86.       Result := OpenFileDlg.Combo.Text
  87.     else Result := '';
  88.   finally
  89.     OpenFileDlg.Free;
  90.     OpenFileDlg := nil;
  91.   end;
  92. end;
  93.  
  94. procedure TOpenFileDlg.FormDestroy(Sender: TObject);
  95. begin
  96.   if Changed then begin
  97.     ini.EraseSection('OpenFileWith');
  98.     ini.WriteStrings('OpenFileWith', Combo.Items);
  99.   end;
  100. end;
  101.  
  102. procedure TOpenFileDlg.ComboDblClick(Sender: TObject);
  103. begin
  104.   if OpenDialog.Execute then
  105.     Combo.Text := Lowercase(OpenDialog.Filename);
  106. end;
  107.  
  108. procedure TOpenFileDlg.ListboxClick(Sender: TObject);
  109. begin
  110.   with Listbox do
  111.     if ItemIndex <> -1 then 
  112.       Combo.Text := Lowercase(ExtractStartInfo(
  113.         TStartMenuItem(Items.Objects[ItemIndex]).Data).Command);
  114. end;
  115.  
  116. end.
  117.