This file is indexed.

/usr/lib/lazarus/0.9.30.4/ide/progresswnd.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
{
 ***************************************************************************
 *                                                                         *
 *   This source is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This code is distributed in the hope that it will be useful, but      *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   A copy of the GNU General Public License is available on the World    *
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 *   obtain it by writing to the Free Software Foundation,                 *
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 *                                                                         *
 ***************************************************************************

  Author: Mattias Gaertner

  Abstract:
    A floating IDE window to show what long tasks are currently running in the
    background.

}
unit ProgressWnd;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LCLProc, FileUtil, Forms, Controls, Graphics, Dialogs,
  ComCtrls, StdCtrls, ExtCtrls, LazIDEIntf, LazarusIDEStrConsts;

type
  TIDEProgressWindow = class;

  { TIDEProgressItem }

  TIDEProgressItem = class(TComponent)
  private
    FCaption: string;
    FCaptionLabel: TLabel;
    FEndPos: integer;
    FHint: string;
    FPanel: TPanel;
    FPosition: integer;
    FProgressBar: TProgressBar;
    FStartPos: integer;
    FWindow: TIDEProgressWindow;
    procedure SetCaption(const AValue: string);
    procedure SetCaptionLabel(const AValue: TLabel);
    procedure SetEndPos(const AValue: integer);
    procedure SetHint(const AValue: string);
    procedure SetPanel(const AValue: TPanel);
    procedure SetPosition(const AValue: integer);
    procedure SetProgressBar(const AValue: TProgressBar);
    procedure SetStartPos(const AValue: integer);
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation);
      override;
  public
    property Caption: string read FCaption write SetCaption;
    property Hint: string read FHint write SetHint;
    property StartPos: integer read FStartPos write SetStartPos;
    property EndPos: integer read FEndPos write SetEndPos; // if EndPos=StartPos then unknown
    property Position: integer read FPosition write SetPosition;
    property Panel: TPanel read FPanel write SetPanel;
    property CaptionLabel: TLabel read FCaptionLabel write SetCaptionLabel;
    property ProgressBar: TProgressBar read FProgressBar write SetProgressBar;
    property Window: TIDEProgressWindow read FWindow;
  end;

  { TIDEProgressWindow }

  TIDEProgressWindow = class(TForm)
  private
    FItems: TFPList; // list of TIDEProgressItem
    function GetItems(Index: integer): TIDEProgressItem;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation);
      override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    function Count: integer;
    property Items[Index: integer]: TIDEProgressItem read GetItems; default;
    procedure ClearItems;
    function IndexByName(AName: string): integer;
    function AddItem(AName, ACaption, AHint: string): TIDEProgressItem;
  end;

var
  IDEProgressWindow: TIDEProgressWindow = nil;

function CreateProgressItem(AName, ACaption, AHint: string): TIDEProgressItem;

implementation

function CreateProgressItem(AName, ACaption, AHint: string): TIDEProgressItem;
begin
  //debugln(['CreateProgressItem Name="',AName,'" Caption="',ACaption,'"']);
  if IDEProgressWindow=nil then
  begin
    IDEProgressWindow:=TIDEProgressWindow.Create(LazarusIDE.OwningComponent);
  end;
  Result:=IDEProgressWindow.AddItem(AName,ACaption,AHint);
end;

{$R *.lfm}

{ TIDEProgressItem }

procedure TIDEProgressItem.SetCaption(const AValue: string);
begin
  if FCaption=AValue then exit;
  FCaption:=AValue;
  if CaptionLabel<>Nil then
    CaptionLabel.Caption:=Caption;
end;

procedure TIDEProgressItem.SetCaptionLabel(const AValue: TLabel);
begin
  if FCaptionLabel=AValue then exit;
  if CaptionLabel<>nil then
    RemoveFreeNotification(CaptionLabel);
  FCaptionLabel:=AValue;
  if CaptionLabel<>nil then
  begin
    FreeNotification(CaptionLabel);
    CaptionLabel.Caption:=Caption;
    CaptionLabel.Hint:=Hint;
  end;
end;

procedure TIDEProgressItem.SetEndPos(const AValue: integer);
begin
  if FEndPos=AValue then exit;
  FEndPos:=AValue;
  if ProgressBar<>nil then
  begin
    if EndPos>StartPos then
    begin
      ProgressBar.Style:=pbstNormal;
      ProgressBar.Min:=StartPos;
      ProgressBar.Position:=Position;
      ProgressBar.Max:=EndPos;
    end else begin
      ProgressBar.Style:=pbstMarquee;
    end;
  end;
end;

procedure TIDEProgressItem.SetHint(const AValue: string);
begin
  if FHint=AValue then exit;
  FHint:=AValue;
  if ProgressBar<>Nil then
    ProgressBar.Hint:=Hint;
  if CaptionLabel<>Nil then
    CaptionLabel.Hint:=Hint;
end;

procedure TIDEProgressItem.SetPanel(const AValue: TPanel);
begin
  if FPanel=AValue then exit;
  if Panel<>nil then
    RemoveFreeNotification(Panel);
  FPanel:=AValue;
  if Panel<>nil then
    FreeNotification(Panel);
end;

