Synchronize.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "WinInterface.h"
  6. #include "Synchronize.h"
  7. #include "VCLCommon.h"
  8. #include "CopyParams.h"
  9. #include "Terminal.h"
  10. #include "GUITools.h"
  11. #include <CoreMain.h>
  12. #include <Configuration.h>
  13. #include <TextsWin.h>
  14. #include <HelpWin.h>
  15. #include <CustomWinConfiguration.h>
  16. #include <StrUtils.hpp>
  17. //---------------------------------------------------------------------------
  18. #pragma package(smart_init)
  19. #pragma link "HistoryComboBox"
  20. #pragma link "GrayedCheckBox"
  21. #ifndef NO_RESOURCES
  22. #pragma resource "*.dfm"
  23. #endif
  24. //---------------------------------------------------------------------------
  25. const int WM_USER_STOP = WM_WINSCP_USER + 2;
  26. //---------------------------------------------------------------------------
  27. bool __fastcall DoSynchronizeDialog(TSynchronizeParamType & Params,
  28. const TCopyParamType * CopyParams, TSynchronizeStartStopEvent OnStartStop,
  29. bool & SaveSettings, int Options, int CopyParamAttrs,
  30. TGetSynchronizeOptionsEvent OnGetOptions,
  31. TFeedSynchronizeError & OnFeedSynchronizeError,
  32. bool Start)
  33. {
  34. bool Result;
  35. TSynchronizeDialog * Dialog = SafeFormCreate<TSynchronizeDialog>(Application);
  36. Dialog->Init(OnStartStop, OnGetOptions, OnFeedSynchronizeError, Start);
  37. try
  38. {
  39. Dialog->Options = Options;
  40. Dialog->CopyParamAttrs = CopyParamAttrs;
  41. Dialog->Params = Params;
  42. Dialog->CopyParams = *CopyParams;
  43. Dialog->SaveSettings = SaveSettings;
  44. Result = Dialog->Execute();
  45. if (Result)
  46. {
  47. SaveSettings = Dialog->SaveSettings;
  48. Params = Dialog->Params;
  49. }
  50. }
  51. __finally
  52. {
  53. delete Dialog;
  54. }
  55. return Result;
  56. }
  57. //---------------------------------------------------------------------------
  58. const TSynchronizeDialog::MaxLogItems = 1000;
  59. //---------------------------------------------------------------------------
  60. struct TLogItemData
  61. {
  62. TSynchronizeLogEntry Entry;
  63. UnicodeString Message;
  64. std::unique_ptr<TStrings> MoreMessages;
  65. TQueryType Type;
  66. UnicodeString HelpKeyword;
  67. };
  68. //---------------------------------------------------------------------------
  69. __fastcall TSynchronizeDialog::TSynchronizeDialog(TComponent * Owner)
  70. : TForm(Owner)
  71. {
  72. UseSystemSettings(this);
  73. FOptions = 0;
  74. FSynchronizing = false;
  75. FMinimizedByMe = false;
  76. FPresetsMenu = new TPopupMenu(this);
  77. FSynchronizeOptions = NULL;
  78. HotTrackLabel(CopyParamLabel);
  79. CopyParamListButton(TransferSettingsButton);
  80. SetGlobalMinimizeHandler(this, GlobalMinimize);
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TSynchronizeDialog::Init(TSynchronizeStartStopEvent OnStartStop,
  84. TGetSynchronizeOptionsEvent OnGetOptions,
  85. TFeedSynchronizeError & OnFeedSynchronizeError,
  86. bool StartImmediately)
  87. {
  88. FOnStartStop = OnStartStop;
  89. FOnGetOptions = OnGetOptions;
  90. FOnFeedSynchronizeError = &OnFeedSynchronizeError;
  91. FStartImmediately = StartImmediately;
  92. }
  93. //---------------------------------------------------------------------------
  94. __fastcall TSynchronizeDialog::~TSynchronizeDialog()
  95. {
  96. // if application is closing OnCloseQuery might not get called
  97. // (this particularly happens if last terminal is disconnected while dialog is
  98. // open)
  99. if (FSynchronizing)
  100. {
  101. OnlyStop();
  102. }
  103. ClearGlobalMinimizeHandler(GlobalMinimize);
  104. delete FSynchronizeOptions;
  105. delete FPresetsMenu;
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TSynchronizeDialog::FeedSynchronizeError(
  109. const UnicodeString & Message, TStrings * MoreMessages, TQueryType Type,
  110. const UnicodeString & HelpKeyword)
  111. {
  112. DoLogInternal(slContinuedError, Message, MoreMessages, Type, HelpKeyword);
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TSynchronizeDialog::UpdateControls()
  116. {
  117. EnableControl(StartButton, !LocalDirectoryEdit->Text.IsEmpty() &&
  118. !RemoteDirectoryEdit->Text.IsEmpty());
  119. TButton * OldButton = FSynchronizing ? StartButton : StopButton;
  120. TButton * NewButton = FSynchronizing ? StopButton : StartButton;
  121. if (!NewButton->Visible || OldButton->Visible)
  122. {
  123. NewButton->Visible = true;
  124. if (OldButton->Focused())
  125. {
  126. NewButton->SetFocus();
  127. }
  128. OldButton->Default = false;
  129. NewButton->Default = true;
  130. OldButton->Visible = false;
  131. // some of the above steps hides accelerators when start button is pressed with mouse
  132. ResetSystemSettings(this);
  133. }
  134. Caption = FormatFormCaption(this, LoadStr(FSynchronizing ? SYNCHRONIZE_SYCHRONIZING : SYNCHRONIZE_TITLE));
  135. EnableControl(TransferSettingsButton, !FSynchronizing);
  136. CancelButton->Visible = !FSynchronizing || FLAGSET(FOptions, soNoMinimize);
  137. EnableControl(CancelButton, !FSynchronizing);
  138. EnableControl(DirectoriesGroup, !FSynchronizing);
  139. EnableControl(OptionsGroup, !FSynchronizing);
  140. EnableControl(CopyParamGroup, !FSynchronizing);
  141. MinimizeButton->Visible = FSynchronizing && FLAGCLEAR(FOptions, soNoMinimize);
  142. EnableControl(SynchronizeSelectedOnlyCheck,
  143. OptionsGroup->Enabled && FLAGSET(FOptions, soAllowSelectedOnly));
  144. UnicodeString InfoStr = CopyParams.GetInfoStr(L"; ", ActualCopyParamAttrs());
  145. CopyParamLabel->Caption = InfoStr;
  146. CopyParamLabel->Hint = InfoStr;
  147. CopyParamLabel->ShowHint =
  148. (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
  149. TransferSettingsButton->Style =
  150. FLAGCLEAR(Options, soDoNotUsePresets) ?
  151. TCustomButton::bsSplitButton : TCustomButton::bsPushButton;
  152. if (LogPanel->Visible != FSynchronizing)
  153. {
  154. if (FSynchronizing)
  155. {
  156. LogPanel->Visible = true;
  157. ClientHeight = ClientHeight + LogPanel->Height;
  158. }
  159. else
  160. {
  161. ClientHeight = ClientHeight - LogPanel->Height;
  162. LogPanel->Visible = false;
  163. }
  164. }
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TSynchronizeDialog::ControlChange(TObject * /*Sender*/)
  168. {
  169. UpdateControls();
  170. }
  171. //---------------------------------------------------------------------------
  172. bool __fastcall TSynchronizeDialog::Execute()
  173. {
  174. // at start assume that copy param is current preset
  175. FPreset = GUIConfiguration->CopyParamCurrent;
  176. LocalDirectoryEdit->Items = CustomWinConfiguration->History[L"LocalDirectory"];
  177. RemoteDirectoryEdit->Items = CustomWinConfiguration->History[L"RemoteDirectory"];
  178. ShowModal();
  179. return true;
  180. }
  181. //---------------------------------------------------------------------------
  182. void __fastcall TSynchronizeDialog::SetParams(const TSynchronizeParamType& value)
  183. {
  184. FParams = value;
  185. RemoteDirectoryEdit->Text = value.RemoteDirectory;
  186. LocalDirectoryEdit->Text = value.LocalDirectory;
  187. SynchronizeDeleteCheck->Checked = FLAGSET(value.Params, spDelete);
  188. SynchronizeExistingOnlyCheck->Checked = FLAGSET(value.Params, spExistingOnly);
  189. SynchronizeSelectedOnlyCheck->Checked = FLAGSET(value.Params, spSelectedOnly);
  190. SynchronizeRecursiveCheck->Checked = FLAGSET(value.Options, soRecurse);
  191. SynchronizeSynchronizeCheck->State =
  192. FLAGSET(value.Options, soSynchronizeAsk) ? cbGrayed :
  193. (FLAGSET(value.Options, soSynchronize) ? cbChecked : cbUnchecked);
  194. ContinueOnErrorCheck->Checked = FLAGSET(value.Options, soContinueOnError);
  195. }
  196. //---------------------------------------------------------------------------
  197. TSynchronizeParamType __fastcall TSynchronizeDialog::GetParams()
  198. {
  199. TSynchronizeParamType Result = FParams;
  200. Result.RemoteDirectory = RemoteDirectoryEdit->Text;
  201. Result.LocalDirectory = LocalDirectoryEdit->Text;
  202. Result.Params =
  203. (Result.Params & ~(spDelete | spExistingOnly | spSelectedOnly | spTimestamp)) |
  204. FLAGMASK(SynchronizeDeleteCheck->Checked, spDelete) |
  205. FLAGMASK(SynchronizeExistingOnlyCheck->Checked, spExistingOnly) |
  206. FLAGMASK(SynchronizeSelectedOnlyCheck->Checked, spSelectedOnly);
  207. Result.Options =
  208. (Result.Options & ~(soRecurse | soSynchronize | soSynchronizeAsk | soContinueOnError)) |
  209. FLAGMASK(SynchronizeRecursiveCheck->Checked, soRecurse) |
  210. FLAGMASK(SynchronizeSynchronizeCheck->State == cbChecked, soSynchronize) |
  211. FLAGMASK(SynchronizeSynchronizeCheck->State == cbGrayed, soSynchronizeAsk) |
  212. FLAGMASK(ContinueOnErrorCheck->Checked, soContinueOnError);
  213. return Result;
  214. }
  215. //---------------------------------------------------------------------------
  216. void __fastcall TSynchronizeDialog::LocalDirectoryBrowseButtonClick(
  217. TObject * /*Sender*/)
  218. {
  219. UnicodeString Directory = LocalDirectoryEdit->Text;
  220. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), false))
  221. {
  222. LocalDirectoryEdit->Text = Directory;
  223. }
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TSynchronizeDialog::SetOptions(int value)
  227. {
  228. if (Options != value)
  229. {
  230. FOptions = value;
  231. UpdateControls();
  232. }
  233. }
  234. //---------------------------------------------------------------------------
  235. void __fastcall TSynchronizeDialog::CopyParamListPopup(TRect R, int AdditionalOptions)
  236. {
  237. // We pass in FCopyParams, although it may not be the exact copy param
  238. // that will be used (because of PreserveTime). The reason is to
  239. // display checkbox next to user-selected preset
  240. ::CopyParamListPopup(
  241. R, FPresetsMenu, FCopyParams, FPreset, CopyParamClick,
  242. cplCustomize | AdditionalOptions, ActualCopyParamAttrs());
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TSynchronizeDialog::TransferSettingsButtonClick(
  246. TObject * /*Sender*/)
  247. {
  248. if (FLAGCLEAR(FOptions, soDoNotUsePresets) && !SupportsSplitButton())
  249. {
  250. CopyParamListPopup(CalculatePopupRect(TransferSettingsButton), 0);
  251. }
  252. else
  253. {
  254. CopyParamGroupClick(NULL);
  255. }
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TSynchronizeDialog::DoStartStop(bool Start, bool Synchronize)
  259. {
  260. if (FOnStartStop)
  261. {
  262. TSynchronizeParamType SParams = GetParams();
  263. SParams.Options =
  264. (SParams.Options & ~(soSynchronize | soSynchronizeAsk)) |
  265. FLAGMASK(Synchronize, soSynchronize);
  266. if (Start)
  267. {
  268. assert(*FOnFeedSynchronizeError == NULL);
  269. *FOnFeedSynchronizeError =
  270. (FLAGSET(SParams.Options, soContinueOnError) ? &FeedSynchronizeError : TFeedSynchronizeError(NULL));
  271. delete FSynchronizeOptions;
  272. FSynchronizeOptions = new TSynchronizeOptions;
  273. FOnGetOptions(SParams.Params, *FSynchronizeOptions);
  274. }
  275. else
  276. {
  277. *FOnFeedSynchronizeError = NULL;
  278. }
  279. FOnStartStop(this, Start, SParams, CopyParams, FSynchronizeOptions, DoAbort,
  280. NULL, DoLog);
  281. }
  282. }
  283. //---------------------------------------------------------------------------
  284. void __fastcall TSynchronizeDialog::Dispatch(void * AMessage)
  285. {
  286. assert(AMessage != NULL);
  287. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  288. if ((Message.Msg == WM_USER_STOP) && FAbort)
  289. {
  290. if (FSynchronizing)
  291. {
  292. Stop();
  293. }
  294. if (FClose)
  295. {
  296. FClose = false;
  297. ModalResult = mrCancel;
  298. }
  299. }
  300. else if (Message.Msg == WM_MANAGES_CAPTION)
  301. {
  302. // caption managed in UpdateControls()
  303. Message.Result = 1;
  304. }
  305. else
  306. {
  307. TForm::Dispatch(AMessage);
  308. }
  309. }
  310. //---------------------------------------------------------------------------
  311. void __fastcall TSynchronizeDialog::DoAbort(TObject * /*Sender*/, bool Close)
  312. {
  313. FAbort = true;
  314. FClose = Close;
  315. PostMessage(Handle, WM_USER_STOP, 0, 0);
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TSynchronizeDialog::DoLogInternal(
  319. TSynchronizeLogEntry Entry, const UnicodeString & Message,
  320. TStrings * MoreMessages, TQueryType Type, const UnicodeString & HelpKeyword)
  321. {
  322. LogView->Items->BeginUpdate();
  323. try
  324. {
  325. TListItem * Item = LogView->Items->Add();
  326. TLogItemData * LogItemData = new TLogItemData();
  327. Item->Data = LogItemData;
  328. LogItemData->Entry = Entry;
  329. LogItemData->Message = Message;
  330. if (MoreMessages != NULL)
  331. {
  332. LogItemData->MoreMessages.reset(new TStringList());
  333. LogItemData->MoreMessages->Assign(MoreMessages);
  334. }
  335. LogItemData->Type = Type;
  336. LogItemData->HelpKeyword = HelpKeyword;
  337. Item->Caption = Now().TimeString();
  338. UnicodeString UnformattedMessage = UnformatMessage(Message);
  339. UnformattedMessage = ReplaceStr(UnformattedMessage, L"\r", L"");
  340. UnformattedMessage = ReplaceStr(UnformattedMessage, L"\n", L" ");
  341. Item->SubItems->Add(UnformattedMessage);
  342. Item->MakeVisible(false);
  343. while (LogView->Items->Count > MaxLogItems)
  344. {
  345. LogView->Items->Delete(0);
  346. }
  347. }
  348. __finally
  349. {
  350. LogView->Items->EndUpdate();
  351. if (Entry == slScan)
  352. {
  353. // redraw log before the scanning block update
  354. LogView->Repaint();
  355. }
  356. }
  357. }
  358. //---------------------------------------------------------------------------
  359. void __fastcall TSynchronizeDialog::DoLog(TSynchronizeController * /*Controller*/,
  360. TSynchronizeLogEntry Entry, const UnicodeString Message)
  361. {
  362. DoLogInternal(Entry, Message,
  363. // these are unused (as Entry is not slContinuedError here)
  364. NULL, qtInformation, UnicodeString());
  365. }
  366. //---------------------------------------------------------------------------
  367. void __fastcall TSynchronizeDialog::StartButtonClick(TObject * /*Sender*/)
  368. {
  369. bool Synchronize;
  370. bool Continue = true;
  371. if (SynchronizeSynchronizeCheck->State == cbGrayed)
  372. {
  373. TMessageParams Params(mpNeverAskAgainCheck);
  374. switch (MoreMessageDialog(LoadStr(SYNCHRONISE_BEFORE_KEEPUPTODATE2),
  375. NULL, qtConfirmation, qaYes | qaNo | qaCancel, HELP_KEEPUPTODATE_SYNCHRONIZE,
  376. &Params))
  377. {
  378. case qaNeverAskAgain:
  379. SynchronizeSynchronizeCheck->State = cbChecked;
  380. // fall thru
  381. case qaYes:
  382. Synchronize = true;
  383. break;
  384. case qaNo:
  385. Synchronize = false;
  386. break;
  387. default:
  388. case qaCancel:
  389. Continue = false;
  390. break;
  391. };
  392. }
  393. else
  394. {
  395. Synchronize = SynchronizeSynchronizeCheck->Checked;
  396. }
  397. if (Continue)
  398. {
  399. assert(!FSynchronizing);
  400. LocalDirectoryEdit->SaveToHistory();
  401. CustomWinConfiguration->History[L"LocalDirectory"] = LocalDirectoryEdit->Items;
  402. RemoteDirectoryEdit->SaveToHistory();
  403. CustomWinConfiguration->History[L"RemoteDirectory"] = RemoteDirectoryEdit->Items;
  404. FSynchronizing = true;
  405. try
  406. {
  407. UpdateControls();
  408. Repaint();
  409. FAbort = false;
  410. DoStartStop(true, Synchronize);
  411. }
  412. catch(...)
  413. {
  414. FSynchronizing = false;
  415. UpdateControls();
  416. throw;
  417. }
  418. }
  419. }
  420. //---------------------------------------------------------------------------
  421. void __fastcall TSynchronizeDialog::StopButtonClick(TObject * /*Sender*/)
  422. {
  423. Stop();
  424. }
  425. //---------------------------------------------------------------------------
  426. void __fastcall TSynchronizeDialog::OnlyStop()
  427. {
  428. FSynchronizing = false;
  429. DoStartStop(false, false);
  430. }
  431. //---------------------------------------------------------------------------
  432. void __fastcall TSynchronizeDialog::Stop()
  433. {
  434. OnlyStop();
  435. UpdateControls();
  436. Repaint();
  437. if (IsApplicationMinimized() && FMinimizedByMe)
  438. {
  439. FMinimizedByMe = false;
  440. ApplicationRestore();
  441. Application->BringToFront();
  442. }
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TSynchronizeDialog::MinimizeButtonClick(TObject * Sender)
  446. {
  447. CallGlobalMinimizeHandler(Sender);
  448. }
  449. //---------------------------------------------------------------------------
  450. void __fastcall TSynchronizeDialog::GlobalMinimize(TObject * /*Sender*/)
  451. {
  452. ApplicationMinimize();
  453. FMinimizedByMe = true;
  454. }
  455. //---------------------------------------------------------------------------
  456. void __fastcall TSynchronizeDialog::SetSaveSettings(bool value)
  457. {
  458. SaveSettingsCheck->Checked = value;
  459. }
  460. //---------------------------------------------------------------------------
  461. bool __fastcall TSynchronizeDialog::GetSaveSettings()
  462. {
  463. return SaveSettingsCheck->Checked;
  464. }
  465. //---------------------------------------------------------------------------
  466. void __fastcall TSynchronizeDialog::FormShow(TObject * /*Sender*/)
  467. {
  468. InstallPathWordBreakProc(LocalDirectoryEdit);
  469. InstallPathWordBreakProc(RemoteDirectoryEdit);
  470. // OnShow gets called more than once sometimes
  471. if (!FSynchronizing)
  472. {
  473. ClearLog();
  474. UpdateControls();
  475. if (FStartImmediately)
  476. {
  477. // if starting get cancelled (from SYNCHRONISE_BEFORE_KEEPUPTODATE2 prompt),
  478. // and OnShow gets called again (FSynchronizing is false),
  479. // we do not want to try to start again
  480. FStartImmediately = false;
  481. StartButtonClick(NULL);
  482. }
  483. }
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TSynchronizeDialog::FormCloseQuery(TObject * /*Sender*/,
  487. bool & /*CanClose*/)
  488. {
  489. if (FSynchronizing)
  490. {
  491. Stop();
  492. }
  493. }
  494. //---------------------------------------------------------------------------
  495. TCopyParamType __fastcall TSynchronizeDialog::GetCopyParams()
  496. {
  497. TCopyParamType Result = FCopyParams;
  498. Result.PreserveTime = true;
  499. Result.NewerOnly = false;
  500. return Result;
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TSynchronizeDialog::SetCopyParams(const TCopyParamType & value)
  504. {
  505. FCopyParams = value;
  506. UpdateControls();
  507. }
  508. //---------------------------------------------------------------------------
  509. int __fastcall TSynchronizeDialog::ActualCopyParamAttrs()
  510. {
  511. return FCopyParamAttrs | cpaNoPreserveTime | cpaNoNewerOnly;
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TSynchronizeDialog::CopyParamClick(TObject * Sender)
  515. {
  516. assert(FLAGCLEAR(FOptions, soDoNotUsePresets));
  517. // PreserveTime is forced for some settings, but avoid hard-setting it until
  518. // user really confirms it on custom dialog
  519. TCopyParamType ACopyParams = CopyParams;
  520. if (CopyParamListPopupClick(Sender, ACopyParams, FPreset,
  521. ActualCopyParamAttrs()))
  522. {
  523. FCopyParams = ACopyParams;
  524. UpdateControls();
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TSynchronizeDialog::CopyParamGroupContextPopup(
  529. TObject * /*Sender*/, TPoint & MousePos, bool & Handled)
  530. {
  531. if (FLAGCLEAR(FOptions, soDoNotUsePresets))
  532. {
  533. CopyParamListPopup(CalculatePopupRect(CopyParamGroup, MousePos),
  534. cplCustomizeDefault);
  535. Handled = true;
  536. }
  537. }
  538. //---------------------------------------------------------------------------
  539. void __fastcall TSynchronizeDialog::CopyParamGroupClick(TObject * /*Sender*/)
  540. {
  541. // PreserveTime is forced for some settings, but avoid hard-setting it until
  542. // user really confirms it on cutom dialog
  543. TCopyParamType ACopyParams = CopyParams;
  544. if (DoCopyParamCustomDialog(ACopyParams, ActualCopyParamAttrs()))
  545. {
  546. FCopyParams = ACopyParams;
  547. UpdateControls();
  548. }
  549. }
  550. //---------------------------------------------------------------------------
  551. void __fastcall TSynchronizeDialog::HelpButtonClick(TObject * /*Sender*/)
  552. {
  553. FormHelp(this);
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TSynchronizeDialog::ClearLog()
  557. {
  558. // TListItems::Clear() does nothing without allocated handle
  559. LogView->HandleNeeded();
  560. LogView->Items->Clear();
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TSynchronizeDialog::CopyLog()
  564. {
  565. TInstantOperationVisualizer Visualizer;
  566. UnicodeString Content;
  567. for (int i = 0; i < LogView->Items->Count; i++)
  568. {
  569. TListItem * Item = LogView->Items->Item[i];
  570. Content += Item->Caption + L"\t" + Item->SubItems->Strings[0] + L"\r\n";
  571. }
  572. CopyToClipboard(Content);
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TSynchronizeDialog::LogViewKeyDown(TObject * /*Sender*/,
  576. WORD & Key, TShiftState Shift)
  577. {
  578. if (Key == VK_DELETE)
  579. {
  580. ClearLog();
  581. Key = 0;
  582. }
  583. else if ((Key == L'C') && Shift.Contains(ssCtrl) && (LogView->Items->Count > 0))
  584. {
  585. CopyLog();
  586. Key = 0;
  587. }
  588. }
  589. //---------------------------------------------------------------------------
  590. void __fastcall TSynchronizeDialog::FormKeyDown(TObject * /*Sender*/, WORD & Key,
  591. TShiftState /*Shift*/)
  592. {
  593. if ((Key == VK_ESCAPE) && FSynchronizing)
  594. {
  595. Stop();
  596. Key = 0;
  597. }
  598. }
  599. //---------------------------------------------------------------------------
  600. void __fastcall TSynchronizeDialog::TransferSettingsButtonDropDownClick(TObject * /*Sender*/)
  601. {
  602. CopyParamListPopup(CalculatePopupRect(TransferSettingsButton), cplCustomizeDefault);
  603. }
  604. //---------------------------------------------------------------------------
  605. void __fastcall TSynchronizeDialog::LogViewCustomDrawItem(TCustomListView * Sender,
  606. TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  607. {
  608. TLogItemData * LogItemData = GetLogItemData(Item);
  609. if (LogItemData->Entry == slContinuedError)
  610. {
  611. Sender->Canvas->Font->Color = clRed;
  612. }
  613. }
  614. //---------------------------------------------------------------------------
  615. TLogItemData * __fastcall TSynchronizeDialog::GetLogItemData(TListItem * Item)
  616. {
  617. return reinterpret_cast<TLogItemData *>(Item->Data);
  618. }
  619. //---------------------------------------------------------------------------
  620. void __fastcall TSynchronizeDialog::LogViewDeletion(TObject * /*Sender*/, TListItem * Item)
  621. {
  622. delete GetLogItemData(Item);
  623. Item->Data = NULL;
  624. }
  625. //---------------------------------------------------------------------------
  626. void __fastcall TSynchronizeDialog::LogViewDblClick(TObject * /*Sender*/)
  627. {
  628. if (LogView->ItemFocused != NULL)
  629. {
  630. TLogItemData * LogItemData = GetLogItemData(LogView->ItemFocused);
  631. if (LogItemData->Entry == slContinuedError)
  632. {
  633. MoreMessageDialog(
  634. LogItemData->Message, LogItemData->MoreMessages.get(), LogItemData->Type,
  635. qaOK, LogItemData->HelpKeyword);
  636. }
  637. }
  638. }
  639. //---------------------------------------------------------------------------