Synchronize.cpp 23 KB

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