forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompSignTools.pas
179 lines (152 loc) · 4.76 KB
/
CompSignTools.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
unit CompSignTools;
{
Inno Setup
Copyright (C) 1997-2020 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Compiler IDE SignTools form
}
interface
uses
Classes, Controls, StdCtrls, UIStateForm;
type
TSignToolsForm = class(TUIStateForm)
OKButton: TButton;
CancelButton: TButton;
GroupBox1: TGroupBox;
SignToolsListBox: TListBox;
AddButton: TButton;
RemoveButton: TButton;
EditButton: TButton;
procedure SignToolsListBoxClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure RemoveButtonClick(Sender: TObject);
procedure EditButtonClick(Sender: TObject);
private
FSignTools: TStringList;
procedure UpdateSignTools;
procedure UpdateSignToolsButtons;
procedure SetSignTools(SignTools: TStringList);
function InputSignTool(var SignToolName, SignToolCommand: String;
ExistingIndex: Integer): Boolean;
protected
procedure CreateWnd; override;
procedure CreateParams(var Params: TCreateParams); override;
public
property SignTools: TStringList read FSignTools write SetSignTools;
end;
implementation
uses
Windows, Messages, CompFunc, CmnFunc, Dialogs, SysUtils;
{$R *.DFM}
procedure TSignToolsForm.UpdateSignTools;
begin
SignToolsListBox.Items.Assign(FSignTools);
UpdateHorizontalExtent(SignToolsListBox);
end;
procedure TSignToolsForm.UpdateSignToolsButtons;
var
Enabled: Boolean;
begin
Enabled := SignToolsListBox.ItemIndex >= 0;
EditButton.Enabled := Enabled;
RemoveButton.Enabled := Enabled;
end;
procedure TSignToolsForm.SetSignTools(SignTools: TStringList);
begin
FSignTools.Assign(SignTools);
UpdateSignTools;
UpdateSignToolsButtons;
end;
procedure TSignToolsForm.FormCreate(Sender: TObject);
begin
FSignTools := TStringList.Create();
InitFormFont(Self);
end;
{ This and CreateParams make bsSizeable (which has an unwanted icon) look like bsDialog, see:
https://stackoverflow.com/questions/32096482/delphi-resizable-bsdialog-form/32098633 }
procedure TSignToolsForm.CreateWnd;
begin
inherited;
SendMessage(Handle, WM_SETICON, ICON_BIG, 0);
end;
procedure TSignToolsForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
end;
procedure TSignToolsForm.FormDestroy(Sender: TObject);
begin
FSignTools.Free();
end;
function TSignToolsForm.InputSignTool(var SignToolName, SignToolCommand: String;
ExistingIndex: Integer): Boolean;
var
I: Integer;
begin
Result := False;
if InputQuery(Caption, 'Name of the Sign Tool:', SignToolName) then begin
if (SignToolName = '') or (Pos('=', SignToolName) <> 0) then begin
AppMessageBox(PChar('Invalid name.'), PChar(Caption), MB_OK or MB_ICONSTOP);
Exit;
end;
for I := 0 to FSignTools.Count-1 do begin
if (I <> ExistingIndex) and (Pos(SignToolName + '=', FSignTools[I]) = 1) then begin
AppMessageBox(PChar('Duplicate name.'), PChar(Caption), MB_OK or MB_ICONSTOP);
Exit;
end;
end;
if InputQuery(Caption, 'Command of the Sign Tool:', SignToolCommand) then begin
if SignToolCommand = '' then begin
AppMessageBox(PChar('Invalid command.'), PChar(Caption), MB_OK or MB_ICONSTOP);
Exit;
end;
end;
Result := True;
end;
end;
procedure TSignToolsForm.AddButtonClick(Sender: TObject);
var
SignToolName, SignToolCommand: String;
begin
SignToolName := '';
SignToolCommand := '';
if InputSignTool(SignToolName, SignToolCommand, -1) then begin
FSignTools.Add(SignToolName + '=' + SignToolCommand);
UpdateSignTools;
UpdateSignToolsButtons;
end;
end;
procedure TSignToolsForm.EditButtonClick(Sender: TObject);
var
SignToolName, SignToolCommand: String;
I, P: Integer;
begin
I := SignToolsListBox.ItemIndex;
P := Pos('=', FSignTools[I]);
if P = 0 then
raise Exception.Create('Internal error: ''='' not found in SignTool');
SignToolName := Copy(FSignTools[I], 1, P-1);
SignToolCommand := Copy(FSignTools[I], P+1, MaxInt);
if InputSignTool(SignToolName, SignToolCommand, I) then begin
FSignTools[I] := SignToolName + '=' + SignToolCommand;
UpdateSignTools;
UpdateSignToolsButtons;
end;
end;
procedure TSignToolsForm.RemoveButtonClick(Sender: TObject);
var
I: Integer;
begin
I := SignToolsListBox.ItemIndex;
FSignTools.Delete(I);
UpdateSignTools;
UpdateSignToolsButtons;
end;
procedure TSignToolsForm.SignToolsListBoxClick(Sender: TObject);
begin
UpdateSignToolsButtons;
end;
end.