Changeset 16 for trunk/Form/UFormMain.pas
- Timestamp:
- Apr 2, 2016, 8:18:30 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Form/UFormMain.pas
r15 r16 15 15 16 16 TFormMain = class(TForm) 17 AOperationAdd: TAction; 18 AOperationRemove: TAction; 19 AViewToolbar: TAction; 17 20 ADriveSelect: TAction; 18 21 AOperationOptions: TAction; … … 28 31 AScanStop: TAction; 29 32 ActionList1: TActionList; 33 Button1: TButton; 30 34 Button2: TButton; 31 35 Button3: TButton; 36 Button4: TButton; 32 37 ButtonScan: TButton; 33 38 ButtonScan1: TButton; … … 35 40 ComboBoxDrive: TComboBox; 36 41 Image1: TImage; 37 ImageList1: TImageList;38 42 Label1: TLabel; 39 43 Label10: TLabel; … … 46 50 Label7: TLabel; 47 51 Label8: TLabel; 48 LabelElapsedTime: TLabel;49 LabelSectorSize: TLabel;50 LabelSectorCount: TLabel;51 52 LabelBlockCurrent: TLabel; 52 53 LabelBlockDamaged: TLabel; 54 LabelElapsedTime: TLabel; 53 55 LabelEstimatedTime: TLabel; 54 56 LabelIOSpeed: TLabel; 57 LabelSectorCount: TLabel; 58 LabelSectorPerBlock: TLabel; 59 LabelSectorSize: TLabel; 55 60 LabelSize: TLabel; 56 LabelSectorPerBlock: TLabel;57 61 LastOpenedList1: TLastOpenedList; 58 62 ListView1: TListView; … … 65 69 MenuItem14: TMenuItem; 66 70 MenuItem15: TMenuItem; 71 MenuItem16: TMenuItem; 72 MenuItem17: TMenuItem; 73 MenuItem18: TMenuItem; 74 MenuItem19: TMenuItem; 67 75 MenuItemOpenRecent: TMenuItem; 68 76 MenuItem2: TMenuItem; … … 75 83 MenuItem9: TMenuItem; 76 84 OpenDialog1: TOpenDialog; 85 Panel1: TPanel; 86 Panel2: TPanel; 87 PopupMenu1: TPopupMenu; 77 88 SaveDialog1: TSaveDialog; 89 Splitter1: TSplitter; 78 90 Timer1: TTimer; 79 91 ToolBar1: TToolBar; … … 81 93 ToolButton2: TToolButton; 82 94 ToolButton3: TToolButton; 83 XMLConfig1: TXMLConfig;84 95 procedure AExitExecute(Sender: TObject); 85 96 procedure AFileCloseExecute(Sender: TObject); … … 88 99 procedure AFileSaveAsExecute(Sender: TObject); 89 100 procedure AFileSaveExecute(Sender: TObject); 101 procedure AOperationAddExecute(Sender: TObject); 90 102 procedure AOperationOptionsExecute(Sender: TObject); 103 procedure AOperationRemoveExecute(Sender: TObject); 91 104 procedure AProjectOptionsExecute(Sender: TObject); 92 105 procedure AScanContinueExecute(Sender: TObject); 93 106 procedure AScanStartExecute(Sender: TObject); 94 107 procedure AScanStopExecute(Sender: TObject); 108 procedure AViewToolbarExecute(Sender: TObject); 95 109 procedure ComboBoxDriveChange(Sender: TObject); 96 110 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 101 115 procedure Image1Resize(Sender: TObject); 102 116 procedure ListView1Data(Sender: TObject; Item: TListItem); 117 procedure ListView1SelectItem(Sender: TObject; Item: TListItem; 118 Selected: Boolean); 103 119 procedure Timer1Timer(Sender: TObject); 104 120 private … … 107 123 RedrawPending: Boolean; 108 124 LastDriveName: string; 125 ShowToolBar: Boolean; 109 126 procedure OpenRecentClick(Sender: TObject); 110 127 procedure ReloadOperationList; … … 165 182 procedure TFormMain.ListView1Data(Sender: TObject; Item: TListItem); 166 183 begin 167 if (Item.Index >= 0) and (Item.Index < Core.Project.Scans.Count) then 168 with TDriveScan(Core.Project.Scans[Item.Index]) do begin 184 with Core.Project do 185 if (Item.Index >= 0) and (Item.Index < Scans.Count) then 186 with TDriveScan(Scans[Item.Index]) do begin 169 187 Item.Caption := IntToStr(Item.Index); 188 Item.Data := TDriveScan(Scans[Item.Index]); 170 189 Item.SubItems.Add(DateTimeToStr(TimeStart)); 171 190 Item.SubItems.Add(DateTimeToStr(TimeEnd)); … … 175 194 end; 176 195 196 procedure TFormMain.ListView1SelectItem(Sender: TObject; Item: TListItem; 197 Selected: Boolean); 198 begin 199 Core.Project.CurrentScan := TDriveScan(Item.Data); 200 Redraw; 201 ReloadOperationList; 202 end; 203 177 204 procedure TFormMain.FormCreate(Sender: TObject); 178 205 begin 179 206 PrefixMultiplier := TPrefixMultiplier.Create; 180 XMLConfig1.Filename := 'config.xml';181 207 end; 182 208 … … 187 213 UpdateInterface; 188 214 end; 215 end; 216 217 procedure TFormMain.AViewToolbarExecute(Sender: TObject); 218 begin 219 ShowToolBar := not ShowToolBar; 220 ToolBar1.Visible := ShowToolBar; 221 AViewToolbar.Checked := ShowToolBar; 189 222 end; 190 223 … … 255 288 Core.Project.Modified := False; 256 289 Core.Project.Scans.Add(TDriveScan.Create); 290 Core.Project.CurrentScan := TDriveScan(Core.Project.Scans.Last); 257 291 258 292 ComboBoxDrive.ItemIndex := Core.DriveList.IndexOf(Core.DriveList.FindByModel(Core.Project.DriveInfo.Model)); … … 300 334 end; 301 335 336 procedure TFormMain.AOperationAddExecute(Sender: TObject); 337 var 338 NewOperation: TDriveScan; 339 begin 340 with Core.Project do begin 341 NewOperation := TDriveScan.Create; 342 Scans.Add(NewOperation); 343 CurrentScan := TDriveScan(Scans.Last); 344 ReloadOperationList; 345 Redraw; 346 Core.Project.Modified := True; 347 end; 348 end; 349 302 350 procedure TFormMain.AOperationOptionsExecute(Sender: TObject); 303 351 begin … … 308 356 UpdateInterface; 309 357 end; 358 end; 359 360 procedure TFormMain.AOperationRemoveExecute(Sender: TObject); 361 begin 362 Core.Project.CurrentScan := nil; 363 Core.Project.Scans.Remove(ListView1.Selected.Data); 364 ReloadOperationList; 365 Redraw; 366 Core.Project.Modified := True; 310 367 end; 311 368 … … 347 404 procedure TFormMain.DoDraw; 348 405 begin 349 if Assigned(Core.Project) then406 if Assigned(Core.Project) and Assigned(Core.Project.CurrentScan) then 350 407 with Core.Project do begin 351 if RedrawPending then 352 with Image1 do begin 353 if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then 354 Picture.Bitmap.SetSize(Width, Height); 408 if RedrawPending then 409 with Image1 do begin 410 if (Width <> Picture.Bitmap.Width) or (Height <> Picture.Bitmap.Height) then 411 Picture.Bitmap.SetSize(Width, Height); 412 try 413 Core.Project.CurrentScan.Lock.Acquire; 414 try 415 Picture.Bitmap.BeginUpdate(True); 416 CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas); 417 finally 418 Picture.Bitmap.EndUpdate; 419 end; 420 LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock); 421 LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent); 422 LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount); 423 finally 424 CurrentScan.Lock.Release; 425 end; 426 RedrawPending := False; 427 end; 355 428 try 356 Core.Project.CurrentScan.Lock.Acquire; 357 try 358 Picture.Bitmap.BeginUpdate(True); 359 CurrentScan.BlockMap.Draw(Picture.Bitmap.Canvas); 360 finally 361 Picture.Bitmap.EndUpdate; 429 CurrentScan.Lock.Acquire; 430 if not CurrentScan.Terminated then begin 431 LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime); 432 LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) / 433 CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent)); 434 LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) * 435 CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s'); 436 LastBlockPos := CurrentScan.SectorCurrent; 437 end else begin 438 LabelElapsedTime.Caption := ''; 439 LabelEstimatedTime.Caption := ''; 440 LabelIOSpeed.Caption := ''; 362 441 end; 363 LabelSectorPerBlock.Caption := IntToStr(CurrentScan.BlockMap.SectorPerBlock);364 LabelBlockCurrent.Caption := IntToStr(CurrentScan.SectorCurrent);365 LabelBlockDamaged.Caption := IntToStr(CurrentScan.DamagedBlockCount);366 442 finally 367 443 CurrentScan.Lock.Release; 368 444 end; 369 RedrawPending := False;370 end;371 try372 CurrentScan.Lock.Acquire;373 if not CurrentScan.Terminated then begin374 LabelElapsedTime.Caption := TimeToStr(CurrentScan.GetElapsedTime);375 LabelEstimatedTime.Caption := TimeToStr((Now - CurrentScan.TimeStart) /376 CurrentScan.SectorCurrent * (CurrentScan.BlockMap.SectorCount - CurrentScan.SectorCurrent));377 LabelIOSpeed.Caption := PrefixMultiplier.Add((CurrentScan.SectorCurrent - LastBlockPos) *378 CurrentScan.SectorSize / (Timer1.Interval / 1000), BasePrefixMultipliers, 'B/s');379 LastBlockPos := CurrentScan.SectorCurrent;380 end else begin381 LabelElapsedTime.Caption := '';382 LabelEstimatedTime.Caption := '';383 LabelIOSpeed.Caption := '';384 end;385 finally386 CurrentScan.Lock.Release;387 end;388 445 end else 389 446 with Image1 do begin … … 445 502 procedure TFormMain.SaveConfig; 446 503 begin 447 XMLConfig1.SetValue('DriveName', LastDriveName); 448 LastOpenedList1.SaveToXMLConfig(XMLConfig1, 'RecentProjects'); 504 Core.XMLConfig1.SetValue('DriveName', LastDriveName); 505 LastOpenedList1.SaveToXMLConfig(Core.XMLConfig1, 'RecentProjects'); 506 Core.XMLConfig1.SetValue('ShowToolBar', ShowToolBar); 449 507 end; 450 508 451 509 procedure TFormMain.LoadConfig; 452 510 begin 453 LastDriveName := XMLConfig1.GetValue('DriveName', ''); 454 LastOpenedList1.LoadFromXMLConfig(XMLConfig1, 'RecentProjects'); 511 LastDriveName := Core.XMLConfig1.GetValue('DriveName', ''); 512 LastOpenedList1.LoadFromXMLConfig(Core.XMLConfig1, 'RecentProjects'); 513 ShowToolBar := Core.XMLConfig1.GetValue('ShowToolBar', False); 514 ToolBar1.Visible := ShowToolBar; 515 AViewToolbar.Checked := ShowToolBar; 455 516 end; 456 517 … … 473 534 end; 474 535 ListView1.Refresh; 536 537 AOperationRemove.Enabled := Assigned(ListView1.Selected); 475 538 end; 476 539
Note:
See TracChangeset
for help on using the changeset viewer.