ToolsUnit.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. unit ToolsUnit;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5. StdCtrls, ComCtrls;
  6. type
  7. TToolsForm = class(TForm)
  8. ToolsList: TListView;
  9. AddButton: TButton;
  10. EditButton: TButton;
  11. RemoveButton: TButton;
  12. OKButton: TButton;
  13. CancelButton: TButton;
  14. procedure AddButtonClick(Sender: TObject);
  15. procedure EditButtonClick(Sender: TObject);
  16. procedure RemoveButtonClick(Sender: TObject);
  17. procedure ToolsListSelectItem(Sender: TObject; Item: TListItem;
  18. Selected: Boolean);
  19. procedure ToolsListKeyDown(Sender: TObject; var Key: Word;
  20. Shift: TShiftState);
  21. procedure ToolsListDragDrop(Sender, Source: TObject; X, Y: Integer);
  22. procedure ToolsListDragOver(Sender, Source: TObject; X, Y: Integer;
  23. State: TDragState; var Accept: Boolean);
  24. private
  25. public
  26. function WindowStateToString(WindowState: TWindowState): string;
  27. function StringToWindowState(const S: string): TWindowState;
  28. end;
  29. const
  30. NormalString = 'Normal';
  31. MaximizedString = 'Maximized';
  32. MinimizedString = 'Minimized';
  33. implementation
  34. {$R *.DFM}
  35. uses
  36. ToolPropertiesUnit;
  37. procedure TToolsForm.AddButtonClick(Sender: TObject);
  38. begin
  39. with TToolPropertiesForm.Create (Self) do try
  40. WindowStateEdit.ItemIndex := 0;
  41. if ShowModal = mrOK then begin
  42. with ToolsList.Items.Add do begin
  43. Caption := TitleEdit.Text;
  44. SubItems.Add (CommandLineEdit.Text);
  45. SubItems.Add (WorkingDirEdit.Text);
  46. SubItems.Add (WindowStateEdit.Text);
  47. end;
  48. end;
  49. finally
  50. Free;
  51. end;
  52. end;
  53. procedure TToolsForm.EditButtonClick(Sender: TObject);
  54. begin
  55. if Assigned (ToolsList.Selected) then
  56. with TToolPropertiesForm.Create (Self) do try
  57. with ToolsList.Selected do begin
  58. TitleEdit.Text := Caption;
  59. CommandLineEdit.Text := SubItems [0];
  60. WorkingDirEdit.Text := SubItems [1];
  61. case StringToWindowState (SubItems [2]) of
  62. wsMaximized:
  63. WindowStateEdit.ItemIndex := 1;
  64. wsMinimized:
  65. WindowStateEdit.ItemIndex := 2;
  66. else
  67. WindowStateEdit.ItemIndex := 0;
  68. end;
  69. end;
  70. if ShowModal = mrOK then begin
  71. with ToolsList.Selected do begin
  72. Caption := TitleEdit.Text;
  73. SubItems [0] := CommandLineEdit.Text;
  74. SubItems [1] := WorkingDirEdit.Text;
  75. case WindowStateEdit.ItemIndex of
  76. 1:
  77. SubItems [2] := MaximizedString;
  78. 2:
  79. SubItems [2] := MinimizedString;
  80. else
  81. SubItems [2] := NormalString;
  82. end;
  83. end;
  84. end;
  85. finally
  86. Free;
  87. end;
  88. end;
  89. procedure TToolsForm.RemoveButtonClick(Sender: TObject);
  90. begin
  91. if Assigned (ToolsList.Selected) then
  92. ToolsList.Selected.Free;
  93. end;
  94. procedure TToolsForm.ToolsListSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
  95. begin
  96. EditButton.Enabled := Assigned (ToolsList.Selected);
  97. RemoveButton.Enabled := Assigned (ToolsList.Selected);
  98. end;
  99. procedure TToolsForm.ToolsListKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  100. begin
  101. if Key = vk_Delete then
  102. RemoveButtonClick (Sender);
  103. end;
  104. procedure TToolsForm.ToolsListDragDrop(Sender, Source: TObject; X, Y: Integer);
  105. var
  106. S,
  107. D: TListItem;
  108. DIndex: Integer;
  109. begin
  110. with ToolsList do begin
  111. S := Selected;
  112. if Assigned (S) then begin
  113. D := GetItemAt (X, Y);
  114. if Assigned (D) and (S <> D) then begin
  115. DIndex := D.Index;
  116. if DIndex > S.Index then
  117. Inc (DIndex);
  118. with Items.Insert (DIndex) do begin
  119. Caption := S.Caption;
  120. SubItems.Assign (S.SubItems);
  121. end;
  122. S.Free;
  123. end;
  124. end;
  125. end;
  126. end;
  127. procedure TToolsForm.ToolsListDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  128. var
  129. S,
  130. D: TListItem;
  131. begin
  132. Accept := False;
  133. with ToolsList do begin
  134. S := Selected;
  135. if Assigned (S) then begin
  136. D := GetItemAt (X, Y);
  137. if Assigned (D) and (S <> D) then
  138. Accept := True;
  139. end;
  140. end;
  141. end;
  142. function TToolsForm.WindowStateToString(WindowState: TWindowState): string;
  143. begin
  144. case WindowState of
  145. wsMaximized:
  146. Result := MaximizedString;
  147. wsMinimized:
  148. Result := MinimizedString;
  149. else
  150. Result := NormalString;
  151. end;
  152. end;
  153. function TToolsForm.StringToWindowState(const S: string): TWindowState;
  154. begin
  155. if S = MaximizedString then
  156. Result := wsMaximized
  157. else if S = MinimizedString then
  158. Result := wsMinimized
  159. else
  160. Result := wsNormal;
  161. end;
  162. end.