home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / MENUEDIT.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  5KB  |  161 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 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.   private
  64.     { Private declarations }
  65.     SaveHistory : Boolean;
  66.   public
  67.     { Public declarations }
  68.     function DataString: string;
  69.     function EditItem(const prompt, captext, data: string): TModalResult;
  70.   end;
  71.  
  72.  
  73. var
  74.   MenuEditDlg: TMenuEditDlg;
  75.  
  76. implementation
  77.  
  78. {$R *.DFM}
  79.  
  80. uses Graphics, FileCtrl, ShellAPI, Strings, Settings, Start, MiscUtil,
  81.   WinProcs, Tree, RefEdit;
  82.  
  83.  
  84. procedure TMenuEditDlg.FormCreate(Sender: TObject);
  85. begin
  86.   Notebook.PageIndex := 0;
  87.   ini.ReadStrings('IconSources', IconDialog.HistoryList);
  88. end;
  89.  
  90.  
  91. procedure TMenuEditDlg.FormDestroy(Sender: TObject);
  92. begin
  93.   if SaveHistory then ini.WriteStrings('IconSources', IconDialog.HistoryList);
  94.   MenuEditDlg := nil;
  95. end;
  96.  
  97.  
  98. procedure TMenuEditDlg.CommandEditDblClick(Sender: TObject);
  99. begin
  100.   if OpenDialog.Execute then CommandEdit.Text := Lowercase(OpenDialog.Filename);
  101. end;
  102.  
  103.  
  104. function TMenuEditDlg.DataString: string;
  105. begin
  106.   Result := PackStartInfo(CommandEdit.Text, FolderEdit.Text,
  107.     ExtractIconFile(IconEdit.Text),
  108.     GetRadioIndex([rbNormal, rbMinimize, rbMaximize]),
  109.     ExtractIconIndex(IconEdit.Text));
  110. end;
  111.  
  112.  
  113. function TMenuEditDlg.EditItem(const prompt, captext, data: string): TModalResult;
  114. begin
  115.   Caption := prompt;
  116.   with ExtractStartInfo(data) do begin
  117.     CaptionEdit.Text := captext;
  118.     CommandEdit.Text := Command;
  119.     FolderEdit.Text := Directory;
  120.     if IconFile > '' then
  121.       IconEdit.Text := Format('%s(%d)', [IconFile, IconIndex])
  122.     else
  123.       IconEdit.Text := '';
  124.     SetRadioIndex([rbNormal, rbMinimize, rbMaximize], ShowMode);
  125.   end;
  126.   ActiveControl := CaptionEdit;
  127.   Result := ShowModal;
  128. end;
  129.  
  130.  
  131. procedure TMenuEditDlg.BrowseIconClick(Sender: TObject);
  132. begin
  133.   with IconDialog do begin
  134.     Filename := ExtractIconFile(IconEdit.Text);
  135.     IconIndex := ExtractIconIndex(IconEdit.Text);
  136.  
  137.     if Execute then begin
  138.       IconEdit.Text := Format('%s(%d)', [Filename, IconIndex]);
  139.       SaveHistory := True;
  140.     end;
  141.   end;
  142. end;
  143.  
  144.  
  145. procedure TMenuEditDlg.FolderEditDblClick(Sender: TObject);
  146. begin
  147.   FolderEdit.Text := SelectFolder(FolderEdit.Text);
  148. end;
  149.  
  150. procedure TMenuEditDlg.FormCloseQuery(Sender: TObject;
  151.   var CanClose: Boolean);
  152. begin
  153.   if (ModalResult = mrOK) and (CaptionEdit.Text = '') then begin
  154.     MsgDialog('The caption must contain some text', mtError, [mbOK], 0);
  155.     CanClose := False;
  156.   end;
  157. end;
  158.  
  159.  
  160. end.
  161.