-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUGetJars.pas
554 lines (470 loc) · 15 KB
/
UGetJars.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
unit UGetJars;
interface
uses
Windows, SysUtils, Classes, vcl.Menus, vcl.ActnList, ToolsAPI, vcl.ComCtrls, vcl.ExtCtrls, vcl.Graphics, vcl.Controls,
System.IOUtils, vcl.Dialogs, Threading, System.Win.Registry, Vcl.Forms, vcl.VirtualImageList, Vcl.ImageCollection;
type
TGraphicHack = class(TGraphic);
TBADIToolsAPIFunctions = record
Class Procedure RegisterFormClassForTheming(Const AFormClass : TCustomFormClass;
Const Component : TComponent = Nil); static;
end;
TGetJarsExpert = class(TObject)
private
{ Private declarations }
FProjectMenu,
FMenuGetJars: TMenuItem;
FActionGetJars: TAction;
procedure GetJarsExecute(Sender: TObject);
protected
{ Protected declarations }
function AddAction(ACaption, AHint, AName : String; AExecuteEvent,
AUpdateEvent : TNotifyEvent) : TAction;
procedure RemoveAction(AAction: TAction; AToolbar: TToolbar);
procedure RemoveActionFromToolbar(AAction: TAction);
public
{ Public declarations }
constructor Create; virtual;
destructor Destroy; override;
class function Instance: TGetJarsExpert;
public
end;
// TIDENotifier = class(TInterfacedObject, IOTAIDENotifier)
// protected
// procedure FileNotification(NotifyCode: TOTAFileNotification;
// const FileName: string; var Cancel: Boolean);
// procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
// procedure AfterCompile(Succeeded: Boolean); overload;
// procedure AfterSave;
// procedure BeforeSave;
// procedure Destroyed;
// procedure Modified;
// end;
function GetJarsExpert: TGetJarsExpert;
implementation
uses
JclStrings, UFGetJars, UFAndroidManifest, UFRepositories, UFHistory, UFSettings, UFBackUp, UFRestore;
var
FGetJarsExpert: TGetJarsExpert;
// IDENot: Integer;
{$IFDEF VER360}
{$ELSEIF VER350}
{$ELSE}
function AddIconToImageList(AIcon: TIcon; ImageList: TCustomImageList;
Stretch: Boolean): Integer;
const
MaskColor = clBtnFace;
var
SrcBmp, DstBmp: TBitmap;
PSrc1, PSrc2, PDst: PRGBArray;
X, Y: Integer;
begin
Assert(Assigned(AIcon));
Assert(Assigned(ImageList));
{$IFDEF DEBUG}
if not AIcon.Empty then
CnDebugger.LogFmt('AddIcon %dx%d To ImageList %dx%d', [AIcon.Width, AIcon.Height,
ImageList.Width, ImageList.Height]);
{$ENDIF}
if (ImageList.Width = 16) and (ImageList.Height = 16) and not AIcon.Empty and
(AIcon.Width = 32) and (AIcon.Height = 32) then
begin
if Stretch then // ImageList 尺寸比图标大,指定拉伸的情况下,使用平滑处理
begin
SrcBmp := nil;
DstBmp := nil;
try
SrcBmp := CreateEmptyBmp24(32, 32, MaskColor);
DstBmp := CreateEmptyBmp24(16, 16, MaskColor);
SrcBmp.Canvas.Draw(0, 0, AIcon);
for Y := 0 to DstBmp.Height - 1 do
begin
PSrc1 := SrcBmp.ScanLine[Y * 2];
PSrc2 := SrcBmp.ScanLine[Y * 2 + 1];
PDst := DstBmp.ScanLine[Y];
for X := 0 to DstBmp.Width - 1 do
begin
PDst^[X].b := (PSrc1^[X * 2].b + PSrc1^[X * 2 + 1].b + PSrc2^[X * 2].b
+ PSrc2^[X * 2 + 1].b) shr 2;
PDst^[X].g := (PSrc1^[X * 2].g + PSrc1^[X * 2 + 1].g + PSrc2^[X * 2].g
+ PSrc2^[X * 2 + 1].g) shr 2;
PDst^[X].r := (PSrc1^[X * 2].r + PSrc1^[X * 2 + 1].r + PSrc2^[X * 2].r
+ PSrc2^[X * 2 + 1].r) shr 2;
end;
end;
Result := ImageList.AddMasked(DstBmp, MaskColor);
finally
if Assigned(SrcBmp) then FreeAndNil(SrcBmp);
if Assigned(DstBmp) then FreeAndNil(DstBmp);
end;
end
else
begin
// 指定不拉伸的情况下,把 32*32 图标的左上角 16*16 部分绘制来加入
DstBmp := nil;
try
DstBmp := CreateEmptyBmp24(16, 16, MaskColor);
DstBmp.Canvas.Draw(0, 0, AIcon);
Result := ImageList.AddMasked(DstBmp, MaskColor);
finally
DstBmp.Free;
end;
end;
end
else if not AIcon.Empty then
Result := ImageList.AddIcon(AIcon)
else
Result := -1;
end;
{$ENDIF}
function AddGraphicToVirtualImageList(Graphic: TGraphic; DstVirtual: TVirtualImageList;
const ANamePrefix: string; Disabled: Boolean): Integer;
var
C: Integer;
R: TRect;
Bmp: TBitmap;
Mem: TMemoryStream;
Collection: TImageCollection;
begin
Result := -1;
if (Graphic = nil) or (DstVirtual = nil) then
Exit;
if DstVirtual.ImageCollection is TImageCollection then
Collection := DstVirtual.ImageCollection as TImageCollection
else
Exit;
C := Collection.Count;
Mem := TMemoryStream.Create;
try
if Graphic is TIcon then // 是 Icon 则直接存避免丢失透明度
begin
Mem.Clear;
(Graphic as TIcon).SaveToStream(Mem);
end
else if Graphic is TBitmap then
begin
Mem.Clear;
(Graphic as TBitmap).SaveToStream(Mem);
end
else
begin
Bmp := TBitmap.Create;
try
Bmp.PixelFormat := pf32bit;
Bmp.AlphaFormat := afIgnored;
Bmp.Width := Graphic.Width;
Bmp.Height := Graphic.Height;
R := Rect(0, 0, Bmp.Width, Bmp.Height);
TGraphicHack(Graphic).Draw(Bmp.Canvas, R);
Mem.Clear;
Bmp.SaveToStream(Mem);
finally
Bmp.Free;
end;
end;
Collection.Add(ANamePrefix + IntToStr(C), Mem);
finally
Mem.Free;
end;
DstVirtual.Add('', C, C, Disabled);
Result := DstVirtual.Count - 1;
end;
function FindMenuItem(MenuCaptions: String): TMenuItem;
var
Captions: TStringList;
NTAServices: INTAServices;
y, i: integer;
MenuItems: TMenuItem;
Caption: String;
Found: Boolean;
begin
Result := nil;
if Supports(BorlandIDEServices, INTAServices, NTAServices)
then
begin
Captions := TStringList.Create;
Captions.Delimiter := ';';
Captions.StrictDelimiter := True;
Captions.DelimitedText := MenuCaptions;
MenuItems := NTAServices.MainMenu.Items;
for y := 0 to Captions.Count - 1 do
begin
Found := False;
for i := 0 to MenuItems.Count - 1 do
begin
Caption := StringReplace(MenuItems.Items[i].Caption, '&', '', []);
if Uppercase(Caption) = Uppercase(Captions[y])
then
begin
MenuItems := MenuItems.Items[i];
Found := True;
Break;
end;
end;
if not Found
then
begin
Captions.Free;
Exit;
end;
end;
Result := MenuItems;
Captions.Free;
end;
end;
function GetJarsExpert: TGetJarsExpert;
begin
Result := TGetJarsExpert.Instance;
end;
class function TGetJarsExpert.Instance: TGetJarsExpert;
begin
if FGetJarsExpert = nil then
FGetJarsExpert := TGetJarsExpert.Create;
Result := FGetJarsExpert;
end;
procedure TGetJarsExpert.GetJarsExecute(Sender: TObject);
begin
FGetJars.ShowModal;
end;
constructor TGetJarsExpert.Create;
var
NTAServices : INTAServices;
Bmp: TBitmap;
ImageIndex: integer;
// Intf2: TIDENotifier;
begin
inherited Create;
{ Main menu item }
if Supports(BorlandIDEServices, INTAServices, NTAServices)
then
begin
FProjectMenu := FindMenuItem('Project');
Bmp := TBitmap.Create;
FActionGetJars := TAction.Create(nil);
FActionGetJars.Category := 'Project';
FActionGetJars.Caption := 'Gradle';
FActionGetJars.Hint := 'Gradle for Delphi';
FActionGetJars.Name := 'GetJarsAction';
FActionGetJars.Visible := True;
FActionGetJars.OnExecute := GetJarsExecute;
FActionGetJars.Enabled := True;
FMenuGetJars := TMenuItem.Create(nil);
FMenuGetJars.Name := 'GetJars';
FMenuGetJars.Caption := 'Gradle for Delphi';
FMenuGetJars.AutoHotkeys := maAutomatic;
FMenuGetJars.Action := FActionGetJars;
NTAServices.AddActionMenu(FProjectMenu.Name, FActionGetJars, FMenuGetJars, False, True);
Bmp.LoadFromResourceName(HInstance, 'AndroidBmp');
{$IFDEF VER360}
ImageIndex := AddGraphicToVirtualImageList(bmp, NTAServices.ImageList as TVirtualImageList, '', False);
{$ELSEIF VER350}
ImageIndex := AddGraphicToVirtualImageList(bmp, NTAServices.ImageList as TVirtualImageList, '', False);
{$ELSE}
ImageIndex := AddIconToImageList(AWizAction.FIcon, Svcs40.ImageList, False);
{$ENDIF}
FActionGetJars.ImageIndex := ImageIndex;
FMenuGetJars.ImageIndex := ImageIndex;
Bmp.Free;
FGetJars := TFGetJars.Create(nil);
FManifest := TFManifest.Create(nil);
FRepositories := TFRepositories.Create(nil);
FHistory := TFHistory.Create(nil);
FSettings := TFSettings.Create(nil);
FBackUp := TFBackUp.Create(nil);
FRestore := TFRestore.Create(nil);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFGetJars, FGetJars);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFManifest, FManifest);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFRepositories, FRepositories);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFHistory, FHistory);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFSettings, FSettings);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFBackUp, FBackUp);
TBADIToolsAPIFunctions.RegisterFormClassForTheming(TFRestore, FRestore);
with TRegIniFile.Create(REG_KEY) do
try
if ReadString(REG_BUILD_OPTIONS, 'Repositories', '') = ''
then
WriteString(REG_BUILD_OPTIONS, 'Repositories', 'mavenCentral()oogle()center()');
finally
Free;
end;
// Intf2 := TIDENotifier.Create;
// IDENot := (BorlandIDEServices as IOTAServices).AddNotifier(Intf2);
end;
end;
procedure TGetJarsExpert.RemoveActionFromToolbar(AAction: TAction);
var
Services : INTAServices;
begin
Services := (BorlandIDEServices as INTAServices);
RemoveAction(AAction, Services.ToolBar[sCustomToolBar]);
RemoveAction(AAction, Services.ToolBar[sDesktopToolBar]);
RemoveAction(AAction, Services.ToolBar[sStandardToolBar]);
RemoveAction(AAction, Services.ToolBar[sDebugToolBar]);
RemoveAction(AAction, Services.ToolBar[sViewToolBar]);
// RemoveAction(AAction, Services.ToolBar['InternetToolBar']);
end;
procedure TGetJarsExpert.RemoveAction(AAction: TAction; AToolbar: TToolbar);
var
iCounter: Integer;
btnTool : TToolButton;
begin
for iCounter := AToolbar.ButtonCount - 1 downto 0 do
begin
btnTool := AToolbar.Buttons[iCounter];
if btnTool.Action = AAction then
begin
AToolbar.Perform(CM_CONTROLCHANGE, WParam(btnTool), 0);
btnTool.Free;
end;
end;
end;
function TGetJarsExpert.AddAction(ACaption, AHint, AName: String;
AExecuteEvent, AUpdateEvent: TNotifyEvent): TAction;
var
Service : INTAServices;
begin
Service := (BorlandIDEServices as INTAServices);
Result := TAction.Create(Service.ActionList);
with Result do
begin
ActionList := Service.ActionList;
Category := 'Build';
Caption := ACaption;
Hint := AHint;
Name := AName;
Visible := True;
OnExecute := AExecuteEvent;
OnUpdate := AUpdateEvent;
end;
end;
destructor TGetJarsExpert.Destroy;
begin
// (BorlandIDEServices as IOTACompileServices).RemoveNotifier(IDENot);
FGetJars.FDCJobs.Connected := False;
//
FMenuGetJars.Free;
FActionGetJars.Free;
FManifest.Free;
FRepositories.Free;
FHistory.Free;
FGetJars.Free;
FSettings.Free;
inherited Destroy;
end;
class procedure TBADIToolsAPIFunctions.RegisterFormClassForTheming(
const AFormClass: TCustomFormClass; const Component: TComponent);
begin
{$IFDEF Ver320}
Var
ITS : IOTAIDEThemingServices250;
{$ENDIF Ver320}
{$IFDEF Ver330}
Var
ITS : IOTAIDEThemingServices250;
{$ENDIF Ver330}
{$IFDEF Ver340}
Var
ITS : IOTAIDEThemingServices;
{$ENDIF Ver340}
{$IFDEF Ver350}
Var
ITS : IOTAIDEThemingServices;
{$ENDIF Ver350}
{$IFDEF Ver360}
Var
ITS : IOTAIDEThemingServices;
{$ENDIF Ver360}
Begin
{$IFDEF Ver360}
If Supports(BorlandIDEServices, IOTAIDEThemingServices, ITS) Then
If ITS.IDEThemingEnabled Then
Begin
ITS.RegisterFormClass(AFormClass);
If Assigned(Component) Then
ITS.ApplyTheme(Component);
End;
{$ENDIF Ver360}
{$IFDEF Ver350}
If Supports(BorlandIDEServices, IOTAIDEThemingServices, ITS) Then
If ITS.IDEThemingEnabled Then
Begin
ITS.RegisterFormClass(AFormClass);
If Assigned(Component) Then
ITS.ApplyTheme(Component);
End;
{$ENDIF Ver350}
{$IFDEF Ver340}
If Supports(BorlandIDEServices, IOTAIDEThemingServices, ITS) Then
If ITS.IDEThemingEnabled Then
Begin
ITS.RegisterFormClass(AFormClass);
If Assigned(Component) Then
ITS.ApplyTheme(Component);
End;
{$ENDIF Ver340}
{$IFDEF Ver330}
If Supports(BorlandIDEServices, IOTAIDEThemingServices250, ITS) Then
If ITS.IDEThemingEnabled Then
Begin
ITS.RegisterFormClass(AFormClass);
If Assigned(Component) Then
ITS.ApplyTheme(Component);
End;
{$ENDIF Ver330}
{$IFDEF Ver320}
If Supports(BorlandIDEServices, IOTAIDEThemingServices250, ITS) Then
If ITS.IDEThemingEnabled Then
Begin
ITS.RegisterFormClass(AFormClass);
If Assigned(Component) Then
ITS.ApplyTheme(Component);
End;
{$ENDIF Ver320}
End;
end;
{ TIDENotifier }
//procedure TIDENotifier.AfterCompile(Succeeded: Boolean);
//begin
//
//end;
//
//procedure TIDENotifier.AfterSave;
//begin
//
//end;
//
//procedure TIDENotifier.BeforeCompile(const Project: IOTAProject;
// var Cancel: Boolean);
//begin
//
//end;
//
//procedure TIDENotifier.BeforeSave;
//begin
//
//end;
//
//procedure TIDENotifier.Destroyed;
//begin
//
//end;
//
//procedure TIDENotifier.FileNotification(NotifyCode: TOTAFileNotification;
// const FileName: string; var Cancel: Boolean);
//begin
//
//// if NotifyCode = ofnActiveProjectChanged
//// then
//// FGetJars.FDCJobs.Connected := False;
//
//end;
//
//procedure TIDENotifier.Modified;
//begin
//
//end;
initialization
FGetJarsExpert := TGetJarsExpert.Instance;
finalization
FreeAndNil(FGetJarsExpert);
end.