home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / SRC / REFEDIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  5.6 KB  |  173 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 Refedit;
  24.  
  25. interface
  26.  
  27. uses Classes, Forms, Controls, Buttons, StdCtrls, ExtCtrls, Dialogs,
  28.   StylSped, Icondlg, SysUtils, TabNotBk, Referenc;
  29.  
  30. type
  31.   TRefEditDlg = class(TForm)
  32.     OKBtn: TBitBtn;
  33.     CancelBtn: TBitBtn;
  34.     IconDialog: TIconDialog;
  35.     Notebook: TTabbedNotebook;
  36.     Label1: TLabel;
  37.     Label2: TLabel;
  38.     TargetLabel: TLabel;
  39.     BrowseIcon: TStyleSpeed;
  40.     CapEdit: TEdit;
  41.     FilePanel: TGroupBox;
  42.     ParamLabel: TLabel;
  43.     Label3: TLabel;
  44.     FolderEdit: TEdit;
  45.     DocFolder: TCheckBox;
  46.     ParamEdit: TEdit;
  47.     TargetEdit: TEdit;
  48.     IconEdit: TEdit;
  49.     ShowGroup: TRadioGroup;
  50.     HelpBtn: TBitBtn;
  51.     OpenDialog: TOpenDialog;
  52.     procedure FormCreate(Sender: TObject);
  53.     procedure FormDestroy(Sender: TObject);
  54.     procedure BrowseIconClick(Sender: TObject);
  55.     procedure FolderEditDblClick(Sender: TObject);
  56.     procedure IconEditDblClick(Sender: TObject);
  57.     procedure TargetEditDblClick(Sender: TObject);
  58.     procedure TargetLabelMouseDown(Sender: TObject; Button: TMouseButton;
  59.       Shift: TShiftState; X, Y: Integer);
  60.     procedure FormShow(Sender: TObject);
  61.   private
  62.     { Private declarations }
  63.     SaveHistory : Boolean;
  64.     FRefKind : TReferenceKind;
  65.     procedure SetRefKind(Value: TReferenceKind);
  66.   public
  67.     { Public declarations }
  68.     property RefKind : TReferenceKind read FRefKind write SetRefKind;
  69.   end;
  70.  
  71. var
  72.   RefEditDlg: TRefEditDlg;
  73.  
  74. function ExtractIconFile(const s: string): TFilename;
  75. function ExtractIconIndex(const s: string): Integer;
  76.  
  77. implementation
  78.  
  79. {$R *.DFM}
  80.  
  81. uses Graphics, FileCtrl, ShellAPI, Strings, Settings, WinProcs,
  82.   Tree, MiscUtil, Locale;
  83.  
  84. function ExtractIconFile(const s: string): TFilename;
  85. begin
  86.   Result := '';
  87.   Unformat(s, '%s(', [@Result, 79]);
  88. end;
  89.  
  90. function ExtractIconIndex(const s: string): Integer;
  91. begin
  92.   Result := 0;
  93.   Unformat(s, '%S(%d', [@Result]);
  94. end;
  95.  
  96.  
  97. procedure TRefEditDlg.FormCreate(Sender: TObject);
  98. begin
  99.   Notebook.PageIndex := 0;
  100.   ini.ReadStrings('IconSources', IconDialog.HistoryList);
  101.   if not ShowBrowseBtns then begin
  102.     IconEdit.Width := TargetEdit.Width;
  103.     IconEdit.ShowHint := True;
  104.   end;
  105. end;
  106.  
  107. procedure TRefEditDlg.FormDestroy(Sender: TObject);
  108. begin
  109.   if SaveHistory then
  110.     ini.RewriteSectionStrings('IconSources', IconDialog.HistoryList);
  111. end;
  112.  
  113. procedure TRefEditDlg.BrowseIconClick(Sender: TObject);
  114. begin
  115.   with IconDialog do begin
  116.     if IconEdit.Text > '' then Filename := ExtractIconFile(IconEdit.Text)
  117.     else Filename := TargetEdit.Text;
  118.     IconIndex := ExtractIconIndex(IconEdit.Text);
  119.  
  120.     if Execute then begin
  121.       IconEdit.Text := Format('%s(%d)', [Filename, IconIndex]);
  122.       SaveHistory := True;
  123.     end;
  124.   end;
  125. end;
  126.  
  127. procedure TRefEditDlg.FolderEditDblClick(Sender: TObject);
  128. begin
  129.   FolderEdit.Text := SelectFolder(FolderEdit.Text);
  130. end;
  131.  
  132. procedure TRefEditDlg.IconEditDblClick(Sender: TObject);
  133. begin
  134.   if not ShowBrowseBtns then BrowseIcon.Click;
  135. end;
  136.  
  137. procedure TRefEditDlg.TargetEditDblClick(Sender: TObject);
  138. begin
  139.   case RefKind of
  140.     rkDrive,
  141.     rkFolder : TargetEdit.Text := SelectFolder(TargetEdit.Text);
  142.     rkFile   : with OpenDialog do if Execute then TargetEdit.Text := Filename;
  143.   end;
  144. end;
  145.  
  146. procedure TRefEditDlg.SetRefKind(Value: TReferenceKind);
  147. const
  148.   Captions : array[TReferenceKind] of Word =
  149.     (SDriveRefPrompt, SFolderRefPrompt, SFileRefPrompt, SInternetRefPrompt);
  150.   TextColours : array[Boolean] of TColor = (clGray, clBlack);
  151. begin
  152.   FRefKind := Value;
  153.   TargetEdit.ShowHint := RefKind <> rkInternet;
  154.   TargetLabel.Caption := LoadStr(Captions[FRefKind]);
  155.  
  156.   FilePanel.Enabled := FRefKind = rkFile;
  157.   FilePanel.Font.Color := TextColours[FRefKind = rkFile];
  158. end;
  159.  
  160. procedure TRefEditDlg.TargetLabelMouseDown(Sender: TObject;
  161.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  162. begin
  163.   RefKind := TReferenceKind((Ord(RefKind) + 1) mod
  164.     (Ord(High(TReferenceKind)) + 1));
  165. end;
  166.  
  167. procedure TRefEditDlg.FormShow(Sender: TObject);
  168. begin
  169.   ActiveControl := CapEdit;
  170. end;
  171.  
  172. end.
  173.