Preferences.cpp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <Common.h>
  6. #include <math.h>
  7. #include "Preferences.h"
  8. #include <CoreMain.h>
  9. #include <Terminal.h>
  10. #include <Bookmarks.h>
  11. #include "VCLCommon.h"
  12. #include "GUITools.h"
  13. #include "Tools.h"
  14. #include "TextsWin.h"
  15. #include "HelpWin.h"
  16. #include "WinInterface.h"
  17. #include "WinConfiguration.h"
  18. #include "Setup.h"
  19. //---------------------------------------------------------------------
  20. #pragma link "GeneralSettings"
  21. #pragma link "LogSettings"
  22. #pragma link "CopyParams"
  23. #pragma link "UpDownEdit"
  24. #pragma link "ComboEdit"
  25. #ifndef NO_RESOURCES
  26. #pragma resource "*.dfm"
  27. #endif
  28. //---------------------------------------------------------------------
  29. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  30. TPreferencesDialogData * DialogData)
  31. {
  32. bool Result;
  33. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(GetFormOwner());
  34. try
  35. {
  36. PreferencesDialog->PreferencesMode = APreferencesMode;
  37. Result = PreferencesDialog->Execute(DialogData);
  38. }
  39. __finally
  40. {
  41. delete PreferencesDialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  47. : TForm(AOwner)
  48. {
  49. SetCorrectFormParent(this);
  50. FNoUpdate = 0;
  51. FPreferencesMode = ::pmDefault;
  52. FEditorFont = new TFont();
  53. FEditorFont->Color = clWindowText;
  54. // color tends to reset in object inspector
  55. EditorFontLabel->Color = clWindow;
  56. // currently useless
  57. FAfterFilenameEditDialog = false;
  58. FCustomCommandList = new TCustomCommandList();
  59. FCustomCommandChanging = false;
  60. FListViewDragDest = -1;
  61. FCopyParamList = new TCopyParamList();
  62. FEditorList = new TEditorList();
  63. UseSystemSettings(this);
  64. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  65. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  66. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView2, true);
  67. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  68. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta);
  69. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  70. LoggingFrame->Init();
  71. InstallPathWordBreakProc(RandomSeedFileEdit);
  72. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  73. InstallPathWordBreakProc(PuttyPathEdit);
  74. HintLabel(ShellIconsText);
  75. HotTrackLabel(CopyParamLabel);
  76. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  77. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  78. }
  79. //---------------------------------------------------------------------------
  80. __fastcall TPreferencesDialog::~TPreferencesDialog()
  81. {
  82. SAFE_DESTROY(FEditorScrollOnDragOver);
  83. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  84. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  85. delete FEditorFont;
  86. delete FCustomCommandList;
  87. delete FCopyParamList;
  88. delete FEditorList;
  89. }
  90. //---------------------------------------------------------------------
  91. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  92. {
  93. FDialogData = DialogData;
  94. LoadConfiguration();
  95. bool Result = (ShowModal() == mrOk);
  96. if (Result)
  97. {
  98. SaveConfiguration();
  99. }
  100. return Result;
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  104. {
  105. Tree->FullExpand();
  106. int i = 0;
  107. while (i < Tree->Items->Count)
  108. {
  109. if ((!WinConfiguration->ExpertMode &&
  110. Tree->Items->Item[i]->SelectedIndex & 128))
  111. {
  112. Tree->Items->Delete(Tree->Items->Item[i]);
  113. }
  114. else
  115. {
  116. for (int pi = 0; pi < PageControl->PageCount; pi++)
  117. {
  118. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  119. {
  120. if (PageControl->Pages[pi]->Enabled)
  121. {
  122. // gets called multiple times occasionally
  123. // (e.g. when called from upload dialog invoked by /upload)
  124. if (!PageControl->Pages[pi]->Hint.IsEmpty())
  125. {
  126. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  127. PageControl->Pages[pi]->Hint = L"";
  128. }
  129. }
  130. else
  131. {
  132. Tree->Items->Delete(Tree->Items->Item[i]);
  133. i--;
  134. }
  135. break;
  136. }
  137. }
  138. i++;
  139. }
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TPreferencesDialog::LoadConfiguration()
  144. {
  145. FNoUpdate++;
  146. try
  147. {
  148. if (FPreferencesMode != pmLogin)
  149. {
  150. LoggingFrame->LoadConfiguration();
  151. GeneralSettingsFrame->LoadConfiguration();
  152. }
  153. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  154. BOOLPROP(DefaultDirIsHome);
  155. BOOLPROP(PreservePanelState);
  156. BOOLPROP(DeleteToRecycleBin);
  157. BOOLPROP(DDTransferConfirmation);
  158. BOOLPROP(DDWarnLackOfTempSpace);
  159. BOOLPROP(ShowHiddenFiles);
  160. BOOLPROP(FormatSizeBytes);
  161. BOOLPROP(RenameWholeName);
  162. BOOLPROP(ShowInaccesibleDirectories);
  163. BOOLPROP(CopyOnDoubleClickConfirmation);
  164. BOOLPROP(ConfirmTransferring);
  165. BOOLPROP(ConfirmOverwriting);
  166. BOOLPROP(ConfirmResume);
  167. BOOLPROP(ConfirmDeleting);
  168. BOOLPROP(ConfirmRecycling);
  169. BOOLPROP(ConfirmClosingSession);
  170. BOOLPROP(ConfirmExitOnCompletion);
  171. BOOLPROP(UseLocationProfiles);
  172. BOOLPROP(ConfirmCommandSession);
  173. BOOLPROP(ContinueOnError);
  174. BOOLPROP(DDAllowMoveInit);
  175. BOOLPROP(BeepOnFinish);
  176. BOOLPROP(TemporaryDirectoryAppendSession);
  177. BOOLPROP(TemporaryDirectoryAppendPath);
  178. BOOLPROP(TemporaryDirectoryCleanup);
  179. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  180. BOOLPROP(FullRowSelect);
  181. BeepOnFinishAfterEdit->AsInteger =
  182. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  183. BOOLPROP(BalloonNotifications);
  184. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  185. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  186. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  187. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  188. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  189. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  190. {
  191. DDSystemTemporaryDirectoryButton->Checked = true;
  192. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  193. }
  194. else
  195. {
  196. DDCustomTemporaryDirectoryButton->Checked = true;
  197. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  198. }
  199. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  200. {
  201. NortonLikeModeCombo->ItemIndex = 2;
  202. }
  203. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  204. {
  205. NortonLikeModeCombo->ItemIndex = 1;
  206. }
  207. else
  208. {
  209. NortonLikeModeCombo->ItemIndex = 0;
  210. }
  211. PreserveLocalDirectoryCheck->Checked =
  212. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  213. SwappedPanelsCheck->Checked =
  214. WinConfiguration->ScpCommander.SwappedPanels;
  215. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  216. ShowFullAddressCheck->Checked =
  217. WinConfiguration->ScpExplorer.ShowFullAddress;
  218. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  219. IniFileStorageButton2->Checked = (Configuration->Storage != stRegistry);
  220. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  221. // editor
  222. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  223. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  224. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  225. {
  226. EditorEncodingCombo->ItemIndex = 1;
  227. }
  228. else
  229. {
  230. EditorEncodingCombo->ItemIndex = 0;
  231. }
  232. FEditorFont->Name = WinConfiguration->Editor.FontName;
  233. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  234. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  235. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  236. (*FEditorList) = *WinConfiguration->EditorList;
  237. UpdateEditorListView();
  238. FCopyParams = GUIConfiguration->DefaultCopyParam;
  239. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  240. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  241. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  242. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  243. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  244. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  245. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  246. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  247. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  248. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  249. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  250. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  251. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  252. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  253. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  254. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  255. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  256. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  257. StorageGroup->Visible = WinConfiguration->ExpertMode;
  258. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  259. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  260. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  261. UpdateCustomCommandsView();
  262. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  263. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  264. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  265. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  266. // Queue
  267. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  268. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  269. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  270. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  271. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  272. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  273. RememberPasswordCheck->Checked = GUIConfiguration->QueueRememberPassword;
  274. if (WinConfiguration->QueueView.Show == qvShow)
  275. {
  276. QueueViewShowButton->Checked = true;
  277. }
  278. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  279. {
  280. QueueViewHideWhenEmptyButton->Checked = true;
  281. }
  282. else
  283. {
  284. QueueViewHideButton->Checked = true;
  285. }
  286. // window
  287. if (WinConfiguration->PathInCaption == picFull)
  288. {
  289. PathInCaptionFullButton->Checked = true;
  290. }
  291. else if (WinConfiguration->PathInCaption == picShort)
  292. {
  293. PathInCaptionShortButton->Checked = true;
  294. }
  295. else
  296. {
  297. PathInCaptionNoneButton->Checked = true;
  298. }
  299. BOOLPROP(MinimizeToTray);
  300. // panels
  301. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  302. BOOLPROP(AutoReadDirectoryAfterOp);
  303. BOOLPROP(RefreshRemotePanel);
  304. RefreshRemotePanelIntervalEdit->Value =
  305. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  306. // updates
  307. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  308. if (int(Updates.Period) <= 0)
  309. {
  310. UpdatesPeriodCombo->ItemIndex = 0;
  311. }
  312. else if (int(Updates.Period) <= 1)
  313. {
  314. UpdatesPeriodCombo->ItemIndex = 1;
  315. }
  316. else if (int(Updates.Period) <= 7)
  317. {
  318. UpdatesPeriodCombo->ItemIndex = 2;
  319. }
  320. else
  321. {
  322. UpdatesPeriodCombo->ItemIndex = 3;
  323. }
  324. CollectUsageCheck->Checked = Configuration->CollectUsage;
  325. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  326. switch (Updates.ConnectionType)
  327. {
  328. case ctDirect:
  329. default:
  330. UpdatesDirectCheck->Checked = true;
  331. break;
  332. case ctAuto:
  333. UpdatesAutoCheck->Checked = true;
  334. break;
  335. case ctProxy:
  336. UpdatesProxyCheck->Checked = true;
  337. break;
  338. }
  339. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  340. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  341. // presets
  342. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  343. UpdateCopyParamListView();
  344. BOOLPROP(CopyParamAutoSelectNotice);
  345. // interface
  346. if (WinConfiguration->Theme == L"OfficeXP")
  347. {
  348. ThemeCombo->ItemIndex = 1;
  349. }
  350. else if (WinConfiguration->Theme == L"Office2003")
  351. {
  352. ThemeCombo->ItemIndex = 2;
  353. }
  354. else
  355. {
  356. ThemeCombo->ItemIndex = 0;
  357. }
  358. // security
  359. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  360. // network
  361. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  362. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  363. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  364. #undef BOOLPROP
  365. }
  366. __finally
  367. {
  368. FNoUpdate--;
  369. }
  370. UpdateControls();
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TPreferencesDialog::SaveConfiguration()
  374. {
  375. Configuration->BeginUpdate();
  376. try
  377. {
  378. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  379. if (FPreferencesMode != pmLogin)
  380. {
  381. LoggingFrame->SaveConfiguration();
  382. GeneralSettingsFrame->SaveConfiguration();
  383. }
  384. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  385. BOOLPROP(DefaultDirIsHome);
  386. BOOLPROP(PreservePanelState);
  387. BOOLPROP(DeleteToRecycleBin);
  388. BOOLPROP(DDTransferConfirmation);
  389. BOOLPROP(DDWarnLackOfTempSpace);
  390. BOOLPROP(ShowHiddenFiles);
  391. BOOLPROP(FormatSizeBytes);
  392. BOOLPROP(RenameWholeName);
  393. BOOLPROP(ShowInaccesibleDirectories);
  394. BOOLPROP(CopyOnDoubleClickConfirmation);
  395. BOOLPROP(ConfirmTransferring);
  396. BOOLPROP(ConfirmOverwriting);
  397. BOOLPROP(ConfirmResume);
  398. BOOLPROP(ConfirmDeleting);
  399. BOOLPROP(ConfirmRecycling);
  400. BOOLPROP(ConfirmClosingSession);
  401. BOOLPROP(ConfirmExitOnCompletion);
  402. BOOLPROP(UseLocationProfiles);
  403. BOOLPROP(ConfirmCommandSession);
  404. BOOLPROP(ContinueOnError);
  405. BOOLPROP(DDAllowMoveInit);
  406. BOOLPROP(BeepOnFinish);
  407. BOOLPROP(TemporaryDirectoryAppendSession);
  408. BOOLPROP(TemporaryDirectoryAppendPath);
  409. BOOLPROP(TemporaryDirectoryCleanup);
  410. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  411. BOOLPROP(FullRowSelect);
  412. GUIConfiguration->BeepOnFinishAfter =
  413. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  414. BOOLPROP(BalloonNotifications);
  415. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  416. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  417. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  418. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  419. if (DDSystemTemporaryDirectoryButton->Checked)
  420. {
  421. WinConfiguration->DDTemporaryDirectory = L"";
  422. }
  423. else
  424. {
  425. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  426. }
  427. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  428. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  429. if (NortonLikeModeCombo->ItemIndex == 2)
  430. {
  431. ScpCommander.NortonLikeMode = nlOff;
  432. }
  433. else if (NortonLikeModeCombo->ItemIndex == 1)
  434. {
  435. ScpCommander.NortonLikeMode = nlKeyboard;
  436. }
  437. else
  438. {
  439. ScpCommander.NortonLikeMode = nlOn;
  440. }
  441. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  442. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  443. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  444. WinConfiguration->ScpCommander = ScpCommander;
  445. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  446. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  447. WinConfiguration->ScpExplorer = ScpExplorer;
  448. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  449. // editor
  450. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  451. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  452. switch (EditorEncodingCombo->ItemIndex)
  453. {
  454. case 1:
  455. WinConfiguration->Editor.Encoding = CP_UTF8;
  456. break;
  457. default:
  458. WinConfiguration->Editor.Encoding = CP_ACP;
  459. break;
  460. }
  461. WinConfiguration->Editor.FontName = FEditorFont->Name;
  462. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  463. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  464. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  465. WinConfiguration->EditorList = FEditorList;
  466. // overwrites only TCopyParamType fields
  467. CopyParam = FCopyParams;
  468. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  469. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  470. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  471. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  472. Configuration->SessionReopenAuto =
  473. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  474. GUIConfiguration->SessionReopenAutoIdle =
  475. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  476. Configuration->SessionReopenAutoStall =
  477. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  478. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  479. WinConfiguration->CustomCommandList = FCustomCommandList;
  480. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  481. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  482. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  483. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  484. // Queue
  485. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  486. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  487. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  488. CopyParam.Queue = QueueCheck->Checked;
  489. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  490. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  491. GUIConfiguration->QueueRememberPassword = RememberPasswordCheck->Checked;
  492. if (QueueViewShowButton->Checked)
  493. {
  494. WinConfiguration->QueueView.Show = qvShow;
  495. }
  496. else if (QueueViewHideWhenEmptyButton->Checked)
  497. {
  498. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  499. }
  500. else
  501. {
  502. WinConfiguration->QueueView.Show = qvHide;
  503. }
  504. GUIConfiguration->DefaultCopyParam = CopyParam;
  505. // window
  506. if (PathInCaptionFullButton->Checked)
  507. {
  508. WinConfiguration->PathInCaption = picFull;
  509. }
  510. else if (PathInCaptionShortButton->Checked)
  511. {
  512. WinConfiguration->PathInCaption = picShort;
  513. }
  514. else
  515. {
  516. WinConfiguration->PathInCaption = picNone;
  517. }
  518. BOOLPROP(MinimizeToTray);
  519. // panels
  520. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  521. BOOLPROP(AutoReadDirectoryAfterOp);
  522. BOOLPROP(RefreshRemotePanel);
  523. WinConfiguration->RefreshRemotePanelInterval =
  524. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  525. // updates
  526. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  527. if (UpdatesPeriodCombo->ItemIndex == 0)
  528. {
  529. Updates.Period = 0;
  530. }
  531. else if (UpdatesPeriodCombo->ItemIndex == 1)
  532. {
  533. Updates.Period = 1;
  534. }
  535. else if (UpdatesPeriodCombo->ItemIndex == 2)
  536. {
  537. Updates.Period = 7;
  538. }
  539. else
  540. {
  541. Updates.Period = 30;
  542. }
  543. Configuration->CollectUsage = CollectUsageCheck->Checked;
  544. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  545. if (UpdatesDirectCheck->Checked)
  546. {
  547. Updates.ConnectionType = ctDirect;
  548. }
  549. else if (UpdatesAutoCheck->Checked)
  550. {
  551. Updates.ConnectionType = ctAuto;
  552. }
  553. else if (UpdatesProxyCheck->Checked)
  554. {
  555. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  556. {
  557. Updates.ConnectionType = ctProxy;
  558. }
  559. else
  560. {
  561. Updates.ConnectionType = ctDirect;
  562. }
  563. }
  564. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  565. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  566. WinConfiguration->Updates = Updates;
  567. // presets
  568. WinConfiguration->CopyParamList = FCopyParamList;
  569. BOOLPROP(CopyParamAutoSelectNotice);
  570. // interface
  571. if (ThemeCombo->ItemIndex == 1)
  572. {
  573. WinConfiguration->Theme = L"OfficeXP";
  574. }
  575. else if (ThemeCombo->ItemIndex == 2)
  576. {
  577. WinConfiguration->Theme = L"Office2003";
  578. }
  579. else
  580. {
  581. WinConfiguration->Theme = L"Default";
  582. }
  583. // network
  584. Configuration->ExternalIpAddress =
  585. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  586. #undef BOOLPROP
  587. }
  588. __finally
  589. {
  590. Configuration->EndUpdate();
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  595. {
  596. if (PreferencesMode != value)
  597. {
  598. FPreferencesMode = value;
  599. GeneralSheet->Enabled = (value != pmLogin);
  600. LogSheet->Enabled = (value != pmLogin);
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  605. {
  606. PrepareNavigationTree(NavigationTree);
  607. switch (PreferencesMode) {
  608. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  609. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  610. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  611. case pmTransfer: PageControl->ActivePage = TransferSheet; break;
  612. case pmLogging: PageControl->ActivePage = LogSheet; break;
  613. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  614. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  615. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  616. default: PageControl->ActivePage = PreferencesSheet; break;
  617. }
  618. PageControlChange(NULL);
  619. }
  620. //---------------------------------------------------------------------------
  621. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  622. {
  623. UpdateControls();
  624. }
  625. //---------------------------------------------------------------------------
  626. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  627. {
  628. UnicodeString Result;
  629. for (int Index = 1; Index <= Values.Length(); Index++)
  630. {
  631. if (Index > 1)
  632. {
  633. Result += L' ';
  634. if (EditorTabSizeEdit->AsInteger > 2)
  635. {
  636. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  637. }
  638. }
  639. Result += Values[Index];
  640. }
  641. return Result;
  642. }
  643. //---------------------------------------------------------------------------
  644. void __fastcall TPreferencesDialog::UpdateControls()
  645. {
  646. if (FNoUpdate == 0)
  647. {
  648. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  649. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  650. EnableControl(BalloonNotificationsCheck, ::TTrayIcon::SupportsBalloons());
  651. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  652. EnableControl(ResumeThresholdUnitLabel, ResumeThresholdEdit->Enabled);
  653. EnableControl(SessionReopenAutoEdit,
  654. SessionReopenAutoCheck->Checked || SessionReopenAutoIdleCheck->Checked);
  655. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  656. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  657. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  658. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  659. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  660. EnableControl(SessionReopenTimeoutEdit,
  661. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  662. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  663. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  664. EnableControl(CopyOnDoubleClickConfirmationCheck,
  665. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  666. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  667. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  668. UnicodeString EditorFontLabelText;
  669. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  670. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  671. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  672. EditorFontLabelText += TabSample(L"1234");
  673. EditorFontLabel->Caption = EditorFontLabelText;
  674. EditorFontLabel->Font = FEditorFont;
  675. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  676. EnableControl(EditCommandButton, CommandSelected);
  677. EnableControl(RemoveCommandButton, CommandSelected);
  678. EnableControl(UpCommandButton, CommandSelected &&
  679. CustomCommandsView->ItemIndex > 0);
  680. EnableControl(DownCommandButton, CommandSelected &&
  681. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  682. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  683. EnableControl(EditCopyParamButton, CopyParamSelected);
  684. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  685. EnableControl(RemoveCopyParamButton, CopyParamSelected);
  686. EnableControl(UpCopyParamButton, CopyParamSelected &&
  687. (CopyParamListView->ItemIndex > 0));
  688. EnableControl(DownCopyParamButton, CopyParamSelected &&
  689. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  690. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  691. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  692. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  693. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  694. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  695. DDCustomTemporaryDirectoryButton->Checked);
  696. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  697. DDAllowMoveInitCheck->Checked);
  698. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  699. TemporaryDirectoryCleanupCheck->Checked);
  700. IniFileStorageButton2->Caption =
  701. AnsiReplaceStr(IniFileStorageButton2->Caption, L"winscp.ini",
  702. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName)));
  703. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  704. bool EditorSelected = (EditorListView2->Selected != NULL);
  705. EnableControl(EditEditorButton, EditorSelected);
  706. EnableControl(RemoveEditorButton, EditorSelected);
  707. EnableControl(UpEditorButton, EditorSelected &&
  708. (EditorListView2->ItemIndex > 0));
  709. EnableControl(DownEditorButton, EditorSelected &&
  710. (EditorListView2->ItemIndex < EditorListView2->Items->Count - 1));
  711. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  712. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  713. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  714. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  715. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  716. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  717. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  718. EnableControl(TelnetForFtpInPuttyCheck, PuttyPasswordCheck2->Enabled);
  719. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  720. // network
  721. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  722. // transfer
  723. UnicodeString InfoStr = FCopyParams.GetInfoStr(L"; ", 0);
  724. CopyParamLabel->Caption = InfoStr;
  725. CopyParamLabel->Hint = InfoStr;
  726. CopyParamLabel->ShowHint =
  727. (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
  728. // integration
  729. // There's no quick launch in Windows 7
  730. EnableControl(QuickLaunchIconButton, !IsWin7());
  731. }
  732. }
  733. //---------------------------------------------------------------------------
  734. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  735. {
  736. if (FontDialog(FEditorFont))
  737. {
  738. UpdateControls();
  739. }
  740. }
  741. //---------------------------------------------------------------------------
  742. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  743. bool & /*CanClose*/)
  744. {
  745. if (ModalResult != mrCancel)
  746. {
  747. ExitActiveControl(this);
  748. }
  749. }
  750. //---------------------------------------------------------------------------
  751. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  752. {
  753. UnicodeString IconName, Params;
  754. int SpecialFolder;
  755. if (Sender == DesktopIconButton)
  756. {
  757. IconName = AppName;
  758. int Result =
  759. MessageDialog(LoadStr(CREATE_DESKTOP_ICON), qtConfirmation,
  760. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  761. switch (Result)
  762. {
  763. case qaYes:
  764. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  765. break;
  766. case qaNo:
  767. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  768. break;
  769. default:
  770. Abort();
  771. break;
  772. }
  773. }
  774. else
  775. {
  776. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  777. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  778. {
  779. if (Sender == SendToHookButton)
  780. {
  781. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppName));
  782. SpecialFolder = CSIDL_SENDTO;
  783. Params = L"/upload";
  784. }
  785. else if (Sender == QuickLaunchIconButton)
  786. {
  787. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  788. AppName;
  789. SpecialFolder = CSIDL_APPDATA;
  790. }
  791. }
  792. else
  793. {
  794. Abort();
  795. }
  796. }
  797. CreateDesktopShortCut(IconName,
  798. Application->ExeName, Params, L"", SpecialFolder);
  799. }
  800. //---------------------------------------------------------------------------
  801. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  802. TListItem * Item)
  803. {
  804. assert(FCustomCommandList != NULL);
  805. int Index = Item->Index;
  806. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  807. const TCustomCommandType * Command = FCustomCommandList->Commands[Index];
  808. UnicodeString Caption = StripHotkey(Command->Name);
  809. if (Command->ShortCut != 0)
  810. {
  811. Caption = FORMAT(L"%s (%s)", (Caption, ShortCutToText(Command->ShortCut)));
  812. }
  813. Item->Caption = Caption;
  814. assert(!Item->SubItems->Count);
  815. Item->SubItems->Add(Command->Command);
  816. int Params = Command->Params;
  817. Item->SubItems->Add(LoadStr(
  818. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  819. UnicodeString ParamsStr;
  820. #define ADDPARAM(PARAM, STR) \
  821. if (FLAGSET(Params, PARAM)) \
  822. ParamsStr += (ParamsStr.IsEmpty() ? L"" : L"/") + LoadStr(STR);
  823. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  824. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  825. #undef ADDPARAM
  826. Item->SubItems->Add(ParamsStr);
  827. }
  828. //---------------------------------------------------------------------------
  829. void __fastcall TPreferencesDialog::ListViewSelectItem(
  830. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  831. {
  832. UpdateControls();
  833. }
  834. //---------------------------------------------------------------------------
  835. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  836. {
  837. CustomCommandsView->Items->Count = FCustomCommandList->Count;
  838. AdjustListColumnsWidth(CustomCommandsView, FCustomCommandList->Count);
  839. CustomCommandsView->Invalidate();
  840. }
  841. //---------------------------------------------------------------------------
  842. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  843. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  844. {
  845. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  846. {
  847. RemoveCommandButtonClick(NULL);
  848. }
  849. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  850. {
  851. AddEditCommandButtonClick(AddCommandButton);
  852. }
  853. }
  854. //---------------------------------------------------------------------------
  855. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  856. TObject * /*Sender*/)
  857. {
  858. if (EditCommandButton->Enabled)
  859. {
  860. AddEditCommandButtonClick(EditCommandButton);
  861. }
  862. }
  863. //---------------------------------------------------------------------------
  864. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  865. {
  866. bool Edit = (Sender == EditCommandButton);
  867. TCustomCommandType Command;
  868. if (Edit)
  869. {
  870. int Index = CustomCommandsView->ItemIndex;
  871. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  872. Command = *FCustomCommandList->Commands[Index];
  873. }
  874. TShortCuts ShortCuts;
  875. if (WinConfiguration->SharedBookmarks != NULL)
  876. {
  877. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  878. }
  879. FCustomCommandList->ShortCuts(ShortCuts);
  880. if (DoCustomCommandDialog(Command, FCustomCommandList,
  881. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  882. {
  883. int Index = CustomCommandsView->ItemIndex;
  884. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  885. if (Edit)
  886. {
  887. FCustomCommandList->Change(Index, ACommand);
  888. }
  889. else
  890. {
  891. if (Index >= 0)
  892. {
  893. FCustomCommandList->Insert(Index, ACommand);
  894. }
  895. else
  896. {
  897. FCustomCommandList->Add(ACommand);
  898. Index = FCustomCommandList->Count - 1;
  899. }
  900. }
  901. UpdateCustomCommandsView();
  902. CustomCommandsView->ItemIndex = Index;
  903. UpdateControls();
  904. }
  905. }
  906. //---------------------------------------------------------------------------
  907. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  908. TObject * /*Sender*/)
  909. {
  910. assert(CustomCommandsView->ItemIndex >= 0 &&
  911. CustomCommandsView->ItemIndex < FCustomCommandList->Count);
  912. FCustomCommandList->Delete(CustomCommandsView->ItemIndex);
  913. UpdateCustomCommandsView();
  914. UpdateControls();
  915. }
  916. //---------------------------------------------------------------------------
  917. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  918. {
  919. if (Source >= 0 && Source < FCustomCommandList->Count &&
  920. Dest >= 0 && Dest < FCustomCommandList->Count)
  921. {
  922. FCustomCommandList->Move(Source, Dest);
  923. // workaround for bug in VCL
  924. CustomCommandsView->ItemIndex = -1;
  925. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  926. CustomCommandsView->ItemIndex = Dest;
  927. UpdateCustomCommandsView();
  928. UpdateControls();
  929. }
  930. }
  931. //---------------------------------------------------------------------------
  932. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  933. {
  934. CustomCommandMove(CustomCommandsView->ItemIndex,
  935. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  936. }
  937. //---------------------------------------------------------------------------
  938. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  939. {
  940. if (ListView == CopyParamListView)
  941. {
  942. return FCopyParamScrollOnDragOver;
  943. }
  944. else if (ListView == CustomCommandsView)
  945. {
  946. return FCustomCommandsScrollOnDragOver;
  947. }
  948. else if (ListView == EditorListView2)
  949. {
  950. return FEditorScrollOnDragOver;
  951. }
  952. else
  953. {
  954. assert(false);
  955. return NULL;
  956. }
  957. }
  958. //---------------------------------------------------------------------------
  959. void __fastcall TPreferencesDialog::ListViewStartDrag(
  960. TObject * Sender, TDragObject *& /*DragObject*/)
  961. {
  962. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  963. FListViewDragDest = -1;
  964. ScrollOnDragOver(Sender)->StartDrag();
  965. }
  966. //---------------------------------------------------------------------------
  967. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  968. {
  969. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  970. FListViewDragDest = Item ? Item->Index : -1;
  971. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  972. }
  973. //---------------------------------------------------------------------------
  974. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  975. TObject * Sender, TObject * Source, int X, int Y)
  976. {
  977. if (Source == CustomCommandsView)
  978. {
  979. if (AllowListViewDrag(Sender, X, Y))
  980. {
  981. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  982. }
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TPreferencesDialog::ListViewDragOver(
  987. TObject * Sender, TObject * Source, int X, int Y,
  988. TDragState /*State*/, bool & Accept)
  989. {
  990. if (Source == Sender)
  991. {
  992. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  993. // (when dropped on item itself, when it was dragged over another item before,
  994. // that another item remains highlighted forever)
  995. Accept = true;
  996. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  997. }
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1001. {
  1002. if (Source >= 0 && Source < FCopyParamList->Count &&
  1003. Dest >= 0 && Dest < FCopyParamList->Count)
  1004. {
  1005. FCopyParamList->Move(Source, Dest);
  1006. // workaround for bug in VCL
  1007. CopyParamListView->ItemIndex = -1;
  1008. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1009. CopyParamListView->ItemIndex = Dest;
  1010. UpdateCopyParamListView();
  1011. UpdateControls();
  1012. }
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1016. TObject * Sender, TObject * Source, int X, int Y)
  1017. {
  1018. if (Source == CopyParamListView)
  1019. {
  1020. if (AllowListViewDrag(Sender, X, Y))
  1021. {
  1022. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1023. }
  1024. }
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1028. {
  1029. CopyParamMove(CopyParamListView->ItemIndex,
  1030. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1031. }
  1032. //---------------------------------------------------------------------------
  1033. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1034. TObject * /*Sender*/)
  1035. {
  1036. assert(CopyParamListView->ItemIndex >= 0 &&
  1037. CopyParamListView->ItemIndex < FCopyParamList->Count);
  1038. FCopyParamList->Delete(CopyParamListView->ItemIndex);
  1039. UpdateCopyParamListView();
  1040. UpdateControls();
  1041. }
  1042. //---------------------------------------------------------------------------
  1043. void __fastcall TPreferencesDialog::AddEditCopyParamButtonClick(
  1044. TObject * Sender)
  1045. {
  1046. TCopyParamPresetMode Mode;
  1047. if (Sender == EditCopyParamButton)
  1048. {
  1049. Mode = cpmEdit;
  1050. }
  1051. else if (Sender == DuplicateCopyParamButton)
  1052. {
  1053. Mode = cpmDuplicate;
  1054. }
  1055. else
  1056. {
  1057. Mode = cpmAdd;
  1058. }
  1059. int Index = CopyParamListView->ItemIndex;
  1060. TCopyParamRuleData * CopyParamRuleData =
  1061. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1062. if (DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData))
  1063. {
  1064. UpdateCopyParamListView();
  1065. CopyParamListView->ItemIndex = Index;
  1066. // when using duplicate button, focu remains on original item
  1067. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1068. UpdateControls();
  1069. }
  1070. }
  1071. //---------------------------------------------------------------------------
  1072. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1073. TObject * /*Sender*/)
  1074. {
  1075. if (EditCopyParamButton->Enabled)
  1076. {
  1077. AddEditCopyParamButtonClick(EditCopyParamButton);
  1078. }
  1079. }
  1080. //---------------------------------------------------------------------------
  1081. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1082. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1083. {
  1084. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1085. {
  1086. RemoveCopyParamButtonClick(NULL);
  1087. }
  1088. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1089. {
  1090. AddEditCopyParamButtonClick(AddCopyParamButton);
  1091. }
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1095. {
  1096. if (Source >= 0 && Source < FEditorList->Count &&
  1097. Dest >= 0 && Dest < FEditorList->Count)
  1098. {
  1099. FEditorList->Move(Source, Dest);
  1100. // workaround for bug in VCL
  1101. EditorListView2->ItemIndex = -1;
  1102. EditorListView2->ItemFocused = EditorListView2->Selected;
  1103. EditorListView2->ItemIndex = Dest;
  1104. UpdateEditorListView();
  1105. UpdateControls();
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. void __fastcall TPreferencesDialog::EditorListView2DragDrop(TObject * Sender,
  1110. TObject * Source, int X, int Y)
  1111. {
  1112. if (Source == EditorListView2)
  1113. {
  1114. if (AllowListViewDrag(Sender, X, Y))
  1115. {
  1116. EditorMove(FListViewDragSource, FListViewDragDest);
  1117. }
  1118. }
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1122. {
  1123. EditorMove(EditorListView2->ItemIndex,
  1124. EditorListView2->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1125. }
  1126. //---------------------------------------------------------------------------
  1127. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1128. TObject * /*Sender*/)
  1129. {
  1130. assert(EditorListView2->ItemIndex >= 0 &&
  1131. EditorListView2->ItemIndex < FEditorList->Count);
  1132. FEditorList->Delete(EditorListView2->ItemIndex);
  1133. UpdateEditorListView();
  1134. UpdateControls();
  1135. }
  1136. //---------------------------------------------------------------------------
  1137. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1138. {
  1139. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1140. int Index = EditorListView2->ItemIndex;
  1141. TEditorPreferences * Editor;
  1142. if (Mode == epmEdit)
  1143. {
  1144. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1145. }
  1146. else
  1147. {
  1148. Editor = new TEditorPreferences();
  1149. }
  1150. try
  1151. {
  1152. bool DummyRemember = false;
  1153. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1154. {
  1155. if (Mode == epmEdit)
  1156. {
  1157. FEditorList->Change(Index, Editor);
  1158. }
  1159. else
  1160. {
  1161. if (Index < 0)
  1162. {
  1163. Index = FEditorList->Count;
  1164. FEditorList->Add(Editor);
  1165. }
  1166. else
  1167. {
  1168. FEditorList->Insert(Index, Editor);
  1169. }
  1170. }
  1171. // ownership of the object lost
  1172. Editor = NULL;
  1173. UpdateEditorListView();
  1174. EditorListView2->ItemIndex = Index;
  1175. UpdateControls();
  1176. }
  1177. }
  1178. __finally
  1179. {
  1180. delete Editor;
  1181. }
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. void __fastcall TPreferencesDialog::EditorListView2DblClick(TObject * /*Sender*/)
  1185. {
  1186. if (EditEditorButton->Enabled)
  1187. {
  1188. AddEditEditorButtonClick(EditEditorButton);
  1189. }
  1190. }
  1191. //---------------------------------------------------------------------------
  1192. void __fastcall TPreferencesDialog::EditorListView2KeyDown(TObject * /*Sender*/,
  1193. WORD & Key, TShiftState /*Shift*/)
  1194. {
  1195. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1196. {
  1197. RemoveEditorButtonClick(NULL);
  1198. }
  1199. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1200. {
  1201. AddEditEditorButtonClick(AddEditorButton);
  1202. }
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1206. {
  1207. EditorListView2->Items->Count = FEditorList->Count;
  1208. AdjustListColumnsWidth(EditorListView2, FEditorList->Count);
  1209. EditorListView2->Invalidate();
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void __fastcall TPreferencesDialog::EditorListView2Data(TObject * /*Sender*/,
  1213. TListItem * Item)
  1214. {
  1215. int Index = Item->Index;
  1216. assert(Index >= 0 && Index <= FEditorList->Count);
  1217. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1218. Item->Caption = Editor->Data->FileMask.Masks;
  1219. Item->SubItems->Add(Editor->Name);
  1220. if (Editor->Data->Editor == edExternal)
  1221. {
  1222. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1223. }
  1224. }
  1225. //---------------------------------------------------------------------------
  1226. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1227. TTreeNode *Node)
  1228. {
  1229. if (Node->SelectedIndex)
  1230. {
  1231. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  1232. {
  1233. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  1234. {
  1235. PageControl->ActivePage = PageControl->Pages[Index];
  1236. // reshow the accelerators, etc
  1237. ResetSystemSettings(this);
  1238. return;
  1239. }
  1240. }
  1241. }
  1242. assert(false);
  1243. }
  1244. //---------------------------------------------------------------------------
  1245. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1246. {
  1247. bool Found = false;
  1248. if (PageControl->ActivePage->Tag)
  1249. {
  1250. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1251. {
  1252. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  1253. PageControl->ActivePage->Tag)
  1254. {
  1255. NavigationTree->Items->Item[Index]->Selected = true;
  1256. Found = true;
  1257. }
  1258. }
  1259. }
  1260. assert(Found);
  1261. if (Found)
  1262. {
  1263. UpdateControls();
  1264. }
  1265. }
  1266. //---------------------------------------------------------------------------
  1267. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1268. {
  1269. if (Message.CharCode == VK_TAB)
  1270. {
  1271. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1272. if (Shift.Contains(ssCtrl))
  1273. {
  1274. TTreeNode * Node = NavigationTree->Selected;
  1275. if (!Shift.Contains(ssShift))
  1276. {
  1277. Node = Node->GetNext();
  1278. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1279. }
  1280. else
  1281. {
  1282. if (Node->GetPrev()) Node = Node->GetPrev();
  1283. else
  1284. while (Node->GetNext()) Node = Node->GetNext();
  1285. }
  1286. Node->Selected = True;
  1287. Message.Result = 1;
  1288. return;
  1289. }
  1290. }
  1291. TForm::Dispatch(&Message);
  1292. }
  1293. //---------------------------------------------------------------------------
  1294. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1295. {
  1296. assert(Message.HelpInfo != NULL);
  1297. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1298. {
  1299. // invoke help for active page (not for whole form), regardless of focus
  1300. // (e.g. even if focus is on control outside pagecontrol)
  1301. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1302. }
  1303. TForm::Dispatch(&Message);
  1304. }
  1305. //---------------------------------------------------------------------------
  1306. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1307. {
  1308. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1309. assert(M);
  1310. if (M->Msg == CM_DIALOGKEY)
  1311. {
  1312. CMDialogKey(*((TWMKeyDown *)Message));
  1313. }
  1314. else if (M->Msg == WM_HELP)
  1315. {
  1316. WMHelp(*((TWMHelp *)Message));
  1317. }
  1318. else
  1319. {
  1320. TForm::Dispatch(Message);
  1321. }
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  1325. TObject * /*Sender*/)
  1326. {
  1327. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  1328. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL) == qaYes)
  1329. {
  1330. RegisterAsUrlHandler();
  1331. }
  1332. }
  1333. //---------------------------------------------------------------------------
  1334. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1335. {
  1336. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1337. SetFocus();
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1341. TObject * /*Sender*/)
  1342. {
  1343. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1344. if (MessageDialog(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath)),
  1345. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1346. {
  1347. AddSearchPath(AppPath);
  1348. }
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1352. TObject * Sender)
  1353. {
  1354. EditorFontButtonClick(Sender);
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1358. {
  1359. CopyParamListView->Items->Count = FCopyParamList->Count;
  1360. AdjustListColumnsWidth(CopyParamListView, FCopyParamList->Count);
  1361. CopyParamListView->Invalidate();
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1365. TListItem * Item)
  1366. {
  1367. int Index = Item->Index;
  1368. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1369. Item->Caption = StripHotkey(FCopyParamList->Names[Index]);
  1370. Item->SubItems->Add(BooleanToStr(FCopyParamList->Rules[Index] != NULL));
  1371. }
  1372. //---------------------------------------------------------------------------
  1373. void __fastcall TPreferencesDialog::CopyParamListViewInfoTip(
  1374. TObject * /*Sender*/, TListItem * Item, UnicodeString & InfoTip)
  1375. {
  1376. int Index = Item->Index;
  1377. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1378. const TCopyParamType * CopyParam = FCopyParamList->CopyParams[Index];
  1379. const TCopyParamRule * Rule = FCopyParamList->Rules[Index];
  1380. InfoTip = CopyParam->GetInfoStr(L"; ", 0);
  1381. if (Rule != NULL)
  1382. {
  1383. InfoTip += L"\n-\n" + Rule->GetInfoStr(L"; ");
  1384. }
  1385. }
  1386. //---------------------------------------------------------------------------
  1387. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1388. {
  1389. FormHelp(this);
  1390. }
  1391. //---------------------------------------------------------------------------
  1392. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1393. TObject * /*Sender*/)
  1394. {
  1395. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY),
  1396. LoadStr(PREFERENCES_PUTTY_FILTER), false, false);
  1397. }
  1398. //---------------------------------------------------------------------------
  1399. void __fastcall TPreferencesDialog::PuttyPathResetButtonClick(
  1400. TObject * /*Sender*/)
  1401. {
  1402. PuttyPathEdit->Text = WinConfiguration->DefaultPuttyPath;
  1403. }
  1404. //---------------------------------------------------------------------------
  1405. void __fastcall TPreferencesDialog::ExportButtonClick(TObject * /*Sender*/)
  1406. {
  1407. UnicodeString PersonalDirectory;
  1408. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
  1409. UnicodeString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1410. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
  1411. if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), L"ini", FileName))
  1412. {
  1413. Configuration->Export(FileName);
  1414. }
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1418. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1419. {
  1420. FBeforeDialogPath = Name;
  1421. Name = ExpandEnvironmentVariables(Name);
  1422. }
  1423. //---------------------------------------------------------------------------
  1424. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1425. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1426. {
  1427. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1428. {
  1429. Name = FBeforeDialogPath;
  1430. }
  1431. }
  1432. //---------------------------------------------------------------------------
  1433. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1434. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1435. {
  1436. AllowCollapse = false;
  1437. }
  1438. //---------------------------------------------------------------------------
  1439. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1440. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1441. {
  1442. ScrollOnDragOver(Sender)->EndDrag();
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TPreferencesDialog::RandomSeedFileEditCreateEditDialog(
  1446. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1447. {
  1448. USEDPARAM(DialogKind);
  1449. assert(DialogKind == dkOpen);
  1450. Dialog = new TOpenDialog(dynamic_cast<TComponent *>(Sender));
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1454. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  1455. {
  1456. if (Value == 0)
  1457. {
  1458. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1459. Handled = true;
  1460. }
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1464. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  1465. {
  1466. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1467. {
  1468. Value = 0;
  1469. Handled = true;
  1470. }
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  1474. TObject * /*Sender*/)
  1475. {
  1476. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  1477. {
  1478. try
  1479. {
  1480. if (UseMasterPasswordCheck->Checked)
  1481. {
  1482. if (DoChangeMasterPasswordDialog())
  1483. {
  1484. MessageDialog(LoadStr(MASTER_PASSWORD_SET), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1485. }
  1486. }
  1487. else
  1488. {
  1489. if (DoMasterPasswordDialog())
  1490. {
  1491. WinConfiguration->ClearMasterPassword();
  1492. MessageDialog(LoadStr(MASTER_PASSWORD_CLEARED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1493. }
  1494. }
  1495. }
  1496. __finally
  1497. {
  1498. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  1499. UpdateControls();
  1500. }
  1501. }
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  1505. TObject * /*Sender*/)
  1506. {
  1507. if (DoChangeMasterPasswordDialog())
  1508. {
  1509. MessageDialog(LoadStr(MASTER_PASSWORD_CHANGED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1510. }
  1511. }
  1512. //---------------------------------------------------------------------------
  1513. void __fastcall TPreferencesDialog::CopyParamGroupClick(TObject * /*Sender*/)
  1514. {
  1515. if (DoCopyParamCustomDialog(FCopyParams, 0))
  1516. {
  1517. UpdateControls();
  1518. }
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  1522. {
  1523. TStrings * Data = new TStringList();
  1524. try
  1525. {
  1526. Data->Text = GetUsageData();
  1527. UnicodeString Message =
  1528. LoadStr(Data->Text.IsEmpty() ? USAGE_DATA_NONE : USAGE_DATA);
  1529. MoreMessageDialog(Message, Data, qtInformation, qaOK, HELP_USAGE);
  1530. }
  1531. __finally
  1532. {
  1533. delete Data;
  1534. }
  1535. }
  1536. //---------------------------------------------------------------------------