Custom.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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. FGroupBox = NULL;
  36. HelpKeyword = AHelpKeyword;
  37. TBorderIcons BI = BorderIcons;
  38. if (HelpKeyword.IsEmpty())
  39. {
  40. BI >> biHelp;
  41. OKButton->Left = CancelButton->Left;
  42. CancelButton->Left = HelpButton->Left;
  43. HelpButton->Visible = false;
  44. }
  45. else
  46. {
  47. BI << biHelp;
  48. }
  49. BorderIcons = BI;
  50. }
  51. //---------------------------------------------------------------------
  52. bool __fastcall TCustomDialog::Execute()
  53. {
  54. Changed();
  55. return (ShowModal() == DefaultResult(this));
  56. }
  57. //---------------------------------------------------------------------
  58. void __fastcall TCustomDialog::DoChange(bool & /*CanSubmit*/)
  59. {
  60. // noop
  61. }
  62. //---------------------------------------------------------------------
  63. void __fastcall TCustomDialog::Changed()
  64. {
  65. bool CanSubmit = true;
  66. DoChange(CanSubmit);
  67. EnableControl(OKButton, CanSubmit);
  68. }
  69. //---------------------------------------------------------------------
  70. void __fastcall TCustomDialog::Change(TObject * /*Sender*/)
  71. {
  72. Changed();
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TCustomDialog::DoHelp()
  76. {
  77. FormHelp(this);
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TCustomDialog::HelpButtonClick(TObject * /*Sender*/)
  81. {
  82. DoHelp();
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TCustomDialog::DoShow()
  86. {
  87. OKButton->TabOrder = FCount;
  88. CancelButton->TabOrder = static_cast<short>(FCount + 1);
  89. HelpButton->TabOrder = static_cast<short>(FCount + 2);
  90. Changed();
  91. TForm::DoShow();
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TCustomDialog::DoValidate()
  95. {
  96. // noop
  97. }
  98. //---------------------------------------------------------------------------
  99. bool __fastcall TCustomDialog::CloseQuery()
  100. {
  101. if (ModalResult == DefaultResult(this))
  102. {
  103. DoValidate();
  104. }
  105. return TForm::CloseQuery();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
  109. {
  110. TImage * Image = new TImage(this);
  111. Image->Name = L"Image";
  112. Image->Parent = GetDefaultParent();
  113. LoadDialogImage(Image, ImageName);
  114. Image->SetBounds(FIndent, FPos + ScaleByTextHeight(this, 3), Image->Picture->Width, Image->Picture->Height);
  115. FIndent += Image->Width + ScaleByTextHeight(this, 12);
  116. }
  117. //---------------------------------------------------------------------------
  118. int __fastcall TCustomDialog::GetMaxControlWidth(TControl * Control)
  119. {
  120. return GetDefaultParent()->ClientWidth - Control->Left - FHorizontalMargin;
  121. }
  122. //---------------------------------------------------------------------------
  123. TWinControl * __fastcall TCustomDialog::GetDefaultParent()
  124. {
  125. return (FGroupBox != NULL) ? FGroupBox : static_cast<TWinControl *>(this);
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TCustomDialog::AdjustHeight(TControl * Control)
  129. {
  130. FPos = Control->Top + Control->Height + FControlPadding;
  131. int Delta = (FPos - FPrePos);
  132. ClientHeight = ClientHeight + Delta;
  133. if (FGroupBox != NULL)
  134. {
  135. FGroupBox->Height = FGroupBox->Height + Delta;
  136. }
  137. FPrePos = FPos;
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TCustomDialog::AddWinControl(TWinControl * Control)
  141. {
  142. Control->TabOrder = FCount;
  143. FCount++;
  144. }
  145. //---------------------------------------------------------------------------
  146. TCheckBox * __fastcall TCustomDialog::CreateAndAddCheckBox(const UnicodeString & Caption)
  147. {
  148. TCheckBox * CheckBox = new TCheckBox(this);
  149. CheckBox->Caption = Caption;
  150. AddButtonControl(CheckBox);
  151. return CheckBox;
  152. }
  153. //---------------------------------------------------------------------------
  154. TLabel * __fastcall TCustomDialog::CreateLabel(UnicodeString Label)
  155. {
  156. TLabel * Result = new TLabel(this);
  157. Result->Caption = Label;
  158. return Result;
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * Label, bool OneLine)
  162. {
  163. Edit->Parent = GetDefaultParent();
  164. // this updates Height property to real value
  165. Edit->HandleNeeded();
  166. Label->Parent = GetDefaultParent();
  167. Label->Left = FIndent;
  168. if (OneLine)
  169. {
  170. DebugAssert(Edit->Height > Label->Height);
  171. Label->Top = FPos + ((Edit->Height - Label->Height) / 2);
  172. }
  173. else
  174. {
  175. Label->Top = FPos;
  176. FPos += Label->Height + ScaleByTextHeight(this, 4);
  177. }
  178. Edit->Top = FPos;
  179. if (OneLine)
  180. {
  181. Edit->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Edit->Width;
  182. }
  183. else
  184. {
  185. Edit->Left = FIndent;
  186. Edit->Width = GetMaxControlWidth(Edit);
  187. }
  188. AdjustHeight(Edit);
  189. if (Label->FocusControl == NULL)
  190. {
  191. Label->FocusControl = Edit;
  192. }
  193. else
  194. {
  195. DebugAssert(Label->FocusControl == Edit);
  196. }
  197. AddWinControl(Edit);
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label)
  201. {
  202. AddEditLikeControl(Edit, Label, false);
  203. TEdit * PublicEdit = reinterpret_cast<TEdit *>(Edit);
  204. if (PublicEdit->OnChange == NULL)
  205. {
  206. PublicEdit->OnChange = Change;
  207. }
  208. }
  209. //---------------------------------------------------------------------------
  210. void __fastcall TCustomDialog::AddComboBox(TCustomCombo * Combo, TLabel * Label, TStrings * Items, bool OneLine)
  211. {
  212. AddEditLikeControl(Combo, Label, OneLine);
  213. if (Items != NULL)
  214. {
  215. Combo->Items = Items;
  216. }
  217. if (OneLine)
  218. {
  219. int Width = 0;
  220. for (int Index = 0; Index < Combo->Items->Count; Index++)
  221. {
  222. Width = Max(Width, Combo->Canvas->TextWidth(Combo->Items->Strings[Index]));
  223. }
  224. Width += ScaleByTextHeight(Combo, 4 + 16 + 14);
  225. Width = Max(Width, HelpButton->Width);
  226. Combo->Width = Width;
  227. Combo->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Width;
  228. }
  229. TComboBox * PublicCombo = reinterpret_cast<TComboBox *>(Combo);
  230. if (PublicCombo->OnChange == NULL)
  231. {
  232. PublicCombo->OnChange = Change;
  233. }
  234. }
  235. //---------------------------------------------------------------------------
  236. void __fastcall TCustomDialog::ScaleButtonControl(TButtonControl * Control)
  237. {
  238. // this updates Height property to real value
  239. Control->HandleNeeded();
  240. // buttons do not scale with text on their own
  241. Control->Height = ScaleByTextHeight(Control, Control->Height);
  242. }
  243. //---------------------------------------------------------------------------
  244. void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
  245. {
  246. Control->Parent = GetDefaultParent();
  247. Control->Left = FIndent + ScaleByTextHeight(this, 6);
  248. Control->Top = FPos;
  249. Control->Width = GetMaxControlWidth(Control);
  250. ScaleButtonControl(Control);
  251. AdjustHeight(Control);
  252. AddWinControl(Control);
  253. TCheckBox * PublicControl = reinterpret_cast<TCheckBox *>(Control);
  254. if (PublicControl->OnClick == NULL)
  255. {
  256. PublicControl->OnClick = Change;
  257. }
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TCustomDialog::AddText(TLabel * Label)
  261. {
  262. Label->Parent = GetDefaultParent();
  263. Label->WordWrap = true;
  264. Label->Left = FIndent;
  265. Label->Width = GetMaxControlWidth(Label);
  266. Label->Top = FPos;
  267. Label->ShowAccelChar = false;
  268. TRect TextRect;
  269. SetRect(&TextRect, 0, 0, Label->Width, 0);
  270. DrawText(Label->Canvas->Handle, Label->Caption.c_str(), Label->Caption.Length() + 1, &TextRect,
  271. DT_EXPANDTABS | DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX |
  272. Label->DrawTextBiDiModeFlagsReadingOnly());
  273. Label->Height = TextRect.Height();
  274. AdjustHeight(Label);
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TCustomDialog::AddText(TStaticText * Label)
  278. {
  279. Label->Parent = GetDefaultParent();
  280. Label->Left = FIndent;
  281. Label->Width = GetMaxControlWidth(Label);
  282. Label->Top = FPos;
  283. Label->ShowAccelChar = false;
  284. AdjustHeight(Label);
  285. AddWinControl(Label);
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TCustomDialog::AddSeparator()
  289. {
  290. TBevel * Bevel = new TBevel(this);
  291. Bevel->Parent = GetDefaultParent();
  292. Bevel->Left = FIndent;
  293. Bevel->Top = FPos;
  294. Bevel->Height = 2;
  295. Bevel->Width = GetMaxControlWidth(Bevel);
  296. AdjustHeight(Bevel);
  297. }
  298. //---------------------------------------------------------------------------
  299. void __fastcall TCustomDialog::StartGroup(const UnicodeString & Caption)
  300. {
  301. if (FGroupBox != NULL)
  302. {
  303. FIndent = FGroupBox->Left;
  304. FPos = FGroupBox->Top + FGroupBox->Height + FControlPadding;
  305. FPrePos = FPos;
  306. FGroupBox = NULL;
  307. }
  308. TGroupBox * GroupBox = new TGroupBox(this);
  309. GroupBox->Parent = this;
  310. GroupBox->Caption = Caption;
  311. GroupBox->Left = FIndent;
  312. GroupBox->Top = FPos;
  313. GroupBox->Height = ScaleByTextHeight(GroupBox, 20);
  314. GroupBox->Width = GetMaxControlWidth(GroupBox);
  315. AdjustHeight(GroupBox);
  316. FPos = ScaleByTextHeight(this, 16);
  317. FPrePos = FPos;
  318. FIndent = FHorizontalMargin;
  319. FGroupBox = GroupBox;
  320. }
  321. //---------------------------------------------------------------------------
  322. //---------------------------------------------------------------------------
  323. class TSaveSessionDialog : public TCustomDialog
  324. {
  325. public:
  326. __fastcall TSaveSessionDialog(TComponent* AOwner);
  327. void __fastcall Init(bool CanSavePassword, bool NotRecommendedSavingPassword,
  328. TStrings * AdditionalFolders);
  329. bool __fastcall Execute(UnicodeString & SessionName, bool & SavePassword,
  330. bool & CreateShortcut, const UnicodeString & OriginalSessionName);
  331. protected:
  332. virtual void __fastcall DoValidate();
  333. virtual void __fastcall DoChange(bool & CanSubmit);
  334. private:
  335. UnicodeString FOriginalSessionName;
  336. TEdit * SessionNameEdit;
  337. TComboBox * FolderCombo;
  338. TCheckBox * SavePasswordCheck;
  339. TCheckBox * CreateShortcutCheck;
  340. UnicodeString FRootFolder;
  341. UnicodeString __fastcall GetSessionName();
  342. };
  343. //---------------------------------------------------------------------------
  344. // Need to have an Owner argument for SafeFormCreate
  345. __fastcall TSaveSessionDialog::TSaveSessionDialog(TComponent* /*AOwner*/) :
  346. TCustomDialog(HELP_SESSION_SAVE)
  347. {
  348. }
  349. //---------------------------------------------------------------------------
  350. void __fastcall TSaveSessionDialog::Init(bool CanSavePassword,
  351. bool NotRecommendedSavingPassword, TStrings * AdditionalFolders)
  352. {
  353. Caption = LoadStr(SAVE_SESSION_CAPTION);
  354. SessionNameEdit = new TEdit(this);
  355. AddEdit(SessionNameEdit, CreateLabel(LoadStr(SAVE_SESSION_PROMPT)));
  356. FRootFolder = LoadStr(SAVE_SESSION_ROOT_FOLDER2);
  357. std::unique_ptr<TStringList> Folders(new TStringList());
  358. if (AdditionalFolders != NULL)
  359. {
  360. Folders->AddStrings(AdditionalFolders);
  361. }
  362. for (int Index = 0; Index < StoredSessions->Count; Index++)
  363. {
  364. TSessionData * Data = StoredSessions->Sessions[Index];
  365. if (!Data->Special && !Data->IsWorkspace)
  366. {
  367. UnicodeString Folder = Data->FolderName;
  368. if (!Folder.IsEmpty() && Folders->IndexOf(Folder) < 0)
  369. {
  370. Folders->Add(Folder);
  371. }
  372. }
  373. }
  374. DebugAssert(!Folders->CaseSensitive);
  375. Folders->Sort();
  376. FolderCombo = new TComboBox(this);
  377. AddComboBox(FolderCombo, CreateLabel(LoadStr(SAVE_SESSION_FOLDER)));
  378. FolderCombo->DropDownCount = Max(FolderCombo->DropDownCount, 16);
  379. FolderCombo->Items->Add(FRootFolder);
  380. FolderCombo->Items->AddStrings(Folders.get());
  381. SavePasswordCheck = CreateAndAddCheckBox(
  382. LoadStr(NotRecommendedSavingPassword ? SAVE_SESSION_PASSWORD :
  383. (CustomWinConfiguration->UseMasterPassword ? SAVE_SESSION_PASSWORD_MASTER : SAVE_SESSION_PASSWORD_RECOMMENDED)));
  384. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  385. EnableControl(SavePasswordCheck, CanSavePassword);
  386. }
  387. //---------------------------------------------------------------------------
  388. bool __fastcall TSaveSessionDialog::Execute(
  389. UnicodeString & SessionName, bool & SavePassword, bool & CreateShortcut,
  390. const UnicodeString & OriginalSessionName)
  391. {
  392. FOriginalSessionName = OriginalSessionName;
  393. SessionNameEdit->Text = TSessionData::ExtractLocalName(SessionName);
  394. UnicodeString Folder = TSessionData::ExtractFolderName(SessionName);
  395. if (Folder.IsEmpty())
  396. {
  397. FolderCombo->Text = FRootFolder;
  398. }
  399. else
  400. {
  401. FolderCombo->Text = Folder;
  402. }
  403. SavePasswordCheck->Checked = SavePassword;
  404. CreateShortcutCheck->Checked = CreateShortcut;
  405. bool Result = TCustomDialog::Execute();
  406. if (Result)
  407. {
  408. SessionName = GetSessionName();
  409. SavePassword = SavePasswordCheck->Checked;
  410. CreateShortcut = CreateShortcutCheck->Checked;
  411. }
  412. return Result;
  413. }
  414. //---------------------------------------------------------------------------
  415. UnicodeString __fastcall TSaveSessionDialog::GetSessionName()
  416. {
  417. UnicodeString Folder;
  418. if (FolderCombo->Text != FRootFolder)
  419. {
  420. Folder = FolderCombo->Text;
  421. }
  422. return TSessionData::ComposePath(Folder, SessionNameEdit->Text);
  423. }
  424. //---------------------------------------------------------------------------
  425. void __fastcall TSaveSessionDialog::DoValidate()
  426. {
  427. TSessionData::ValidateName(SessionNameEdit->Text);
  428. SessionNameValidate(GetSessionName(), FOriginalSessionName);
  429. UnicodeString Folder = TSessionData::ExtractFolderName(GetSessionName());
  430. if (!Folder.IsEmpty() && StoredSessions->IsWorkspace(Folder))
  431. {
  432. throw Exception(FMTLOAD(WORKSPACE_NOT_FOLDER, (Folder)));
  433. }
  434. if (SavePasswordCheck->Enabled && SavePasswordCheck->Checked &&
  435. CustomWinConfiguration->UseMasterPassword)
  436. {
  437. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  438. }
  439. TCustomDialog::DoValidate();
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TSaveSessionDialog::DoChange(bool & CanSubmit)
  443. {
  444. CanSubmit = !SessionNameEdit->Text.IsEmpty();
  445. TCustomDialog::DoChange(CanSubmit);
  446. }
  447. //---------------------------------------------------------------------------
  448. TSessionData * __fastcall DoSaveSession(TSessionData * SessionData,
  449. TSessionData * OriginalSession, bool ForceDialog,
  450. TStrings * AdditionalFolders)
  451. {
  452. bool SavePassword = false;
  453. bool * PSavePassword;
  454. bool NotRecommendedSavingPassword =
  455. !CustomWinConfiguration->UseMasterPassword &&
  456. !SameText(SessionData->UserName, AnonymousUserName);
  457. if (Configuration->DisablePasswordStoring ||
  458. !SessionData->HasAnySessionPassword())
  459. {
  460. PSavePassword = NULL;
  461. }
  462. else
  463. {
  464. PSavePassword = &SavePassword;
  465. SavePassword =
  466. ((OriginalSession != NULL) && OriginalSession->HasAnySessionPassword()) ||
  467. !NotRecommendedSavingPassword;
  468. }
  469. UnicodeString SessionName = SessionData->SessionName;
  470. bool Result;
  471. bool CreateShortcut = false;
  472. if (!ForceDialog && ((PSavePassword == NULL) || SavePassword))
  473. {
  474. CustomWinConfiguration->AskForMasterPasswordIfNotSetAndNeededToPersistSessionData(SessionData);
  475. Result = true;
  476. }
  477. else
  478. {
  479. // This can be a standalone dialog when used with save URL (from GetLoginData)
  480. TSaveSessionDialog * Dialog = SafeFormCreate<TSaveSessionDialog>();
  481. try
  482. {
  483. Dialog->Init((PSavePassword != NULL), NotRecommendedSavingPassword, AdditionalFolders);
  484. Result = Dialog->Execute(SessionName, SavePassword, CreateShortcut, SessionData->Name);
  485. }
  486. __finally
  487. {
  488. delete Dialog;
  489. }
  490. }
  491. TSessionData * NewSession = NULL;
  492. if (Result)
  493. {
  494. if ((PSavePassword != NULL) && !SavePassword)
  495. {
  496. SessionData->ClearSessionPasswords();
  497. }
  498. NewSession =
  499. StoredSessions->NewSession(SessionName, SessionData);
  500. // modified only, explicit
  501. StoredSessions->Save(false, true);
  502. if (!SessionData->HostKey.IsEmpty())
  503. {
  504. SessionData->CacheHostKeyIfNotCached();
  505. }
  506. if (CreateShortcut)
  507. {
  508. TOperationVisualizer Visualizer;
  509. UnicodeString AdditionalParams =
  510. TProgramParams::FormatSwitch(DESKTOP_SWITCH) + L" " +
  511. TProgramParams::FormatSwitch(UPLOAD_IF_ANY_SWITCH);
  512. CreateDesktopSessionShortCut(SessionName, L"", AdditionalParams, -1, SITE_ICON);
  513. }
  514. }
  515. return NewSession;
  516. }
  517. //---------------------------------------------------------------------------
  518. void __fastcall SessionNameValidate(const UnicodeString & Text,
  519. const UnicodeString & OriginalName)
  520. {
  521. TSessionData::ValidatePath(Text);
  522. DebugAssert(StoredSessions);
  523. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  524. if (Data && Data->Special)
  525. {
  526. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  527. qtError, qaOK, HELP_NONE);
  528. Abort();
  529. }
  530. else if ((Data != NULL) && !Data->IsSameName(OriginalName) &&
  531. MessageDialog(MainInstructions(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text))),
  532. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  533. {
  534. Abort();
  535. }
  536. }
  537. //---------------------------------------------------------------------------
  538. //---------------------------------------------------------------------------
  539. class TSaveWorkspaceDialog : public TCustomDialog
  540. {
  541. public:
  542. __fastcall TSaveWorkspaceDialog(bool CanSavePasswords,
  543. bool NotRecommendedSavingPasswords);
  544. bool __fastcall Execute(
  545. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  546. bool & EnableAutoSave);
  547. protected:
  548. virtual void __fastcall DoValidate();
  549. virtual void __fastcall DoChange(bool & CanSubmit);
  550. private:
  551. TComboBox * WorkspaceNameCombo;
  552. TCheckBox * SavePasswordsCheck;
  553. TCheckBox * CreateShortcutCheck;
  554. TCheckBox * EnableAutoSaveCheck;
  555. };
  556. //---------------------------------------------------------------------------
  557. __fastcall TSaveWorkspaceDialog::TSaveWorkspaceDialog(
  558. bool CanSavePasswords, bool NotRecommendedSavingPasswords) :
  559. TCustomDialog(HELP_WORKSPACE_SAVE)
  560. {
  561. Caption = LoadStr(SAVE_WORKSPACE_CAPTION);
  562. WorkspaceNameCombo = new TComboBox(this);
  563. WorkspaceNameCombo->AutoComplete = false;
  564. AddComboBox(WorkspaceNameCombo, CreateLabel(LoadStr(SAVE_WORKSPACE_PROMPT)));
  565. WorkspaceNameCombo->DropDownCount = Max(WorkspaceNameCombo->DropDownCount, 16);
  566. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  567. WorkspaceNameCombo->Items->AddStrings(Workspaces.get());
  568. SavePasswordsCheck = CreateAndAddCheckBox(
  569. LoadStr(NotRecommendedSavingPasswords ? SAVE_WORKSPACE_PASSWORDS :
  570. (CustomWinConfiguration->UseMasterPassword ?
  571. SAVE_WORKSPACE_PASSWORDS_MASTER : SAVE_WORKSPACE_PASSWORDS_RECOMMENDED)));
  572. EnableControl(SavePasswordsCheck, CanSavePasswords);
  573. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  574. EnableAutoSaveCheck = CreateAndAddCheckBox(LoadStr(SAVE_WORKSPACE_AUTO));
  575. }
  576. //---------------------------------------------------------------------------
  577. bool __fastcall TSaveWorkspaceDialog::Execute(
  578. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  579. bool & EnableAutoSave)
  580. {
  581. WorkspaceNameCombo->Text = WorkspaceName;
  582. SavePasswordsCheck->Checked = SavePasswords;
  583. CreateShortcutCheck->Checked = CreateShortcut;
  584. EnableAutoSaveCheck->Checked = EnableAutoSave;
  585. bool Result = TCustomDialog::Execute();
  586. if (Result)
  587. {
  588. WorkspaceName = WorkspaceNameCombo->Text;
  589. SavePasswords = SavePasswordsCheck->Checked;
  590. CreateShortcut = CreateShortcutCheck->Checked;
  591. EnableAutoSave = EnableAutoSaveCheck->Checked;
  592. }
  593. return Result;
  594. }
  595. //---------------------------------------------------------------------------
  596. void __fastcall TSaveWorkspaceDialog::DoValidate()
  597. {
  598. TSessionData::ValidateName(WorkspaceNameCombo->Text);
  599. if (StoredSessions->IsFolder(WorkspaceNameCombo->Text))
  600. {
  601. throw Exception(FMTLOAD(FOLDER_NOT_WORKSPACE, (WorkspaceNameCombo->Text)));
  602. }
  603. if (SavePasswordsCheck->Enabled && SavePasswordsCheck->Checked &&
  604. CustomWinConfiguration->UseMasterPassword)
  605. {
  606. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  607. }
  608. TCustomDialog::DoValidate();
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TSaveWorkspaceDialog::DoChange(bool & CanSubmit)
  612. {
  613. CanSubmit = !WorkspaceNameCombo->Text.IsEmpty();
  614. TCustomDialog::DoChange(CanSubmit);
  615. }
  616. //---------------------------------------------------------------------------
  617. bool __fastcall DoSaveWorkspaceDialog(UnicodeString & WorkspaceName,
  618. bool * SavePasswords, bool NotRecommendedSavingPasswords,
  619. bool & CreateShortcut, bool & EnableAutoSave)
  620. {
  621. std::unique_ptr<TSaveWorkspaceDialog> Dialog(
  622. new TSaveWorkspaceDialog((SavePasswords != NULL), NotRecommendedSavingPasswords));
  623. bool Dummy = false;
  624. if (SavePasswords == NULL)
  625. {
  626. SavePasswords = &Dummy;
  627. }
  628. return
  629. Dialog->Execute(
  630. WorkspaceName, *SavePasswords, CreateShortcut, EnableAutoSave);
  631. }
  632. //---------------------------------------------------------------------------
  633. //---------------------------------------------------------------------------
  634. class TShortCutDialog : public TCustomDialog
  635. {
  636. public:
  637. __fastcall TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword);
  638. bool __fastcall Execute(TShortCut & ShortCut);
  639. private:
  640. TComboBox * ShortCutCombo;
  641. };
  642. //---------------------------------------------------------------------------
  643. __fastcall TShortCutDialog::TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword) :
  644. TCustomDialog(HelpKeyword)
  645. {
  646. Caption = LoadStr(SHORTCUT_CAPTION);
  647. ShortCutCombo = new TComboBox(this);
  648. AddComboBox(ShortCutCombo, CreateLabel(LoadStr(SHORTCUT_LABEL)));
  649. InitializeShortCutCombo(ShortCutCombo, ShortCuts);
  650. }
  651. //---------------------------------------------------------------------------
  652. bool __fastcall TShortCutDialog::Execute(TShortCut & ShortCut)
  653. {
  654. SetShortCutCombo(ShortCutCombo, ShortCut);
  655. bool Result = TCustomDialog::Execute();
  656. if (Result)
  657. {
  658. ShortCut = GetShortCutCombo(ShortCutCombo);
  659. }
  660. return Result;
  661. }
  662. //---------------------------------------------------------------------------
  663. bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
  664. const TShortCuts & ShortCuts, UnicodeString HelpKeyword)
  665. {
  666. bool Result;
  667. TShortCutDialog * Dialog = new TShortCutDialog(ShortCuts, HelpKeyword);
  668. try
  669. {
  670. Result = Dialog->Execute(ShortCut);
  671. }
  672. __finally
  673. {
  674. delete Dialog;
  675. }
  676. return Result;
  677. }
  678. //---------------------------------------------------------------------------
  679. //---------------------------------------------------------------------------
  680. class TRemoteMoveDialog : public TCustomDialog
  681. {
  682. public:
  683. __fastcall TRemoteMoveDialog(bool Multi);
  684. bool __fastcall Execute(UnicodeString & Target, UnicodeString & FileMask);
  685. protected:
  686. DYNAMIC void __fastcall DoShow();
  687. virtual void __fastcall DoValidate();
  688. UnicodeString __fastcall GetFileMask();
  689. private:
  690. THistoryComboBox * Combo;
  691. bool FMulti;
  692. };
  693. //---------------------------------------------------------------------------
  694. __fastcall TRemoteMoveDialog::TRemoteMoveDialog(bool Multi) :
  695. TCustomDialog(HELP_REMOTE_MOVE)
  696. {
  697. Caption = LoadStr(REMOTE_MOVE_TITLE);
  698. // The same as TRemoteTransferDialog
  699. ClientWidth = ScaleByTextHeight(this, 420);
  700. FMulti = Multi;
  701. AddImage(L"Move To");
  702. Combo = new THistoryComboBox(this);
  703. Combo->AutoComplete = false;
  704. AddComboBox(Combo, CreateLabel(LoadStr(REMOTE_TRANSFER_PROMPT2)));
  705. }
  706. //---------------------------------------------------------------------------
  707. bool __fastcall TRemoteMoveDialog::Execute(UnicodeString & Target, UnicodeString & FileMask)
  708. {
  709. Combo->Items = CustomWinConfiguration->History[L"RemoteTarget"];
  710. Combo->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
  711. bool Result = TCustomDialog::Execute();
  712. if (Result)
  713. {
  714. Target = UnixExtractFilePath(Combo->Text);
  715. FileMask = GetFileMask();
  716. Combo->SaveToHistory();
  717. CustomWinConfiguration->History[L"RemoteTarget"] = Combo->Items;
  718. }
  719. return Result;
  720. }
  721. //---------------------------------------------------------------------------
  722. UnicodeString __fastcall TRemoteMoveDialog::GetFileMask()
  723. {
  724. return UnixExtractFileName(Combo->Text);
  725. }
  726. //---------------------------------------------------------------------------
  727. void __fastcall TRemoteMoveDialog::DoShow()
  728. {
  729. TCustomDialog::DoShow();
  730. InstallPathWordBreakProc(Combo);
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TRemoteMoveDialog::DoValidate()
  734. {
  735. if (!IsFileNameMask(GetFileMask()) && FMulti)
  736. {
  737. UnicodeString Message =
  738. FormatMultiFilesToOneConfirmation(Combo->Text, true);
  739. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_NONE) == qaCancel)
  740. {
  741. Abort();
  742. }
  743. }
  744. TCustomDialog::DoValidate();
  745. }
  746. //---------------------------------------------------------------------------
  747. bool __fastcall DoRemoteMoveDialog(bool Multi, UnicodeString & Target, UnicodeString & FileMask)
  748. {
  749. std::unique_ptr<TRemoteMoveDialog> Dialog(new TRemoteMoveDialog(Multi));
  750. return Dialog->Execute(Target, FileMask);
  751. }
  752. //---------------------------------------------------------------------------
  753. //---------------------------------------------------------------------------
  754. class TCustomCommandOptionsDialog : public TCustomDialog
  755. {
  756. public:
  757. __fastcall TCustomCommandOptionsDialog(const TCustomCommandType * Command, TStrings * CustomCommandOptions);
  758. bool __fastcall Execute();
  759. protected:
  760. virtual void __fastcall DoHelp();
  761. private:
  762. const TCustomCommandType * FCommand;
  763. TStrings * FCustomCommandOptions;
  764. std::vector<TControl *> FControls;
  765. std::vector<std::vector<UnicodeString> > FValues;
  766. UnicodeString __fastcall HistoryKey(const TCustomCommandType::TOption & Option);
  767. THistoryComboBox * __fastcall CreateHistoryComboBox(const TCustomCommandType::TOption & Option, const UnicodeString & Value);
  768. void __fastcall BrowseButtonClick(TObject * Sender);
  769. void __fastcall LinkLabelClick(TObject * Sender);
  770. UnicodeString __fastcall SaveHistoryComboBoxValue(TControl * Control, const TCustomCommandType::TOption & Option);
  771. void __fastcall AddOptionComboBox(
  772. TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option,
  773. std::vector<UnicodeString> & Values);
  774. UnicodeString __fastcall GetComboBoxValue(TControl * Control, const UnicodeString & Default);
  775. };
  776. //---------------------------------------------------------------------------
  777. __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
  778. const TCustomCommandType * Command, TStrings * CustomCommandOptions) :
  779. TCustomDialog(HELP_EXTENSION_OPTIONS)
  780. {
  781. FCommand = Command;
  782. FCustomCommandOptions = CustomCommandOptions;
  783. Caption = FMTLOAD(EXTENSION_OPTIONS_CAPTION, (StripEllipsis(StripHotkey(FCommand->Name))));
  784. Width = ScaleByTextHeight(this, 400);
  785. for (int Index = 0; Index < FCommand->OptionsCount; Index++)
  786. {
  787. const TCustomCommandType::TOption & Option = FCommand->GetOption(Index);
  788. UnicodeString OptionKey = FCommand->GetOptionKey(Option);
  789. UnicodeString Value;
  790. if (FCustomCommandOptions->IndexOfName(OptionKey) >= 0)
  791. {
  792. Value = FCustomCommandOptions->Values[OptionKey];
  793. }
  794. else
  795. {
  796. Value = Option.Default;
  797. }
  798. TControl * Control = NULL;
  799. std::vector<UnicodeString> Values;
  800. if (Option.Kind == TCustomCommandType::okUnknown)
  801. {
  802. Control = NULL;
  803. }
  804. else if (Option.Kind == TCustomCommandType::okLabel)
  805. {
  806. TLabel * Label = CreateLabel(Option.Caption);
  807. AddText(Label);
  808. Control = Label;
  809. }
  810. else if (Option.Kind == TCustomCommandType::okLink)
  811. {
  812. TStaticText * Label = new TStaticText(this);
  813. Label->Caption = Option.Caption;
  814. if (IsHttpOrHttpsUrl(Label->Caption))
  815. {
  816. Label->Caption = SecureUrl(Label->Caption);
  817. LinkLabel(Label);
  818. Label->TabStop = true;
  819. }
  820. else if (!Option.Default.IsEmpty() && IsHttpOrHttpsUrl(Option.Default))
  821. {
  822. Label->OnClick = LinkLabelClick;
  823. LinkLabel(Label);
  824. Label->TabStop = true;
  825. }
  826. else
  827. {
  828. // keep it plain text, as we have no URL
  829. }
  830. AddText(Label);
  831. Control = Label;
  832. }
  833. else if (Option.Kind == TCustomCommandType::okGroup)
  834. {
  835. StartGroup(Option.Caption);
  836. }
  837. else if (Option.Kind == TCustomCommandType::okSeparator)
  838. {
  839. AddSeparator();
  840. }
  841. else if (Option.Kind == TCustomCommandType::okTextBox)
  842. {
  843. Control = CreateHistoryComboBox(Option, Value);
  844. }
  845. else if (Option.Kind == TCustomCommandType::okFile)
  846. {
  847. THistoryComboBox * ComboBox = CreateHistoryComboBox(Option, Value);
  848. TButton * Button = new TButton(this);
  849. Button->Parent = GetDefaultParent();
  850. Button->Width = HelpButton->Width;
  851. Button->Left = GetDefaultParent()->ClientWidth - Button->Width - HorizontalMargin;
  852. ComboBox->Width = Button->Left - ComboBox->Left - ScaleByTextHeight(this, 6);
  853. Button->Top = ComboBox->Top - ScaleByTextHeight(this, 2);
  854. Button->Tag = Index;
  855. Button->Caption = LoadStr(EXTENSION_OPTIONS_BROWSE);
  856. Button->OnClick = BrowseButtonClick;
  857. ScaleButtonControl(Button);
  858. AddWinControl(Button);
  859. Control = ComboBox;
  860. }
  861. else if (Option.Kind == TCustomCommandType::okDropDownList)
  862. {
  863. TComboBox * ComboBox = new TComboBox(this);
  864. ComboBox->Style = csDropDownList;
  865. AddOptionComboBox(ComboBox, Value, Option, Values);
  866. Control = ComboBox;
  867. }
  868. else if (Option.Kind == TCustomCommandType::okComboBox)
  869. {
  870. TComboBox * ComboBox = new TComboBox(this);
  871. ComboBox->Style = csDropDown;
  872. AddOptionComboBox(ComboBox, Value, Option, Values);
  873. if (ComboBox->ItemIndex < 0)
  874. {
  875. ComboBox->Text = Value;
  876. }
  877. Control = ComboBox;
  878. }
  879. else if (Option.Kind == TCustomCommandType::okCheckBox)
  880. {
  881. TCheckBox * CheckBox = CreateAndAddCheckBox(Option.Caption);
  882. CheckBox->Checked =
  883. (Option.Params.size() >= 1) &&
  884. (Value == Option.Params[0]);
  885. Control = CheckBox;
  886. }
  887. else
  888. {
  889. DebugFail();
  890. }
  891. if (Control != NULL)
  892. {
  893. Control->Tag = Index;
  894. }
  895. FControls.push_back(Control);
  896. FValues.push_back(Values);
  897. }
  898. DebugAssert(FCommand->OptionsCount == static_cast<int>(FControls.size()));
  899. }
  900. //---------------------------------------------------------------------------
  901. void __fastcall TCustomCommandOptionsDialog::AddOptionComboBox(
  902. TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option, std::vector<UnicodeString> & Values)
  903. {
  904. std::unique_ptr<TStringList> Items(new TStringList());
  905. int ItemIndex = -1;
  906. TCustomCommandType::TOption::TParams::const_iterator ParamI = Option.Params.begin();
  907. while (ParamI != Option.Params.end())
  908. {
  909. UnicodeString Item = (*ParamI);
  910. int P = Item.Pos(L"=");
  911. UnicodeString ParamValue;
  912. if (P > 0)
  913. {
  914. ParamValue = Item.SubString(1, P - 1);
  915. Item.Delete(1, P);
  916. }
  917. else
  918. {
  919. ParamValue = Item;
  920. }
  921. Items->Add(Item);
  922. if (Value == ParamValue)
  923. {
  924. ItemIndex = Items->Count - 1;
  925. }
  926. Values.push_back(ParamValue);
  927. ParamI++;
  928. }
  929. AddComboBox(ComboBox, CreateLabel(Option.Caption), Items.get(), true);
  930. ComboBox->ItemIndex = ItemIndex;
  931. }
  932. //---------------------------------------------------------------------------
  933. void __fastcall TCustomCommandOptionsDialog::LinkLabelClick(TObject * Sender)
  934. {
  935. TStaticText * Label = DebugNotNull(dynamic_cast<TStaticText *>(Sender));
  936. const TCustomCommandType::TOption & Option = FCommand->GetOption(Label->Tag);
  937. OpenBrowser(SecureUrl(Option.Default));
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TCustomCommandOptionsDialog::BrowseButtonClick(TObject * Sender)
  941. {
  942. TButton * Button = DebugNotNull(dynamic_cast<TButton *>(Sender));
  943. int Index = Button->Tag;
  944. THistoryComboBox * ComboBox = dynamic_cast<THistoryComboBox *>(FControls[Index]);
  945. std::unique_ptr<TOpenDialog> OpenDialog(new TOpenDialog(Application));
  946. UnicodeString Caption = FCommand->GetOption(Index).Caption;
  947. Caption = StripHotkey(Caption);
  948. if (!Caption.IsEmpty() && (Caption[Caption.Length()] == L':'))
  949. {
  950. Caption.SetLength(Caption.Length() - 1);
  951. }
  952. OpenDialog->Title = FMTLOAD(EXTENSION_OPTIONS_BROWSE_TITLE, (Caption));
  953. UnicodeString ExpandedValue = ExpandEnvironmentVariables(ComboBox->Text);
  954. OpenDialog->FileName = ExpandedValue;
  955. UnicodeString InitialDir = ExtractFilePath(ExpandedValue);
  956. if (!InitialDir.IsEmpty())
  957. {
  958. OpenDialog->InitialDir = InitialDir;
  959. }
  960. if (OpenDialog->Execute())
  961. {
  962. if (OpenDialog->FileName != ExpandedValue)
  963. {
  964. ComboBox->Text = OpenDialog->FileName;
  965. }
  966. }
  967. }
  968. //---------------------------------------------------------------------------
  969. THistoryComboBox * __fastcall TCustomCommandOptionsDialog::CreateHistoryComboBox(
  970. const TCustomCommandType::TOption & Option, const UnicodeString & Value)
  971. {
  972. THistoryComboBox * ComboBox = new THistoryComboBox(this);
  973. ComboBox->AutoComplete = false;
  974. AddComboBox(ComboBox, CreateLabel(Option.Caption));
  975. ComboBox->Items = CustomWinConfiguration->History[HistoryKey(Option)];
  976. ComboBox->Text = Value;
  977. return ComboBox;
  978. }
  979. //---------------------------------------------------------------------------
  980. UnicodeString __fastcall TCustomCommandOptionsDialog::HistoryKey(const TCustomCommandType::TOption & Option)
  981. {
  982. UnicodeString Result = FCommand->GetOptionKey(Option);
  983. Result = CustomWinConfiguration->GetValidHistoryKey(Result);
  984. return L"CustomCommandOption_" + Result;
  985. }
  986. //---------------------------------------------------------------------------
  987. bool __fastcall TCustomCommandOptionsDialog::Execute()
  988. {
  989. bool Result = TCustomDialog::Execute();
  990. if (Result)
  991. {
  992. DebugAssert(FCommand->OptionsCount == static_cast<int>(FControls.size()));
  993. for (int Index = 0; Index < FCommand->OptionsCount; Index++)
  994. {
  995. const TCustomCommandType::TOption & Option = FCommand->GetOption(Index);
  996. if ((Option.Kind != TCustomCommandType::okUnknown) &&
  997. Option.IsControl)
  998. {
  999. UnicodeString OptionKey = FCommand->GetOptionKey(Option);
  1000. TControl * Control = FControls[Index];
  1001. UnicodeString Value;
  1002. if (Option.Kind == TCustomCommandType::okTextBox)
  1003. {
  1004. Value = SaveHistoryComboBoxValue(Control, Option);
  1005. }
  1006. else if (Option.Kind == TCustomCommandType::okFile)
  1007. {
  1008. Value = SaveHistoryComboBoxValue(Control, Option);
  1009. }
  1010. else if (Option.Kind == TCustomCommandType::okDropDownList)
  1011. {
  1012. Value = GetComboBoxValue(Control, Option.Default);
  1013. }
  1014. else if (Option.Kind == TCustomCommandType::okComboBox)
  1015. {
  1016. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
  1017. Value = GetComboBoxValue(Control, ComboBox->Text);
  1018. }
  1019. else if (Option.Kind == TCustomCommandType::okCheckBox)
  1020. {
  1021. TCheckBox * CheckBox = DebugNotNull(dynamic_cast<TCheckBox *>(Control));
  1022. int Index = (CheckBox->Checked ? 0 : 1);
  1023. Value = (Index < static_cast<int>(Option.Params.size())) ? Option.Params[Index] : UnicodeString();
  1024. }
  1025. else
  1026. {
  1027. DebugFail();
  1028. }
  1029. // The default value setter deletes the "name" when the value is empty.
  1030. // It would cause us to fall back to the default value, but we want to remember the empty value.
  1031. if (Value.IsEmpty())
  1032. {
  1033. int Index = FCustomCommandOptions->IndexOfName(OptionKey);
  1034. if (Index < 0)
  1035. {
  1036. Index = FCustomCommandOptions->Add(L"");
  1037. }
  1038. UnicodeString Line = OptionKey + FCustomCommandOptions->NameValueSeparator;
  1039. FCustomCommandOptions->Strings[Index] = Line;
  1040. }
  1041. else
  1042. {
  1043. FCustomCommandOptions->Values[OptionKey] = Value;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. return Result;
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. UnicodeString __fastcall TCustomCommandOptionsDialog::GetComboBoxValue(
  1052. TControl * Control, const UnicodeString & Default)
  1053. {
  1054. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
  1055. UnicodeString Result;
  1056. if (ComboBox->ItemIndex < 0)
  1057. {
  1058. Result = Default;
  1059. }
  1060. else
  1061. {
  1062. Result = FValues[Control->Tag][ComboBox->ItemIndex];
  1063. }
  1064. return Result;
  1065. }
  1066. //---------------------------------------------------------------------------
  1067. UnicodeString __fastcall TCustomCommandOptionsDialog::SaveHistoryComboBoxValue(
  1068. TControl * Control, const TCustomCommandType::TOption & Option)
  1069. {
  1070. THistoryComboBox * ComboBox = DebugNotNull(dynamic_cast<THistoryComboBox *>(Control));
  1071. ComboBox->SaveToHistory();
  1072. CustomWinConfiguration->History[HistoryKey(Option)] = ComboBox->Items;
  1073. return ComboBox->Text;
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall TCustomCommandOptionsDialog::DoHelp()
  1077. {
  1078. UnicodeString HelpPage;
  1079. if (!FCommand->OptionsPage.IsEmpty())
  1080. {
  1081. HelpPage = FCommand->OptionsPage;
  1082. }
  1083. else
  1084. {
  1085. HelpPage = FCommand->HomePage;
  1086. }
  1087. if (!HelpPage.IsEmpty())
  1088. {
  1089. OpenBrowser(HelpPage);
  1090. }
  1091. else
  1092. {
  1093. TCustomDialog::DoHelp();
  1094. }
  1095. }
  1096. //---------------------------------------------------------------------------
  1097. bool __fastcall DoCustomCommandOptionsDialog(const TCustomCommandType * Command, TStrings * CustomCommandOptions)
  1098. {
  1099. std::unique_ptr<TCustomCommandOptionsDialog> Dialog(new TCustomCommandOptionsDialog(Command, CustomCommandOptions));
  1100. return Dialog->Execute();
  1101. }