home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / SRC / MENUEDIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  6.8 KB  |  220 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 MenuEdit;
  24.  
  25. { Start menu item editor
  26.  
  27.   This dialog accepts input through the EditItem procedure.  After
  28.   the modal state is finished, the edited data can be retrieved
  29.   through the DataString function
  30. }
  31.  
  32. interface
  33.  
  34. uses Classes, Forms, Controls, Buttons, StdCtrls, ExtCtrls, Dialogs,
  35.   StylSped, Icondlg, SysUtils, TabNotBk;
  36.  
  37. type
  38.   TMenuEditDlg = class(TForm)
  39.     OKBtn: TBitBtn;
  40.     CancelBtn: TBitBtn;
  41.     IconDialog: TIconDialog;
  42.     OpenDialog: TOpenDialog;
  43.     Notebook: TTabbedNotebook;
  44.     Label1: TLabel;
  45.     Label2: TLabel;
  46.     TargetLabel: TLabel;
  47.     Label3: TLabel;
  48.     BrowseIcon: TStyleSpeed;
  49.     FolderEdit: TEdit;
  50.     CaptionEdit: TEdit;
  51.     IconEdit: TEdit;
  52.     rbNormal: TRadioButton;
  53.     rbMinimize: TRadioButton;
  54.     rbMaximize: TRadioButton;
  55.     HelpBtn: TBitBtn;
  56.     CommandEdit: TComboBox;
  57.     procedure FormCreate(Sender: TObject);
  58.     procedure FormDestroy(Sender: TObject);
  59.     procedure CommandEditDblClick(Sender: TObject);
  60.     procedure BrowseIconClick(Sender: TObject);
  61.     procedure FolderEditDblClick(Sender: TObject);
  62.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  63.     procedure IconEditDblClick(Sender: TObject);
  64.     procedure FormShow(Sender: TObject);
  65.     procedure CommandEditChange(Sender: TObject);
  66.     procedure OKBtnClick(Sender: TObject);
  67.     procedure rbNormalDblClick(Sender: TObject);
  68.   private
  69.     { Private declarations }
  70.     SaveHistory : Boolean;
  71.   public
  72.     { Public declarations }
  73.     IconChanged : Boolean;
  74.     function DataString: string;
  75.     function EditItem(const prompt, captext, data: string): TModalResult;
  76.   end;
  77.  
  78.  
  79. var
  80.   MenuEditDlg: TMenuEditDlg;
  81.  
  82. implementation
  83.  
  84. {$R *.DFM}
  85.  
  86. uses Graphics, FileCtrl, ShellAPI, Strings, Settings, Start, MiscUtil,
  87.   WinProcs, Tree, RefEdit, Locale;
  88.  
  89.  
  90. procedure TMenuEditDlg.FormCreate(Sender: TObject);
  91. begin
  92.   Notebook.PageIndex := 0;
  93.   ini.ReadStrings('IconSources', IconDialog.HistoryList);
  94.   if not ShowBrowseBtns then begin
  95.     IconEdit.Width := FolderEdit.Width;
  96.     IconEdit.ShowHint := True;
  97.   end;
  98. end;
  99.  
  100.  
  101. procedure TMenuEditDlg.FormDestroy(Sender: TObject);
  102. begin
  103.   if SaveHistory then
  104.     ini.RewriteSectionStrings('IconSources', IconDialog.HistoryList);
  105.   MenuEditDlg := nil;
  106. end;
  107.  
  108.  
  109. procedure TMenuEditDlg.CommandEditDblClick(Sender: TObject);
  110. var lctext : string;
  111. begin
  112.   with CommandEdit do begin
  113.     lctext := Lowercase(Text);
  114.  
  115.     if Pos('$folder', lctext) = 1 then
  116.       Text := '$Folder ' + SelectFolder(Copy(Text, 9, 255))
  117.     else if Pos('$largeiconfolder', lctext) = 1 then
  118.       Text := '$LargeIconFolder ' + SelectFolder(Copy(Text, 18, 255))
  119.     else if Pos('$smalliconfolder', lctext) = 1 then
  120.       Text := '$SmallIconFolder ' + SelectFolder(Copy(Text, 18, 255))
  121.     else if Pos('$listfolder', lctext) = 1 then
  122.       Text := '$ListFolder ' + SelectFolder(Copy(Text, 13, 255))
  123.     else
  124.       if OpenDialog.Execute then Text := Lowercase(OpenDialog.Filename);
  125.   end;
  126. end;
  127.  
  128.  
  129. function TMenuEditDlg.DataString: string;
  130. begin
  131.   Result := PackStartInfo(CommandEdit.Text, FolderEdit.Text,
  132.     ExtractIconFile(IconEdit.Text),
  133.     GetRadioIndex([rbNormal, rbMinimize, rbMaximize]),
  134.     ExtractIconIndex(IconEdit.Text));
  135. end;
  136.  
  137.  
  138. function TMenuEditDlg.EditItem(const prompt, captext, data: string): TModalResult;
  139. begin
  140.   Caption := prompt;
  141.   with ExtractStartInfo(data) do begin
  142.     CaptionEdit.Text := captext;
  143.     CommandEdit.Text := Command;
  144.     FolderEdit.Text := Directory;
  145.     if IconFile > '' then
  146.       IconEdit.Text := Format('%s(%d)', [IconFile, IconIndex])
  147.     else
  148.       IconEdit.Text := '';
  149.     SetRadioIndex([rbNormal, rbMinimize, rbMaximize], ShowMode);
  150.   end;
  151.   ActiveControl := CaptionEdit;
  152.   Result := ShowModal;
  153. end;
  154.  
  155.  
  156. procedure TMenuEditDlg.BrowseIconClick(Sender: TObject);
  157. begin
  158.   with IconDialog do begin
  159.     { Calmira 1.1 bug fix to search default file }
  160.     if IconEdit.Text > '' then Filename := ExtractIconFile(IconEdit.Text)
  161.     else Filename := FirstWord(CommandEdit.Text);
  162.     IconIndex := ExtractIconIndex(IconEdit.Text);
  163.  
  164.     if Execute then begin
  165.       IconEdit.Text := Format('%s(%d)', [Filename, IconIndex]);
  166.       SaveHistory := True;
  167.     end;
  168.   end;
  169. end;
  170.  
  171.  
  172. procedure TMenuEditDlg.FolderEditDblClick(Sender: TObject);
  173. begin
  174.   FolderEdit.Text := SelectFolder(FolderEdit.Text);
  175. end;
  176.  
  177. procedure TMenuEditDlg.FormCloseQuery(Sender: TObject;
  178.   var CanClose: Boolean);
  179. begin
  180.   if (ModalResult = mrOK) and Blank(CaptionEdit.Text) then begin
  181.     ErrorMsgRes(SCaptionNeedsText);
  182.     CanClose := False;
  183.   end;
  184. end;
  185.  
  186.  
  187. procedure TMenuEditDlg.IconEditDblClick(Sender: TObject);
  188. begin
  189.   if not ShowBrowseBtns then BrowseIcon.Click;
  190. end;
  191.  
  192. function IsSpecialItem(const s: string): Boolean;
  193. begin
  194.   Result := (s > '') and ((s[1] = '*') or (s[1] = '-'));
  195. end;
  196.  
  197.  
  198. procedure TMenuEditDlg.FormShow(Sender: TObject);
  199. begin
  200.   ActiveControl := CaptionEdit;
  201.   IconChanged := IsSpecialItem(CaptionEdit.Text);
  202. end;
  203.  
  204. procedure TMenuEditDlg.CommandEditChange(Sender: TObject);
  205. begin
  206.   IconChanged := True;
  207. end;
  208.  
  209. procedure TMenuEditDlg.OKBtnClick(Sender: TObject);
  210. begin
  211.   IconChanged := IconChanged or IsSpecialItem(CaptionEdit.Text);
  212. end;
  213.  
  214. procedure TMenuEditDlg.rbNormalDblClick(Sender: TObject);
  215. begin
  216.   OKBtn.Click;
  217. end;
  218.  
  219. end.
  220.