Changeset 512 for Common


Ignore:
Timestamp:
Apr 19, 2018, 4:05:54 PM (7 years ago)
Author:
chronos
Message:
Location:
Common
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • Common/Languages/UJobProgressView.cs.po

    r510 r512  
    2424msgstr "Dokončené"
    2525
     26#: ujobprogressview.soperations
     27msgid "Operations:"
     28msgstr ""
     29
    2630#: ujobprogressview.spleasewait
    2731msgid "Please wait..."
  • Common/Languages/UJobProgressView.po

    r510 r512  
    1414msgstr ""
    1515
     16#: ujobprogressview.soperations
     17msgid "Operations:"
     18msgstr ""
     19
    1620#: ujobprogressview.spleasewait
    1721msgid "Please wait..."
  • Common/UJobProgressView.lfm

    r510 r512  
    11object FormJobProgressView: TFormJobProgressView
    22  Left = 467
    3   Height = 246
     3  Height = 345
    44  Top = 252
    5   Width = 328
     5  Width = 539
    66  BorderIcons = [biSystemMenu]
    7   ClientHeight = 246
    8   ClientWidth = 328
     7  ClientHeight = 345
     8  ClientWidth = 539
    99  DesignTimePPI = 120
    10   Font.Height = -11
    11   Font.Name = 'MS Sans Serif'
    1210  OnClose = FormClose
    1311  OnCloseQuery = FormCloseQuery
    1412  OnCreate = FormCreate
    1513  OnDestroy = FormDestroy
     14  OnHide = FormHide
     15  OnShow = FormShow
    1616  Position = poScreenCenter
    1717  LCLVersion = '1.8.2.0'
    1818  object PanelOperationsTitle: TPanel
    1919    Left = 0
    20     Height = 24
     20    Height = 32
    2121    Top = 0
    22     Width = 328
    23     Align = alTop
    24     BevelOuter = bvNone
    25     ClientHeight = 24
    26     ClientWidth = 328
     22    Width = 539
     23    Align = alTop
     24    BevelOuter = bvNone
     25    ClientHeight = 32
     26    ClientWidth = 539
    2727    FullRepaint = False
    2828    TabOrder = 0
    2929    object LabelOperation: TLabel
    3030      Left = 8
    31       Height = 13
     31      Height = 20
    3232      Top = 8
    33       Width = 66
     33      Width = 76
    3434      Caption = 'Operations:'
    35       Font.Height = -11
    36       Font.Name = 'MS Sans Serif'
    37       Font.Style = [fsBold]
    3835      ParentColor = False
    3936      ParentFont = False
     
    4239  object PanelLog: TPanel
    4340    Left = 0
    44     Height = 122
    45     Top = 124
    46     Width = 328
     41    Height = 133
     42    Top = 212
     43    Width = 539
    4744    Align = alClient
    4845    BevelOuter = bvSpace
    49     ClientHeight = 122
    50     ClientWidth = 328
     46    ClientHeight = 133
     47    ClientWidth = 539
    5148    TabOrder = 1
    5249    object MemoLog: TMemo
    5350      Left = 8
    54       Height = 106
     51      Height = 117
    5552      Top = 8
    56       Width = 312
     53      Width = 523
    5754      Anchors = [akTop, akLeft, akRight, akBottom]
    5855      ReadOnly = True
     
    6360  object PanelProgress: TPanel
    6461    Left = 0
    65     Height = 38
    66     Top = 50
    67     Width = 328
    68     Align = alTop
    69     BevelOuter = bvNone
    70     ClientHeight = 38
    71     ClientWidth = 328
     62    Height = 54
     63    Top = 106
     64    Width = 539
     65    Align = alTop
     66    BevelOuter = bvNone
     67    ClientHeight = 54
     68    ClientWidth = 539
    7269    TabOrder = 2
    7370    object ProgressBarPart: TProgressBar
    74       Left = 8
    75       Height = 17
    76       Top = 16
    77       Width = 312
     71      Left = 10
     72      Height = 24
     73      Top = 24
     74      Width = 523
    7875      Anchors = [akTop, akLeft, akRight]
    7976      TabOrder = 0
     
    8178    object LabelEstimatedTimePart: TLabel
    8279      Left = 8
    83       Height = 13
     80      Height = 20
    8481      Top = -2
    85       Width = 71
     82      Width = 103
    8683      Caption = 'Estimated time:'
    8784      ParentColor = False
     
    9087  object PanelOperations: TPanel
    9188    Left = 0
    92     Height = 26
    93     Top = 24
    94     Width = 328
    95     Align = alTop
    96     BevelOuter = bvNone
    97     ClientHeight = 26
    98     ClientWidth = 328
     89    Height = 42
     90    Top = 64
     91    Width = 539
     92    Align = alTop
     93    BevelOuter = bvNone
     94    ClientHeight = 42
     95    ClientWidth = 539
    9996    FullRepaint = False
    10097    TabOrder = 3
    10198    object ListViewJobs: TListView
    10299      Left = 8
    103       Height = 16
     100      Height = 32
    104101      Top = 5
    105       Width = 312
     102      Width = 523
    106103      Anchors = [akTop, akLeft, akRight, akBottom]
    107104      AutoWidthLastColumn = True
     
    110107      Columns = <     
    111108        item
    112           Width = 312
     109          Width = 523
    113110        end>
    114111      OwnerData = True
     
    123120  object PanelProgressTotal: TPanel
    124121    Left = 0
    125     Height = 36
    126     Top = 88
    127     Width = 328
    128     Align = alTop
    129     BevelOuter = bvNone
    130     ClientHeight = 36
    131     ClientWidth = 328
     122    Height = 52
     123    Top = 160
     124    Width = 539
     125    Align = alTop
     126    BevelOuter = bvNone
     127    ClientHeight = 52
     128    ClientWidth = 539
    132129    TabOrder = 4
    133130    object LabelEstimatedTimeTotal: TLabel
    134131      Left = 8
    135       Height = 13
     132      Height = 20
    136133      Top = 0
    137       Width = 97
     134      Width = 141
    138135      Caption = 'Total estimated time:'
    139136      ParentColor = False
     
    141138    object ProgressBarTotal: TProgressBar
    142139      Left = 8
    143       Height = 16
    144       Top = 16
    145       Width = 312
     140      Height = 24
     141      Top = 24
     142      Width = 523
    146143      Anchors = [akTop, akLeft, akRight]
    147144      TabOrder = 0
     145    end
     146  end
     147  object PanelText: TPanel
     148    Left = 0
     149    Height = 32
     150    Top = 32
     151    Width = 539
     152    Align = alTop
     153    BevelOuter = bvNone
     154    ClientHeight = 32
     155    ClientWidth = 539
     156    TabOrder = 5
     157    object LabelText: TLabel
     158      Left = 8
     159      Height = 24
     160      Top = 8
     161      Width = 525
     162      Anchors = [akTop, akLeft, akRight]
     163      AutoSize = False
     164      ParentColor = False
    148165    end
    149166  end
  • Common/UJobProgressView.pas

    r510 r512  
    77uses
    88  SysUtils, Variants, Classes, Graphics, Controls, Forms, Syncobjs,
    9   Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading,
     9  Dialogs, ComCtrls, StdCtrls, ExtCtrls, Contnrs, UThreading, Math,
    1010  DateUtils;
    1111
     
    1313  EstimatedTimeShowTreshold = 4;
    1414  EstimatedTimeShowTresholdTotal = 1;
    15   MemoLogHeight = 200;
    1615  UpdateInterval = 100; // ms
    1716
     
    2423    FLock: TCriticalSection;
    2524    FOnChange: TNotifyEvent;
     25    FText: string;
    2626    FValue: Integer;
    2727    FMax: Integer;
    2828    procedure SetMax(const AValue: Integer);
     29    procedure SetText(AValue: string);
    2930    procedure SetValue(const AValue: Integer);
    3031  public
     
    3536    property Value: Integer read FValue write SetValue;
    3637    property Max: Integer read FMax write SetMax;
     38    property Text: string read FText write SetText;
    3739    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    3840  end;
     
    6971  end;
    7072
     73  TJobs = class(TObjectList)
     74  end;
     75
    7176  TJobThread = class(TListedThread)
    7277    procedure Execute; override;
     
    8085  TFormJobProgressView = class(TForm)
    8186    ImageList1: TImageList;
     87    LabelText: TLabel;
    8288    Label2: TLabel;
    8389    LabelOperation: TLabel;
     
    8692    ListViewJobs: TListView;
    8793    MemoLog: TMemo;
     94    PanelText: TPanel;
    8895    PanelProgressTotal: TPanel;
    8996    PanelOperationsTitle: TPanel;
     
    94101    ProgressBarTotal: TProgressBar;
    95102    TimerUpdate: TTimer;
     103    procedure FormHide(Sender: TObject);
     104    procedure FormShow(Sender: TObject);
     105    procedure ReloadJobList;
    96106    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    97107    procedure FormDestroy(Sender: TObject);
     
    100110    procedure FormCreate(Sender: TObject);
    101111    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     112    procedure UpdateHeight;
    102113  public
    103114    JobProgressView: TJobProgressView;
     
    120131    procedure SetTerminate(const AValue: Boolean);
    121132    procedure UpdateProgress;
    122     procedure ReloadJobList;
    123     procedure StartJobs;
    124     procedure UpdateHeight;
    125133    procedure JobProgressChange(Sender: TObject);
    126134  public
    127135    Form: TFormJobProgressView;
    128     Jobs: TObjectList; // TListObject<TJob>
     136    Jobs: TJobs;
    129137    CurrentJob: TJob;
    130138    CurrentJobIndex: Integer;
     
    134142    procedure AddJob(Title: string; Method: TJobProgressViewMethod;
    135143      NoThreaded: Boolean = False; WaitFor: Boolean = False);
    136     procedure Start(AAutoClose: Boolean = True);
     144    procedure Start;
    137145    procedure Stop;
    138146    procedure TermSleep(Delay: Integer);
     
    166174  STotalEstimatedTime = 'Total estimated time: %s';
    167175  SFinished = 'Finished';
     176  SOperations = 'Operations:';
    168177
    169178procedure Register;
     
    207216end;
    208217
    209 procedure TJobProgressView.Start(AAutoClose: Boolean = True);
    210 begin
    211   AutoClose := AAutoClose;
    212   StartJobs;
    213 end;
    214 
    215 procedure TJobProgressView.StartJobs;
     218procedure TJobProgressView.Start;
    216219var
    217220  I: Integer;
     
    228231    Form.MemoLog.Clear;
    229232
     233    Form.PanelText.Visible := False;
    230234    Form.LabelEstimatedTimePart.Visible := False;
    231235    Form.LabelEstimatedTimeTotal.Visible := False;
     
    257261      Form.ProgressBarPart.Visible := False;
    258262      //Show;
    259       ReloadJobList;
     263      Form.ReloadJobList;
    260264      Application.ProcessMessages;
    261265      if NoThreaded then begin
     
    295299    //if Visible then Hide;
    296300    Form.MemoLog.Lines.Assign(Log);
    297     if (Form.MemoLog.Lines.Count = 0) and AutoClose then begin
     301    if (Form.MemoLog.Lines.Count = 0) and FAutoClose then begin
    298302      Form.Hide;
    299303    end;
    300     Clear;
     304    //Clear;
    301305    Form.Caption := SFinished;
    302306    //LabelEstimatedTimePart.Visible := False;
    303307    Finished := True;
    304308    CurrentJobIndex := -1;
    305     ReloadJobList;
    306   end;
    307 end;
    308 
    309 procedure TJobProgressView.UpdateHeight;
     309    Form.ReloadJobList;
     310  end;
     311end;
     312
     313procedure TFormJobProgressView.UpdateHeight;
    310314var
    311315  H: Integer;
     
    315319  PanelProgressTotalVisible: Boolean;
    316320  PanelLogVisible: Boolean;
    317 begin
    318   with Form do begin
    319   H := PanelOperationsTitle.Height;
    320   PanelOperationsVisible := Jobs.Count > 0;
    321   if PanelOperationsVisible <> PanelOperations.Visible then
    322     PanelOperations.Visible := PanelOperationsVisible;
    323   PanelOperationsHeight := 8 + 18 * Jobs.Count;
    324   if PanelOperationsHeight <> PanelOperations.Height then
    325     PanelOperations.Height := PanelOperationsHeight;
    326   if PanelOperationsVisible then
    327     H := H + PanelOperations.Height;
    328 
    329   PanelProgressVisible := (Jobs.Count > 0) and not Finished;
    330   if PanelProgressVisible <> PanelProgress.Visible then
    331     PanelProgress.Visible := PanelProgressVisible;
    332   if PanelProgressVisible then
    333     H := H + PanelProgress.Height;
    334   PanelProgressTotalVisible := (Jobs.Count > 1) and not Finished;
    335   if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
    336     PanelProgressTotal.Visible := PanelProgressTotalVisible;
    337   if PanelProgressTotalVisible then
    338     H := H + PanelProgressTotal.Height;
    339   Constraints.MinHeight := H;
    340   PanelLogVisible := MemoLog.Lines.Count > 0;
    341   if PanelLogVisible <> PanelLog.Visible then
    342     PanelLog.Visible := PanelLogVisible;
    343   if PanelLogVisible then
    344     H := H + MemoLogHeight;
    345   if Height <> H then Height := H;
    346   end;
     321  MemoLogHeight: Integer = 200;
     322  I: Integer;
     323  ItemRect: TRect;
     324  MaxH: Integer;
     325begin
     326    H := PanelOperationsTitle.Height;
     327    PanelOperationsVisible := JobProgressView.Jobs.Count > 0;
     328    if PanelOperationsVisible <> PanelOperations.Visible then
     329      PanelOperations.Visible := PanelOperationsVisible;
     330    if ListViewJobs.Items.Count > 0 then begin
     331      Maxh := 0;
     332      for I := 0 to ListViewJobs.Items.Count - 1 do
     333      begin
     334        ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds);
     335        Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top));
     336      end;
     337      PanelOperationsHeight := Scale96ToScreen(12) + Maxh;
     338    end else PanelOperationsHeight := Scale96ToScreen(8);
     339    if PanelOperationsHeight <> PanelOperations.Height then
     340      PanelOperations.Height := PanelOperationsHeight;
     341    if PanelOperationsVisible then
     342      H := H + PanelOperations.Height;
     343
     344    PanelProgressVisible := (JobProgressView.Jobs.Count > 0) and not JobProgressView.Finished;
     345    if PanelProgressVisible <> PanelProgress.Visible then
     346      PanelProgress.Visible := PanelProgressVisible;
     347    if PanelProgressVisible then
     348      H := H + PanelProgress.Height;
     349    PanelProgressTotalVisible := (JobProgressView.Jobs.Count > 1) and not JobProgressView.Finished;
     350    if PanelProgressTotalVisible <> PanelProgressTotal.Visible then
     351      PanelProgressTotal.Visible := PanelProgressTotalVisible;
     352    if PanelProgressTotalVisible then
     353      H := H + PanelProgressTotal.Height;
     354    Constraints.MinHeight := H;
     355    PanelLogVisible := MemoLog.Lines.Count > 0;
     356    if PanelLogVisible <> PanelLog.Visible then
     357      PanelLog.Visible := PanelLogVisible;
     358    if PanelLogVisible then
     359      H := H + Scale96ToScreen(MemoLogHeight);
     360    if PanelText.Visible then
     361      H := H + PanelText.Height;
     362    if Height <> H then Height := H;
    347363end;
    348364
     
    373389    if not JobProgressView.OwnerDraw then Show;
    374390  end;
     391  if Assigned(JobProgressView.CurrentJob) then begin
     392    LabelText.Caption := JobProgressView.CurrentJob.Progress.Text;
     393    if LabelText.Caption <> '' then begin
     394      PanelText.Visible := True;
     395      UpdateHeight;
     396    end;
     397  end;
    375398end;
    376399
     
    394417  var CloseAction: TCloseAction);
    395418begin
    396   ListViewJobs.Clear;
    397419end;
    398420
     
    407429
    408430  end;
     431end;
     432
     433procedure TFormJobProgressView.ReloadJobList;
     434begin
     435  // Workaround for not showing first line
     436  //Form.ListViewJobs.Items.Count := Jobs.Count + 1;
     437  //Form.ListViewJobs.Refresh;
     438
     439  if ListViewJobs.Items.Count <> JobProgressView.Jobs.Count then
     440    ListViewJobs.Items.Count := JobProgressView.Jobs.Count;
     441  ListViewJobs.Refresh;
     442  Application.ProcessMessages;
     443  UpdateHeight;
     444end;
     445
     446procedure TFormJobProgressView.FormShow(Sender: TObject);
     447begin
     448  ReloadJobList;
     449end;
     450
     451procedure TFormJobProgressView.FormHide(Sender: TObject);
     452begin
     453  JobProgressView.Jobs.Clear;
     454  ReloadJobList;
    409455end;
    410456
     
    489535end;
    490536
    491 procedure TJobProgressView.ReloadJobList;
    492 begin
    493   UpdateHeight;
    494   // Workaround for not showing first line
    495   Form.ListViewJobs.Items.Count := Jobs.Count + 1;
    496   Form.ListViewJobs.Refresh;
    497 
    498   if Form.ListViewJobs.Items.Count <> Jobs.Count then
    499     Form.ListViewJobs.Items.Count := Jobs.Count;
    500   Form.ListViewJobs.Refresh;
    501   //Application.ProcessMessages;
    502 end;
    503 
    504537constructor TJobProgressView.Create(TheOwner: TComponent);
    505538begin
     
    509542    Form.JobProgressView := Self;
    510543  end;
    511   Jobs := TObjectList.Create;
     544  Jobs := TJobs.Create;
    512545  Log := TStringList.Create;
    513546  //PanelOperationsTitle.Height := 80;
     
    535568    if FMax < 1 then FMax := 1;
    536569    if FValue >= FMax then FValue := FMax;
     570  finally
     571    FLock.Release;
     572  end;
     573end;
     574
     575procedure TProgress.SetText(AValue: string);
     576begin
     577  try
     578    FLock.Acquire;
     579    if FText = AValue then Exit;
     580    FText := AValue;
    537581  finally
    538582    FLock.Release;
Note: See TracChangeset for help on using the changeset viewer.