Custom.cpp 21 KB

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