Custom.cpp 25 KB

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