-
Notifications
You must be signed in to change notification settings - Fork 1
/
UDSAStorage.pas
285 lines (238 loc) · 12.1 KB
/
UDSAStorage.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
unit UDSAStorage;
{$I Information.inc}
// basic review and reformatting: done
interface
uses
// Delphi
System.Classes, System.UITypes, Vcl.Dialogs, Vcl.Graphics;
//--------------------------------------------------------------------------------------------------
// Custom "Don't Show Again" (DSA) dialog registration
//--------------------------------------------------------------------------------------------------
function RegisterDSAMessage(const Name: string; const Description: string): Integer; overload;
function RegisterDSAQuestion(const Name: string; const Description: string): Integer; overload;
function RegisterDSAWarning(const Name: string; const Description: string): Integer; overload;
function RegisterDSAMessage(const DlgID: Integer; const Name: string; const Description: string): Integer; overload;
function RegisterDSAQuestion(const DlgID: Integer; const Name: string; const Description: string): Integer; overload;
function RegisterDSAWarning(const DlgID: Integer; const Name: string; const Description: string): Integer; overload;
// Additional values for DefaultButton, CancelButton and HelpButton parameters
const
mbNone = TMsgDlgBtn(-1);
mbDefault = TMsgDlgBtn(-2);
//--------------------------------------------------------------------------------------------------
// "Don't Show Again" (DSA) dialogs
//--------------------------------------------------------------------------------------------------
procedure DSAShowMessage(const DlgID: Integer; const Msg: string; const Timeout: Integer = 0);
procedure DSAShowMessageFmt(const DlgID: Integer; const Msg: string; const Params: array of const; const Timeout: Integer = 0);
function DSAMessageDlg(const DlgID: Integer; const Msg: string; const DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult; overload;
function DSAMessageDlg(const DlgID: Integer; const Caption, Msg: string; const DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult; overload;
function DSAMessageDlg(const DlgID: Integer; const Caption, Msg: string; const Picture: TGraphic;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult; overload;
function DSAMessageDlgEx(const DlgID: Integer; const Msg: string; const DlgType: TMsgDlgType;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0;
const DefaultButton: Integer = 0; const CancelButton: Integer = 1; const HelpButton: Integer = -1): Integer; overload;
function DSAMessageDlgEx(const DlgID: Integer; const Caption, Msg: string; const DlgType: TMsgDlgType;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: Integer = 0;
const CancelButton: Integer = 1; const HelpButton: Integer = -1): TModalResult; overload;
function DSAMessageDlgEx(const DlgID: Integer; const Caption, Msg: string; const Picture: TGraphic;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: Integer = 0;
const CancelButton: Integer = 1; const HelpButton: Integer = -1): Integer; overload;
//----------------------------------------------------------------------------
// DSA state setting/retrieving
//----------------------------------------------------------------------------
function GetDSAState(const DlgID: Integer): Boolean; overload;
function GetDSAState(const DlgID: Integer; OUT LastResult: Integer): Boolean; overload;
procedure SetDSAState(const DlgID: Integer; const DontShowAgain: Boolean;
const LastResult: Integer = mrNone);
//----------------------------------------------------------------------------
// DSA state loading/saving
//----------------------------------------------------------------------------
procedure LoadDSAStates(const DSAData: TStrings);
procedure SaveDSAStates(const DSAData: TStrings);
implementation
uses JvDSADialogs,
SysUtils,
StrUtils;
var
DSAStorage : TDSAStorage;
DlgID : Integer;
function RegisterDSADialog(
const DlgID: Integer;
const Name: string;
const Description: string;
const CheckTextKind: TDSACheckTextKind): Integer; overload;
begin
JvDSADialogs.RegisterDSA(DlgID, Name, Description, DSAStorage, CheckTextKind);
if DlgID > UDSAStorage.DlgID then
UDSAStorage.DlgID := DlgID;
Result := DlgID;
end;
function RegisterDSADialog(
const Name: string;
const Description: string;
const CheckTextKind: TDSACheckTextKind): Integer; overload;
begin
JvDSADialogs.RegisterDSA(DlgID + 1, Name, Description, DSAStorage, CheckTextKind);
DlgID := DlgID + 1;
Result := DlgID;
end;
function RegisterDSAMessage(const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(Name, Description, ctkShow);
end;
function RegisterDSAQuestion(const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(Name, Description, ctkAsk);
end;
function RegisterDSAWarning(const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(Name, Description, ctkWarn);
end;
function RegisterDSAMessage(const DlgID: Integer; const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(DlgID, Name, Description, ctkShow);
end;
function RegisterDSAQuestion(const DlgID: Integer; const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(DlgID, Name, Description, ctkAsk);
end;
function RegisterDSAWarning(const DlgID: Integer; const Name: string; const Description: string): Integer;
begin
Result := RegisterDSADialog(DlgID, Name, Description, ctkWarn);
end;
procedure DSAShowMessage(const DlgID: Integer; const Msg: string;
const Timeout: Integer = 0);
begin
JvDSADialogs.DSAShowMessage(DlgID, Msg, dckActiveForm, Timeout);
end;
procedure DSAShowMessageFmt(const DlgID: Integer; const Msg: string; const Params: array of const;
const Timeout: Integer = 0);
begin
JvDSADialogs.DSAShowMessageFmt(DlgID, Msg, Params, dckActiveForm, Timeout);
end;
function DSAMessageDlg(const DlgID: Integer; const Msg: string; const DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult;
begin
Result := JvDSADialogs.DSAMessageDlg(DlgID, Msg, DlgType, Buttons, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
function DSAMessageDlg(const DlgID: Integer; const Caption, Msg: string; const DlgType: TMsgDlgType;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult;
begin
Result := JvDSADialogs.DSAMessageDlg(DlgID, Msg, DlgType, Buttons, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
function DSAMessageDlg(const DlgID: Integer; const Caption, Msg: string; const Picture: TGraphic;
const Buttons: TMsgDlgButtons; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: TMsgDlgBtn = mbDefault;
const CancelButton: TMsgDlgBtn = mbDefault; const HelpButton: TMsgDlgBtn = mbHelp): TModalResult;
begin
Result := JvDSADialogs.DSAMessageDlg(DlgID, Caption, Msg, Picture, Buttons, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
function DSAMessageDlgEx(const DlgID: Integer; const Msg: string; const DlgType: TMsgDlgType;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0;
const DefaultButton: Integer = 0; const CancelButton: Integer = 1; const HelpButton: Integer = -1): Integer; overload;
begin
Result := JvDSADialogs.DSAMessageDlgEx(DlgID, Msg, DlgType, Buttons, Results, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
function DSAMessageDlgEx(const DlgID: Integer; const Caption, Msg: string; const DlgType: TMsgDlgType;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: Integer = 0;
const CancelButton: Integer = 1; const HelpButton: Integer = -1): TModalResult; overload;
begin
Result := JvDSADialogs.DSAMessageDlgEx(DlgID, Caption, Msg, DlgType, Buttons, Results, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
function DSAMessageDlgEx(const DlgID: Integer; const Caption, Msg: string; const Picture: TGraphic;
const Buttons: array of string; const Results: array of Integer; const HelpCtx: Longint;
const Timeout: Integer = 0; const DefaultButton: Integer = 0;
const CancelButton: Integer = 1; const HelpButton: Integer = -1): Integer; overload;
begin
Result := JvDSADialogs.DSAMessageDlgEx(DlgID, Caption, Msg, Picture, Buttons, Results, HelpCtx, dckActiveForm, Timeout, DefaultButton, CancelButton, HelpButton);
end;
//----------------------------------------------------------------------------
// DSA state setting/retrieving
//----------------------------------------------------------------------------
function GetDSAState(const DlgID: Integer): Boolean;
begin
Result := JvDSADialogs.GetDSAState(DlgID);
end;
function GetDSAState(const DlgID: Integer; OUT LastResult: Integer): Boolean;
begin
Result := JvDSADialogs.GetDSAState(DlgID, LastResult);
end;
procedure SetDSAState(const DlgID: Integer; const DontShowAgain: Boolean; const LastResult: Integer = mrNone);
begin
JvDSADialogs.SetDSAState(DlgID, DontShowAgain, LastResult);
end;
//----------------------------------------------------------------------------
// DSA state loading/saving
//----------------------------------------------------------------------------
procedure LoadDSAStates(const DSAData: TStrings);
function NextWord(var s: string): Integer;
var
delimPos: Integer;
begin
delimPos := Pos(';', s);
if delimPos > 0 then
begin
Result := StrToIntDef(Copy(s, 1, delimPos - 1), -1);
Delete(s, 1, delimPos);
end else
Result := -1;
end;
var
item: string;
idx, dlgID, DontShowAgain, LastResult, Check: Integer;
begin
if Assigned(DSAData) then
begin
for idx := 0 to Pred(DSAData.Count) do
begin
item := DSAData.Strings[idx];
dlgID := NextWord(item);
LastResult := NextWord(item);
DontShowAgain := NextWord(item);
Check := NextWord(item);
if (Check > 0) and (Check = dlgID + LastResult + DontShowAgain) then
if (dlgId <> -1) and (LastResult <> -1) and (DontShowAgain <> -1) then
JvDSADialogs.SetDSAState(dlgId, DontShowAgain = 0, LastResult);
end;
end;
end;
procedure SaveDSAStates(const DSAData: TStrings);
var
item: TDSARegItem;
idx, LastResult, DontShowAgain: Integer;
begin
if Assigned(DSAData) then
begin
for idx := 0 to Pred(JvDSADialogs.DSACount) do
begin
item := JvDSADialogs.DSAItem(idx);
if DSAStorage.GetState(item, LastResult) then
DontShowAgain := 0
else
DontShowAgain := 1;
DSAData.Append(Format('%d;%d;%d;%d', [item.ID, LastResult, DontShowAgain, item.ID + LastResult + DontShowAgain]));
end;
end;
end;
initialization
DlgID := -1;
DSAStorage := TDSAQueueStorage.Create;
finalization
FreeAndNil(DSAStorage);
end.