Custom.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Dialogs.hpp>
  5. //---------------------------------------------------------------------
  6. #include <Common.h>
  7. #include <CustomWinConfiguration.h>
  8. #include <WinInterface.h>
  9. #include <VCLCommon.h>
  10. #include <TextsWin.h>
  11. #include <HelpWin.h>
  12. #include <CoreMain.h>
  13. #include <PasTools.hpp>
  14. #include <ProgParams.h>
  15. #include <Tools.h>
  16. #include <GUITools.h>
  17. #include <HistoryComboBox.hpp>
  18. #include <Math.hpp>
  19. #include "Custom.h"
  20. //---------------------------------------------------------------------
  21. #pragma link "PasswordEdit"
  22. #ifndef NO_RESOURCES
  23. #pragma resource "*.dfm"
  24. #endif
  25. //---------------------------------------------------------------------
  26. __fastcall TCustomDialog::TCustomDialog(UnicodeString AHelpKeyword)
  27. : TForm(GetFormOwner())
  28. {
  29. UseSystemSettings(this);
  30. FPos = ScaleByTextHeight(this, 8);
  31. FHorizontalMargin = ScaleByTextHeight(this, 8);
  32. FIndent = FHorizontalMargin;
  33. HelpKeyword = AHelpKeyword;
  34. TBorderIcons BI = BorderIcons;
  35. if (HelpKeyword.IsEmpty())
  36. {
  37. BI >> biHelp;
  38. OKButton->Left = CancelButton->Left;
  39. CancelButton->Left = HelpButton->Left;
  40. HelpButton->Visible = false;
  41. }
  42. else
  43. {
  44. BI << biHelp;
  45. }
  46. BorderIcons = BI;
  47. }
  48. //---------------------------------------------------------------------
  49. bool __fastcall TCustomDialog::Execute()
  50. {
  51. Changed();
  52. return (ShowModal() == DefaultResult(this));
  53. }
  54. //---------------------------------------------------------------------
  55. void __fastcall TCustomDialog::DoChange(bool & /*CanSubmit*/)
  56. {
  57. // noop
  58. }
  59. //---------------------------------------------------------------------
  60. void __fastcall TCustomDialog::Changed()
  61. {
  62. bool CanSubmit = true;
  63. DoChange(CanSubmit);
  64. EnableControl(OKButton, CanSubmit);
  65. }
  66. //---------------------------------------------------------------------
  67. void __fastcall TCustomDialog::Change(TObject * /*Sender*/)
  68. {
  69. Changed();
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TCustomDialog::HelpButtonClick(TObject * /*Sender*/)
  73. {
  74. FormHelp(this);
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TCustomDialog::DoShow()
  78. {
  79. OKButton->TabOrder = FCount;
  80. CancelButton->TabOrder = static_cast<short>(FCount + 1);
  81. HelpButton->TabOrder = static_cast<short>(FCount + 2);
  82. Changed();
  83. TForm::DoShow();
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TCustomDialog::DoValidate()
  87. {
  88. // noop
  89. }
  90. //---------------------------------------------------------------------------
  91. bool __fastcall TCustomDialog::CloseQuery()
  92. {
  93. if (ModalResult == DefaultResult(this))
  94. {
  95. DoValidate();
  96. }
  97. return TForm::CloseQuery();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
  101. {
  102. TImage * Image = new TImage(this);
  103. Image->Name = L"Image";
  104. Image->Parent = this;
  105. LoadDialogImage(Image, ImageName);
  106. Image->SetBounds(FIndent, FPos + ScaleByTextHeight(this, 3), Image->Picture->Width, Image->Picture->Height);
  107. FIndent += Image->Width + ScaleByTextHeight(this, 12);
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TCustomDialog::AddWinControl(TWinControl * Control)
  111. {
  112. Control->TabOrder = FCount;
  113. FCount++;
  114. }
  115. //---------------------------------------------------------------------------
  116. TCheckBox * __fastcall TCustomDialog::CreateAndAddCheckBox(const UnicodeString & Caption)
  117. {
  118. TCheckBox * CheckBox = new TCheckBox(this);
  119. CheckBox->Caption = Caption;
  120. AddButtonControl(CheckBox);
  121. return CheckBox;
  122. }
  123. //---------------------------------------------------------------------------
  124. TLabel * __fastcall TCustomDialog::CreateLabel(UnicodeString Label)
  125. {
  126. TLabel * Result = new TLabel(this);
  127. Result->Caption = Label;
  128. return Result;
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * Label)
  132. {
  133. int PrePos = FPos;
  134. Label->Parent = this;
  135. Label->Left = FIndent;
  136. Label->Top = FPos;
  137. FPos += Label->Height + ScaleByTextHeight(this, 4);
  138. Edit->Parent = this;
  139. Edit->Left = FIndent;
  140. Edit->Top = FPos;
  141. Edit->Width = ClientWidth - Edit->Left - FHorizontalMargin;
  142. // this updates Height property to real value
  143. Edit->HandleNeeded();
  144. FPos += Edit->Height + ScaleByTextHeight(this, 8);
  145. if (Label->FocusControl == NULL)
  146. {
  147. Label->FocusControl = Edit;
  148. }
  149. else
  150. {
  151. DebugAssert(Label->FocusControl == Edit);
  152. }
  153. ClientHeight = ClientHeight + (FPos - PrePos);
  154. AddWinControl(Edit);
  155. }
  156. //---------------------------------------------------------------------------
  157. void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label)
  158. {
  159. AddEditLikeControl(Edit, Label);
  160. TEdit * PublicEdit = reinterpret_cast<TEdit *>(Edit);
  161. if (PublicEdit->OnChange == NULL)
  162. {
  163. PublicEdit->OnChange = Change;
  164. }
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TCustomDialog::AddComboBox(TCustomCombo * Combo, TLabel * Label)
  168. {
  169. AddEditLikeControl(Combo, Label);
  170. TComboBox * PublicCombo = reinterpret_cast<TComboBox *>(Combo);
  171. if (PublicCombo->OnChange == NULL)
  172. {
  173. PublicCombo->OnChange = Change;
  174. }
  175. }
  176. //---------------------------------------------------------------------------
  177. void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
  178. {
  179. int PrePos = FPos;
  180. Control->Parent = this;
  181. Control->Left = FIndent + ScaleByTextHeight(this, 6);
  182. Control->Top = FPos;
  183. Control->Width = ClientWidth - Control->Left - FHorizontalMargin;
  184. // this updates Height property to real value
  185. Control->HandleNeeded();
  186. // buttons do not scale with text on their own
  187. Control->Height = ScaleByTextHeight(Control, Control->Height);
  188. FPos += Control->Height + ScaleByTextHeight(this, 8);
  189. ClientHeight = ClientHeight + (FPos - PrePos);
  190. AddWinControl(Control);
  191. TCheckBox * PublicControl = reinterpret_cast<TCheckBox *>(Control);
  192. if (PublicControl->OnClick == NULL)
  193. {
  194. PublicControl->OnClick = Change;
  195. }
  196. }
  197. //---------------------------------------------------------------------------
  198. //---------------------------------------------------------------------------
  199. class TSaveSessionDialog : public TCustomDialog
  200. {
  201. public:
  202. __fastcall TSaveSessionDialog(TComponent* AOwner);
  203. void __fastcall Init(bool CanSavePassword, bool NotRecommendedSavingPassword,
  204. TStrings * AdditionalFolders);
  205. bool __fastcall Execute(UnicodeString & SessionName, bool & SavePassword,
  206. bool & CreateShortcut, const UnicodeString & OriginalSessionName);
  207. protected:
  208. virtual void __fastcall DoValidate();
  209. virtual void __fastcall DoChange(bool & CanSubmit);
  210. private:
  211. UnicodeString FOriginalSessionName;
  212. TEdit * SessionNameEdit;
  213. TComboBox * FolderCombo;
  214. TCheckBox * SavePasswordCheck;
  215. TCheckBox * CreateShortcutCheck;
  216. UnicodeString FRootFolder;
  217. UnicodeString __fastcall GetSessionName();
  218. };
  219. //---------------------------------------------------------------------------
  220. // Need to have an Owner argument for SafeFormCreate
  221. __fastcall TSaveSessionDialog::TSaveSessionDialog(TComponent* /*AOwner*/) :
  222. TCustomDialog(HELP_SESSION_SAVE)
  223. {
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TSaveSessionDialog::Init(bool CanSavePassword,
  227. bool NotRecommendedSavingPassword, TStrings * AdditionalFolders)
  228. {
  229. Caption = LoadStr(SAVE_SESSION_CAPTION);
  230. SessionNameEdit = new TEdit(this);
  231. AddEdit(SessionNameEdit, CreateLabel(LoadStr(SAVE_SESSION_PROMPT)));
  232. FRootFolder = LoadStr(SAVE_SESSION_ROOT_FOLDER2);
  233. std::unique_ptr<TStringList> Folders(new TStringList());
  234. if (AdditionalFolders != NULL)
  235. {
  236. Folders->AddStrings(AdditionalFolders);
  237. }
  238. for (int Index = 0; Index < StoredSessions->Count; Index++)
  239. {
  240. TSessionData * Data = StoredSessions->Sessions[Index];
  241. if (!Data->Special && !Data->IsWorkspace)
  242. {
  243. UnicodeString Folder = Data->FolderName;
  244. if (!Folder.IsEmpty() && Folders->IndexOf(Folder) < 0)
  245. {
  246. Folders->Add(Folder);
  247. }
  248. }
  249. }
  250. DebugAssert(!Folders->CaseSensitive);
  251. Folders->Sort();
  252. FolderCombo = new TComboBox(this);
  253. AddComboBox(FolderCombo, CreateLabel(LoadStr(SAVE_SESSION_FOLDER)));
  254. FolderCombo->DropDownCount = Max(FolderCombo->DropDownCount, 16);
  255. FolderCombo->Items->Add(FRootFolder);
  256. FolderCombo->Items->AddStrings(Folders.get());
  257. SavePasswordCheck = CreateAndAddCheckBox(
  258. LoadStr(NotRecommendedSavingPassword ? SAVE_SESSION_PASSWORD :
  259. (CustomWinConfiguration->UseMasterPassword ? SAVE_SESSION_PASSWORD_MASTER : SAVE_SESSION_PASSWORD_RECOMMENDED)));
  260. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  261. EnableControl(SavePasswordCheck, CanSavePassword);
  262. }
  263. //---------------------------------------------------------------------------
  264. bool __fastcall TSaveSessionDialog::Execute(
  265. UnicodeString & SessionName, bool & SavePassword, bool & CreateShortcut,
  266. const UnicodeString & OriginalSessionName)
  267. {
  268. FOriginalSessionName = OriginalSessionName;
  269. SessionNameEdit->Text = TSessionData::ExtractLocalName(SessionName);
  270. UnicodeString Folder = TSessionData::ExtractFolderName(SessionName);
  271. if (Folder.IsEmpty())
  272. {
  273. FolderCombo->Text = FRootFolder;
  274. }
  275. else
  276. {
  277. FolderCombo->Text = Folder;
  278. }
  279. SavePasswordCheck->Checked = SavePassword;
  280. CreateShortcutCheck->Checked = CreateShortcut;
  281. bool Result = TCustomDialog::Execute();
  282. if (Result)
  283. {
  284. SessionName = GetSessionName();
  285. SavePassword = SavePasswordCheck->Checked;
  286. CreateShortcut = CreateShortcutCheck->Checked;
  287. }
  288. return Result;
  289. }
  290. //---------------------------------------------------------------------------
  291. UnicodeString __fastcall TSaveSessionDialog::GetSessionName()
  292. {
  293. UnicodeString Folder;
  294. if (FolderCombo->Text != FRootFolder)
  295. {
  296. Folder = FolderCombo->Text;
  297. }
  298. return TSessionData::ComposePath(Folder, SessionNameEdit->Text);
  299. }
  300. //---------------------------------------------------------------------------
  301. void __fastcall TSaveSessionDialog::DoValidate()
  302. {
  303. TSessionData::ValidateName(SessionNameEdit->Text);
  304. SessionNameValidate(GetSessionName(), FOriginalSessionName);
  305. UnicodeString Folder = TSessionData::ExtractFolderName(GetSessionName());
  306. if (!Folder.IsEmpty() && StoredSessions->IsWorkspace(Folder))
  307. {
  308. throw Exception(FMTLOAD(WORKSPACE_NOT_FOLDER, (Folder)));
  309. }
  310. if (SavePasswordCheck->Enabled && SavePasswordCheck->Checked &&
  311. CustomWinConfiguration->UseMasterPassword)
  312. {
  313. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  314. }
  315. TCustomDialog::DoValidate();
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TSaveSessionDialog::DoChange(bool & CanSubmit)
  319. {
  320. CanSubmit = !SessionNameEdit->Text.IsEmpty();
  321. TCustomDialog::DoChange(CanSubmit);
  322. }
  323. //---------------------------------------------------------------------------
  324. TSessionData * __fastcall DoSaveSession(TSessionData * SessionData,
  325. TSessionData * OriginalSession, bool ForceDialog,
  326. TStrings * AdditionalFolders)
  327. {
  328. bool SavePassword = false;
  329. bool * PSavePassword;
  330. bool NotRecommendedSavingPassword =
  331. !CustomWinConfiguration->UseMasterPassword &&
  332. !SameText(SessionData->UserName, AnonymousUserName);
  333. if (Configuration->DisablePasswordStoring ||
  334. !SessionData->HasAnySessionPassword())
  335. {
  336. PSavePassword = NULL;
  337. }
  338. else
  339. {
  340. PSavePassword = &SavePassword;
  341. SavePassword =
  342. ((OriginalSession != NULL) && OriginalSession->HasAnySessionPassword()) ||
  343. !NotRecommendedSavingPassword;
  344. }
  345. UnicodeString SessionName = SessionData->SessionName;
  346. bool Result;
  347. bool CreateShortcut = false;
  348. if (!ForceDialog && ((PSavePassword == NULL) || SavePassword))
  349. {
  350. CustomWinConfiguration->AskForMasterPasswordIfNotSetAndNeededToPersistSessionData(SessionData);
  351. Result = true;
  352. }
  353. else
  354. {
  355. // This can be a standalone dialog when used with save URL (from GetLoginData)
  356. TSaveSessionDialog * Dialog = SafeFormCreate<TSaveSessionDialog>();
  357. try
  358. {
  359. Dialog->Init((PSavePassword != NULL), NotRecommendedSavingPassword, AdditionalFolders);
  360. Result = Dialog->Execute(SessionName, SavePassword, CreateShortcut, SessionData->Name);
  361. }
  362. __finally
  363. {
  364. delete Dialog;
  365. }
  366. }
  367. TSessionData * NewSession = NULL;
  368. if (Result)
  369. {
  370. if ((PSavePassword != NULL) && !SavePassword)
  371. {
  372. SessionData->ClearSessionPasswords();
  373. }
  374. NewSession =
  375. StoredSessions->NewSession(SessionName, SessionData);
  376. // modified only, explicit
  377. StoredSessions->Save(false, true);
  378. if (!SessionData->HostKey.IsEmpty())
  379. {
  380. SessionData->CacheHostKeyIfNotCached();
  381. }
  382. if (CreateShortcut)
  383. {
  384. TOperationVisualizer Visualizer;
  385. UnicodeString AdditionalParams =
  386. TProgramParams::FormatSwitch(DESKTOP_SWITCH) + L" " +
  387. TProgramParams::FormatSwitch(UPLOAD_IF_ANY_SWITCH);
  388. CreateDesktopSessionShortCut(SessionName, L"", AdditionalParams, -1, SITE_ICON);
  389. }
  390. }
  391. return NewSession;
  392. }
  393. //---------------------------------------------------------------------------
  394. void __fastcall SessionNameValidate(const UnicodeString & Text,
  395. const UnicodeString & OriginalName)
  396. {
  397. TSessionData::ValidatePath(Text);
  398. DebugAssert(StoredSessions);
  399. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  400. if (Data && Data->Special)
  401. {
  402. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  403. qtError, qaOK, HELP_NONE);
  404. Abort();
  405. }
  406. else if ((Data != NULL) && !Data->IsSameName(OriginalName) &&
  407. MessageDialog(MainInstructions(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text))),
  408. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  409. {
  410. Abort();
  411. }
  412. }
  413. //---------------------------------------------------------------------------
  414. //---------------------------------------------------------------------------
  415. class TSaveWorkspaceDialog : public TCustomDialog
  416. {
  417. public:
  418. __fastcall TSaveWorkspaceDialog(bool CanSavePasswords,
  419. bool NotRecommendedSavingPasswords);
  420. bool __fastcall Execute(
  421. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  422. bool & EnableAutoSave);
  423. protected:
  424. virtual void __fastcall DoValidate();
  425. virtual void __fastcall DoChange(bool & CanSubmit);
  426. private:
  427. TComboBox * WorkspaceNameCombo;
  428. TCheckBox * SavePasswordsCheck;
  429. TCheckBox * CreateShortcutCheck;
  430. TCheckBox * EnableAutoSaveCheck;
  431. };
  432. //---------------------------------------------------------------------------
  433. __fastcall TSaveWorkspaceDialog::TSaveWorkspaceDialog(
  434. bool CanSavePasswords, bool NotRecommendedSavingPasswords) :
  435. TCustomDialog(HELP_WORKSPACE_SAVE)
  436. {
  437. Caption = LoadStr(SAVE_WORKSPACE_CAPTION);
  438. WorkspaceNameCombo = new TComboBox(this);
  439. WorkspaceNameCombo->AutoComplete = false;
  440. AddComboBox(WorkspaceNameCombo, CreateLabel(LoadStr(SAVE_WORKSPACE_PROMPT)));
  441. WorkspaceNameCombo->DropDownCount = Max(WorkspaceNameCombo->DropDownCount, 16);
  442. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  443. WorkspaceNameCombo->Items->AddStrings(Workspaces.get());
  444. SavePasswordsCheck = CreateAndAddCheckBox(
  445. LoadStr(NotRecommendedSavingPasswords ? SAVE_WORKSPACE_PASSWORDS :
  446. (CustomWinConfiguration->UseMasterPassword ?
  447. SAVE_WORKSPACE_PASSWORDS_MASTER : SAVE_WORKSPACE_PASSWORDS_RECOMMENDED)));
  448. EnableControl(SavePasswordsCheck, CanSavePasswords);
  449. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  450. EnableAutoSaveCheck = CreateAndAddCheckBox(LoadStr(SAVE_WORKSPACE_AUTO));
  451. }
  452. //---------------------------------------------------------------------------
  453. bool __fastcall TSaveWorkspaceDialog::Execute(
  454. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  455. bool & EnableAutoSave)
  456. {
  457. WorkspaceNameCombo->Text = WorkspaceName;
  458. SavePasswordsCheck->Checked = SavePasswords;
  459. CreateShortcutCheck->Checked = CreateShortcut;
  460. EnableAutoSaveCheck->Checked = EnableAutoSave;
  461. bool Result = TCustomDialog::Execute();
  462. if (Result)
  463. {
  464. WorkspaceName = WorkspaceNameCombo->Text;
  465. SavePasswords = SavePasswordsCheck->Checked;
  466. CreateShortcut = CreateShortcutCheck->Checked;
  467. EnableAutoSave = EnableAutoSaveCheck->Checked;
  468. }
  469. return Result;
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TSaveWorkspaceDialog::DoValidate()
  473. {
  474. TSessionData::ValidateName(WorkspaceNameCombo->Text);
  475. if (StoredSessions->IsFolder(WorkspaceNameCombo->Text))
  476. {
  477. throw Exception(FMTLOAD(FOLDER_NOT_WORKSPACE, (WorkspaceNameCombo->Text)));
  478. }
  479. if (SavePasswordsCheck->Enabled && SavePasswordsCheck->Checked &&
  480. CustomWinConfiguration->UseMasterPassword)
  481. {
  482. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  483. }
  484. TCustomDialog::DoValidate();
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TSaveWorkspaceDialog::DoChange(bool & CanSubmit)
  488. {
  489. CanSubmit = !WorkspaceNameCombo->Text.IsEmpty();
  490. TCustomDialog::DoChange(CanSubmit);
  491. }
  492. //---------------------------------------------------------------------------
  493. bool __fastcall DoSaveWorkspaceDialog(UnicodeString & WorkspaceName,
  494. bool * SavePasswords, bool NotRecommendedSavingPasswords,
  495. bool & CreateShortcut, bool & EnableAutoSave)
  496. {
  497. std::unique_ptr<TSaveWorkspaceDialog> Dialog(
  498. new TSaveWorkspaceDialog((SavePasswords != NULL), NotRecommendedSavingPasswords));
  499. bool Dummy = false;
  500. if (SavePasswords == NULL)
  501. {
  502. SavePasswords = &Dummy;
  503. }
  504. return
  505. Dialog->Execute(
  506. WorkspaceName, *SavePasswords, CreateShortcut, EnableAutoSave);
  507. }
  508. //---------------------------------------------------------------------------
  509. //---------------------------------------------------------------------------
  510. class TShortCutDialog : public TCustomDialog
  511. {
  512. public:
  513. __fastcall TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword);
  514. bool __fastcall Execute(TShortCut & ShortCut);
  515. private:
  516. TComboBox * ShortCutCombo;
  517. };
  518. //---------------------------------------------------------------------------
  519. __fastcall TShortCutDialog::TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword) :
  520. TCustomDialog(HelpKeyword)
  521. {
  522. Caption = LoadStr(SHORTCUT_CAPTION);
  523. ShortCutCombo = new TComboBox(this);
  524. AddComboBox(ShortCutCombo, CreateLabel(LoadStr(SHORTCUT_LABEL)));
  525. InitializeShortCutCombo(ShortCutCombo, ShortCuts);
  526. }
  527. //---------------------------------------------------------------------------
  528. bool __fastcall TShortCutDialog::Execute(TShortCut & ShortCut)
  529. {
  530. SetShortCutCombo(ShortCutCombo, ShortCut);
  531. bool Result = TCustomDialog::Execute();
  532. if (Result)
  533. {
  534. ShortCut = GetShortCutCombo(ShortCutCombo);
  535. }
  536. return Result;
  537. }
  538. //---------------------------------------------------------------------------
  539. bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
  540. const TShortCuts & ShortCuts, UnicodeString HelpKeyword)
  541. {
  542. bool Result;
  543. TShortCutDialog * Dialog = new TShortCutDialog(ShortCuts, HelpKeyword);
  544. try
  545. {
  546. Result = Dialog->Execute(ShortCut);
  547. }
  548. __finally
  549. {
  550. delete Dialog;
  551. }
  552. return Result;
  553. }
  554. //---------------------------------------------------------------------------
  555. //---------------------------------------------------------------------------
  556. class TRemoteMoveDialog : public TCustomDialog
  557. {
  558. public:
  559. __fastcall TRemoteMoveDialog(bool Multi);
  560. bool __fastcall Execute(UnicodeString & Target, UnicodeString & FileMask);
  561. protected:
  562. DYNAMIC void __fastcall DoShow();
  563. virtual void __fastcall DoValidate();
  564. UnicodeString __fastcall GetFileMask();
  565. private:
  566. THistoryComboBox * Combo;
  567. bool FMulti;
  568. };
  569. //---------------------------------------------------------------------------
  570. __fastcall TRemoteMoveDialog::TRemoteMoveDialog(bool Multi) :
  571. TCustomDialog(HELP_REMOTE_MOVE)
  572. {
  573. Caption = LoadStr(REMOTE_MOVE_TITLE);
  574. // The same as TRemoteTransferDialog
  575. ClientWidth = ScaleByTextHeight(this, 420);
  576. FMulti = Multi;
  577. AddImage(L"Move To");
  578. Combo = new THistoryComboBox(this);
  579. Combo->AutoComplete = false;
  580. AddComboBox(Combo, CreateLabel(LoadStr(REMOTE_TRANSFER_PROMPT2)));
  581. }
  582. //---------------------------------------------------------------------------
  583. bool __fastcall TRemoteMoveDialog::Execute(UnicodeString & Target, UnicodeString & FileMask)
  584. {
  585. Combo->Items = CustomWinConfiguration->History[L"RemoteTarget"];
  586. Combo->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
  587. bool Result = TCustomDialog::Execute();
  588. if (Result)
  589. {
  590. Target = UnixExtractFilePath(Combo->Text);
  591. FileMask = GetFileMask();
  592. Combo->SaveToHistory();
  593. CustomWinConfiguration->History[L"RemoteTarget"] = Combo->Items;
  594. }
  595. return Result;
  596. }
  597. //---------------------------------------------------------------------------
  598. UnicodeString __fastcall TRemoteMoveDialog::GetFileMask()
  599. {
  600. return UnixExtractFileName(Combo->Text);
  601. }
  602. //---------------------------------------------------------------------------
  603. void __fastcall TRemoteMoveDialog::DoShow()
  604. {
  605. TCustomDialog::DoShow();
  606. InstallPathWordBreakProc(Combo);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TRemoteMoveDialog::DoValidate()
  610. {
  611. if (!IsFileNameMask(GetFileMask()) && FMulti)
  612. {
  613. UnicodeString Message =
  614. FormatMultiFilesToOneConfirmation(Combo->Text, true);
  615. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_NONE) == qaCancel)
  616. {
  617. Abort();
  618. }
  619. }
  620. TCustomDialog::DoValidate();
  621. }
  622. //---------------------------------------------------------------------------
  623. bool __fastcall DoRemoteMoveDialog(bool Multi, UnicodeString & Target, UnicodeString & FileMask)
  624. {
  625. std::unique_ptr<TRemoteMoveDialog> Dialog(new TRemoteMoveDialog(Multi));
  626. return Dialog->Execute(Target, FileMask);
  627. }