SynchronizeChecklist.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "WinInterface.h"
  6. #include "SynchronizeChecklist.h"
  7. #include <Terminal.h>
  8. #include <TextsWin.h>
  9. #include <CoreMain.h>
  10. #include <VCLCommon.h>
  11. #include <Tools.h>
  12. #include <BaseUtils.hpp>
  13. #include <Math.hpp>
  14. #include <WinConfiguration.h>
  15. #include <GUITools.h>
  16. //---------------------------------------------------------------------
  17. #pragma link "IEListView"
  18. #pragma link "NortonLikeListView"
  19. #pragma link "PngImageList"
  20. #ifndef NO_RESOURCES
  21. #pragma resource "*.dfm"
  22. #endif
  23. //---------------------------------------------------------------------
  24. const int ImageColumnIndex = 4;
  25. //---------------------------------------------------------------------
  26. bool __fastcall DoSynchronizeChecklistDialog(TSynchronizeChecklist * Checklist,
  27. TSynchronizeMode Mode, int Params,
  28. const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
  29. TCustomCommandMenuEvent OnCustomCommandMenu, TFullSynchronizeEvent OnSynchronize,
  30. TSynchronizeChecklistCalculateSize OnSynchronizeChecklistCalculateSize, void * Token)
  31. {
  32. std::unique_ptr<TSynchronizeChecklistDialog> Dialog(
  33. new TSynchronizeChecklistDialog(
  34. Application, Mode, Params, LocalDirectory, RemoteDirectory, OnCustomCommandMenu, OnSynchronize,
  35. OnSynchronizeChecklistCalculateSize, Token));
  36. return Dialog->Execute(Checklist);
  37. }
  38. //---------------------------------------------------------------------
  39. __fastcall TSynchronizeChecklistDialog::TSynchronizeChecklistDialog(
  40. TComponent * AOwner, TSynchronizeMode Mode, int Params,
  41. const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
  42. TCustomCommandMenuEvent OnCustomCommandMenu, TFullSynchronizeEvent OnSynchronize,
  43. TSynchronizeChecklistCalculateSize OnSynchronizeChecklistCalculateSize, void * Token)
  44. : TForm(AOwner)
  45. {
  46. FFormRestored = false;
  47. FMode = Mode;
  48. FParams = Params;
  49. FLocalDirectory = ExcludeTrailingBackslash(LocalDirectory);
  50. FRemoteDirectory = UnixExcludeTrailingBackslash(RemoteDirectory);
  51. FOnCustomCommandMenu = OnCustomCommandMenu;
  52. FOnSynchronizeChecklistCalculateSize = OnSynchronizeChecklistCalculateSize;
  53. DebugAssert(OnSynchronize != NULL);
  54. FOnSynchronize = OnSynchronize;
  55. FToken = Token;
  56. UseSystemSettings(this);
  57. UseDesktopFont(ListView);
  58. UseDesktopFont(StatusBar);
  59. FChecklist = NULL;
  60. FChangingItem = NULL;
  61. FChangingItemIgnore = false;
  62. FChangingItemMass = false;
  63. FGeneralHint = StatusBar->Hint;
  64. FSynchronizing = false;
  65. SelectScaledImageList(ActionImages);
  66. FOrigListViewWindowProc = ListView->WindowProc;
  67. ListView->WindowProc = ListViewWindowProc;
  68. UpdateImages();
  69. CustomCommandsAction->Visible = (FOnCustomCommandMenu != NULL);
  70. // button visibility cannot be bound to action visibility
  71. CustomCommandsButton2->Visible = CustomCommandsAction->Visible;
  72. MenuButton(CustomCommandsButton2);
  73. }
  74. //---------------------------------------------------------------------
  75. __fastcall TSynchronizeChecklistDialog::~TSynchronizeChecklistDialog()
  76. {
  77. ListView->WindowProc = FOrigListViewWindowProc;
  78. }
  79. //---------------------------------------------------------------------
  80. bool __fastcall TSynchronizeChecklistDialog::Execute(TSynchronizeChecklist * Checklist)
  81. {
  82. FChecklist = Checklist;
  83. bool Result = (ShowModal() == DefaultResult(this));
  84. if (Result)
  85. {
  86. TSynchronizeChecklistConfiguration FormConfiguration =
  87. CustomWinConfiguration->SynchronizeChecklist;
  88. FormConfiguration.ListParams = ListView->ColProperties->ParamsStr;
  89. UnicodeString WindowParams = FormConfiguration.WindowParams;
  90. // if there is no main window, keep previous "custom pos" indication,
  91. bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
  92. if (!IsMainFormLike(this))
  93. {
  94. CustomPos = (Application->MainForm->BoundsRect != BoundsRect);
  95. }
  96. FormConfiguration.WindowParams =
  97. FORMAT(L"%d;%s", ((CustomPos ? 1 : 0), StoreForm(this)));
  98. CustomWinConfiguration->SynchronizeChecklist = FormConfiguration;
  99. }
  100. if (FException.get() != NULL)
  101. {
  102. RethrowException(FException.get());
  103. }
  104. return Result;
  105. }
  106. //---------------------------------------------------------------------
  107. void __fastcall TSynchronizeChecklistDialog::UpdateControls()
  108. {
  109. Caption = FormatFormCaption(this, LoadStr(FSynchronizing ? SYNCHRONIZE_PROGRESS_SYNCHRONIZE2 : SYNCHRONIZE_CHECKLIST_CAPTION));
  110. StatusBar->Invalidate();
  111. bool AllChecked = true;
  112. bool AllUnchecked = true;
  113. bool AnyBoth = false;
  114. bool AnyNonBoth = false;
  115. bool AnyDirectory = false;
  116. TListItem * Item = ListView->Selected;
  117. while (Item != NULL)
  118. {
  119. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  120. TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
  121. if ((Action == TSynchronizeChecklist::saUploadUpdate) ||
  122. (Action == TSynchronizeChecklist::saDownloadUpdate))
  123. {
  124. AnyBoth = true;
  125. }
  126. else
  127. {
  128. AnyNonBoth = true;
  129. }
  130. if (Item->Checked)
  131. {
  132. AllUnchecked = false;
  133. }
  134. else
  135. {
  136. AllChecked = false;
  137. }
  138. if (ChecklistItem->IsDirectory)
  139. {
  140. AnyDirectory = true;
  141. }
  142. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  143. }
  144. EnableControl(OkButton, (FChecked[0] > 0) && !FSynchronizing);
  145. EnableControl(CancelButton, !FSynchronizing);
  146. EnableControl(HelpButton, !FSynchronizing);
  147. CheckAction->Enabled = !AllChecked && !FSynchronizing;
  148. UncheckAction->Enabled = !AllUnchecked && !FSynchronizing;
  149. CheckAllAction->Enabled = (FChecked[0] < FTotals[0]) && !FSynchronizing;
  150. UncheckAllAction->Enabled = (FChecked[0] > 0) && !FSynchronizing;
  151. CustomCommandsAction->Enabled = AnyBoth && !AnyNonBoth && DebugAlwaysTrue(!FSynchronizing);
  152. ReverseAction->Enabled = (ListView->SelCount > 0) && DebugAlwaysTrue(!FSynchronizing);
  153. CalculateSizeAction->Enabled = (ListView->SelCount > 0) && AnyDirectory && DebugAlwaysTrue(!FSynchronizing);
  154. SelectAllAction->Enabled = (ListView->SelCount < ListView->Items->Count) && !FSynchronizing;
  155. }
  156. //---------------------------------------------------------------------------
  157. bool __fastcall TSynchronizeChecklistDialog::GetWindowParams(UnicodeString & WindowParams)
  158. {
  159. WindowParams = CustomWinConfiguration->SynchronizeChecklist.WindowParams;
  160. bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
  161. return CustomPos || IsMainFormLike(this);
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TSynchronizeChecklistDialog::CreateParams(TCreateParams & Params)
  165. {
  166. UnicodeString WindowParams;
  167. if (GetWindowParams(WindowParams))
  168. {
  169. // This is only to set correct TForm::Position. Actual bounds are set later after DPI scaling
  170. RestoreForm(WindowParams, this, true);
  171. }
  172. TForm::CreateParams(Params);
  173. }
  174. //---------------------------------------------------------------------------
  175. void __fastcall TSynchronizeChecklistDialog::HelpButtonClick(TObject * /*Sender*/)
  176. {
  177. FormHelp(this);
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TSynchronizeChecklistDialog::AddSubItem(TListItem * Item, int & Index, const UnicodeString & S)
  181. {
  182. if (Index < Item->SubItems->Count)
  183. {
  184. Item->SubItems->Strings[Index] = S;
  185. }
  186. else
  187. {
  188. DebugAssert(Index == Item->SubItems->Count);
  189. Item->SubItems->Add(S);
  190. }
  191. Index++;
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TSynchronizeChecklistDialog::LoadItem(TListItem * Item)
  195. {
  196. UnicodeString S;
  197. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  198. if (ChecklistItem->ImageIndex >= 0)
  199. {
  200. Item->ImageIndex = ChecklistItem->ImageIndex;
  201. }
  202. else
  203. {
  204. Item->ImageIndex = FakeFileImageIndex(ChecklistItem->GetFileName(),
  205. FLAGMASK(ChecklistItem->IsDirectory, FILE_ATTRIBUTE_DIRECTORY));
  206. }
  207. S = ChecklistItem->GetFileName();
  208. if (ChecklistItem->IsDirectory)
  209. {
  210. S = IncludeTrailingBackslash(S);
  211. }
  212. Item->Caption = S;
  213. int Index = 0;
  214. TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
  215. if (Action == TSynchronizeChecklist::saDeleteRemote)
  216. {
  217. AddSubItem(Item, Index, L"");
  218. AddSubItem(Item, Index, L"");
  219. AddSubItem(Item, Index, L"");
  220. }
  221. else
  222. {
  223. S = ChecklistItem->Local.Directory;
  224. if (AnsiSameText(FLocalDirectory, S.SubString(1, FLocalDirectory.Length())))
  225. {
  226. S[1] = L'.';
  227. S.Delete(2, FLocalDirectory.Length() - 1);
  228. }
  229. else
  230. {
  231. DebugFail();
  232. }
  233. AddSubItem(Item, Index, S);
  234. if (Action == TSynchronizeChecklist::saDownloadNew)
  235. {
  236. AddSubItem(Item, Index, L"");
  237. AddSubItem(Item, Index, L"");
  238. }
  239. else
  240. {
  241. if (!ChecklistItem->HasSize())
  242. {
  243. AddSubItem(Item, Index, L"");
  244. }
  245. else
  246. {
  247. AddSubItem(Item, Index,
  248. FormatPanelBytes(ChecklistItem->Local.Size, WinConfiguration->FormatSizeBytes));
  249. }
  250. AddSubItem(Item, Index,
  251. UserModificationStr(ChecklistItem->Local.Modification,
  252. ChecklistItem->Local.ModificationFmt));
  253. }
  254. }
  255. AddSubItem(Item, Index, L"");
  256. DebugAssert(Index == ImageColumnIndex);
  257. if (Action == TSynchronizeChecklist::saDeleteLocal)
  258. {
  259. AddSubItem(Item, Index, L"");
  260. AddSubItem(Item, Index, L"");
  261. AddSubItem(Item, Index, L"");
  262. }
  263. else
  264. {
  265. S = ChecklistItem->Remote.Directory;
  266. if (AnsiSameText(FRemoteDirectory, S.SubString(1, FRemoteDirectory.Length())))
  267. {
  268. S[1] = L'.';
  269. S.Delete(2, FRemoteDirectory.Length() - 1);
  270. }
  271. else
  272. {
  273. DebugFail();
  274. }
  275. AddSubItem(Item, Index, S);
  276. if (Action == TSynchronizeChecklist::saUploadNew)
  277. {
  278. AddSubItem(Item, Index, L"");
  279. AddSubItem(Item, Index, L"");
  280. }
  281. else
  282. {
  283. if (!ChecklistItem->HasSize())
  284. {
  285. AddSubItem(Item, Index, L"");
  286. }
  287. else
  288. {
  289. AddSubItem(Item, Index,
  290. FormatPanelBytes(ChecklistItem->Remote.Size, WinConfiguration->FormatSizeBytes));
  291. }
  292. AddSubItem(Item, Index, UserModificationStr(ChecklistItem->Remote.Modification,
  293. ChecklistItem->Remote.ModificationFmt));
  294. }
  295. }
  296. }
  297. //---------------------------------------------------------------------------
  298. void __fastcall TSynchronizeChecklistDialog::LoadList()
  299. {
  300. memset(&FTotals, 0, sizeof(FTotals));
  301. memset(&FChecked, 0, sizeof(FChecked));
  302. memset(&FCheckedSize, 0, sizeof(FCheckedSize));
  303. FTotals[0] = FChecklist->Count;
  304. ListView->Items->BeginUpdate();
  305. try
  306. {
  307. ListView->Items->Clear();
  308. for (int Index = 0; Index < FChecklist->Count; Index++)
  309. {
  310. const TSynchronizeChecklist::TItem * ChecklistItem =
  311. FChecklist->Item[ListView->Items->Count];
  312. FChangingItemIgnore = true;
  313. try
  314. {
  315. TListItem * Item = ListView->Items->Add();
  316. TSynchronizeChecklist::TAction Action = ChecklistItem->Action;
  317. FActions.insert(std::make_pair(ChecklistItem, Action));
  318. Item->Data = const_cast<TSynchronizeChecklist::TItem *>(ChecklistItem);
  319. Item->Checked = ChecklistItem->Checked;
  320. LoadItem(Item);
  321. }
  322. __finally
  323. {
  324. FChangingItemIgnore = false;
  325. }
  326. int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
  327. FTotals[ActionIndex]++;
  328. if (ChecklistItem->Checked)
  329. {
  330. FChecked[ActionIndex]++;
  331. FChecked[0]++;
  332. __int64 ItemSize = GetItemSize(ChecklistItem);
  333. FCheckedSize[ActionIndex] += ItemSize;
  334. FCheckedSize[0] += ItemSize;
  335. }
  336. }
  337. }
  338. __finally
  339. {
  340. ListView->Items->EndUpdate();
  341. }
  342. ListView->AlphaSort();
  343. UpdateControls();
  344. }
  345. //---------------------------------------------------------------------------
  346. bool __fastcall TSynchronizeChecklistDialog::IsItemSizeIrrelevant(TSynchronizeChecklist::TAction Action)
  347. {
  348. switch (Action)
  349. {
  350. case TSynchronizeChecklist::saNone:
  351. case TSynchronizeChecklist::saDeleteRemote:
  352. case TSynchronizeChecklist::saDeleteLocal:
  353. return true;
  354. default:
  355. return false;
  356. }
  357. }
  358. //---------------------------------------------------------------------------
  359. __int64 __fastcall TSynchronizeChecklistDialog::GetItemSize(const TSynchronizeChecklist::TItem * Item)
  360. {
  361. TSynchronizeChecklist::TAction Action = GetChecklistItemAction(Item);
  362. if (IsItemSizeIrrelevant(Action))
  363. {
  364. return 0;
  365. }
  366. else
  367. {
  368. switch (Action)
  369. {
  370. case TSynchronizeChecklist::saUploadNew:
  371. case TSynchronizeChecklist::saUploadUpdate:
  372. return Item->Local.Size;
  373. case TSynchronizeChecklist::saDownloadNew:
  374. case TSynchronizeChecklist::saDownloadUpdate:
  375. return Item->Remote.Size;
  376. default:
  377. DebugFail();
  378. return 0;
  379. }
  380. }
  381. }
  382. //---------------------------------------------------------------------------
  383. void __fastcall TSynchronizeChecklistDialog::FormShow(TObject * /*Sender*/)
  384. {
  385. // Moved here from CreateParams (see also TEditorForm::CreateParams), because there it breaks per-monitor DPI.
  386. // For example BoundsRect is matched to the main form too soon, so it gets rescaled later.
  387. // Also it happens before constructor, what causes UseDesktopFont-flagged controls to rescale twice.
  388. // But Position is already set in the CreateParams, as it cannot be set here anymore.
  389. if (!FFormRestored)
  390. {
  391. FFormRestored = True;
  392. UnicodeString WindowParams;
  393. if (GetWindowParams(WindowParams))
  394. {
  395. RestoreForm(WindowParams, this);
  396. }
  397. else
  398. {
  399. BoundsRect = Application->MainForm->BoundsRect;
  400. }
  401. }
  402. ListView->ColProperties->ParamsStr = CustomWinConfiguration->SynchronizeChecklist.ListParams;
  403. LoadList();
  404. UpdateStatusBarSize();
  405. }
  406. //---------------------------------------------------------------------------
  407. TRect __fastcall TSynchronizeChecklistDialog::GetColumnHeaderRect(int Index)
  408. {
  409. HWND HeaderHandle = ListView_GetHeader(ListView->Handle);
  410. TRect R;
  411. Header_GetItemRect(HeaderHandle, Index, &R);
  412. // Can be simplified using GetScrollPos
  413. TScrollInfo ScrollInfo;
  414. ZeroMemory(&ScrollInfo, sizeof(ScrollInfo));
  415. ScrollInfo.cbSize = sizeof(ScrollInfo);
  416. ScrollInfo.fMask = SIF_POS;
  417. GetScrollInfo(ListView->Handle, SB_HORZ, &ScrollInfo);
  418. R.Left -= ScrollInfo.nPos;
  419. R.Right -= ScrollInfo.nPos;
  420. return R;
  421. }
  422. //---------------------------------------------------------------------------
  423. void __fastcall TSynchronizeChecklistDialog::ListViewWindowProc(TMessage & Message)
  424. {
  425. if (Message.Msg == CN_NOTIFY)
  426. {
  427. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  428. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  429. {
  430. // workaround
  431. // Due to a bug in VCL, OnAdvancedCustomDrawSubItem is not called for any
  432. // other stage except for cdPrePaint. So we must call it ourselves.
  433. TNMLVCustomDraw * CustomDraw =
  434. reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  435. if (FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEM) &&
  436. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_SUBITEM) &&
  437. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT) &&
  438. (CustomDraw->iSubItem == ImageColumnIndex) &&
  439. (ActionImages->Width <= ListView->Columns->Items[CustomDraw->iSubItem]->Width))
  440. {
  441. TListItem * Item = ListView->Items->Item[CustomDraw->nmcd.dwItemSpec];
  442. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  443. TRect HeaderR = GetColumnHeaderRect(CustomDraw->iSubItem);
  444. TRect R = Item->DisplayRect(drBounds);
  445. R.Left = HeaderR.Left + (HeaderR.Width() - ActionImages->Width) / 2;
  446. R.Right = HeaderR.Right;
  447. // workaround
  448. // doing this from ListViewAdvancedCustomDraw corrupts list view on Windows 7
  449. ImageList_Draw(reinterpret_cast<HIMAGELIST>(ActionImages->Handle),
  450. int(GetChecklistItemAction(ChecklistItem)), CustomDraw->nmcd.hdc,
  451. R.Left, ((R.Top + R.Bottom - ActionImages->Height) / 2), ILD_TRANSPARENT);
  452. }
  453. }
  454. }
  455. FOrigListViewWindowProc(Message);
  456. }
  457. //---------------------------------------------------------------------------
  458. void __fastcall TSynchronizeChecklistDialog::ListViewAdvancedCustomDrawSubItem(
  459. TCustomListView * /*Sender*/, TListItem * /*Item*/, int /*SubItem*/,
  460. TCustomDrawState /*State*/, TCustomDrawStage /*Stage*/, bool & /*DefaultDraw*/)
  461. {
  462. // this is just fake handler that makes the list view request custom draw notification above
  463. }
  464. //---------------------------------------------------------------------------
  465. void __fastcall TSynchronizeChecklistDialog::StatusBarDrawPanel(
  466. TStatusBar * StatusBar, TStatusPanel * Panel, const TRect & Rect)
  467. {
  468. bool Possible;
  469. int ActionIndex = Panel->Index;
  470. TSynchronizeChecklist::TAction Action = TSynchronizeChecklist::TAction(ActionIndex);
  471. if (FTotals[ActionIndex] > 0)
  472. {
  473. // if direction is overriden to an action that is otherwise not possible
  474. // in given synchronization mode, we still want to show the stats
  475. Possible = true;
  476. }
  477. else
  478. {
  479. switch (Action)
  480. {
  481. case TSynchronizeChecklist::saNone:
  482. Possible = true;
  483. break;
  484. case TSynchronizeChecklist::saUploadNew:
  485. Possible = ((FMode == smRemote) || (FMode == smBoth)) &&
  486. FLAGCLEAR(FParams, TTerminal::spTimestamp);
  487. break;
  488. case TSynchronizeChecklist::saDownloadNew:
  489. Possible = ((FMode == smLocal) || (FMode == smBoth)) &&
  490. FLAGCLEAR(FParams, TTerminal::spTimestamp);
  491. break;
  492. case TSynchronizeChecklist::saUploadUpdate:
  493. Possible =
  494. ((FMode == smRemote) || (FMode == smBoth)) &&
  495. (FLAGCLEAR(FParams, TTerminal::spNotByTime) || FLAGSET(FParams, TTerminal::spBySize));
  496. break;
  497. case TSynchronizeChecklist::saDownloadUpdate:
  498. Possible =
  499. ((FMode == smLocal) || (FMode == smBoth)) &&
  500. (FLAGCLEAR(FParams, TTerminal::spNotByTime) || FLAGSET(FParams, TTerminal::spBySize));
  501. break;
  502. case TSynchronizeChecklist::saDeleteRemote:
  503. Possible = (FMode == smRemote) &&
  504. FLAGCLEAR(FParams, TTerminal::spTimestamp);
  505. break;
  506. case TSynchronizeChecklist::saDeleteLocal:
  507. Possible = (FMode == smLocal) &&
  508. FLAGCLEAR(FParams, TTerminal::spTimestamp);
  509. break;
  510. default:
  511. DebugFail();
  512. Possible = false;
  513. break;
  514. }
  515. }
  516. UnicodeString PanelText;
  517. if (Possible)
  518. {
  519. PanelText = FORMAT(LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 1),
  520. (FormatNumber(FChecked[ActionIndex]),
  521. FormatNumber(FTotals[ActionIndex])));
  522. if ((FChecked[ActionIndex] > 0) &&
  523. ((ActionIndex == 0) || !IsItemSizeIrrelevant(Action)))
  524. {
  525. PanelText += FORMAT(L" (%s)", (FormatBytes(FCheckedSize[ActionIndex])));
  526. }
  527. }
  528. else
  529. {
  530. PanelText = LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 2);
  531. }
  532. int TextHeight = StatusBar->Canvas->TextHeight(PanelText);
  533. int X = Rect.Left + ActionImages->Width + 4;
  534. int Y = (Rect.Top + Rect.Bottom - TextHeight) / 2;
  535. StatusBar->Canvas->TextRect(Rect, X, Y, PanelText);
  536. X = Rect.Left + 1;
  537. Y = ((Rect.Top + Rect.Bottom - ActionImages->Height) / 2);
  538. int ImageIndex = ActionIndex;
  539. ActionImages->Draw(StatusBar->Canvas, X, Y, ImageIndex, Possible);
  540. }
  541. //---------------------------------------------------------------------------
  542. int __fastcall TSynchronizeChecklistDialog::PanelCount()
  543. {
  544. // last "panel" is technical
  545. return StatusBar->Panels->Count - 1;
  546. }
  547. //---------------------------------------------------------------------------
  548. int __fastcall TSynchronizeChecklistDialog::PanelAt(int X)
  549. {
  550. int Result = 0;
  551. while ((X > StatusBar->Panels->Items[Result]->Width) &&
  552. (Result < PanelCount()))
  553. {
  554. X -= StatusBar->Panels->Items[Result]->Width;
  555. Result++;
  556. }
  557. return ((Result < StatusBar->Panels->Count - 1) ? Result : -1);
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TSynchronizeChecklistDialog::StatusBarMouseMove(
  561. TObject * /*Sender*/, TShiftState /*Shift*/, int X, int /*Y*/)
  562. {
  563. UnicodeString Hint;
  564. int IPanel = PanelAt(X);
  565. if (IPanel >= 0)
  566. {
  567. Hint = StatusBar->Panels->Items[IPanel]->Text;
  568. if (IPanel > 0)
  569. {
  570. Hint = FORMAT(L"%s\n%s", (Hint, FGeneralHint));
  571. }
  572. }
  573. if (Hint != StatusBar->Hint)
  574. {
  575. Application->CancelHint();
  576. StatusBar->Hint = Hint;
  577. }
  578. }
  579. //---------------------------------------------------------------------------
  580. void __fastcall TSynchronizeChecklistDialog::ListViewChange(
  581. TObject * /*Sender*/, TListItem * Item, TItemChange Change)
  582. {
  583. if ((Change == ctState) && (FChangingItem == Item) && (FChangingItem != NULL))
  584. {
  585. if (!FChangingItemIgnore)
  586. {
  587. DebugAssert(Item->Data != NULL);
  588. if ((FChangingItemChecked != Item->Checked) && (Item->Data != NULL))
  589. {
  590. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  591. int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
  592. int Diff = Item->Checked ? 1 : -1;
  593. FChecked[ActionIndex] += Diff;
  594. FChecked[0] += Diff;
  595. __int64 ItemSize = GetItemSize(ChecklistItem);
  596. if (!Item->Checked)
  597. {
  598. ItemSize = -ItemSize;
  599. }
  600. FCheckedSize[ActionIndex] += ItemSize;
  601. FCheckedSize[0] += ItemSize;
  602. if (!FChangingItemMass)
  603. {
  604. UpdateControls();
  605. }
  606. }
  607. }
  608. FChangingItem = NULL;
  609. }
  610. }
  611. //---------------------------------------------------------------------------
  612. void __fastcall TSynchronizeChecklistDialog::ListViewChanging(
  613. TObject * /*Sender*/, TListItem * Item, TItemChange Change,
  614. bool & /*AllowChange*/)
  615. {
  616. if (Change == ctState)
  617. {
  618. FChangingItem = Item;
  619. FChangingItemChecked = Item->Checked;
  620. }
  621. else
  622. {
  623. DebugAssert(FChangingItem == NULL);
  624. FChangingItem = NULL;
  625. }
  626. }
  627. //---------------------------------------------------------------------------
  628. void __fastcall TSynchronizeChecklistDialog::CheckAll(bool Check)
  629. {
  630. FChangingItemMass = true;
  631. try
  632. {
  633. for (int Index = 0; Index < ListView->Items->Count; Index++)
  634. {
  635. ListView->Items->Item[Index]->Checked = Check;
  636. }
  637. }
  638. __finally
  639. {
  640. FChangingItemMass = false;
  641. }
  642. UpdateControls();
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TSynchronizeChecklistDialog::CheckAllActionExecute(TObject * /*Sender*/)
  646. {
  647. CheckAll(true);
  648. }
  649. //---------------------------------------------------------------------------
  650. void __fastcall TSynchronizeChecklistDialog::UncheckAllActionExecute(TObject * /*Sender*/)
  651. {
  652. CheckAll(false);
  653. }
  654. //---------------------------------------------------------------------------
  655. void __fastcall TSynchronizeChecklistDialog::Check(bool Check)
  656. {
  657. FChangingItemMass = true;
  658. try
  659. {
  660. TListItem * Item = ListView->Selected;
  661. while (Item != NULL)
  662. {
  663. Item->Checked = Check;
  664. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  665. }
  666. }
  667. __finally
  668. {
  669. FChangingItemMass = false;
  670. }
  671. UpdateControls();
  672. }
  673. //---------------------------------------------------------------------------
  674. void __fastcall TSynchronizeChecklistDialog::CheckActionExecute(TObject * /*Sender*/)
  675. {
  676. Check(true);
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TSynchronizeChecklistDialog::UncheckActionExecute(TObject * /*Sender*/)
  680. {
  681. Check(false);
  682. }
  683. //---------------------------------------------------------------------------
  684. void __fastcall TSynchronizeChecklistDialog::ListViewSelectItem(
  685. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  686. {
  687. // Delayed update of button status in case many items are being selected at once
  688. // Also change of selection causes buttons to flash, as for short period of time,
  689. // no item is selected
  690. UpdateTimer->Enabled = true;
  691. }
  692. //---------------------------------------------------------------------------
  693. void __fastcall TSynchronizeChecklistDialog::UpdateTimerTimer(
  694. TObject * /*Sender*/)
  695. {
  696. UpdateTimer->Enabled = false;
  697. UpdateControls();
  698. }
  699. //---------------------------------------------------------------------------
  700. TListItem * __fastcall TSynchronizeChecklistDialog::SelectAll(bool Select, int Action,
  701. bool OnlyTheAction)
  702. {
  703. TListItem * Result = NULL;
  704. for (int Index = 0; Index < ListView->Items->Count; Index++)
  705. {
  706. TListItem * Item = ListView->Items->Item[Index];
  707. if (Action == 0)
  708. {
  709. Item->Selected = Select;
  710. if (Result == NULL)
  711. {
  712. Result = Item;
  713. }
  714. }
  715. else
  716. {
  717. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  718. bool WantedAction = (int(GetChecklistItemAction(ChecklistItem)) == Action);
  719. if (WantedAction || !OnlyTheAction)
  720. {
  721. Item->Selected = Select && WantedAction;
  722. if (WantedAction && (Result == NULL))
  723. {
  724. Result = Item;
  725. }
  726. }
  727. }
  728. }
  729. return Result;
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TSynchronizeChecklistDialog::SelectAllActionExecute(
  733. TObject * /*Sender*/)
  734. {
  735. SelectAll(true);
  736. }
  737. //---------------------------------------------------------------------------
  738. void __fastcall TSynchronizeChecklistDialog::StatusBarMouseDown(
  739. TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState Shift, int X,
  740. int /*Y*/)
  741. {
  742. int IPanel = PanelAt(X);
  743. if (IPanel >= 0)
  744. {
  745. TListItem * Item = SelectAll(true, IPanel, Shift.Contains(ssCtrl));
  746. if (Item != NULL)
  747. {
  748. Item->MakeVisible(false);
  749. Item->Focused = true;
  750. ListView->SetFocus();
  751. }
  752. }
  753. }
  754. //---------------------------------------------------------------------------
  755. int __fastcall TSynchronizeChecklistDialog::CompareNumber(__int64 Value1,
  756. __int64 Value2)
  757. {
  758. int Result;
  759. if (Value1 < Value2)
  760. {
  761. Result = -1;
  762. }
  763. else if (Value1 == Value2)
  764. {
  765. Result = 0;
  766. }
  767. else
  768. {
  769. Result = 1;
  770. }
  771. return Result;
  772. }
  773. //---------------------------------------------------------------------------
  774. void __fastcall TSynchronizeChecklistDialog::ListViewCompare(
  775. TObject * /*Sender*/, TListItem * Item1, TListItem * Item2, int /*Data*/,
  776. int & Compare)
  777. {
  778. const TSynchronizeChecklist::TItem * ChecklistItem1 = GetChecklistItem(Item1);
  779. const TSynchronizeChecklist::TItem * ChecklistItem2 = GetChecklistItem(Item2);
  780. TIEListViewColProperties * ColProperties =
  781. dynamic_cast<TIEListViewColProperties *>(ListView->ColProperties);
  782. switch (ColProperties->SortColumn)
  783. {
  784. case 0: // name
  785. Compare = AnsiCompareText(ChecklistItem1->GetFileName(), ChecklistItem2->GetFileName());
  786. break;
  787. // sorting by local and remote dir is the same
  788. case 1: // local dir
  789. case 5: // remote dir
  790. Compare = 0; // default sorting
  791. break;
  792. case 2: // local size
  793. Compare = CompareNumber(ChecklistItem1->Local.Size, ChecklistItem2->Local.Size);
  794. break;
  795. case 3: // local changed
  796. Compare = CompareFileTime(ChecklistItem1->Local.Modification,
  797. ChecklistItem2->Local.Modification);
  798. break;
  799. case ImageColumnIndex: // action
  800. Compare = CompareNumber(GetChecklistItemAction(ChecklistItem1), GetChecklistItemAction(ChecklistItem2));
  801. break;
  802. case 6: // remote size
  803. Compare = CompareNumber(ChecklistItem1->Remote.Size, ChecklistItem2->Remote.Size);
  804. break;
  805. case 7: // remote changed
  806. Compare = CompareFileTime(ChecklistItem1->Remote.Modification,
  807. ChecklistItem2->Remote.Modification);
  808. break;
  809. }
  810. if (Compare == 0)
  811. {
  812. if (!ChecklistItem1->Local.Directory.IsEmpty())
  813. {
  814. Compare = AnsiCompareText(ChecklistItem1->Local.Directory, ChecklistItem2->Local.Directory);
  815. }
  816. else
  817. {
  818. DebugAssert(!ChecklistItem1->Remote.Directory.IsEmpty());
  819. Compare = AnsiCompareText(ChecklistItem1->Remote.Directory, ChecklistItem2->Remote.Directory);
  820. }
  821. if (Compare == 0)
  822. {
  823. Compare = AnsiCompareText(ChecklistItem1->GetFileName(), ChecklistItem2->GetFileName());
  824. }
  825. }
  826. if (!ColProperties->SortAscending)
  827. {
  828. Compare = -Compare;
  829. }
  830. }
  831. //---------------------------------------------------------------------------
  832. void __fastcall TSynchronizeChecklistDialog::ListViewSecondaryColumnHeader(
  833. TCustomIEListView * /*Sender*/, int Index, int & SecondaryColumn)
  834. {
  835. // "remote dir" column is sorting alias for "local dir" column
  836. if (Index == 5)
  837. {
  838. SecondaryColumn = 1;
  839. }
  840. else
  841. {
  842. SecondaryColumn = -1;
  843. }
  844. }
  845. //---------------------------------------------------------------------------
  846. void __fastcall TSynchronizeChecklistDialog::ListViewContextPopup(
  847. TObject * Sender, TPoint & MousePos, bool & Handled)
  848. {
  849. // to update source popup menu before TBX menu is created
  850. UpdateControls();
  851. MenuPopup(Sender, MousePos, Handled);
  852. }
  853. //---------------------------------------------------------------------------
  854. void __fastcall TSynchronizeChecklistDialog::CustomCommandsActionExecute(
  855. TObject * /*Sender*/)
  856. {
  857. TStrings * LocalFileList = new TStringList();
  858. TStrings * RemoteFileList = new TStringList();
  859. try
  860. {
  861. TListItem * Item = ListView->Selected;
  862. DebugAssert(Item != NULL);
  863. while (Item != NULL)
  864. {
  865. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  866. DebugAssert((GetChecklistItemAction(ChecklistItem) == TSynchronizeChecklist::saUploadUpdate) ||
  867. (GetChecklistItemAction(ChecklistItem) == TSynchronizeChecklist::saDownloadUpdate));
  868. DebugAssert(ChecklistItem->RemoteFile != NULL);
  869. UnicodeString LocalPath =
  870. IncludeTrailingBackslash(ChecklistItem->Local.Directory) +
  871. ChecklistItem->Local.FileName;
  872. LocalFileList->Add(LocalPath);
  873. UnicodeString RemotePath =
  874. UnixIncludeTrailingBackslash(ChecklistItem->Remote.Directory) +
  875. ChecklistItem->Remote.FileName;
  876. RemoteFileList->AddObject(RemotePath, ChecklistItem->RemoteFile);
  877. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  878. }
  879. }
  880. catch(...)
  881. {
  882. delete LocalFileList;
  883. delete RemoteFileList;
  884. throw;
  885. }
  886. DebugAssert(FOnCustomCommandMenu != NULL);
  887. FOnCustomCommandMenu(CustomCommandsAction, LocalFileList, RemoteFileList);
  888. }
  889. //---------------------------------------------------------------------------
  890. void __fastcall TSynchronizeChecklistDialog::UpdateStatusBarSize()
  891. {
  892. int PanelWidth = Min(StatusBar->Width / PanelCount(), ScaleByTextHeight(this, 160));
  893. for (int Index = 0; Index < PanelCount(); Index++)
  894. {
  895. StatusBar->Panels->Items[Index]->Width = PanelWidth;
  896. }
  897. }
  898. //---------------------------------------------------------------------------
  899. void __fastcall TSynchronizeChecklistDialog::StatusBarResize(TObject * /*Sender*/)
  900. {
  901. UpdateStatusBarSize();
  902. }
  903. //---------------------------------------------------------------------------
  904. const TSynchronizeChecklist::TItem * TSynchronizeChecklistDialog::GetChecklistItem(
  905. TListItem * Item)
  906. {
  907. return static_cast<const TSynchronizeChecklist::TItem *>(Item->Data);
  908. }
  909. //---------------------------------------------------------------------------
  910. TSynchronizeChecklist::TAction & TSynchronizeChecklistDialog::GetChecklistItemAction(
  911. const TSynchronizeChecklist::TItem * ChecklistItem)
  912. {
  913. TActions::iterator i = FActions.find(ChecklistItem);
  914. if (i == FActions.end())
  915. {
  916. throw EInvalidOperation(L"");
  917. }
  918. return i->second;
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TSynchronizeChecklistDialog::ReverseActionExecute(TObject * /*Sender*/)
  922. {
  923. TAutoFlag Flag(FChangingItemMass);
  924. TListItem * Item = ListView->Selected;
  925. while (Item != NULL)
  926. {
  927. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  928. TSynchronizeChecklist::TAction & Action = GetChecklistItemAction(ChecklistItem);
  929. TSynchronizeChecklist::TAction NewAction = TSynchronizeChecklist::Reverse(Action);
  930. if (DebugAlwaysTrue(Action != NewAction))
  931. {
  932. int ActionIndex = int(Action);
  933. FTotals[ActionIndex]--;
  934. if (Item->Checked)
  935. {
  936. FChecked[ActionIndex]--;
  937. __int64 ItemSize = GetItemSize(ChecklistItem);
  938. FCheckedSize[ActionIndex] -= ItemSize;
  939. FCheckedSize[0] -= ItemSize;
  940. }
  941. Action = NewAction;
  942. ActionIndex = int(Action);
  943. FTotals[ActionIndex]++;
  944. if (Item->Checked)
  945. {
  946. FChecked[ActionIndex]++;
  947. // item size may differ with action (0 for delete, but non-0 for new file transfer)
  948. __int64 ItemSize = GetItemSize(ChecklistItem);
  949. FCheckedSize[ActionIndex] += ItemSize;
  950. FCheckedSize[0] += ItemSize;
  951. }
  952. LoadItem(Item);
  953. }
  954. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  955. }
  956. Flag.Release();
  957. UpdateControls();
  958. }
  959. //---------------------------------------------------------------------------
  960. void __fastcall TSynchronizeChecklistDialog::ListViewClick(TObject * /*Sender*/)
  961. {
  962. TKeyboardState KeyState;
  963. GetKeyboardState(KeyState);
  964. TShiftState ShiftState = KeyboardStateToShiftState(KeyState);
  965. // when selecting, do not reverse, even when user clicked on action column
  966. if (!ShiftState.Contains(ssShift) && !ShiftState.Contains(ssCtrl))
  967. {
  968. TPoint P = ListView->ScreenToClient(Mouse->CursorPos);
  969. TRect R = GetColumnHeaderRect(ImageColumnIndex);
  970. if ((R.Left <= P.x) && (P.x <= R.Right))
  971. {
  972. // If no item was selected before the click, the action is not enabled yet here,
  973. // and Execute would be noop, force update
  974. UpdateControls();
  975. ReverseAction->Execute();
  976. }
  977. }
  978. }
  979. //---------------------------------------------------------------------------
  980. void __fastcall TSynchronizeChecklistDialog::Dispatch(void * Message)
  981. {
  982. TMessage * M = reinterpret_cast<TMessage*>(Message);
  983. if (M->Msg == WM_SYSCOMMAND)
  984. {
  985. if (!HandleMinimizeSysCommand(*M))
  986. {
  987. TForm::Dispatch(Message);
  988. }
  989. }
  990. else if (M->Msg == CM_DPICHANGED)
  991. {
  992. CMDpiChanged(*M);
  993. }
  994. else if (M->Msg == WM_WANTS_MOUSEWHEEL_INACTIVE)
  995. {
  996. M->Result = FSynchronizing ? 1 : 0;
  997. }
  998. else
  999. {
  1000. TForm::Dispatch(Message);
  1001. }
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. void __fastcall TSynchronizeChecklistDialog::UpdateImages()
  1005. {
  1006. ListView->SmallImages = ShellImageListForControl(this, ilsSmall);
  1007. }
  1008. //---------------------------------------------------------------------------
  1009. void __fastcall TSynchronizeChecklistDialog::CMDpiChanged(TMessage & Message)
  1010. {
  1011. TForm::Dispatch(&Message);
  1012. UpdateImages();
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TSynchronizeChecklistDialog::ProcessedItem(const void * Token)
  1016. {
  1017. TTokens::const_iterator I = FTokens.find(Token);
  1018. if (DebugAlwaysTrue(I != FTokens.end()))
  1019. {
  1020. TListItem * Item = I->second;
  1021. DebugAssert(Item->Checked);
  1022. Item->Checked = false;
  1023. Item->MakeVisible(false);
  1024. }
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. void __fastcall TSynchronizeChecklistDialog::OkButtonClick(TObject * /*Sender*/)
  1028. {
  1029. ListView->SelectAll(smNone);
  1030. FTokens.clear();
  1031. for (int Index = 0; Index < ListView->Items->Count; Index++)
  1032. {
  1033. TListItem * Item = ListView->Items->Item[Index];
  1034. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  1035. FChecklist->Update(ChecklistItem, Item->Checked, GetChecklistItemAction(ChecklistItem));
  1036. FTokens.insert(std::make_pair(ChecklistItem, Item));
  1037. if (ChecklistItem->RemoteFile != NULL)
  1038. {
  1039. FTokens.insert(std::make_pair(ChecklistItem->RemoteFile, Item));
  1040. }
  1041. }
  1042. TAutoFlag Flag(FSynchronizing);
  1043. UpdateControls();
  1044. try
  1045. {
  1046. FOnSynchronize(FToken, ProcessedItem);
  1047. }
  1048. catch (Exception & E)
  1049. {
  1050. FException.reset(CloneException(&E));
  1051. }
  1052. }
  1053. //---------------------------------------------------------------------------
  1054. void __fastcall TSynchronizeChecklistDialog::CalculateSizeActionExecute(TObject * /*Sender*/)
  1055. {
  1056. std::map<const TSynchronizeChecklist::TItem *, TListItem *> ChecklistToListViewMap;
  1057. TSynchronizeChecklistItemList Items;
  1058. TListItem * Item = ListView->Selected;
  1059. while (Item != NULL)
  1060. {
  1061. const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
  1062. ChecklistToListViewMap.insert(std::make_pair(ChecklistItem, Item));
  1063. Items.push_back(ChecklistItem);
  1064. if (Item->Checked)
  1065. {
  1066. __int64 ItemSize = GetItemSize(ChecklistItem);
  1067. int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
  1068. FCheckedSize[ActionIndex] -= ItemSize;
  1069. FCheckedSize[0] -= ItemSize;
  1070. }
  1071. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  1072. }
  1073. try
  1074. {
  1075. FOnSynchronizeChecklistCalculateSize(FChecklist, Items, FToken);
  1076. }
  1077. __finally
  1078. {
  1079. TSynchronizeChecklistItemList::const_iterator Iter = Items.begin();
  1080. while (Iter != Items.end())
  1081. {
  1082. const TSynchronizeChecklist::TItem * ChecklistItem = *Iter;
  1083. TListItem * Item = ChecklistToListViewMap[ChecklistItem];
  1084. LoadItem(Item);
  1085. if (Item->Checked)
  1086. {
  1087. __int64 ItemSize = GetItemSize(ChecklistItem);
  1088. int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
  1089. FCheckedSize[ActionIndex] += ItemSize;
  1090. FCheckedSize[0] += ItemSize;
  1091. }
  1092. Iter++;
  1093. }
  1094. UpdateControls();
  1095. }
  1096. }
  1097. //---------------------------------------------------------------------------