procedure TIDEProgressItem.SetPosition(const AValue: integer);
begin
  if FPosition=AValue then exit;
  FPosition:=AValue;
  if ProgressBar<>nil then
    ProgressBar.Position:=Position;
end;

procedure TIDEProgressItem.SetProgressBar(const AValue: TProgressBar);
begin
  if FProgressBar=AValue then exit;
  if ProgressBar<>nil then
    RemoveFreeNotification(ProgressBar);
  FProgressBar:=AValue;
  if ProgressBar<>nil then begin
    FreeNotification(ProgressBar);
    if EndPos>StartPos then
    begin
      ProgressBar.Style:=pbstNormal;
      ProgressBar.Min:=StartPos;
      ProgressBar.Position:=Position;
      ProgressBar.Max:=EndPos;
    end else begin
      ProgressBar.Style:=pbstMarquee;
    end;
    ProgressBar.Hint:=Hint;
  end;
end;

procedure TIDEProgressItem.SetStartPos(const AValue: integer);
begin
  if FStartPos=AValue then exit;
  FStartPos:=AValue;
  if ProgressBar<>Nil then
  begin
    if EndPos>StartPos then
    begin
      ProgressBar.Style:=pbstNormal;
      ProgressBar.Min:=StartPos;
      ProgressBar.Position:=Position;
      ProgressBar.Max:=EndPos;
    end else begin
      ProgressBar.Style:=pbstMarquee;
    end;
  end;
end;

procedure TIDEProgressItem.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if Operation=opRemove then
  begin
    if AComponent=Panel then
      FPanel:=nil;
    if AComponent=ProgressBar then
      fProgressBar:=nil;
    if AComponent=CaptionLabel then
      fCaptionLabel:=nil;
  end;
end;

{ TIDEProgressWindow }

function TIDEProgressWindow.GetItems(Index: integer): TIDEProgressItem;
begin
  Result:=TIDEProgressItem(FItems[Index]);
end;

procedure TIDEProgressWindow.Notification(AComponent: TComponent;
  Operation: TOperation);
var
  i: Integer;
begin
  inherited Notification(AComponent, Operation);
  if Operation=opRemove then
  begin
    DisableAutoSizing;
    try
      for i:=Count-1 downto 0 do
        if Items[i]=AComponent then
        begin
          FreeAndNil(Items[i].fPanel);
          FItems.Delete(i);
        end;
      if Count=0 then
        Hide;
    finally
      EnableAutoSizing;
    end;
  end;
end;

constructor TIDEProgressWindow.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  FItems:=TFPList.Create;
  Caption:=lisPDProgress;
end;

destructor TIDEProgressWindow.Destroy;
begin
  ClearItems;
  FreeAndNil(FItems);
  if IDEProgressWindow=Self then IDEProgressWindow:=nil;
  inherited Destroy;
end;

function TIDEProgressWindow.Count: integer;
begin
  Result:=FItems.Count;
end;

procedure TIDEProgressWindow.ClearItems;
var
  i: Integer;
begin
  for i:=Count-1 downto 0 do Items[i].Free;
end;

function TIDEProgressWindow.IndexByName(AName: string): integer;
begin
  Result:=Count-1;
  while (Result>=0) and (SysUtils.CompareText(AName,Items[Result].Name)<>0) do
    dec(Result);
end;

function TIDEProgressWindow.AddItem(AName, ACaption, AHint: string
  ): TIDEProgressItem;
var
  i: Integer;
  NewName: String;
begin
  //debugln(['TIDEProgressWindow.AddItem Name="',AName,'" Caption="',ACaption,'"']);
  if FindComponent(AName)<>nil then
  begin
    i:=1;
    repeat
      NewName:=AName+IntToStr(i);
    until FindComponent(NewName)=nil;
    AName:=NewName;
  end;
  Result:=TIDEProgressItem.Create(Self);
  Result.FWindow:=Self;
  Result.Name:=AName;
  Result.Caption:=ACaption;
  Result.Hint:=AHint;
  // add a panel
  Result.Panel:=TPanel.Create(Result);
  Result.Panel.Align:=alTop;
  Result.Panel.AutoSize:=true;
  Result.Panel.Constraints.MinWidth:=100;
  Result.Panel.Constraints.MinHeight:=30;
  // add a label into the panel
  Result.CaptionLabel:=TLabel.Create(Result.Panel);
  Result.CaptionLabel.Align:=alTop;
  Result.CaptionLabel.AutoSize:=true;
  Result.CaptionLabel.Parent:=Result.Panel;
  Result.CaptionLabel.ShowHint:=true;
  // add a progressbar below the label
  Result.ProgressBar:=TProgressBar.Create(Result.Panel);
  Result.ProgressBar.Align:=alTop;
  Result.ProgressBar.AutoSize:=true;
  Result.ProgressBar.Parent:=Result.Panel;
  Result.ProgressBar.ShowHint:=true;
  Result.ProgressBar.Top:=10;

  // show panel
  DisableAutoSizing;
  try
    AutoSize:=false;
    Result.Panel.Parent:=Self;
    AutoSize:=true;
    Show;
  finally
    EnableAutoSizing;
  end;
end;

end.