| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863 | 
							- //---------------------------------------------------------------------
 
- #include <vcl.h>
 
- #pragma hdrstop
 
- #include <Common.h>
 
- #include "WinInterface.h"
 
- #include "SynchronizeChecklist.h"
 
- #include <Terminal.h>
 
- #include <TextsWin.h>
 
- #include <CoreMain.h>
 
- #include <VCLCommon.h>
 
- #include <Tools.h>
 
- #include <BaseUtils.hpp>
 
- #include <Math.hpp>
 
- #include <WinConfiguration.h>
 
- #include <TerminalManager.h>
 
- #include <System.IOUtils.hpp>
 
- #include <System.StrUtils.hpp>
 
- #include <algorithm>
 
- //---------------------------------------------------------------------
 
- #pragma link "IEListView"
 
- #pragma link "NortonLikeListView"
 
- #pragma link "PngImageList"
 
- #pragma resource "*.dfm"
 
- //---------------------------------------------------------------------
 
- const int ImageColumnIndex = 4;
 
- //---------------------------------------------------------------------
 
- bool __fastcall DoSynchronizeChecklistDialog(TSynchronizeChecklist * Checklist,
 
-   TSynchronizeMode Mode, int Params,
 
-   const UnicodeString LocalDirectory, const UnicodeString RemoteDirectory,
 
-   TCustomCommandMenuEvent OnCustomCommandMenu, TFullSynchronizeEvent OnSynchronize,
 
-   TQueueSynchronizeEvent OnQueueSynchronize,
 
-   TSynchronizeChecklistCalculateSize OnSynchronizeChecklistCalculateSize, TSynchronizeMoveEvent OnSynchronizeMove,
 
-   TSynchronizeExploreEvent OnSynchronizeExplore, void * Token)
 
- {
 
-   std::unique_ptr<TSynchronizeChecklistDialog> Dialog(
 
-     new TSynchronizeChecklistDialog(
 
-       Application, Mode, Params, LocalDirectory, RemoteDirectory, OnCustomCommandMenu, OnSynchronize,
 
-       OnQueueSynchronize, OnSynchronizeChecklistCalculateSize, OnSynchronizeMove, OnSynchronizeExplore, Token));
 
-   return Dialog->Execute(Checklist);
 
- }
 
- //---------------------------------------------------------------------
 
- __fastcall TSynchronizeChecklistDialog::TSynchronizeChecklistDialog(
 
-   TComponent * AOwner, TSynchronizeMode Mode, int Params,
 
-   const UnicodeString & LocalDirectory, const UnicodeString & RemoteDirectory,
 
-   TCustomCommandMenuEvent OnCustomCommandMenu, TFullSynchronizeEvent OnSynchronize,
 
-   TQueueSynchronizeEvent OnQueueSynchronize,
 
-   TSynchronizeChecklistCalculateSize OnSynchronizeChecklistCalculateSize, TSynchronizeMoveEvent OnSynchronizeMove,
 
-   TSynchronizeExploreEvent OnSynchronizeExplore, void * Token)
 
-   : TForm(AOwner)
 
