ToolsUnit.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. }
  16. unit ToolsUnit;
  17. interface
  18. uses
  19. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20. StdCtrls, ComCtrls;
  21. type
  22. TToolsForm = class(TForm)
  23. ToolsList: TListView;
  24. AddButton: TButton;
  25. EditButton: TButton;
  26. RemoveButton: TButton;
  27. OKButton: TButton;
  28. CancelButton: TButton;
  29. procedure AddButtonClick(Sender: TObject);
  30. procedure EditButtonClick(Sender: TObject);
  31. procedure RemoveButtonClick(Sender: TObject);
  32. procedure ToolsListSelectItem(Sender: TObject; Item: TListItem;
  33. Selected: Boolean);
  34. procedure ToolsListKeyDown(Sender: TObject; var Key: Word;
  35. Shift: TShiftState);
  36. procedure ToolsListDragDrop(Sender, Source: TObject; X, Y: Integer);
  37. procedure ToolsListDragOver(Sender, Source: TObject; X, Y: Integer;
  38. State: TDragState; var Accept: Boolean);
  39. private
  40. public
  41. function WindowStateToString(WindowState: TWindowState): string;
  42. function StringToWindowState(const S: string): TWindowState;
  43. end;
  44. const
  45. NormalString = 'Normal';
  46. MaximizedString = 'Maximized';
  47. MinimizedString = 'Minimized';
  48. implementation
  49. {$R *.DFM}
  50. uses
  51. ToolPropertiesUnit;
  52. procedure TToolsForm.AddButtonClick(Sender: TObject);
  53. begin
  54. with TToolPropertiesForm.Create (Self) do try
  55. WindowStateEdit.ItemIndex := 0;
  56. if ShowModal = mrOK then begin
  57. with ToolsList.Items.Add do begin
  58. Caption := TitleEdit.Text;
  59. SubItems.Add (CommandLineEdit.Text);
  60. SubItems.Add (WorkingDirEdit.Text);
  61. SubItems.Add (WindowStateEdit.Text);
  62. end;
  63. end;
  64. finally
  65. Free;
  66. end;
  67. end;
  68. procedure TToolsForm.EditButtonClick(Sender: TObject);
  69. begin
  70. if Assigned (ToolsList.Selected) then
  71. with TToolPropertiesForm.Create (Self) do try
  72. with ToolsList.Selected do begin
  73. TitleEdit.Text := Caption;
  74. CommandLineEdit.Text := SubItems [0];
  75. WorkingDirEdit.Text := SubItems [1];
  76. case StringToWindowState (SubItems [2]) of
  77. wsMaximized:
  78. WindowStateEdit.ItemIndex := 1;
  79. wsMinimized:
  80. WindowStateEdit.ItemIndex := 2;
  81. else
  82. WindowStateEdit.ItemIndex := 0;
  83. end;
  84. end;
  85. if ShowModal = mrOK then begin
  86. with ToolsList.Selected do begin
  87. Caption := TitleEdit.Text;
  88. SubItems [0] := CommandLineEdit.Text;
  89. SubItems [1] := WorkingDirEdit.Text;
  90. case WindowStateEdit.ItemIndex of
  91. 1:
  92. SubItems [2] := MaximizedString;
  93. 2:
  94. SubItems [2] := MinimizedString;
  95. else
  96. SubItems [2] := NormalString;
  97. end;
  98. end;
  99. end;
  100. finally
  101. Free;
  102. end;
  103. end;
  104. procedure TToolsForm.RemoveButtonClick(Sender: TObject);
  105. begin
  106. if Assigned (ToolsList.Selected) then
  107. ToolsList.Selected.Free;
  108. end;
  109. procedure TToolsForm.ToolsListSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
  110. begin
  111. EditButton.Enabled := Assigned (ToolsList.Selected);
  112. RemoveButton.Enabled := Assigned (ToolsList.Selected);
  113. end;
  114. procedure TToolsForm.ToolsListKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  115. begin
  116. if Key = vk_Delete then
  117. RemoveButtonClick (Sender);
  118. end;
  119. procedure TToolsForm.ToolsListDragDrop(Sender, Source: TObject; X, Y: Integer);
  120. var
  121. S,
  122. D: TListItem;
  123. DIndex: Integer;
  124. begin
  125. with ToolsList do begin
  126. S := Selected;
  127. if Assigned (S) then begin
  128. D := GetItemAt (X, Y);
  129. if Assigned (D) and (S <> D) then begin
  130. DIndex := D.Index;
  131. if DIndex > S.Index then
  132. Inc (DIndex);
  133. with Items.Insert (DIndex) do begin
  134. Caption := S.Caption;
  135. SubItems.Assign (S.SubItems);
  136. end;
  137. S.Free;
  138. end;
  139. end;
  140. end;
  141. end;
  142. procedure TToolsForm.ToolsListDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  143. var
  144. S,
  145. D: TListItem;
  146. begin
  147. Accept := False;
  148. with ToolsList do begin
  149. S := Selected;
  150. if Assigned (S) then begin
  151. D := GetItemAt (X, Y);
  152. if Assigned (D) and (S <> D) then
  153. Accept := True;
  154. end;
  155. end;
  156. end;
  157. function TToolsForm.WindowStateToString(WindowState: TWindowState): string;
  158. begin
  159. case WindowState of
  160. wsMaximized:
  161. Result := MaximizedString;
  162. wsMinimized:
  163. Result := MinimizedString;
  164. else
  165. Result := NormalString;
  166. end;
  167. end;
  168. function TToolsForm.StringToWindowState(const S: string): TWindowState;
  169. begin
  170. if S = MaximizedString then
  171. Result := wsMaximized
  172. else if S = MinimizedString then
  173. Result := wsMinimized
  174. else
  175. Result := wsNormal;
  176. end;
  177. end.