- {
 
-   FFormRestored = false;
 
-   FMode = Mode;
 
-   FParams = Params;
 
-   FLocalDirectory = ExcludeTrailingBackslash(LocalDirectory);
 
-   FRemoteDirectory = UnixExcludeTrailingBackslash(RemoteDirectory);
 
-   FOnCustomCommandMenu = OnCustomCommandMenu;
 
-   FOnSynchronizeChecklistCalculateSize = OnSynchronizeChecklistCalculateSize;
 
-   FOnSynchronizeMove = OnSynchronizeMove;
 
-   FOnSynchronizeExplore = OnSynchronizeExplore;
 
-   DebugAssert(OnSynchronize != NULL);
 
-   FOnSynchronize = OnSynchronize;
 
-   FOnQueueSynchronize = OnQueueSynchronize;
 
-   FToken = Token;
 
-   UseSystemSettings(this);
 
-   UseDesktopFont(ListView2);
 
-   UseDesktopFont(StatusBar);
 
-   FChecklist = NULL;
 
-   FChangingItem = NULL;
 
-   FChangingItemIgnore = false;
 
-   FChangingItemMass = false;
 
-   FSynchronizing = false;
 
-   FMoveCandidatesValidForSort = MaxInt;
 
-   FDirectories = 0;
 
-   SelectScaledImageList(ActionImages);
 
-   FOrigListViewWindowProc = ListView2->WindowProc;
 
-   ListView2->WindowProc = ListViewWindowProc;
 
-   FOrigStatusBarWindowProc = StatusBar->WindowProc;
 
-   StatusBar->WindowProc = StatusBarWindowProc;
 
-   UpdateImages();
 
-   CustomCommandsAction->Visible = (FOnCustomCommandMenu != NULL);
 
-   // button visibility cannot be bound to action visibility
 
-   CustomCommandsButton2->Visible = CustomCommandsAction->Visible;
 
-   MenuButton(CustomCommandsButton2);
 
-   MenuButton(ToolsMenuButton);
 
-   // Other dialogs use !IsMainFormLike
 
-   if (FOnQueueSynchronize != NULL)
 
-   {
 
-     OkButton->Style = TCustomButton::bsSplitButton;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- __fastcall TSynchronizeChecklistDialog::~TSynchronizeChecklistDialog()
 
- {
 
-   StatusBar->WindowProc = FOrigStatusBarWindowProc;
 
-   ListView2->WindowProc = FOrigListViewWindowProc;
 
- }
 
- //---------------------------------------------------------------------
 
- bool __fastcall TSynchronizeChecklistDialog::Execute(TSynchronizeChecklist * Checklist)
 
- {
 
-   FChecklist = Checklist;
 
-   bool Result = (ShowModal() == DefaultResult(this));
 
-   if (Result)
 
-   {
 
-     TSynchronizeChecklistConfiguration FormConfiguration =
 
-       CustomWinConfiguration->SynchronizeChecklist;
 
-     FormConfiguration.ListParams = ListView2->ColProperties->ParamsStr;
 
-     UnicodeString WindowParams = FormConfiguration.WindowParams;
 
-     // if there is no main window, keep previous "custom pos" indication,
 
-     bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
 
-     if (!IsMainFormLike(this))
 
-     {
 
-       CustomPos = (Application->MainForm->BoundsRect != BoundsRect);
 
-     }
 
-     FormConfiguration.WindowParams =
 
-       FORMAT(L"%d;%s", ((CustomPos ? 1 : 0), StoreForm(this)));
 
-     CustomWinConfiguration->SynchronizeChecklist = FormConfiguration;
 
-   }
 
-   if (FException.get() != NULL)
 
-   {
 
-     RethrowException(FException.get());
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdateCaption()
 
- {
 
-   TTerminalManager * Manager = TTerminalManager::Instance();
 
-   UnicodeString Title = Manager->GetAppProgressTitle();
 
-   UnicodeString StatusTitle = LoadStr(FSynchronizing ? SYNCHRONIZE_PROGRESS_SYNCHRONIZE2 : SYNCHRONIZE_CHECKLIST_CAPTION);
 
-   if (Title.Pos(StatusTitle) <= 0)
 
-   {
 
-     AddToList(Title, StatusTitle, TitleSeparator);
 
-   }
 
-   Caption = Manager->FormatFormCaptionWithSession(this, Title);
 
- }
 
- //---------------------------------------------------------------------------
 
- static bool IsTransferNewAction(TSynchronizeChecklist::TAction Action)
 
- {
 
-   return (Action == TSynchronizeChecklist::saUploadNew) || (Action == TSynchronizeChecklist::saDownloadNew);
 
- }
 
- //---------------------------------------------------------------------------
 
- static TSynchronizeChecklist::TAction GetOppositeMoveAction(TSynchronizeChecklist::TAction Action1)
 
- {
 
-   switch (Action1)
 
-   {
 
-     case TSynchronizeChecklist::saUploadNew:
 
-       return TSynchronizeChecklist::saDeleteRemote;
 
-     case TSynchronizeChecklist::saDownloadNew:
 
-       return TSynchronizeChecklist::saDeleteLocal;
 
-     case TSynchronizeChecklist::saDeleteRemote:
 
-       return TSynchronizeChecklist::saUploadNew;
 
-     case TSynchronizeChecklist::saDeleteLocal:
 
-       return TSynchronizeChecklist::saDownloadNew;
 
-     default:
 
-       return TSynchronizeChecklist::saNone;
 
-   }
 
- }
 
- //---------------------------------------------------------------------
 
- struct TMoveActionData
 
- {
 
-   TSynchronizeChecklist::TAction Action;
 
-   bool AllItemsFiles;
 
-   bool AllItemsDirectories;
 
-   int ItemsCount;
 
-   std::unique_ptr<TStrings> FileList;
 
-   typedef std::vector<const TSynchronizeChecklist::TItem *> TChecklistItems;
 
-   TChecklistItems ChecklistItems;
 
-   TMoveActionData()
 
-   {
 
-     Action = TSynchronizeChecklist::saNone;
 
-     AllItemsFiles = true;
 
-     AllItemsDirectories = true;
 
-     ItemsCount = 0;
 
-   }
 
-   bool Collect(const TSynchronizeChecklist::TItem * ChecklistItem, TSynchronizeChecklist::TAction AAction, bool CollectFileList)
 
-   {
 
-     bool Result = (ItemsCount == 0) || (Action == AAction);
 
-     if (Result)
 
-     {
 
-       Action = AAction;
 
-       if (ChecklistItem->IsDirectory)
 
-       {
 
-         AllItemsFiles = false;
 
-       }
 
-       else
 
-       {
 
-         AllItemsDirectories = false;
 
-       }
 
-       ItemsCount++;
 
-       if (CollectFileList)
 
-       {
 
-         UnicodeString FileName;
 
-         TObject * Object = NULL;
 
-         if (Action == TSynchronizeChecklist::saDeleteRemote)
 
-         {
 
-           FileName = ChecklistItem->GetRemotePath();
 
-           Object = ChecklistItem->RemoteFile;
 
-         }
 
-         else if (Action == TSynchronizeChecklist::saDeleteLocal)
 
-         {
 
-           FileName = ChecklistItem->GetLocalPath();
 
-         }
 
-         bool CollectFile = !FileName.IsEmpty();
 
-         DebugAssert(CollectFile == IsTransferNewAction(GetOppositeMoveAction(Action)));
 
-         if (CollectFile)
 
-         {
 
-           if (FileList.get() == NULL)
 
-           {
 
-             FileList.reset(new TStringList());
 
-           }
 
-           FileList->AddObject(FileName, Object);
 
-         }
 
-         ChecklistItems.push_back(ChecklistItem);
 
-       }
 
-     }
 
-     return Result;
 
-   }
 
-   bool IsOnlyDirectoryTransferAction()
 
-   {
 
-     return
 
-       IsTransferNewAction(Action) &&
 
-       (ItemsCount == 1) &&
 
-       AllItemsDirectories &&
 
-       DebugAlwaysTrue(!AllItemsFiles);
 
-   }
 
- };
 
- //---------------------------------------------------------------------
 
- struct TMoveData
 
- {
 
-   TMoveActionData FirstAction;
 
-   TMoveActionData SecondAction;
 
-   bool ThreeActions;
 
-   TMoveData(bool CollectFileList)
 
-   {
 
-     ThreeActions = false;
 
-     FCollectFileList = CollectFileList;
 
-   }
 
-   void Collect(const TSynchronizeChecklist::TItem * ChecklistItem, TSynchronizeChecklist::TAction Action)
 
-   {
 
-     if (!FirstAction.Collect(ChecklistItem, Action, FCollectFileList) &&
 
-         !SecondAction.Collect(ChecklistItem, Action, FCollectFileList))
 
-     {
 
-       ThreeActions = true;
 
-     }
 
-   }
 
- private:
 
-   bool FCollectFileList;
 
- };
 
- //---------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdateControls()
 
- {
 
-   UpdateCaption();
 
-   StatusBar->Invalidate();
 
-   bool AllChecked = true;
 
-   bool AllUnchecked = true;
 
-   bool AnyBoth = false;
 
-   bool AnyNonBoth = false;
 
-   bool AnyDirectory = false;
 
-   TMoveData MoveData(false);
 
-   TListItem * Item = NULL;
 
-   while (IterateSelectedItems(Item))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-     if ((Action == TSynchronizeChecklist::saUploadUpdate) ||
 
-         (Action == TSynchronizeChecklist::saDownloadUpdate))
 
-     {
 
-       AnyBoth = true;
 
-     }
 
-     else
 
-     {
 
-       AnyNonBoth = true;
 
-     }
 
-     MoveData.Collect(ChecklistItem, Action);
 
-     if (Item->Checked)
 
-     {
 
-       AllUnchecked = false;
 
-     }
 
-     else
 
-     {
 
-       AllChecked = false;
 
-     }
 
-     if (ChecklistItem->IsDirectory)
 
-     {
 
-       AnyDirectory = true;
 
-     }
 
-   }
 
-   int SelCount = ListView2->SelCount;
 
-   EnableControl(OkButton, (FChecked[0] > 0) && !FSynchronizing);
 
-   EnableControl(CancelButton, !FSynchronizing);
 
-   EnableControl(HelpButton, !FSynchronizing);
 
-   CheckAction->Enabled = !AllChecked && !FSynchronizing;
 
-   UncheckAction->Enabled = !AllUnchecked && !FSynchronizing;
 
-   CheckAllAction->Enabled = (FChecked[0] < FTotals[0]) && !FSynchronizing;
 
-   UncheckAllAction->Enabled = (FChecked[0] > 0) && !FSynchronizing;
 
-   CheckDirectoryAction->Enabled = CheckAllAction->Enabled; // sic
 
-   UncheckDirectoryAction->Enabled = UncheckAllAction->Enabled; // sic
 
-   CustomCommandsAction->Enabled = AnyBoth && !AnyNonBoth && DebugAlwaysTrue(!FSynchronizing);
 
-   ReverseAction->Enabled = (SelCount > 0) && DebugAlwaysTrue(!FSynchronizing);
 
-   MoveAction->Enabled =
 
-     // All actions are of exactly two and opposite types
 
-     (MoveData.SecondAction.Action != TSynchronizeChecklist::saNone) &&
 
-     !MoveData.ThreeActions &&
 
-     (GetOppositeMoveAction(MoveData.FirstAction.Action) == MoveData.SecondAction.Action) &&
 
-     // ... and there are exactly two of them of the same file/dir type
 
-     (((SelCount == 2) && (MoveData.FirstAction.AllItemsFiles == MoveData.SecondAction.AllItemsFiles)) ||
 
-     // ... or the "transfer new" side is exactly one directory
 
-      MoveData.FirstAction.IsOnlyDirectoryTransferAction() ||
 
-      MoveData.SecondAction.IsOnlyDirectoryTransferAction());
 
-   CalculateSizeAction->Enabled = (SelCount > 0) && AnyDirectory && DebugAlwaysTrue(!FSynchronizing);
 
-   CalculateSizeAllAction->Enabled = (FDirectories > 0) && !FSynchronizing;
 
-   TSynchronizeChecklist::TAction SelectedItemAction =
 
-     (SelCount == 1) ? GetChecklistItemAction(GetChecklistItem(ListView2->Selected)) : TSynchronizeChecklist::saNone;
 
-   ExploreLocalAction2->Enabled = (SelCount == 1) && (SelectedItemAction != TSynchronizeChecklist::saDeleteRemote);
 
-   ExploreRemoteAction2->Enabled = (SelCount == 1) && (SelectedItemAction != TSynchronizeChecklist::saDeleteLocal);
 
-   LocalPathToClipboardAction->Enabled = (SelCount > 0);
 
-   RemotePathToClipboardAction->Enabled = LocalPathToClipboardAction->Enabled;
 
-   int Count = ListView2->Items->Count;
 
-   DebugAssert(FTotals[0] == Count);
 
-   SelectAllAction->Enabled = (SelCount < Count) && !FSynchronizing;
 
-   FindMoveCandidateAction->Enabled = (Count > 0) && !FSynchronizing;
 
- }
 
- //---------------------------------------------------------------------------
 
- bool __fastcall TSynchronizeChecklistDialog::GetWindowParams(UnicodeString & WindowParams)
 
- {
 
-   WindowParams = CustomWinConfiguration->SynchronizeChecklist.WindowParams;
 
-   bool CustomPos = (StrToIntDef(CutToChar(WindowParams, L';', true), 0) != 0);
 
-   return CustomPos || IsMainFormLike(this);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CreateParams(TCreateParams & Params)
 
- {
 
-   UnicodeString WindowParams;
 
-   if (GetWindowParams(WindowParams))
 
-   {
 
-     // This is only to set correct TForm::Position. Actual bounds are set later after DPI scaling
 
-     RestoreForm(WindowParams, this, true);
 
-   }
 
-   TForm::CreateParams(Params);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::HelpButtonClick(TObject * /*Sender*/)
 
- {
 
-   FormHelp(this);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::AddSubItem(TListItem * Item, int & Index, const UnicodeString & S)
 
- {
 
-   if (Index < Item->SubItems->Count)
 
-   {
 
-     Item->SubItems->Strings[Index] = S;
 
-   }
 
-   else
 
-   {
 
-     DebugAssert(Index == Item->SubItems->Count);
 
-     Item->SubItems->Add(S);
 
-   }
 
-   Index++;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::LoadItem(TListItem * Item)
 
- {
 
-   UnicodeString S;
 
-   const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-   if (ChecklistItem->ImageIndex >= 0)
 
-   {
 
-     Item->ImageIndex = ChecklistItem->ImageIndex;
 
-   }
 
-   else
 
-   {
 
-     Item->ImageIndex = FakeFileImageIndex(ChecklistItem->GetFileName(),
 
-       FLAGMASK(ChecklistItem->IsDirectory, FILE_ATTRIBUTE_DIRECTORY));
 
-   }
 
-   S = ChecklistItem->GetFileName();
 
-   if (ChecklistItem->IsDirectory)
 
-   {
 
-     S = IncludeTrailingBackslash(S);
 
-   }
 
-   Item->Caption = S;
 
-   int Index = 0;
 
-   TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-   if (Action == TSynchronizeChecklist::saDeleteRemote)
 
-   {
 
-     AddSubItem(Item, Index, L"");
 
-     AddSubItem(Item, Index, L"");
 
-     AddSubItem(Item, Index, L"");
 
-   }
 
-   else
 
-   {
 
-     S = ChecklistItem->Local.Directory;
 
-     if (AnsiSameText(FLocalDirectory, S.SubString(1, FLocalDirectory.Length())))
 
-     {
 
-       S[1] = L'.';
 
-       S.Delete(2, FLocalDirectory.Length() - 1);
 
-     }
 
-     else
 
-     {
 
-       DebugFail();
 
-     }
 
-     AddSubItem(Item, Index, S);
 
-     if (Action == TSynchronizeChecklist::saDownloadNew)
 
-     {
 
-       AddSubItem(Item, Index, L"");
 
-       AddSubItem(Item, Index, L"");
 
-     }
 
-     else
 
-     {
 
-       if (!ChecklistItem->HasSize())
 
-       {
 
-         AddSubItem(Item, Index, L"");
 
-       }
 
-       else
 
-       {
 
-         AddSubItem(Item, Index,
 
-           FormatPanelBytes(ChecklistItem->Local.Size, WinConfiguration->FormatSizeBytes));
 
-       }
 
-       AddSubItem(Item, Index,
 
-         UserModificationStr(ChecklistItem->Local.Modification,
 
-           ChecklistItem->Local.ModificationFmt));
 
-     }
 
-   }
 
-   AddSubItem(Item, Index, L"");
 
-   DebugAssert(Index == ImageColumnIndex);
 
-   if (Action == TSynchronizeChecklist::saDeleteLocal)
 
-   {
 
-     AddSubItem(Item, Index, L"");
 
-     AddSubItem(Item, Index, L"");
 
-     AddSubItem(Item, Index, L"");
 
-   }
 
-   else
 
-   {
 
-     S = ChecklistItem->Remote.Directory;
 
-     if (AnsiSameText(FRemoteDirectory, S.SubString(1, FRemoteDirectory.Length())))
 
-     {
 
-       S[1] = L'.';
 
-       S.Delete(2, FRemoteDirectory.Length() - 1);
 
-     }
 
-     else
 
-     {
 
-       DebugFail();
 
-     }
 
-     AddSubItem(Item, Index, S);
 
-     if (Action == TSynchronizeChecklist::saUploadNew)
 
-     {
 
-       AddSubItem(Item, Index, L"");
 
-       AddSubItem(Item, Index, L"");
 
-     }
 
-     else
 
-     {
 
-       if (!ChecklistItem->HasSize())
 
-       {
 
-         AddSubItem(Item, Index, L"");
 
-       }
 
-       else
 
-       {
 
-         AddSubItem(Item, Index,
 
-           FormatPanelBytes(ChecklistItem->Remote.Size, WinConfiguration->FormatSizeBytes));
 
-       }
 
-       AddSubItem(Item, Index, UserModificationStr(ChecklistItem->Remote.Modification,
 
-         ChecklistItem->Remote.ModificationFmt));
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CountItemSize(const TSynchronizeChecklist::TItem * ChecklistItem, int Factor)
 
- {
 
-   TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-   int ActionIndex = int(Action);
 
-   __int64 ItemSize = ChecklistItem->GetSize(Action);
 
-   FCheckedSize[ActionIndex] += Factor * ItemSize;
 
-   FCheckedSize[0] += Factor * ItemSize;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CountItem(const TSynchronizeChecklist::TItem * ChecklistItem, int Factor)
 
- {
 
-   int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
 
-   FChecked[ActionIndex] += Factor;
 
-   FChecked[0] += Factor;
 
-   CountItemSize(ChecklistItem, Factor);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CountItemTotal(const TSynchronizeChecklist::TItem * ChecklistItem, int Factor)
 
- {
 
-   FTotals[0] += Factor;
 
-   int ActionIndex = int(GetChecklistItemAction(ChecklistItem));
 
-   FTotals[ActionIndex] += Factor;
 
-   if (ChecklistItem->IsDirectory)
 
-   {
 
-     FDirectories += Factor;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::LoadList()
 
- {
 
-   memset(&FTotals, 0, sizeof(FTotals));
 
-   memset(&FChecked, 0, sizeof(FChecked));
 
-   memset(&FCheckedSize, 0, sizeof(FCheckedSize));
 
-   FDirectories = 0;
 
-   ListView2->Items->BeginUpdate();
 
-   try
 
-   {
 
-     ListView2->Items->Clear();
 
-     for (int Index = 0; Index < FChecklist->Count; Index++)
 
-     {
 
-       const TSynchronizeChecklist::TItem * ChecklistItem =
 
-         FChecklist->Item[ListView2->Items->Count];
 
-       FChangingItemIgnore = true;
 
-       try
 
-       {
 
-         TListItem * Item = ListView2->Items->Add();
 
-         TSynchronizeChecklist::TAction Action = ChecklistItem->Action;
 
-         FActions.insert(std::make_pair(ChecklistItem, Action));
 
-         FChecklistToListViewMap.insert(std::make_pair(ChecklistItem, Item));
 
-         Item->Data = const_cast<TSynchronizeChecklist::TItem *>(ChecklistItem);
 
-         Item->Checked = ChecklistItem->Checked;
 
-         LoadItem(Item);
 
-       }
 
-       __finally
 
-       {
 
-         FChangingItemIgnore = false;
 
-       }
 
-       CountItemTotal(ChecklistItem, 1);
 
-       if (ChecklistItem->Checked)
 
-       {
 
-         CountItem(ChecklistItem, 1);
 
-       }
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     ListView2->Items->EndUpdate();
 
-   }
 
-   ListView2->AlphaSort();
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::FormShow(TObject * /*Sender*/)
 
- {
 
-   // Moved here from CreateParams (see also TEditorForm::CreateParams), because there it breaks per-monitor DPI.
 
-   // For example BoundsRect is matched to the main form too soon, so it gets rescaled later.
 
-   // Also it happens before constructor, what causes UseDesktopFont-flagged controls to rescale twice.
 
-   // But Position is already set in the CreateParams, as it cannot be set here anymore.
 
-   if (!FFormRestored)
 
-   {
 
-     FFormRestored = True;
 
-     UnicodeString WindowParams;
 
-     if (GetWindowParams(WindowParams))
 
-     {
 
-       RestoreForm(WindowParams, this);
 
-     }
 
-     else
 
-     {
 
-       BoundsRect = Application->MainForm->BoundsRect;
 
-     }
 
-     FlashOnBackground();
 
-   }
 
-   ListView2->ColProperties->ParamsStr = CustomWinConfiguration->SynchronizeChecklist.ListParams;
 
-   LoadList();
 
-   UpdateStatusBarSize();
 
- }
 
- //---------------------------------------------------------------------------
 
- TRect __fastcall TSynchronizeChecklistDialog::GetColumnHeaderRect(int Index)
 
- {
 
-   HWND HeaderHandle = ListView_GetHeader(ListView2->Handle);
 
-   TRect R;
 
-   Header_GetItemRect(HeaderHandle, Index, &R);
 
-   // Can be simplified using GetScrollPos
 
-   TScrollInfo ScrollInfo;
 
-   ZeroMemory(&ScrollInfo, sizeof(ScrollInfo));
 
-   ScrollInfo.cbSize = sizeof(ScrollInfo);
 
-   ScrollInfo.fMask = SIF_POS;
 
-   GetScrollInfo(ListView2->Handle, SB_HORZ, &ScrollInfo);
 
-   R.Left -= ScrollInfo.nPos;
 
-   R.Right -= ScrollInfo.nPos;
 
-   return R;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListViewWindowProc(TMessage & Message)
 
- {
 
-   if (Message.Msg == CN_NOTIFY)
 
-   {
 
-     TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
 
-     if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
 
-     {
 
-       // workaround
 
-       // Due to a bug in VCL, OnAdvancedCustomDrawSubItem is not called for any
 
-       // other stage except for cdPrePaint. So we must call it ourselves.
 
-       TNMLVCustomDraw * CustomDraw =
 
-         reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
 
-       if (FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEM) &&
 
-           FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_SUBITEM) &&
 
-           FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT) &&
 
-           (CustomDraw->iSubItem == ImageColumnIndex) &&
 
-           (ActionImages->Width <= ListView2->Columns->Items[CustomDraw->iSubItem]->Width))
 
-       {
 
-         TListItem * Item = ListView2->Items->Item[CustomDraw->nmcd.dwItemSpec];
 
-         const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-         TRect HeaderR = GetColumnHeaderRect(CustomDraw->iSubItem);
 
-         TRect R = Item->DisplayRect(drBounds);
 
-         R.Left = HeaderR.Left + (HeaderR.Width() - ActionImages->Width) / 2;
 
-         R.Right = HeaderR.Right;
 
-         // workaround
 
-         // doing this from ListViewAdvancedCustomDraw corrupts list view on Windows 7
 
-         ImageList_Draw(reinterpret_cast<HIMAGELIST>(ActionImages->Handle),
 
-           int(GetChecklistItemAction(ChecklistItem)), CustomDraw->nmcd.hdc,
 
-           R.Left, ((R.Top + R.Bottom - ActionImages->Height) / 2), ILD_TRANSPARENT);
 
-       }
 
-     }
 
-     FOrigListViewWindowProc(Message);
 
-   }
 
-   else if (Message.Msg == CM_HINTSHOW)
 
-   {
 
-     ListViewHintShow(reinterpret_cast<TCMHintShow &>(Message));
 
-   }
 
-   else if (Message.Msg == WM_WANTS_SCREEN_TIPS)
 
-   {
 
-     Message.Result = 1;
 
-   }
 
-   else
 
-   {
 
-     FOrigListViewWindowProc(Message);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListViewHintShow(TCMHintShow & HintShow)
 
- {
 
-   TLVHitTestInfo HitTest;
 
-   HitTest.pt = HintShow.HintInfo->CursorPos;
 
-   int Index = ListView_SubItemHitTest(ListView2->Handle, &HitTest);
 
-   if ((Index >= 0) && (HitTest.iSubItem == ImageColumnIndex))
 
-   {
 
-     TListItem * Item = ListView2->Items->Item[Index];
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     int ActionHint = 0;
 
-     switch (int(GetChecklistItemAction(ChecklistItem)))
 
-     {
 
-       case TSynchronizeChecklist::saUploadNew:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_UPLOAD_NEW;
 
-         break;
 
-       case TSynchronizeChecklist::saDownloadNew:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_DOWNLOAD_NEW;
 
-         break;
 
-       case TSynchronizeChecklist::saUploadUpdate:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_UPLOAD_UPDATE;
 
-         break;
 
-       case TSynchronizeChecklist::saDownloadUpdate:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_DOWNLOAD_UPDATE;
 
-         break;
 
-       case TSynchronizeChecklist::saDeleteRemote:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_DELETE_REMOTE;
 
-         break;
 
-       case TSynchronizeChecklist::saDeleteLocal:
 
-         ActionHint = SYNCHRONIZE_CHECKLIST_DELETE_LOCAL;
 
-         break;
 
-     }
 
-     if (DebugAlwaysTrue(ActionHint != 0))
 
-     {
 
-       HintShow.HintInfo->HintStr = FORMAT(L"%s|%s", (LoadStr(ActionHint), LoadStr(SYNCHRONIZE_CHECKLIST_REVERSE)));
 
-       ListView_GetSubItemRect(ListView2->Handle, Index, ImageColumnIndex, LVIR_BOUNDS, &HintShow.HintInfo->CursorRect);
 
-       HintShow.Result = 0;
 
-     }
 
-   }
 
-   FOrigListViewWindowProc(reinterpret_cast<TMessage &>(HintShow));
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StatusBarHintShow(TCMHintShow & HintShow)
 
- {
 
-   int IPanel = PanelAt(HintShow.HintInfo->CursorPos.x);
 
-   if (IPanel >= 0)
 
-   {
 
-     TStatusPanel * Panel = StatusBar->Panels->Items[IPanel];
 
-     HintShow.HintInfo->HintStr = FORMAT(L"%s|%s", (Panel->Text, StatusBar->Hint));
 
-     HintShow.HintInfo->CursorRect.Left = 0;
 
-     while (IPanel > 0)
 
-     {
 
-       IPanel--;
 
-       HintShow.HintInfo->CursorRect.Left += StatusBar->Panels->Items[IPanel]->Width;
 
-     }
 
-     HintShow.HintInfo->CursorRect.Top = 0;
 
-     HintShow.HintInfo->CursorRect.Bottom = StatusBar->ClientHeight;
 
-     HintShow.HintInfo->CursorRect.Right = HintShow.HintInfo->CursorRect.Left + Panel->Width;
 
-     HintShow.Result = 0;
 
-   }
 
-   FOrigListViewWindowProc(reinterpret_cast<TMessage &>(HintShow));
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StatusBarWindowProc(TMessage & Message)
 
- {
 
-   if (Message.Msg == WM_WANTS_SCREEN_TIPS)
 
-   {
 
-     Message.Result = 1;
 
-   }
 
-   else if (Message.Msg == CM_HINTSHOW)
 
-   {
 
-     StatusBarHintShow(reinterpret_cast<TCMHintShow &>(Message));
 
-   }
 
-   else
 
-   {
 
-     FOrigStatusBarWindowProc(Message);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2AdvancedCustomDrawSubItem(
 
-   TCustomListView * /*Sender*/, TListItem * /*Item*/, int /*SubItem*/,
 
-   TCustomDrawState /*State*/, TCustomDrawStage /*Stage*/, bool & /*DefaultDraw*/)
 
- {
 
-   // this is just fake handler that makes the list view request custom draw notification above
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StatusBarDrawPanel(
 
-   TStatusBar * StatusBar, TStatusPanel * Panel, const TRect & Rect)
 
- {
 
-   bool Possible;
 
-   int ActionIndex = Panel->Index;
 
-   TSynchronizeChecklist::TAction Action = TSynchronizeChecklist::TAction(ActionIndex);
 
-   if (FTotals[ActionIndex] > 0)
 
-   {
 
-     // if direction is overriden to an action that is otherwise not possible
 
-     // in given synchronization mode, we still want to show the stats
 
-     Possible = true;
 
-   }
 
-   else
 
-   {
 
-     switch (Action)
 
-     {
 
-       case TSynchronizeChecklist::saNone:
 
-         Possible = true;
 
-         break;
 
-       case TSynchronizeChecklist::saUploadNew:
 
-         Possible = ((FMode == smRemote) || (FMode == smBoth)) &&
 
-           FLAGCLEAR(FParams, TTerminal::spTimestamp);
 
-         break;
 
-       case TSynchronizeChecklist::saDownloadNew:
 
-         Possible = ((FMode == smLocal) || (FMode == smBoth)) &&
 
-           FLAGCLEAR(FParams, TTerminal::spTimestamp);
 
-         break;
 
-       case TSynchronizeChecklist::saUploadUpdate:
 
-         Possible =
 
-           ((FMode == smRemote) || (FMode == smBoth)) &&
 
-           (FLAGCLEAR(FParams, TTerminal::spNotByTime) || FLAGSET(FParams, TTerminal::spBySize) || FLAGSET(FParams, TTerminal::spByChecksum));
 
-         break;
 
-       case TSynchronizeChecklist::saDownloadUpdate:
 
-         Possible =
 
-           ((FMode == smLocal) || (FMode == smBoth)) &&
 
-           (FLAGCLEAR(FParams, TTerminal::spNotByTime) || FLAGSET(FParams, TTerminal::spBySize) || FLAGSET(FParams, TTerminal::spByChecksum));
 
-         break;
 
-       case TSynchronizeChecklist::saDeleteRemote:
 
-         Possible = (FMode == smRemote) &&
 
-           FLAGCLEAR(FParams, TTerminal::spTimestamp);
 
-         break;
 
-       case TSynchronizeChecklist::saDeleteLocal:
 
-         Possible = (FMode == smLocal) &&
 
-           FLAGCLEAR(FParams, TTerminal::spTimestamp);
 
-         break;
 
-       default:
 
-         DebugFail();
 
-         Possible = false;
 
-         break;
 
-     }
 
-   }
 
-   UnicodeString PanelText;
 
-   if (Possible)
 
-   {
 
-     PanelText = FORMAT(LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 1),
 
-       (FormatNumber(FChecked[ActionIndex]),
 
-        FormatNumber(FTotals[ActionIndex])));
 
-     if ((FChecked[ActionIndex] > 0) &&
 
-         ((ActionIndex == 0) || !TSynchronizeChecklist::IsItemSizeIrrelevant(Action)))
 
-     {
 
-       PanelText += FORMAT(L" (%s)", (FormatBytes(FCheckedSize[ActionIndex])));
 
-     }
 
-   }
 
-   else
 
-   {
 
-     PanelText = LoadStrPart(SYNCHRONIZE_SELECTED_ACTIONS, 2);
 
-   }
 
-   int TextHeight = StatusBar->Canvas->TextHeight(PanelText);
 
-   int X = Rect.Left + ActionImages->Width + 4;
 
-   int Y = (Rect.Top + Rect.Bottom - TextHeight) / 2;
 
-   StatusBar->Canvas->TextRect(Rect, X, Y, PanelText);
 
-   X = Rect.Left + 1;
 
-   Y = ((Rect.Top + Rect.Bottom - ActionImages->Height) / 2);
 
-   int ImageIndex = ActionIndex;
 
-   ActionImages->Draw(StatusBar->Canvas, X, Y, ImageIndex, Possible);
 
- }
 
- //---------------------------------------------------------------------------
 
- int __fastcall TSynchronizeChecklistDialog::PanelCount()
 
- {
 
-   // last "panel" is technical
 
-   return StatusBar->Panels->Count - 1;
 
- }
 
- //---------------------------------------------------------------------------
 
- int __fastcall TSynchronizeChecklistDialog::PanelAt(int X)
 
- {
 
-   int Result = 0;
 
-   while ((X > StatusBar->Panels->Items[Result]->Width) &&
 
-     (Result < PanelCount()))
 
-   {
 
-     X -= StatusBar->Panels->Items[Result]->Width;
 
-     Result++;
 
-   }
 
-   return ((Result < StatusBar->Panels->Count - 1) ? Result : -1);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2Change(
 
-   TObject * /*Sender*/, TListItem * Item, TItemChange Change)
 
- {
 
-   if ((Change == ctState) && (FChangingItem == Item) && (FChangingItem != NULL))
 
-   {
 
-     if (!FChangingItemIgnore)
 
-     {
 
-       DebugAssert(Item->Data != NULL);
 
-       if ((FChangingItemChecked != Item->Checked) && (Item->Data != NULL))
 
-       {
 
-         const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-         CountItem(ChecklistItem, Item->Checked ? 1 : -1);
 
-         if (!FChangingItemMass)
 
-         {
 
-           UpdateControls();
 
-         }
 
-       }
 
-     }
 
-     FChangingItem = NULL;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2Changing(
 
-   TObject * /*Sender*/, TListItem * Item, TItemChange Change,
 
-   bool & /*AllowChange*/)
 
- {
 
-   if (Change == ctState)
 
-   {
 
-     FChangingItem = Item;
 
-     FChangingItemChecked = Item->Checked;
 
-   }
 
-   else
 
-   {
 
-     DebugAssert(FChangingItem == NULL);
 
-     FChangingItem = NULL;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CheckAll(bool Check)
 
- {
 
-   FChangingItemMass = true;
 
-   try
 
-   {
 
-     for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-     {
 
-       ListView2->Items->Item[Index]->Checked = Check;
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     FChangingItemMass = false;
 
-   }
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CheckAllActionExecute(TObject * /*Sender*/)
 
- {
 
-   CheckAll(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UncheckAllActionExecute(TObject * /*Sender*/)
 
- {
 
-   CheckAll(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- bool TSynchronizeChecklistDialog::IterateItems(TListItem *& Item, TItemStates States)
 
- {
 
-   Item = ListView2->GetNextItem(Item, sdAll, States);
 
-   return (Item != NULL);
 
- }
 
- //---------------------------------------------------------------------------
 
- bool TSynchronizeChecklistDialog::IterateSelectedItems(TListItem *& Item)
 
- {
 
-   return IterateItems(Item, TItemStates() << isSelected);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::Check(bool Check)
 
- {
 
-   FChangingItemMass = true;
 
-   try
 
-   {
 
-     TListItem * Item = NULL;
 
-     while (IterateSelectedItems(Item))
 
-     {
 
-       Item->Checked = Check;
 
-     }
 
-   }
 
-   __finally
 
-   {
 
-     FChangingItemMass = false;
 
-   }
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CheckActionExecute(TObject * /*Sender*/)
 
- {
 
-   Check(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UncheckActionExecute(TObject * /*Sender*/)
 
- {
 
-   Check(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2SelectItem(
 
-   TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
 
- {
 
-   // Delayed update of button status in case many items are being selected at once
 
-   // Also change of selection causes buttons to flash, as for short period of time,
 
-   // no item is selected
 
-   UpdateTimer->Enabled = true;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdateTimerTimer(
 
-   TObject * /*Sender*/)
 
- {
 
-   UpdateTimer->Enabled = false;
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- TListItem * __fastcall TSynchronizeChecklistDialog::SelectAll(bool Select, int Action,
 
-   bool OnlyTheAction)
 
- {
 
-   TListItem * Result = NULL;
 
-   for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-   {
 
-     TListItem * Item = ListView2->Items->Item[Index];
 
-     if (Action == 0)
 
-     {
 
-       Item->Selected = Select;
 
-       if (Result == NULL)
 
-       {
 
-         Result = Item;
 
-       }
 
-     }
 
-     else
 
-     {
 
-       const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-       bool WantedAction = (int(GetChecklistItemAction(ChecklistItem)) == Action);
 
-       if (WantedAction || !OnlyTheAction)
 
-       {
 
-         Item->Selected = Select && WantedAction;
 
-         if (WantedAction && (Result == NULL))
 
-         {
 
-           Result = Item;
 
-         }
 
-       }
 
-     }
 
-   }
 
-   return Result;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::SelectAllActionExecute(
 
-   TObject * /*Sender*/)
 
- {
 
-   SelectAll(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StatusBarMouseDown(
 
-   TObject * /*Sender*/, TMouseButton /*Button*/, TShiftState Shift, int X,
 
-   int /*Y*/)
 
- {
 
-   int IPanel = PanelAt(X);
 
-   if (IPanel >= 0)
 
-   {
 
-     TListItem * Item = SelectAll(true, IPanel, Shift.Contains(ssCtrl));
 
-     if (Item != NULL)
 
-     {
 
-       Item->MakeVisible(false);
 
-       Item->Focused = true;
 
-       ListView2->SetFocus();
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- TIEListViewColProperties * TSynchronizeChecklistDialog::GetColProperties()
 
- {
 
-   return dynamic_cast<TIEListViewColProperties *>(ListView2->ColProperties);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2Compare(
 
-   TObject * /*Sender*/, TListItem * Item1, TListItem * Item2, int /*Data*/,
 
-   int & Compare)
 
- {
 
-   const TSynchronizeChecklist::TItem * ChecklistItem1 = GetChecklistItem(Item1);
 
-   const TSynchronizeChecklist::TItem * ChecklistItem2 = GetChecklistItem(Item2);
 
-   TIEListViewColProperties * ColProperties = GetColProperties();
 
-   switch (ColProperties->SortColumn)
 
-   {
 
-     case 0: // name
 
-       Compare = AnsiCompareText(ChecklistItem1->GetFileName(), ChecklistItem2->GetFileName());
 
-       break;
 
-     // sorting by local and remote dir is the same
 
-     case 1: // local dir
 
-     case 5: // remote dir
 
-       Compare = 0; // default sorting
 
-       break;
 
-     case 2: // local size
 
-       Compare = CompareNumber(ChecklistItem1->Local.Size, ChecklistItem2->Local.Size);
 
-       break;
 
-     case 3: // local changed
 
-       Compare = CompareFileTime(ChecklistItem1->Local.Modification,
 
-         ChecklistItem2->Local.Modification);
 
-       break;
 
-     case ImageColumnIndex: // action
 
-       Compare = CompareNumber(GetChecklistItemAction(ChecklistItem1), GetChecklistItemAction(ChecklistItem2));
 
-       break;
 
-     case 6: // remote size
 
-       Compare = CompareNumber(ChecklistItem1->Remote.Size, ChecklistItem2->Remote.Size);
 
-       break;
 
-     case 7: // remote changed
 
-       Compare = CompareFileTime(ChecklistItem1->Remote.Modification,
 
-         ChecklistItem2->Remote.Modification);
 
-       break;
 
-   }
 
-   if (Compare == 0)
 
-   {
 
-     Compare = TSynchronizeChecklist::Compare(ChecklistItem1, ChecklistItem2);
 
-   }
 
-   if (!ColProperties->SortAscending)
 
-   {
 
-     Compare = -Compare;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2SecondaryColumnHeader(
 
-   TCustomIEListView * /*Sender*/, int Index, int & SecondaryColumn)
 
- {
 
-   // "remote dir" column is sorting alias for "local dir" column
 
-   if (Index == 5)
 
-   {
 
-     SecondaryColumn = 1;
 
-   }
 
-   else
 
-   {
 
-     SecondaryColumn = -1;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2ContextPopup(
 
-   TObject * Sender, TPoint & MousePos, bool & Handled)
 
- {
 
-   // to update source popup menu before TBX menu is created
 
-   UpdateControls();
 
-   MenuPopup(Sender, MousePos, Handled);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CustomCommandsActionExecute(
 
-   TObject * /*Sender*/)
 
- {
 
-   TStrings * LocalFileList = new TStringList();
 
-   TStrings * RemoteFileList = new TStringList();
 
-   try
 
-   {
 
-     TListItem * Item = NULL;
 
-     while (IterateSelectedItems(Item))
 
-     {
 
-       const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-       DebugAssert((GetChecklistItemAction(ChecklistItem) == TSynchronizeChecklist::saUploadUpdate) ||
 
-              (GetChecklistItemAction(ChecklistItem) == TSynchronizeChecklist::saDownloadUpdate));
 
-       DebugAssert(ChecklistItem->RemoteFile != NULL);
 
-       UnicodeString LocalPath = ChecklistItem->GetLocalPath();
 
-       LocalFileList->Add(LocalPath);
 
-       UnicodeString RemotePath = ChecklistItem->GetRemotePath();
 
-       RemoteFileList->AddObject(RemotePath, ChecklistItem->RemoteFile);
 
-     }
 
-   }
 
-   catch(...)
 
-   {
 
-     delete LocalFileList;
 
-     delete RemoteFileList;
 
-     throw;
 
-   }
 
-   DebugAssert(FOnCustomCommandMenu != NULL);
 
-   FOnCustomCommandMenu(CustomCommandsAction, LocalFileList, RemoteFileList);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdateStatusBarSize()
 
- {
 
-   int PanelWidth = Min(StatusBar->Width / PanelCount(), ScaleByTextHeight(this, 160));
 
-   for (int Index = 0; Index < PanelCount(); Index++)
 
-   {
 
-     StatusBar->Panels->Items[Index]->Width = PanelWidth;
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StatusBarResize(TObject * /*Sender*/)
 
- {
 
-   UpdateStatusBarSize();
 
- }
 
- //---------------------------------------------------------------------------
 
- const TSynchronizeChecklist::TItem * TSynchronizeChecklistDialog::GetChecklistItem(
 
-   TListItem * Item)
 
- {
 
-   return static_cast<const TSynchronizeChecklist::TItem *>(Item->Data);
 
- }
 
- //---------------------------------------------------------------------------
 
- TSynchronizeChecklist::TAction & TSynchronizeChecklistDialog::GetChecklistItemAction(
 
-   const TSynchronizeChecklist::TItem * ChecklistItem)
 
- {
 
-   TActions::iterator i = FActions.find(ChecklistItem);
 
-   if (i == FActions.end())
 
-   {
 
-     throw EInvalidOperation(L"");
 
-   }
 
-   return i->second;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ReverseActionExecute(TObject * /*Sender*/)
 
- {
 
-   TAutoFlag Flag(FChangingItemMass);
 
-   TListItem * Item = NULL;
 
-   while (IterateSelectedItems(Item))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     TSynchronizeChecklist::TAction & Action = GetChecklistItemAction(ChecklistItem);
 
-     TSynchronizeChecklist::TAction NewAction = TSynchronizeChecklist::Reverse(Action);
 
-     if (DebugAlwaysTrue(Action != NewAction))
 
-     {
 
-       CountItemTotal(ChecklistItem, -1);
 
-       if (Item->Checked)
 
-       {
 
-         CountItem(ChecklistItem, -1);
 
-       }
 
-       Action = NewAction;
 
-       CountItemTotal(ChecklistItem, 1);
 
-       if (Item->Checked)
 
-       {
 
-         // item size may differ with action (0 for delete, but non-0 for new file transfer)
 
-         CountItem(ChecklistItem, 1);
 
-       }
 
-       LoadItem(Item);
 
-     }
 
-   }
 
-   Flag.Release();
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2Click(TObject * /*Sender*/)
 
- {
 
-   TKeyboardState KeyState;
 
-   GetKeyboardState(KeyState);
 
-   TShiftState ShiftState = KeyboardStateToShiftState(KeyState);
 
-   // when selecting, do not reverse, even when user clicked on action column
 
-   if (!ShiftState.Contains(ssShift) && !ShiftState.Contains(ssCtrl))
 
-   {
 
-     TPoint P = ListView2->ScreenToClient(Mouse->CursorPos);
 
-     TRect R = GetColumnHeaderRect(ImageColumnIndex);
 
-     if ((R.Left <= P.x) && (P.x <= R.Right))
 
-     {
 
-       // If no item was selected before the click, the action is not enabled yet here,
 
-       // and Execute would be noop, force update
 
-       UpdateControls();
 
-       ReverseAction->Execute();
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::Dispatch(void * AMessage)
 
- {
 
-   TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
 
-   if (Message.Msg == WM_SYSCOMMAND)
 
-   {
 
-     if (!HandleMinimizeSysCommand(Message))
 
-     {
 
-       TForm::Dispatch(AMessage);
 
-     }
 
-   }
 
-   else if (Message.Msg == WM_WANTS_MOUSEWHEEL_INACTIVE)
 
-   {
 
-     Message.Result = FSynchronizing ? 1 : 0;
 
-   }
 
-   else if (Message.Msg == WM_MANAGES_CAPTION)
 
-   {
 
-     // calling UpdateControls would cause status bar flicker
 
-     UpdateCaption();
 
-     Message.Result = 1;
 
-   }
 
-   else
 
-   {
 
-     TForm::Dispatch(AMessage);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdateImages()
 
- {
 
-   ListView2->SmallImages = ShellImageListForControl(this, ilsSmall);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
 
- {
 
-   DebugUsedParam2(OldDPI, NewDPI);
 
-   UpdateImages();
 
-   UpdateStatusBarSize();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ProcessedItem(void * /*Token*/, const TSynchronizeChecklist::TItem * ChecklistItem)
 
- {
 
-   TListItem * Item = FChecklistToListViewMap[ChecklistItem];
 
-   DebugAssert(Item->Checked);
 
-   Item->Checked = false;
 
-   Item->MakeVisible(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UpdatedSynchronizationChecklistItems(
 
-   const TSynchronizeChecklist::TItemList & Items)
 
- {
 
-   TSynchronizeChecklist::TItemList::const_iterator Iter = Items.begin();
 
-   while (Iter != Items.end())
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = *Iter;
 
-     TListItem * Item = FChecklistToListViewMap[ChecklistItem];
 
-     LoadItem(Item);
 
-     // When called from FOnSynchronize, we rely on a caller never to update size of an item that had size already,
 
-     // otherwise we get it counted twice here.
 
-     if (Item->Checked)
 
-     {
 
-       CountItemSize(ChecklistItem, 1);
 
-     }
 
-     Iter++;
 
-   }
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void TSynchronizeChecklistDialog::DoSynchronize(bool Queue)
 
- {
 
-   ListView2->SelectAll(smNone);
 
-   for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-   {
 
-     TListItem * Item = ListView2->Items->Item[Index];
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     FChecklist->Update(ChecklistItem, Item->Checked, GetChecklistItemAction(ChecklistItem));
 
-   }
 
-   TAutoFlag Flag(FSynchronizing);
 
-   UpdateControls();
 
-   try
 
-   {
 
-     if (Queue)
 
-     {
 
-       FOnQueueSynchronize(FToken);
 
-     }
 
-     else
 
-     {
 
-       FOnSynchronize(FToken, ProcessedItem, UpdatedSynchronizationChecklistItems);
 
-     }
 
-   }
 
-   catch (Exception & E)
 
-   {
 
-     FException.reset(CloneException(&E));
 
-   }
 
-   // Needed when called from the drop down menu
 
-   ModalResult = OkButton->ModalResult;
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::OkButtonClick(TObject *)
 
- {
 
-   bool Queue = OpenInNewWindow();
 
-   if (Queue && (FOnQueueSynchronize == NULL))
 
-   {
 
-     Beep();
 
-   }
 
-   else
 
-   {
 
-     DoSynchronize(Queue);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void TSynchronizeChecklistDialog::CalculateSize(bool All)
 
- {
 
-   TItemStates States;
 
-   if (!All)
 
-   {
 
-     States << isSelected;
 
-   }
 
-   TSynchronizeChecklist::TItemList Items;
 
-   TListItem * Item = NULL;
 
-   while (IterateItems(Item, States))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     Items.push_back(ChecklistItem);
 
-     if (Item->Checked)
 
-     {
 
-       CountItemSize(ChecklistItem, -1);
 
-     }
 
-   }
 
-   try
 
-   {
 
-     FOnSynchronizeChecklistCalculateSize(FChecklist, Items, FToken);
 
-   }
 
-   __finally
 
-   {
 
-     UpdatedSynchronizationChecklistItems(Items);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CalculateSizeActionExecute(TObject *)
 
- {
 
-   CalculateSize(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CalculateSizeAllActionExecute(TObject *)
 
- {
 
-   CalculateSize(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::DeleteItem(const TSynchronizeChecklist::TItem * ChecklistItem)
 
- {
 
-   TListItem * Item = FChecklistToListViewMap[ChecklistItem];
 
-   CountItemTotal(ChecklistItem, -1);
 
-   if (Item->Checked)
 
-   {
 
-     CountItem(ChecklistItem, -1);
 
-   }
 
-   FActions.erase(ChecklistItem);
 
-   FChecklistToListViewMap.erase(ChecklistItem);
 
-   FChecklist->Delete(ChecklistItem);
 
-   int Index = Item->Index;
 
-   if (Item->Focused)
 
-   {
 
-     int FocusIndex = Index;
 
-     if (FocusIndex == ListView2->Items->Count - 1)
 
-     {
 
-       FocusIndex--;
 
-     }
 
-     else
 
-     {
 
-       FocusIndex++;
 
-     }
 
-     ListView2->ItemFocused = ListView2->Items->Item[FocusIndex];
 
-   }
 
-   ListView2->Items->Delete(Index);
 
-   FMoveCandidatesValidForSort = MaxInt; // can be optimized
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::MoveActionExecute(TObject *)
 
- {
 
-   TMoveData MoveData(true);
 
-   TListItem * Item = NULL;
 
-   while (IterateSelectedItems(Item))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-     MoveData.Collect(ChecklistItem, Action);
 
-   }
 
-   TMoveActionData * TransferAction = &MoveData.FirstAction;
 
-   TMoveActionData * DeleteAction = &MoveData.SecondAction;
 
-   if (IsTransferNewAction(DeleteAction->Action))
 
-   {
 
-     std::swap(TransferAction, DeleteAction);
 
-   }
 
-   DebugAssert(IsTransferNewAction(TransferAction->Action));
 
-   DebugAssert(GetOppositeMoveAction(DeleteAction->Action) == TransferAction->Action);
 
-   TOperationSide Side = TOperationSide(); // shut up
 
-   UnicodeString NewFileName;
 
-   DebugAssert(TransferAction->ChecklistItems.size() == 1);
 
-   const TSynchronizeChecklist::TItem * TransferChecklistItem = TransferAction->ChecklistItems[0];
 
-   if (DeleteAction->Action == TSynchronizeChecklist::saDeleteRemote)
 
-   {
 
-     Side = osRemote;
 
-     NewFileName = UnixCombinePaths(TransferChecklistItem->Remote.Directory, TransferChecklistItem->Local.FileName);
 
-   }
 
-   else if (DebugAlwaysTrue(DeleteAction->Action == TSynchronizeChecklist::saDeleteLocal))
 
-   {
 
-     Side = osLocal;
 
-     NewFileName = CombinePaths(TransferChecklistItem->Local.Directory, TransferChecklistItem->Remote.FileName);
 
-   }
 
-   if (DebugAlwaysTrue(!NewFileName.IsEmpty()))
 
-   {
 
-     bool Move = false;
 
-     bool TargetIsDirectory = false; // shut up
 
-     if ((TransferAction->AllItemsDirectories == DeleteAction->AllItemsDirectories) &&
 
-         DebugAlwaysTrue(TransferAction->ItemsCount == 1) &&
 
-         DebugAlwaysTrue(DeleteAction->ItemsCount == 1))
 
-     {
 
-       Move = true;
 
-       TargetIsDirectory = false;
 
-     }
 
-     else if (DebugAlwaysTrue(TransferAction->AllItemsDirectories && (TransferAction->ItemsCount == 1)))
 
-     {
 
-       TargetIsDirectory = true;
 
-       Move = true;
 
-     }
 
-     if (DebugAlwaysTrue(Move))
 
-     {
 
-       FOnSynchronizeMove(Side, DeleteAction->FileList.get(), NewFileName, TargetIsDirectory, FToken);
 
-       TMoveActionData::TChecklistItems::const_iterator I = DeleteAction->ChecklistItems.begin();
 
-       while (I != DeleteAction->ChecklistItems.end())
 
-       {
 
-         DeleteItem(*I);
 
-         I++;
 
-       }
 
-       if (!TargetIsDirectory)
 
-       {
 
-         DeleteItem(TransferChecklistItem);
 
-       }
 
-       else
 
-       {
 
-         // The remaning "transfer" item
 
-         ListView2->Selected->MakeVisible(false);
 
-       }
 
-       UpdateControls();
 
-     }
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CheckDirectory(bool Check)
 
- {
 
-   std::unique_ptr<TStringList> Directories(new TStringList());
 
-   TListItem * Item = NULL;
 
-   while (IterateSelectedItems(Item))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     // It does not matter if we use local or remote directory
 
-     Directories->Add(IncludeTrailingBackslash(ChecklistItem->Local.Directory));
 
-   }
 
-   TAutoFlag ChangingItemMassSwitch(FChangingItemMass);
 
-   for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-   {
 
-     TListItem * Item = ListView2->Items->Item[Index];
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     UnicodeString Directory = IncludeTrailingBackslash(ChecklistItem->Local.Directory);
 
-     for (int Index2 = 0; Index2 < Directories->Count; Index2++)
 
-     {
 
-       if (StartsText(Directories->Strings[Index2], Directory))
 
-       {
 
-         Item->Checked = Check;
 
-       }
 
-     }
 
-   }
 
-   ChangingItemMassSwitch.Release();
 
-   UpdateControls();
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::CheckDirectoryActionExecute(TObject *)
 
- {
 
-   CheckDirectory(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::UncheckDirectoryActionExecute(TObject *)
 
- {
 
-   CheckDirectory(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::DoExplore(TOperationSide Side)
 
- {
 
-   const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(ListView2->Selected);
 
-   TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-   FOnSynchronizeExplore(Side, Action, ChecklistItem);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ExploreLocalAction2Execute(TObject *)
 
- {
 
-   DoExplore(osLocal);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ExploreRemoteAction2Execute(TObject *)
 
- {
 
-   DoExplore(osRemote);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::KeyDown(Word & Key, TShiftState Shift)
 
- {
 
-   TShortCut KeyShortCut = ShortCut(Key, Shift);
 
-   TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
 
-   if (IsCustomShortCut(CustomShortCut))
 
-   {
 
-     TTBXItem * MenuItem = new TTBXItem(this);
 
-     CustomCommandsAction->ActionComponent = MenuItem;
 
-     CustomCommandsAction->Execute();
 
-     for (int Index = 0; Index < MenuItem->Count; Index++)
 
-     {
 
-       TTBCustomItem * Item = MenuItem->Items[Index];
 
-       if (Item->Enabled && (Item->ShortCut == CustomShortCut))
 
-       {
 
-         TAutoFlag DontCopyCommandToClipboardFlag(DontCopyCommandToClipboard);
 
-         Item->Click();
 
-         Key = 0;
 
-         break;
 
-       }
 
-     }
 
-   }
 
-   TForm::KeyDown(Key, Shift);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ListView2Recreate(TObject *)
 
- {
 
-   FChecklistToListViewMap.clear();
 
-   for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-   {
 
-     TListItem * Item = ListView2->Items->Item[Index];
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     FChecklistToListViewMap.insert(std::make_pair(ChecklistItem, Item));
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::ToolsMenuButtonClick(TObject *)
 
- {
 
-   MenuPopup(ToolsPopupMenu, ToolsMenuButton);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::FindMoveCandidateActionExecute(TObject *)
 
- {
 
-   TIEListViewColProperties * ColProperties = GetColProperties();
 
-   int Sort = (ColProperties->SortAscending ? 1 : -1) * ColProperties->SortColumn;
 
-   if (FMoveCandidatesValidForSort != Sort)
 
-   {
 
-     FMoveCandidatesFileName.clear();
 
-     FMoveCandidatesSize.clear();
 
-     for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-     {
 
-       const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(ListView2->Items->Item[Index]);
 
-       if (ChecklistItem->IsLocalOnly() || ChecklistItem->IsRemoteOnly())
 
-       {
 
-         if (ChecklistItem->IsDirectory)
 
-         {
 
-           FMoveCandidatesFileName[ChecklistItem->GetFileName().LowerCase()].push_back(ChecklistItem);
 
-         }
 
-         else
 
-         {
 
-           FMoveCandidatesSize[ChecklistItem->GetBaseSize()].push_back(ChecklistItem);
 
-         }
 
-       }
 
-     }
 
-     FMoveCandidatesValidForSort = Sort;
 
-   }
 
-   bool Found = false;
 
-   if (!FMoveCandidatesFileName.empty() || !FMoveCandidatesSize.empty())
 
-   {
 
-     TListItem * ItemFocused = ListView2->ItemFocused;
 
-     TListItem * Item;
 
-     if (ItemFocused != NULL)
 
-     {
 
-       Item = ItemFocused;
 
-     }
 
-     // Can we have a selection without focus?
 
-     else if (DebugAlwaysFalse(ListView2->Selected != NULL))
 
-     {
 
-       Item = ListView2->Selected;
 
-     }
 
-     else if (ListView2->Items->Count > 0)
 
-     {
 
-       Item = ListView2->Items->Item[0];
 
-     }
 
-     else
 
-     {
 
-       DebugFail(); // the action is disabled when there are no items
 
-       Item = NULL;
 
-     }
 
-     TListItem * FirstItem = NULL;
 
-     while (!Found && (Item != NULL))
 
-     {
 
-       const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-       TSynchronizeChecklist::TAction Action = GetChecklistItemAction(ChecklistItem);
 
-       TSynchronizeChecklist::TAction OppositeAction = GetOppositeMoveAction(Action);
 
-       if ((OppositeAction != TSynchronizeChecklist::saNone) &&
 
-           // For focused item, we search pair even if the focused item is "delete" action,
 
-           // but when searching the next items, consider "transfer" actions only
 
-           ((Item == ItemFocused) || IsTransferNewAction(Action)))
 
-       {
 
-         TChecklistItems Candidates;
 
-         if (ChecklistItem->IsDirectory)
 
-         {
 
-           UnicodeString FileName = ChecklistItem->GetFileName().LowerCase();
 
-           TMoveCandidatesFileNameMap::const_iterator I = FMoveCandidatesFileName.find(FileName);
 
-           if (I != FMoveCandidatesFileName.end())
 
-           {
 
-             const TChecklistItems & NameCandidates = I->second;
 
-             for (size_t I = 0; I < NameCandidates.size(); I++)
 
-             {
 
-               const TSynchronizeChecklist::TItem * ChecklistItem2 = NameCandidates[I];
 
-               if ((GetChecklistItemAction(ChecklistItem2) == OppositeAction) &&
 
-                   DebugAlwaysTrue(ChecklistItem2->IsDirectory))
 
-               {
 
-                 Candidates.push_back(ChecklistItem2);
 
-               }
 
-             }
 
-           }
 
-         }
 
-         else
 
-         {
 
-           __int64 Size = ChecklistItem->GetBaseSize();
 
-           TMoveCandidatesSizeMap::const_iterator I = FMoveCandidatesSize.find(Size);
 
-           if (I != FMoveCandidatesSize.end())
 
-           {
 
-             UnicodeString FileName = ChecklistItem->GetFileName();
 
-             const TChecklistItems & SizeCandidates = I->second;
 
-             for (size_t I = 0; I < SizeCandidates.size(); I++)
 
-             {
 
-               const TSynchronizeChecklist::TItem * ChecklistItem2 = SizeCandidates[I];
 
-               if ((GetChecklistItemAction(ChecklistItem2) == OppositeAction) &&
 
-                   DebugAlwaysTrue(!ChecklistItem2->IsDirectory))
 
-               {
 
-                 bool IsCandidate;
 
-                 // in addition to the same size, also the same file filename (although possibly different directory)
 
-                 if (SameText(FileName, ChecklistItem2->GetFileName()))
 
-                 {
 
-                   IsCandidate = true;
 
-                 }
 
-                 // or different filename but the same directory (in addition to the same size)
 
-                 else if ((Action == TSynchronizeChecklist::saDeleteLocal) ||
 
-                          (Action == TSynchronizeChecklist::saDownloadNew))
 
-                 {
 
-                   IsCandidate = SamePaths(ChecklistItem->Local.Directory, ChecklistItem2->Local.Directory);
 
-                 }
 
-                 else if ((Action == TSynchronizeChecklist::saDeleteRemote) ||
 
-                          (Action == TSynchronizeChecklist::saUploadNew))
 
-                 {
 
-                   IsCandidate = UnixSamePath(ChecklistItem->Remote.Directory, ChecklistItem2->Remote.Directory);
 
-                 }
 
-                 else
 
-                 {
 
-                   DebugFail();
 
-                   IsCandidate = false;
 
-                 }
 
-                 if (IsCandidate)
 
-                 {
 
-                   Candidates.push_back(ChecklistItem2);
 
-                 }
 
-               }
 
-             }
 
-           }
 
-         }
 
-         if (!Candidates.empty())
 
-         {
 
-           const TSynchronizeChecklist::TItem * ChecklistItem2 = Candidates[0];
 
-           if ((FirstItem == NULL) && Item->Selected && (ListView2->SelCount == 2))
 
-           {
 
-             TListItem * NextSelected = ListView2->GetNextItem(Item, sdAll, TItemStates() << isSelected);
 
-             if (NextSelected == NULL)
 
-             {
 
-               NextSelected = ListView2->Selected; // Shorthand for GetNextItem(NULL, sdAll, isSelected)
 
-             }
 
-             TChecklistItems::const_iterator I = std::find(Candidates.begin(), Candidates.end(), GetChecklistItem(NextSelected));
 
-             if (I < Candidates.end() - 1)
 
-             {
 
-               ChecklistItem2 = *(I + 1);
 
-             }
 
-             else if (I == Candidates.end() - 1)
 
-             {
 
-               ChecklistItem2 = NULL;
 
-             }
 
-           }
 
-           if (ChecklistItem2 != NULL)
 
-           {
 
-             TListItem * Item2 = FChecklistToListViewMap[ChecklistItem2];
 
-             for (int Index = 0; Index < ListView2->Items->Count; Index++)
 
-             {
 
-               TListItem * ItemI = ListView2->Items->Item[Index];
 
-               ItemI->Selected = (ItemI == Item) || (ItemI == Item2);
 
-             }
 
-             ListView2->ItemFocused = Item;
 
-             // IsItemVisible returns true even on partial visibility,
 
-             // so it is still worth trying MakeVisible to make them completelly visible
 
-             bool FlickerExpected = !ListView2->IsItemVisible(Item) || !ListView2->IsItemVisible(Item2);
 
-             if (FlickerExpected)
 
-             {
 
-               // does not seem to have any effect
 
-               ListView2->LockDrawing();
 
-             }
 
-             try
 
-             {
 
-               // even if the item turns to be invisible in the end, it at least scrolls the view towards it
 
-               Item2->MakeVisible(false);
 
-               // Should do minimal scroll needed to make the first item whole visible, but not hiding the second
 
-               Item->MakeVisible(false);
 
-             }
 
-             __finally
 
-             {
 
-               if (FlickerExpected)
 
-               {
 
-                 ListView2->UnlockDrawing();
 
-               }
 
-             }
 
-             Found = true;
 
-           }
 
-         }
 
-       }
 
-       // Allow going through the first item twice, to make sure we roll over its previous pair candidates
 
-       if (Item == FirstItem)
 
-       {
 
-         Item = NULL;
 
-       }
 
-       else
 
-       {
 
-         if (FirstItem == NULL)
 
-         {
 
-           FirstItem = Item;
 
-         }
 
-         Item = ListView2->GetNextItem(Item, sdAll, TItemStates());
 
-         if (Item == NULL)
 
-         {
 
-           Item = ListView2->Items->Item[0];
 
-         }
 
-       }
 
-     }
 
-   }
 
-   if (!Found)
 
-   {
 
-     MessageBeep(MB_ICONHAND);
 
-   }
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StartItemClick(TObject *)
 
- {
 
-   DoSynchronize(false);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::OkButtonDropDownClick(TObject *)
 
- {
 
-   MenuPopup(OkPopupMenu, OkButton);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::StartQueueItemClick(TObject *)
 
- {
 
-   DoSynchronize(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void TSynchronizeChecklistDialog::PathToClipboard(bool Local)
 
- {
 
-   std::unique_ptr<TStrings> Paths(new TStringList());
 
-   TListItem * Item = NULL;
 
-   while (IterateSelectedItems(Item))
 
-   {
 
-     const TSynchronizeChecklist::TItem * ChecklistItem = GetChecklistItem(Item);
 
-     UnicodeString Path = Local ? ChecklistItem->ForceGetLocalPath() : ChecklistItem->ForceGetRemotePath();
 
-     Paths->Add(Path);
 
-   }
 
-   TInstantOperationVisualizer Visualizer;
 
-   CopyToClipboard(Paths.get());
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::LocalPathToClipboardActionExecute(TObject *)
 
- {
 
-   PathToClipboard(true);
 
- }
 
- //---------------------------------------------------------------------------
 
- void __fastcall TSynchronizeChecklistDialog::RemotePathToClipboardActionExecute(TObject *)
 
- {
 
-   PathToClipboard(false);
 
- }
 
- //---------------------------------------------------------------------------
 
 
  |