Preferences.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  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. #include "ProgParams.h"
  20. //---------------------------------------------------------------------
  21. #pragma link "CopyParams"
  22. #pragma link "UpDownEdit"
  23. #pragma link "ComboEdit"
  24. #ifndef NO_RESOURCES
  25. #pragma link "HistoryComboBox"
  26. #pragma resource "*.dfm"
  27. #endif
  28. //---------------------------------------------------------------------
  29. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  30. TPreferencesDialogData * DialogData)
  31. {
  32. bool Result;
  33. TPreferencesDialog * PreferencesDialog =
  34. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  35. try
  36. {
  37. Result = PreferencesDialog->Execute(DialogData);
  38. if (Result)
  39. {
  40. Configuration->SaveExplicit();
  41. }
  42. }
  43. __finally
  44. {
  45. delete PreferencesDialog;
  46. }
  47. return Result;
  48. }
  49. //---------------------------------------------------------------------
  50. __fastcall TPreferencesDialog::TPreferencesDialog(
  51. TComponent* AOwner, TPreferencesMode PreferencesMode)
  52. : TForm(AOwner)
  53. {
  54. SetCorrectFormParent(this);
  55. FNoUpdate = 0;
  56. FPreferencesMode = PreferencesMode;
  57. FEditorFont.reset(new TFont());
  58. FEditorFont->Color = clWindowText;
  59. FPanelFont.reset(new TFont());
  60. FPanelFont->Color = clWindowText;
  61. // currently useless
  62. FAfterFilenameEditDialog = false;
  63. FCustomCommandList = new TCustomCommandList();
  64. FCustomCommandChanging = false;
  65. FListViewDragDest = -1;
  66. FCopyParamList = new TCopyParamList();
  67. FEditorList = new TEditorList();
  68. UseSystemSettings(this);
  69. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  70. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  71. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  72. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  73. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta);
  74. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  75. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  76. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  77. HintLabel(ShellIconsText2);
  78. HotTrackLabel(CopyParamLabel);
  79. HintLabel(PuttyPathHintText, LoadStr(PUTTY_PATTERNS_HINT));
  80. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  81. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  82. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  83. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  84. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  85. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  86. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  87. MenuButton(RegisterAsUrlHandlersButton);
  88. }
  89. //---------------------------------------------------------------------------
  90. __fastcall TPreferencesDialog::~TPreferencesDialog()
  91. {
  92. SAFE_DESTROY(FEditorScrollOnDragOver);
  93. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  94. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  95. delete FCustomCommandList;
  96. FCustomCommandList = NULL;
  97. delete FCopyParamList;
  98. FCopyParamList = NULL;
  99. delete FEditorList;
  100. FEditorList = NULL;
  101. }
  102. //---------------------------------------------------------------------
  103. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  104. {
  105. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  106. FDialogData = DialogData;
  107. LoadConfiguration();
  108. bool Result = (ShowModal() == DefaultResult(this));
  109. if (Result)
  110. {
  111. SaveConfiguration();
  112. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  113. }
  114. return Result;
  115. }
  116. //---------------------------------------------------------------------------
  117. void __fastcall TPreferencesDialog::LoadLanguages()
  118. {
  119. if (!FLanguagesLoaded)
  120. {
  121. LanguagesView->Items->Clear();
  122. TStrings * Locales = GUIConfiguration->Locales;
  123. for (int Index = 0; Index < Locales->Count; Index++)
  124. {
  125. TListItem * Item = LanguagesView->Items->Add();
  126. Item->Caption = Locales->Strings[Index];
  127. Item->Data = Locales->Objects[Index];
  128. Item->Focused =
  129. (reinterpret_cast<LCID>(Locales->Objects[Index]) == GUIConfiguration->Locale);
  130. Item->Selected = Item->Focused;
  131. }
  132. FLanguagesLoaded = false;
  133. }
  134. }
  135. //---------------------------------------------------------------------------
  136. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  137. {
  138. for (int pi = 0; pi < PageControl->PageCount; pi++)
  139. {
  140. TTabSheet * Sheet = PageControl->Pages[pi];
  141. if (Sheet->Tag == Node->SelectedIndex)
  142. {
  143. return Sheet;
  144. }
  145. }
  146. FAIL;
  147. return NULL;
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  151. {
  152. Tree->FullExpand();
  153. int i = 0;
  154. while (i < Tree->Items->Count)
  155. {
  156. TTreeNode * Node = Tree->Items->Item[i];
  157. TTabSheet * Sheet = FindPageForTreeNode(Node);
  158. if (NOT_NULL(Sheet))
  159. {
  160. if (Sheet->Enabled)
  161. {
  162. // gets called multiple times occasionally
  163. // (e.g. when called from upload dialog invoked by /upload)
  164. if (!Sheet->Caption.IsEmpty())
  165. {
  166. Node->Text = Sheet->Caption;
  167. Sheet->Caption = L"";
  168. }
  169. }
  170. else
  171. {
  172. Tree->Items->Delete(Node);
  173. i--;
  174. }
  175. }
  176. i++;
  177. }
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TPreferencesDialog::LoadConfiguration()
  181. {
  182. FNoUpdate++;
  183. try
  184. {
  185. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  186. BOOLPROP(DefaultDirIsHome);
  187. BOOLPROP(PreservePanelState);
  188. BOOLPROP(DeleteToRecycleBin);
  189. BOOLPROP(DDTransferConfirmation);
  190. BOOLPROP(DDWarnLackOfTempSpace);
  191. BOOLPROP(ShowHiddenFiles);
  192. BOOLPROP(RenameWholeName);
  193. BOOLPROP(ShowInaccesibleDirectories);
  194. BOOLPROP(CopyOnDoubleClickConfirmation);
  195. BOOLPROP(ConfirmTransferring);
  196. BOOLPROP(ConfirmOverwriting);
  197. BOOLPROP(ConfirmResume);
  198. BOOLPROP(ConfirmDeleting);
  199. BOOLPROP(ConfirmRecycling);
  200. BOOLPROP(ConfirmClosingSession);
  201. BOOLPROP(ConfirmExitOnCompletion);
  202. BOOLPROP(ConfirmCommandSession);
  203. BOOLPROP(ContinueOnError);
  204. BOOLPROP(DDAllowMoveInit);
  205. BOOLPROP(BeepOnFinish);
  206. BOOLPROP(TemporaryDirectoryAppendSession);
  207. BOOLPROP(TemporaryDirectoryAppendPath);
  208. BOOLPROP(TemporaryDirectoryDeterministic);
  209. BOOLPROP(TemporaryDirectoryCleanup);
  210. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  211. BOOLPROP(FullRowSelect);
  212. if (WinConfiguration->DDTransferConfirmation == asAuto)
  213. {
  214. // allow grayed state only initially,
  215. // once the off state is confirmed, never allow returning
  216. // to the undefined state
  217. DDTransferConfirmationCheck->AllowGrayed = true;
  218. }
  219. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck, WinConfiguration->DDTransferConfirmation);
  220. BeepOnFinishAfterEdit->AsInteger =
  221. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  222. BOOLPROP(BalloonNotifications);
  223. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  224. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  225. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  226. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  227. {
  228. DDSystemTemporaryDirectoryButton->Checked = true;
  229. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  230. }
  231. else
  232. {
  233. DDCustomTemporaryDirectoryButton->Checked = true;
  234. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  235. }
  236. // Commander
  237. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  238. {
  239. NortonLikeModeCombo->ItemIndex = 2;
  240. }
  241. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  242. {
  243. NortonLikeModeCombo->ItemIndex = 1;
  244. }
  245. else
  246. {
  247. NortonLikeModeCombo->ItemIndex = 0;
  248. }
  249. SwappedPanelsCheck->Checked =
  250. WinConfiguration->ScpCommander.SwappedPanels;
  251. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  252. ExplorerKeyboardShortcutsCombo->ItemIndex =
  253. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  254. BOOLPROP(UseLocationProfiles);
  255. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  256. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  257. // Local panel
  258. PreserveLocalDirectoryCheck->Checked =
  259. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  260. SystemContextMenuCheck->Checked =
  261. WinConfiguration->ScpCommander.SystemContextMenu;
  262. // Explorer
  263. ShowFullAddressCheck->Checked =
  264. WinConfiguration->ScpExplorer.ShowFullAddress;
  265. // select none when stNul
  266. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  267. IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
  268. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  269. // editor
  270. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  271. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  272. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  273. {
  274. EditorEncodingCombo->ItemIndex = 1;
  275. }
  276. else
  277. {
  278. EditorEncodingCombo->ItemIndex = 0;
  279. }
  280. TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
  281. (*FEditorList) = *WinConfiguration->EditorList;
  282. UpdateEditorListView();
  283. FCopyParams = GUIConfiguration->DefaultCopyParam;
  284. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  285. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  286. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  287. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  288. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  289. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  290. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  291. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  292. SessionReopenAutoIdleEdit->Value = (GUIConfiguration->SessionReopenAutoIdle > 0 ?
  293. (GUIConfiguration->SessionReopenAutoIdle / MSecsPerSec) : 5);
  294. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  295. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  296. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  297. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  298. GeneralSheet->Enabled = WinConfiguration->ExpertMode;
  299. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  300. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  301. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  302. StorageGroup->Visible = WinConfiguration->ExpertMode;
  303. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  304. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  305. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  306. UpdateCustomCommandsView();
  307. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  308. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  309. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  310. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  311. SelectPuttyRegistryStorageKey(GUIConfiguration->PuttyRegistryStorageKey);
  312. // Queue
  313. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  314. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  315. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  316. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  317. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  318. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  319. if (!GUIConfiguration->QueueKeepDoneItems)
  320. {
  321. QueueKeepDoneItemsForCombo->ItemIndex = 0;
  322. }
  323. else if (GUIConfiguration->QueueKeepDoneItemsFor < 0)
  324. {
  325. QueueKeepDoneItemsForCombo->ItemIndex = 5;
  326. }
  327. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15)
  328. {
  329. QueueKeepDoneItemsForCombo->ItemIndex = 1;
  330. }
  331. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60)
  332. {
  333. QueueKeepDoneItemsForCombo->ItemIndex = 2;
  334. }
  335. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15 * 60)
  336. {
  337. QueueKeepDoneItemsForCombo->ItemIndex = 3;
  338. }
  339. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60 * 60)
  340. {
  341. QueueKeepDoneItemsForCombo->ItemIndex = 4;
  342. }
  343. if (WinConfiguration->QueueView.Show == qvShow)
  344. {
  345. QueueViewShowButton->Checked = true;
  346. }
  347. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  348. {
  349. QueueViewHideWhenEmptyButton->Checked = true;
  350. }
  351. else
  352. {
  353. QueueViewHideButton->Checked = true;
  354. }
  355. // window
  356. AutoSaveWorkspaceCheck->Checked = WinConfiguration->AutoSaveWorkspace;
  357. AutoWorkspaceCombo->Text =
  358. DefaultStr(WinConfiguration->AutoWorkspace,
  359. // It will rarely happen that LastWorkspace is set, while AutoWorkspace not.
  360. // It can happen only when user saved workspace before opening the Preferences
  361. // dialog for the first time
  362. DefaultStr(WinConfiguration->LastWorkspace, LoadStr(NEW_WORKSPACE)));
  363. AutoSaveWorkspacePasswordsCheck->Checked = WinConfiguration->AutoSaveWorkspacePasswords;
  364. if (WinConfiguration->PathInCaption == picFull)
  365. {
  366. PathInCaptionFullButton->Checked = true;
  367. }
  368. else if (WinConfiguration->PathInCaption == picShort)
  369. {
  370. PathInCaptionShortButton->Checked = true;
  371. }
  372. else
  373. {
  374. PathInCaptionNoneButton->Checked = true;
  375. }
  376. BOOLPROP(MinimizeToTray);
  377. BOOLPROP(ExternalSessionInExistingInstance);
  378. // panels
  379. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  380. BOOLPROP(AutoReadDirectoryAfterOp);
  381. BOOLPROP(RefreshRemotePanel);
  382. RefreshRemotePanelIntervalEdit->Value =
  383. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  384. switch (WinConfiguration->FormatSizeBytes)
  385. {
  386. case fbNone:
  387. FormatSizeBytesCombo->ItemIndex = 0;
  388. break;
  389. case fbKilobytes:
  390. FormatSizeBytesCombo->ItemIndex = 1;
  391. break;
  392. case fbShort:
  393. FormatSizeBytesCombo->ItemIndex = 2;
  394. break;
  395. default:
  396. FAIL;
  397. }
  398. bool CustomPanelFont = !WinConfiguration->PanelFont.FontName.IsEmpty();
  399. PanelFontCheck->Checked = CustomPanelFont;
  400. if (CustomPanelFont)
  401. {
  402. TWinConfiguration::RestoreFont(WinConfiguration->PanelFont, FPanelFont.get());
  403. }
  404. else
  405. {
  406. FPanelFont->Assign(WinConfiguration->SystemIconFont);
  407. }
  408. // updates
  409. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  410. if (int(Updates.Period) <= 0)
  411. {
  412. UpdatesPeriodCombo->ItemIndex = 0;
  413. }
  414. else if (int(Updates.Period) <= 1)
  415. {
  416. UpdatesPeriodCombo->ItemIndex = 1;
  417. }
  418. else if (int(Updates.Period) <= 7)
  419. {
  420. UpdatesPeriodCombo->ItemIndex = 2;
  421. }
  422. else
  423. {
  424. UpdatesPeriodCombo->ItemIndex = 3;
  425. }
  426. UpdatesShowOnStartup->Checked = Updates.ShowOnStartup;
  427. CollectUsageCheck->Checked = Configuration->CollectUsage;
  428. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  429. switch (Updates.ConnectionType)
  430. {
  431. case ctDirect:
  432. default:
  433. UpdatesDirectCheck->Checked = true;
  434. break;
  435. case ctAuto:
  436. UpdatesAutoCheck->Checked = true;
  437. break;
  438. case ctProxy:
  439. UpdatesProxyCheck->Checked = true;
  440. break;
  441. }
  442. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  443. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  444. // presets
  445. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  446. UpdateCopyParamListView();
  447. CopyParamListView->ItemIndex = 0;
  448. BOOLPROP(CopyParamAutoSelectNotice);
  449. // interface
  450. switch (CustomWinConfiguration->Interface)
  451. {
  452. case ifCommander:
  453. CommanderInterfaceButton2->Checked = true;
  454. break;
  455. case ifExplorer:
  456. ExplorerInterfaceButton2->Checked = true;
  457. break;
  458. default:
  459. FAIL;
  460. break;
  461. }
  462. if (WinConfiguration->Theme == L"OfficeXP")
  463. {
  464. ThemeCombo->ItemIndex = 1;
  465. }
  466. else if (WinConfiguration->Theme == L"Office2003")
  467. {
  468. ThemeCombo->ItemIndex = 2;
  469. }
  470. else
  471. {
  472. ThemeCombo->ItemIndex = 0;
  473. }
  474. // security
  475. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  476. SessionRememberPasswordCheck->Checked = GUIConfiguration->SessionRememberPassword;
  477. // network
  478. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  479. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  480. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  481. TryFtpWhenSshFailsCheck->Checked = Configuration->TryFtpWhenSshFails;
  482. // logging
  483. EnableLoggingCheck->Checked = Configuration->Logging;
  484. LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
  485. LogToFileCheck->Checked = Configuration->LogToFile;
  486. LogFileNameEdit3->Text =
  487. !Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
  488. if (Configuration->LogFileAppend)
  489. {
  490. LogFileAppendButton->Checked = true;
  491. }
  492. else
  493. {
  494. LogFileOverwriteButton->Checked = true;
  495. }
  496. LogShowWindowCheck->Checked = (CustomWinConfiguration->LogView == lvWindow);
  497. if (Configuration->LogWindowComplete)
  498. {
  499. LogWindowCompleteButton->Checked = true;
  500. }
  501. else
  502. {
  503. LogWindowLinesButton->Checked = true;
  504. }
  505. if (!Configuration->LogWindowComplete)
  506. {
  507. LogWindowLinesEdit->AsInteger = Configuration->LogWindowLines;
  508. }
  509. else
  510. {
  511. LogWindowLinesEdit->AsInteger = 500;
  512. }
  513. BOOLPROP(LogSensitive);
  514. EnableActionsLoggingCheck->Checked = Configuration->LogActions;
  515. ActionsLogFileNameEdit->Text = Configuration->ActionsLogFileName;
  516. #undef BOOLPROP
  517. }
  518. __finally
  519. {
  520. FNoUpdate--;
  521. }
  522. UpdateControls();
  523. }
  524. //---------------------------------------------------------------------------
  525. void __fastcall TPreferencesDialog::SaveConfiguration()
  526. {
  527. Configuration->BeginUpdate();
  528. try
  529. {
  530. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  531. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  532. BOOLPROP(DefaultDirIsHome);
  533. BOOLPROP(PreservePanelState);
  534. BOOLPROP(DeleteToRecycleBin);
  535. BOOLPROP(DDWarnLackOfTempSpace);
  536. BOOLPROP(ShowHiddenFiles);
  537. BOOLPROP(RenameWholeName);
  538. BOOLPROP(ShowInaccesibleDirectories);
  539. BOOLPROP(CopyOnDoubleClickConfirmation);
  540. BOOLPROP(ConfirmTransferring);
  541. BOOLPROP(ConfirmOverwriting);
  542. BOOLPROP(ConfirmResume);
  543. BOOLPROP(ConfirmDeleting);
  544. BOOLPROP(ConfirmRecycling);
  545. BOOLPROP(ConfirmClosingSession);
  546. BOOLPROP(ConfirmExitOnCompletion);
  547. BOOLPROP(ConfirmCommandSession);
  548. BOOLPROP(ContinueOnError);
  549. BOOLPROP(DDAllowMoveInit);
  550. BOOLPROP(BeepOnFinish);
  551. BOOLPROP(TemporaryDirectoryAppendSession);
  552. BOOLPROP(TemporaryDirectoryAppendPath);
  553. BOOLPROP(TemporaryDirectoryDeterministic);
  554. BOOLPROP(TemporaryDirectoryCleanup);
  555. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  556. BOOLPROP(FullRowSelect);
  557. WinConfiguration->DDTransferConfirmation =
  558. CheckBoxAutoSwitchSave(DDTransferConfirmationCheck);
  559. GUIConfiguration->BeepOnFinishAfter =
  560. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  561. BOOLPROP(BalloonNotifications);
  562. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  563. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  564. if (DDSystemTemporaryDirectoryButton->Checked)
  565. {
  566. WinConfiguration->DDTemporaryDirectory = L"";
  567. }
  568. else
  569. {
  570. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  571. }
  572. // Commander
  573. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  574. if (NortonLikeModeCombo->ItemIndex == 2)
  575. {
  576. ScpCommander.NortonLikeMode = nlOff;
  577. }
  578. else if (NortonLikeModeCombo->ItemIndex == 1)
  579. {
  580. ScpCommander.NortonLikeMode = nlKeyboard;
  581. }
  582. else
  583. {
  584. ScpCommander.NortonLikeMode = nlOn;
  585. }
  586. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  587. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  588. ScpCommander.ExplorerKeyboardShortcuts =
  589. (ExplorerKeyboardShortcutsCombo->ItemIndex != 0);
  590. BOOLPROP(UseLocationProfiles);
  591. ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  592. ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  593. // Local panel
  594. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  595. ScpCommander.SystemContextMenu = SystemContextMenuCheck->Checked;
  596. WinConfiguration->ScpCommander = ScpCommander;
  597. // Explorer
  598. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  599. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  600. WinConfiguration->ScpExplorer = ScpExplorer;
  601. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  602. // editor
  603. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  604. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  605. switch (EditorEncodingCombo->ItemIndex)
  606. {
  607. case 1:
  608. WinConfiguration->Editor.Encoding = CP_UTF8;
  609. break;
  610. default:
  611. WinConfiguration->Editor.Encoding = CP_ACP;
  612. break;
  613. }
  614. TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
  615. WinConfiguration->EditorList = FEditorList;
  616. // overwrites only TCopyParamType fields
  617. CopyParam = FCopyParams;
  618. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  619. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  620. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  621. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  622. Configuration->SessionReopenAuto =
  623. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  624. GUIConfiguration->SessionReopenAutoIdle =
  625. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoIdleEdit->AsInteger * MSecsPerSec) : 0);
  626. Configuration->SessionReopenAutoStall =
  627. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  628. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  629. WinConfiguration->CustomCommandList = FCustomCommandList;
  630. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  631. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  632. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  633. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  634. // do not overwrite custom keys
  635. if (PuttyRegistryStorageKeyEdit->ItemIndex >= 0)
  636. {
  637. GUIConfiguration->PuttyRegistryStorageKey = PuttyRegistryStorageKeyEdit->Text;
  638. }
  639. // Queue
  640. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  641. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  642. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  643. CopyParam.Queue = QueueCheck->Checked;
  644. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  645. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  646. GUIConfiguration->QueueKeepDoneItems = (QueueKeepDoneItemsForCombo->ItemIndex != 0);
  647. switch (QueueKeepDoneItemsForCombo->ItemIndex)
  648. {
  649. case 0:
  650. GUIConfiguration->QueueKeepDoneItemsFor = 0;
  651. break;
  652. case 1:
  653. GUIConfiguration->QueueKeepDoneItemsFor = 15;
  654. break;
  655. case 2:
  656. GUIConfiguration->QueueKeepDoneItemsFor = 60;
  657. break;
  658. case 3:
  659. GUIConfiguration->QueueKeepDoneItemsFor = 15 * 60;
  660. break;
  661. case 4:
  662. GUIConfiguration->QueueKeepDoneItemsFor = 60 * 60;
  663. break;
  664. default:
  665. GUIConfiguration->QueueKeepDoneItemsFor = -1;
  666. break;
  667. }
  668. if (QueueViewShowButton->Checked)
  669. {
  670. WinConfiguration->QueueView.Show = qvShow;
  671. }
  672. else if (QueueViewHideWhenEmptyButton->Checked)
  673. {
  674. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  675. }
  676. else
  677. {
  678. WinConfiguration->QueueView.Show = qvHide;
  679. }
  680. GUIConfiguration->DefaultCopyParam = CopyParam;
  681. // window
  682. WinConfiguration->AutoSaveWorkspace =
  683. !AutoWorkspaceCombo->Text.IsEmpty() &&
  684. AutoSaveWorkspaceCheck->Checked;
  685. if (!AutoWorkspaceCombo->Text.IsEmpty())
  686. {
  687. WinConfiguration->AutoWorkspace = AutoWorkspaceCombo->Text;
  688. }
  689. WinConfiguration->AutoSaveWorkspacePasswords = AutoSaveWorkspacePasswordsCheck->Checked;
  690. if (PathInCaptionFullButton->Checked)
  691. {
  692. WinConfiguration->PathInCaption = picFull;
  693. }
  694. else if (PathInCaptionShortButton->Checked)
  695. {
  696. WinConfiguration->PathInCaption = picShort;
  697. }
  698. else
  699. {
  700. WinConfiguration->PathInCaption = picNone;
  701. }
  702. BOOLPROP(MinimizeToTray);
  703. BOOLPROP(ExternalSessionInExistingInstance);
  704. // panels
  705. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  706. BOOLPROP(AutoReadDirectoryAfterOp);
  707. BOOLPROP(RefreshRemotePanel);
  708. WinConfiguration->RefreshRemotePanelInterval =
  709. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  710. switch (FormatSizeBytesCombo->ItemIndex)
  711. {
  712. case 0:
  713. WinConfiguration->FormatSizeBytes = fbNone;
  714. break;
  715. case 1:
  716. WinConfiguration->FormatSizeBytes = fbKilobytes;
  717. break;
  718. case 2:
  719. WinConfiguration->FormatSizeBytes = fbShort;
  720. break;
  721. default:
  722. FAIL;
  723. }
  724. TFontConfiguration PanelFontConfiguration;
  725. if (PanelFontCheck->Checked)
  726. {
  727. TWinConfiguration::StoreFont(FPanelFont.get(), PanelFontConfiguration);
  728. }
  729. WinConfiguration->PanelFont = PanelFontConfiguration;
  730. // updates
  731. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  732. if (UpdatesPeriodCombo->ItemIndex == 0)
  733. {
  734. Updates.Period = 0;
  735. }
  736. else if (UpdatesPeriodCombo->ItemIndex == 1)
  737. {
  738. Updates.Period = 1;
  739. }
  740. else if (UpdatesPeriodCombo->ItemIndex == 2)
  741. {
  742. Updates.Period = 7;
  743. }
  744. else
  745. {
  746. Updates.Period = 30;
  747. }
  748. Updates.ShowOnStartup = UpdatesShowOnStartup->Checked;
  749. Configuration->CollectUsage = CollectUsageCheck->Checked;
  750. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  751. if (UpdatesDirectCheck->Checked)
  752. {
  753. Updates.ConnectionType = ctDirect;
  754. }
  755. else if (UpdatesAutoCheck->Checked)
  756. {
  757. Updates.ConnectionType = ctAuto;
  758. }
  759. else if (UpdatesProxyCheck->Checked)
  760. {
  761. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  762. {
  763. Updates.ConnectionType = ctProxy;
  764. }
  765. else
  766. {
  767. Updates.ConnectionType = ctDirect;
  768. }
  769. }
  770. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  771. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  772. WinConfiguration->Updates = Updates;
  773. // presets
  774. WinConfiguration->CopyParamList = FCopyParamList;
  775. BOOLPROP(CopyParamAutoSelectNotice);
  776. // interface
  777. if (GetInterface() != CustomWinConfiguration->Interface)
  778. {
  779. Configuration->Usage->Inc(L"InterfaceChanges");
  780. }
  781. CustomWinConfiguration->Interface = GetInterface();
  782. if (ThemeCombo->ItemIndex == 1)
  783. {
  784. WinConfiguration->Theme = L"OfficeXP";
  785. }
  786. else if (ThemeCombo->ItemIndex == 2)
  787. {
  788. WinConfiguration->Theme = L"Office2003";
  789. }
  790. else
  791. {
  792. WinConfiguration->Theme = L"Default";
  793. }
  794. // network
  795. Configuration->ExternalIpAddress =
  796. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  797. Configuration->TryFtpWhenSshFails = TryFtpWhenSshFailsCheck->Checked;
  798. // security
  799. GUIConfiguration->SessionRememberPassword = SessionRememberPasswordCheck->Checked;
  800. // logging
  801. Configuration->Logging = EnableLoggingCheck->Checked;
  802. Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
  803. Configuration->LogFileName = LogToFileCheck->Checked ? LogFileNameEdit3->Text : UnicodeString();
  804. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  805. CustomWinConfiguration->LogView = LogShowWindowCheck->Checked ? lvWindow : lvNone;
  806. Configuration->LogWindowComplete = LogWindowCompleteButton->Checked;
  807. if (!LogWindowCompleteButton->Checked)
  808. {
  809. Configuration->LogWindowLines = LogWindowLinesEdit->AsInteger;
  810. }
  811. BOOLPROP(LogSensitive);
  812. Configuration->LogActions = EnableActionsLoggingCheck->Checked;
  813. Configuration->ActionsLogFileName = ActionsLogFileNameEdit->Text;
  814. // languages
  815. // As this dialog does not explicitly support run-time locale changing,
  816. // make this last, otherwise we lose some settings (or even worse
  817. // we end-up saving default text box values=control names as our configuration)
  818. if (LanguagesView->ItemFocused != NULL)
  819. {
  820. GUIConfiguration->Locale =
  821. reinterpret_cast<LCID>(LanguagesView->ItemFocused->Data);
  822. }
  823. // This possibly fails, make it last, so that the other settings are preserved.
  824. // Do nothing when no option is selected (i.e. storage is stNul).
  825. if (RegistryStorageButton->Checked)
  826. {
  827. Configuration->Storage = stRegistry;
  828. }
  829. else if (IniFileStorageButton2->Checked)
  830. {
  831. Configuration->Storage = stIniFile;
  832. }
  833. #undef BOOLPROP
  834. }
  835. __finally
  836. {
  837. Configuration->EndUpdate();
  838. }
  839. }
  840. //---------------------------------------------------------------------------
  841. TInterface __fastcall TPreferencesDialog::GetInterface()
  842. {
  843. return CommanderInterfaceButton2->Checked ? ifCommander : ifExplorer;
  844. }
  845. //---------------------------------------------------------------------------
  846. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  847. {
  848. InstallPathWordBreakProc(RandomSeedFileEdit);
  849. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  850. InstallPathWordBreakProc(PuttyPathEdit);
  851. InstallPathWordBreakProc(LogFileNameEdit3);
  852. InstallPathWordBreakProc(ActionsLogFileNameEdit);
  853. PrepareNavigationTree(NavigationTree);
  854. switch (FPreferencesMode) {
  855. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  856. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  857. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  858. case pmLogging: PageControl->ActivePage = LogSheet; break;
  859. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  860. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  861. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  862. default: PageControl->ActivePage = PreferencesSheet; break;
  863. }
  864. PageControlChange(NULL);
  865. }
  866. //---------------------------------------------------------------------------
  867. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  868. {
  869. UpdateControls();
  870. }
  871. //---------------------------------------------------------------------------
  872. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  873. {
  874. UnicodeString Result;
  875. for (int Index = 1; Index <= Values.Length(); Index++)
  876. {
  877. if (Index > 1)
  878. {
  879. Result += L' ';
  880. if (EditorTabSizeEdit->AsInteger > 2)
  881. {
  882. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  883. }
  884. }
  885. Result += Values[Index];
  886. }
  887. return Result;
  888. }
  889. //---------------------------------------------------------------------------
  890. void __fastcall TPreferencesDialog::UpdateControls()
  891. {
  892. if (FNoUpdate == 0)
  893. {
  894. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  895. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  896. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  897. EnableControl(ResumeThresholdUnitLabel2, ResumeThresholdEdit->Enabled);
  898. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  899. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  900. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  901. EnableControl(SessionReopenAutoIdleEdit, SessionReopenAutoIdleCheck->Checked);
  902. EnableControl(SessionReopenAutoIdleLabel, SessionReopenAutoIdleEdit->Enabled);
  903. EnableControl(SessionReopenAutoIdleSecLabel, SessionReopenAutoIdleEdit->Enabled);
  904. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  905. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  906. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  907. EnableControl(SessionReopenTimeoutEdit,
  908. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  909. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  910. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  911. EnableControl(CopyOnDoubleClickConfirmationCheck,
  912. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  913. TFont * ActualPanelFont = PanelFontCheck->Checked ? FPanelFont.get() : WinConfiguration->SystemIconFont;
  914. UnicodeString PanelFontLabelText;
  915. PanelFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  916. (ActualPanelFont->Name, ActualPanelFont->Size));
  917. PanelFontLabel->Caption = PanelFontLabelText;
  918. if (!SameFont(PanelFontLabel->Font, ActualPanelFont))
  919. {
  920. PanelFontLabel->Font = ActualPanelFont;
  921. }
  922. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  923. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  924. UnicodeString EditorFontLabelText;
  925. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  926. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  927. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  928. EditorFontLabelText += TabSample(L"1234");
  929. EditorFontLabel->Caption = EditorFontLabelText;
  930. if (!SameFont(EditorFontLabel->Font, FEditorFont.get()))
  931. {
  932. EditorFontLabel->Font = FEditorFont.get();
  933. }
  934. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  935. EnableControl(EditCommandButton, CommandSelected);
  936. EnableControl(RemoveCommandButton, CommandSelected);
  937. EnableControl(UpCommandButton, CommandSelected &&
  938. CustomCommandsView->ItemIndex > 0);
  939. EnableControl(DownCommandButton, CommandSelected &&
  940. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  941. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  942. EnableControl(EditCopyParamButton, CopyParamSelected);
  943. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  944. EnableControl(RemoveCopyParamButton,
  945. CopyParamSelected && (CopyParamListView->ItemIndex >= 1));
  946. EnableControl(UpCopyParamButton,
  947. CopyParamSelected && (CopyParamListView->ItemIndex > 1));
  948. EnableControl(DownCopyParamButton,
  949. CopyParamSelected &&
  950. (CopyParamListView->ItemIndex >= 1) &&
  951. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  952. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  953. UnicodeString InfoStr;
  954. if (CopyParamSelected)
  955. {
  956. const TCopyParamType * SelectedCopyParam = GetCopyParam(CopyParamListView->ItemIndex);
  957. InfoStr = SelectedCopyParam->GetInfoStr(L"; ", 0);
  958. if (CopyParamListView->ItemIndex >= 1)
  959. {
  960. const TCopyParamRule * Rule = FCopyParamList->Rules[CopyParamListView->ItemIndex - 1];
  961. if (Rule != NULL)
  962. {
  963. InfoStr += L"\n" + FORMAT(ReplaceStr(LoadStr(COPY_PARAM_RULE), L"\n", L" "), (Rule->GetInfoStr(L"; ")));
  964. }
  965. }
  966. }
  967. CopyParamLabel->Caption = InfoStr;
  968. CopyParamLabel->Hint = InfoStr;
  969. CopyParamLabel->ShowHint =
  970. (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
  971. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  972. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  973. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  974. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  975. DDCustomTemporaryDirectoryButton->Checked);
  976. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  977. DDAllowMoveInitCheck->Checked);
  978. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  979. TemporaryDirectoryCleanupCheck->Checked);
  980. // allow only when some of the known storages is selected,
  981. // and particularly do not allow switching storage, when we start with stNul,
  982. // as that would destroy the stored configuration
  983. EnableControl(StorageGroup, RegistryStorageButton->Checked || IniFileStorageButton2->Checked);
  984. IniFileStorageButton2->Caption =
  985. AnsiReplaceStr(IniFileStorageButton2->Caption, L"(winscp.ini)",
  986. FORMAT(L"(%s)", (ExpandEnvironmentVariables(Configuration->IniFileStorageName))));
  987. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  988. bool EditorSelected = (EditorListView3->Selected != NULL);
  989. EnableControl(EditEditorButton, EditorSelected);
  990. EnableControl(RemoveEditorButton, EditorSelected);
  991. EnableControl(UpEditorButton, EditorSelected &&
  992. (EditorListView3->ItemIndex > 0));
  993. EnableControl(DownEditorButton, EditorSelected &&
  994. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  995. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  996. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  997. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  998. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  999. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1000. bool IsSiteCommand = false;
  1001. try
  1002. {
  1003. TRemoteCustomCommand RemoteCustomCommand;
  1004. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1005. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1006. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1007. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1008. }
  1009. catch (...)
  1010. {
  1011. // noop
  1012. }
  1013. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  1014. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  1015. EnableControl(TelnetForFtpInPuttyCheck,
  1016. PuttyPasswordCheck2->Enabled && !IsSiteCommand);
  1017. EnableControl(PuttyRegistryStorageKeyEdit,
  1018. PuttyPasswordCheck2->Enabled && !IsSiteCommand);
  1019. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1020. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1021. // network
  1022. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1023. // window
  1024. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1025. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1026. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1027. !Configuration->DisablePasswordStoring &&
  1028. AutoWorkspaceCombo->Enabled);
  1029. // integration
  1030. // There's no quick launch in Windows 7
  1031. EnableControl(QuickLaunchIconButton, !::IsWin7());
  1032. MakeDefaultHandlerItem->Visible = IsWinVista();
  1033. // languages
  1034. LanguageChangeLabel->Visible =
  1035. !GUIConfiguration->CanApplyLocaleImmediately &&
  1036. (LanguagesView->ItemFocused != NULL) &&
  1037. (reinterpret_cast<LCID>(LanguagesView->ItemFocused->Data) != GUIConfiguration->AppliedLocale);
  1038. // logging
  1039. EnableControl(LogProtocolCombo, EnableLoggingCheck->Checked);
  1040. EnableControl(LogToFileCheck, LogProtocolCombo->Enabled);
  1041. EnableControl(LogFileNameEdit3, LogToFileCheck->Enabled && LogToFileCheck->Checked);
  1042. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1043. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1044. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1045. EnableControl(LogShowWindowCheck, LogProtocolCombo->Enabled);
  1046. EnableControl(LogWindowCompleteButton, LogShowWindowCheck->Enabled && LogShowWindowCheck->Checked);
  1047. EnableControl(LogWindowLinesButton, LogWindowCompleteButton->Enabled);
  1048. EnableControl(LogWindowLinesEdit, LogWindowLinesButton->Enabled && LogWindowLinesButton->Checked);
  1049. EnableControl(LogWindowLinesText, LogWindowLinesEdit->Enabled);
  1050. EnableControl(LogSensitiveCheck, LogProtocolCombo->Enabled);
  1051. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1052. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1053. // interface
  1054. InterfaceChangeLabel->Visible =
  1055. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1056. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1057. }
  1058. }
  1059. //---------------------------------------------------------------------------
  1060. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1061. {
  1062. if (FontDialog(FEditorFont.get()))
  1063. {
  1064. UpdateControls();
  1065. }
  1066. }
  1067. //---------------------------------------------------------------------------
  1068. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1069. {
  1070. if (FontDialog(FPanelFont.get()))
  1071. {
  1072. PanelFontCheck->Checked = true;
  1073. UpdateControls();
  1074. }
  1075. }
  1076. //---------------------------------------------------------------------------
  1077. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1078. bool & /*CanClose*/)
  1079. {
  1080. if (ModalResult == DefaultResult(this))
  1081. {
  1082. ExitActiveControl(this);
  1083. }
  1084. }
  1085. //---------------------------------------------------------------------------
  1086. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1087. {
  1088. UnicodeString IconName, Params;
  1089. int SpecialFolder;
  1090. if (Sender == DesktopIconButton)
  1091. {
  1092. IconName = AppName;
  1093. int Result =
  1094. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1095. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1096. switch (Result)
  1097. {
  1098. case qaYes:
  1099. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1100. break;
  1101. case qaNo:
  1102. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1103. break;
  1104. default:
  1105. Abort();
  1106. break;
  1107. }
  1108. }
  1109. else
  1110. {
  1111. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1112. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1113. {
  1114. if (Sender == SendToHookButton)
  1115. {
  1116. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppName));
  1117. SpecialFolder = CSIDL_SENDTO;
  1118. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1119. }
  1120. else if (Sender == QuickLaunchIconButton)
  1121. {
  1122. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  1123. AppName;
  1124. SpecialFolder = CSIDL_APPDATA;
  1125. }
  1126. }
  1127. else
  1128. {
  1129. Abort();
  1130. }
  1131. }
  1132. TInstantOperationVisualizer Visualizer;
  1133. CreateDesktopShortCut(IconName,
  1134. Application->ExeName, Params, L"", SpecialFolder);
  1135. }
  1136. //---------------------------------------------------------------------------
  1137. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1138. TListItem * Item)
  1139. {
  1140. // WORKAROUND We get here on Wine after destructor is called
  1141. if (FCustomCommandList != NULL)
  1142. {
  1143. int Index = Item->Index;
  1144. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  1145. const TCustomCommandType * Command = FCustomCommandList->Commands[Index];
  1146. UnicodeString Caption = StripHotkey(Command->Name);
  1147. if (Command->ShortCut != 0)
  1148. {
  1149. Caption = FORMAT(L"%s (%s)", (Caption, ShortCutToText(Command->ShortCut)));
  1150. }
  1151. Item->Caption = Caption;
  1152. assert(!Item->SubItems->Count);
  1153. Item->SubItems->Add(Command->Command);
  1154. int Params = Command->Params;
  1155. Item->SubItems->Add(LoadStr(
  1156. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1157. UnicodeString ParamsStr;
  1158. #define ADDPARAM(PARAM, STR) \
  1159. if (FLAGSET(Params, PARAM)) \
  1160. ParamsStr += (ParamsStr.IsEmpty() ? L"" : L"/") + LoadStr(STR);
  1161. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  1162. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  1163. #undef ADDPARAM
  1164. Item->SubItems->Add(ParamsStr);
  1165. }
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1169. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1170. {
  1171. UpdateControls();
  1172. }
  1173. //---------------------------------------------------------------------------
  1174. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1175. {
  1176. CustomCommandsView->Items->Count = FCustomCommandList->Count;
  1177. AdjustListColumnsWidth(CustomCommandsView);
  1178. CustomCommandsView->Invalidate();
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1182. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1183. {
  1184. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1185. {
  1186. RemoveCommandButtonClick(NULL);
  1187. }
  1188. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1189. {
  1190. AddEditCommandButtonClick(AddCommandButton);
  1191. }
  1192. }
  1193. //---------------------------------------------------------------------------
  1194. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1195. TObject * /*Sender*/)
  1196. {
  1197. if (EditCommandButton->Enabled)
  1198. {
  1199. AddEditCommandButtonClick(EditCommandButton);
  1200. }
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  1204. {
  1205. bool Edit = (Sender == EditCommandButton);
  1206. TCustomCommandType Command;
  1207. if (Edit)
  1208. {
  1209. int Index = CustomCommandsView->ItemIndex;
  1210. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  1211. Command = *FCustomCommandList->Commands[Index];
  1212. }
  1213. TShortCuts ShortCuts;
  1214. if (WinConfiguration->SharedBookmarks != NULL)
  1215. {
  1216. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1217. }
  1218. FCustomCommandList->ShortCuts(ShortCuts);
  1219. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1220. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1221. {
  1222. int Index = CustomCommandsView->ItemIndex;
  1223. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1224. if (Edit)
  1225. {
  1226. FCustomCommandList->Change(Index, ACommand);
  1227. }
  1228. else
  1229. {
  1230. if (Index >= 0)
  1231. {
  1232. FCustomCommandList->Insert(Index, ACommand);
  1233. }
  1234. else
  1235. {
  1236. FCustomCommandList->Add(ACommand);
  1237. Index = FCustomCommandList->Count - 1;
  1238. }
  1239. }
  1240. UpdateCustomCommandsView();
  1241. CustomCommandsView->ItemIndex = Index;
  1242. UpdateControls();
  1243. }
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1247. TObject * /*Sender*/)
  1248. {
  1249. assert(CustomCommandsView->ItemIndex >= 0 &&
  1250. CustomCommandsView->ItemIndex < FCustomCommandList->Count);
  1251. FCustomCommandList->Delete(CustomCommandsView->ItemIndex);
  1252. UpdateCustomCommandsView();
  1253. UpdateControls();
  1254. }
  1255. //---------------------------------------------------------------------------
  1256. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1257. {
  1258. if (Source >= 0 && Source < FCustomCommandList->Count &&
  1259. Dest >= 0 && Dest < FCustomCommandList->Count)
  1260. {
  1261. FCustomCommandList->Move(Source, Dest);
  1262. // workaround for bug in VCL
  1263. CustomCommandsView->ItemIndex = -1;
  1264. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  1265. CustomCommandsView->ItemIndex = Dest;
  1266. UpdateCustomCommandsView();
  1267. UpdateControls();
  1268. }
  1269. }
  1270. //---------------------------------------------------------------------------
  1271. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1272. {
  1273. CustomCommandMove(CustomCommandsView->ItemIndex,
  1274. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1275. }
  1276. //---------------------------------------------------------------------------
  1277. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1278. {
  1279. if (ListView == CopyParamListView)
  1280. {
  1281. return FCopyParamScrollOnDragOver;
  1282. }
  1283. else if (ListView == CustomCommandsView)
  1284. {
  1285. return FCustomCommandsScrollOnDragOver;
  1286. }
  1287. else if (ListView == EditorListView3)
  1288. {
  1289. return FEditorScrollOnDragOver;
  1290. }
  1291. else
  1292. {
  1293. FAIL;
  1294. return NULL;
  1295. }
  1296. }
  1297. //---------------------------------------------------------------------------
  1298. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1299. TObject * Sender, TDragObject *& /*DragObject*/)
  1300. {
  1301. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1302. FListViewDragDest = -1;
  1303. ScrollOnDragOver(Sender)->StartDrag();
  1304. }
  1305. //---------------------------------------------------------------------------
  1306. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1307. {
  1308. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1309. FListViewDragDest = Item ? Item->Index : -1;
  1310. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1314. TObject * Sender, TObject * Source, int X, int Y)
  1315. {
  1316. if (Source == CustomCommandsView)
  1317. {
  1318. if (AllowListViewDrag(Sender, X, Y))
  1319. {
  1320. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1321. }
  1322. }
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TPreferencesDialog::ListViewDragOver(
  1326. TObject * Sender, TObject * Source, int X, int Y,
  1327. TDragState /*State*/, bool & Accept)
  1328. {
  1329. if (Source == Sender)
  1330. {
  1331. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1332. // (when dropped on item itself, when it was dragged over another item before,
  1333. // that another item remains highlighted forever)
  1334. Accept = true;
  1335. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1336. }
  1337. }
  1338. //---------------------------------------------------------------------------
  1339. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1340. {
  1341. if (Index == 0)
  1342. {
  1343. return &FCopyParams;
  1344. }
  1345. else
  1346. {
  1347. return FCopyParamList->CopyParams[Index - 1];
  1348. }
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1352. {
  1353. if (Source >= 1 && Source < (1 + FCopyParamList->Count) &&
  1354. Dest >= 0 && Dest < (1 + FCopyParamList->Count))
  1355. {
  1356. if (Dest == 0)
  1357. {
  1358. Dest = 1;
  1359. }
  1360. FCopyParamList->Move(Source - 1, Dest - 1);
  1361. // workaround for bug in VCL
  1362. CopyParamListView->ItemIndex = -1;
  1363. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1364. CopyParamListView->ItemIndex = Dest;
  1365. UpdateCopyParamListView();
  1366. UpdateControls();
  1367. }
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1371. TObject * Sender, TObject * Source, int X, int Y)
  1372. {
  1373. if (Source == CopyParamListView)
  1374. {
  1375. if (AllowListViewDrag(Sender, X, Y))
  1376. {
  1377. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1378. }
  1379. }
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1383. {
  1384. CopyParamMove(CopyParamListView->ItemIndex,
  1385. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1386. }
  1387. //---------------------------------------------------------------------------
  1388. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1389. TObject * /*Sender*/)
  1390. {
  1391. assert(CopyParamListView->ItemIndex >= 1 &&
  1392. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1393. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1394. UpdateCopyParamListView();
  1395. UpdateControls();
  1396. }
  1397. //---------------------------------------------------------------------------
  1398. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1399. {
  1400. int Index = CopyParamListView->ItemIndex;
  1401. bool Result;
  1402. if ((Index == 0) && (Mode == cpmEdit))
  1403. {
  1404. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1405. }
  1406. else
  1407. {
  1408. TCopyParamRuleData * CopyParamRuleData =
  1409. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1410. // negative (when default is selected) means add to the end
  1411. Index--;
  1412. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, FCopyParams);
  1413. if (Result)
  1414. {
  1415. UpdateCopyParamListView();
  1416. CopyParamListView->ItemIndex = Index + 1;
  1417. // when using duplicate button, focus remains on original item
  1418. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1419. }
  1420. }
  1421. if (Result)
  1422. {
  1423. UpdateControls();
  1424. }
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1428. {
  1429. AddEditCopyParam(cpmAdd);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1433. {
  1434. AddEditCopyParam(cpmEdit);
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1438. {
  1439. AddEditCopyParam(cpmDuplicate);
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1443. TObject * /*Sender*/)
  1444. {
  1445. if (EditCopyParamButton->Enabled)
  1446. {
  1447. AddEditCopyParam(cpmEdit);
  1448. }
  1449. }
  1450. //---------------------------------------------------------------------------
  1451. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1452. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1453. {
  1454. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1455. {
  1456. RemoveCopyParamButtonClick(NULL);
  1457. }
  1458. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1459. {
  1460. AddEditCopyParam(cpmAdd);
  1461. }
  1462. }
  1463. //---------------------------------------------------------------------------
  1464. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1465. {
  1466. if (Source >= 0 && Source < FEditorList->Count &&
  1467. Dest >= 0 && Dest < FEditorList->Count)
  1468. {
  1469. FEditorList->Move(Source, Dest);
  1470. // workaround for bug in VCL
  1471. EditorListView3->ItemIndex = -1;
  1472. EditorListView3->ItemFocused = EditorListView3->Selected;
  1473. EditorListView3->ItemIndex = Dest;
  1474. UpdateEditorListView();
  1475. UpdateControls();
  1476. }
  1477. }
  1478. //---------------------------------------------------------------------------
  1479. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1480. TObject * Source, int X, int Y)
  1481. {
  1482. if (Source == EditorListView3)
  1483. {
  1484. if (AllowListViewDrag(Sender, X, Y))
  1485. {
  1486. EditorMove(FListViewDragSource, FListViewDragDest);
  1487. }
  1488. }
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1492. {
  1493. EditorMove(EditorListView3->ItemIndex,
  1494. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1495. }
  1496. //---------------------------------------------------------------------------
  1497. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1498. TObject * /*Sender*/)
  1499. {
  1500. assert(EditorListView3->ItemIndex >= 0 &&
  1501. EditorListView3->ItemIndex < FEditorList->Count);
  1502. FEditorList->Delete(EditorListView3->ItemIndex);
  1503. UpdateEditorListView();
  1504. UpdateControls();
  1505. }
  1506. //---------------------------------------------------------------------------
  1507. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1508. {
  1509. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1510. int Index = EditorListView3->ItemIndex;
  1511. TEditorPreferences * Editor;
  1512. if (Mode == epmEdit)
  1513. {
  1514. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1515. }
  1516. else
  1517. {
  1518. Editor = new TEditorPreferences();
  1519. }
  1520. try
  1521. {
  1522. bool DummyRemember = false;
  1523. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1524. {
  1525. if (Mode == epmEdit)
  1526. {
  1527. FEditorList->Change(Index, Editor);
  1528. }
  1529. else
  1530. {
  1531. if (Index < 0)
  1532. {
  1533. Index = FEditorList->Count;
  1534. FEditorList->Add(Editor);
  1535. }
  1536. else
  1537. {
  1538. FEditorList->Insert(Index, Editor);
  1539. }
  1540. }
  1541. // ownership of the object lost
  1542. Editor = NULL;
  1543. UpdateEditorListView();
  1544. EditorListView3->ItemIndex = Index;
  1545. UpdateControls();
  1546. }
  1547. }
  1548. __finally
  1549. {
  1550. delete Editor;
  1551. }
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1555. {
  1556. if (EditEditorButton->Enabled)
  1557. {
  1558. AddEditEditorButtonClick(EditEditorButton);
  1559. }
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1563. WORD & Key, TShiftState /*Shift*/)
  1564. {
  1565. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1566. {
  1567. RemoveEditorButtonClick(NULL);
  1568. }
  1569. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1570. {
  1571. AddEditEditorButtonClick(AddEditorButton);
  1572. }
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1576. {
  1577. EditorListView3->Items->Count = FEditorList->Count;
  1578. AdjustListColumnsWidth(EditorListView3);
  1579. EditorListView3->Invalidate();
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1583. TListItem * Item)
  1584. {
  1585. // WORKAROUND We get here on Wine after destructor is called
  1586. if (FEditorList != NULL)
  1587. {
  1588. int Index = Item->Index;
  1589. assert(Index >= 0 && Index <= FEditorList->Count);
  1590. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1591. Item->Caption = Editor->Name;
  1592. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1593. if (Editor->Data->Editor == edExternal)
  1594. {
  1595. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1596. }
  1597. }
  1598. }
  1599. //---------------------------------------------------------------------------
  1600. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1601. TTreeNode * Node)
  1602. {
  1603. if (ALWAYS_TRUE(Node->SelectedIndex > 0))
  1604. {
  1605. PageControl->ActivePage = NOT_NULL(FindPageForTreeNode(Node));
  1606. // reshow the accelerators, etc
  1607. ResetSystemSettings(this);
  1608. // This is particularly here to enable EditCopyParamButton,
  1609. // as to some reason CopyParamListView->Selected is NULL until
  1610. // its page is shown for the first time
  1611. UpdateControls();
  1612. }
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1616. {
  1617. // this is probably only ever called from FormShow (explicitly)
  1618. bool Found = false;
  1619. if (ALWAYS_TRUE(PageControl->ActivePage->Tag > 0))
  1620. {
  1621. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1622. {
  1623. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1624. PageControl->ActivePage->Tag)
  1625. {
  1626. NavigationTree->Items->Item[Index]->Selected = true;
  1627. Found = true;
  1628. }
  1629. }
  1630. }
  1631. if (ALWAYS_TRUE(Found))
  1632. {
  1633. UpdateControls();
  1634. }
  1635. }
  1636. //---------------------------------------------------------------------------
  1637. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1638. {
  1639. if (Message.CharCode == VK_TAB)
  1640. {
  1641. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1642. if (Shift.Contains(ssCtrl))
  1643. {
  1644. TTreeNode * Node = NavigationTree->Selected;
  1645. if (!Shift.Contains(ssShift))
  1646. {
  1647. Node = Node->GetNext();
  1648. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1649. }
  1650. else
  1651. {
  1652. if (Node->GetPrev()) Node = Node->GetPrev();
  1653. else
  1654. while (Node->GetNext()) Node = Node->GetNext();
  1655. }
  1656. Node->Selected = True;
  1657. Message.Result = 1;
  1658. return;
  1659. }
  1660. }
  1661. TForm::Dispatch(&Message);
  1662. }
  1663. //---------------------------------------------------------------------------
  1664. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1665. {
  1666. assert(Message.HelpInfo != NULL);
  1667. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1668. {
  1669. // invoke help for active page (not for whole form), regardless of focus
  1670. // (e.g. even if focus is on control outside pagecontrol)
  1671. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1672. }
  1673. TForm::Dispatch(&Message);
  1674. }
  1675. //---------------------------------------------------------------------------
  1676. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1677. {
  1678. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1679. assert(M);
  1680. if (M->Msg == CM_DIALOGKEY)
  1681. {
  1682. CMDialogKey(*((TWMKeyDown *)Message));
  1683. }
  1684. else if (M->Msg == WM_HELP)
  1685. {
  1686. WMHelp(*((TWMHelp *)Message));
  1687. }
  1688. else
  1689. {
  1690. TForm::Dispatch(Message);
  1691. }
  1692. }
  1693. //---------------------------------------------------------------------------
  1694. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  1695. TObject * /*Sender*/)
  1696. {
  1697. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  1698. }
  1699. //---------------------------------------------------------------------------
  1700. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  1701. {
  1702. unsigned int Result =
  1703. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  1704. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1705. if (Result == qaYes)
  1706. {
  1707. TInstantOperationVisualizer Visualizer;
  1708. RegisterForDefaultProtocols();
  1709. }
  1710. }
  1711. //---------------------------------------------------------------------------
  1712. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  1713. {
  1714. unsigned int Result =
  1715. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  1716. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1717. if (Result == qaYes)
  1718. {
  1719. TInstantOperationVisualizer Visualizer;
  1720. UnregisterForProtocols();
  1721. }
  1722. }
  1723. //---------------------------------------------------------------------------
  1724. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  1725. {
  1726. TOperationVisualizer Visualizer;
  1727. LaunchAdvancedAssociationUI();
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1731. {
  1732. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1733. SetFocus();
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1737. TObject * /*Sender*/)
  1738. {
  1739. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1740. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  1741. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1742. {
  1743. TInstantOperationVisualizer Visualizer;
  1744. AddSearchPath(AppPath);
  1745. }
  1746. }
  1747. //---------------------------------------------------------------------------
  1748. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1749. TObject * Sender)
  1750. {
  1751. EditorFontButtonClick(Sender);
  1752. }
  1753. //---------------------------------------------------------------------------
  1754. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1755. {
  1756. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  1757. AdjustListColumnsWidth(CopyParamListView);
  1758. CopyParamListView->Invalidate();
  1759. }
  1760. //---------------------------------------------------------------------------
  1761. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1762. TListItem * Item)
  1763. {
  1764. // WORKAROUND We get here on Wine after destructor is called
  1765. if (FCopyParamList != NULL)
  1766. {
  1767. UnicodeString Name;
  1768. UnicodeString Rule;
  1769. int Index = Item->Index;
  1770. if (Index == 0)
  1771. {
  1772. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  1773. }
  1774. else
  1775. {
  1776. assert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  1777. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  1778. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  1779. }
  1780. Item->Caption = Name;
  1781. Item->SubItems->Add(Rule);
  1782. }
  1783. }
  1784. //---------------------------------------------------------------------------
  1785. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1786. {
  1787. FormHelp(this);
  1788. }
  1789. //---------------------------------------------------------------------------
  1790. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1791. TObject * /*Sender*/)
  1792. {
  1793. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  1794. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  1795. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  1796. }
  1797. //---------------------------------------------------------------------------
  1798. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1799. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1800. {
  1801. FBeforeDialogPath = Name;
  1802. Name = ExpandEnvironmentVariables(Name);
  1803. }
  1804. //---------------------------------------------------------------------------
  1805. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1806. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1807. {
  1808. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1809. {
  1810. Name = FBeforeDialogPath;
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1815. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1816. {
  1817. AllowCollapse = false;
  1818. }
  1819. //---------------------------------------------------------------------------
  1820. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1821. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1822. {
  1823. ScrollOnDragOver(Sender)->EndDrag();
  1824. }
  1825. //---------------------------------------------------------------------------
  1826. void __fastcall TPreferencesDialog::PathEditCreateEditDialog(
  1827. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1828. {
  1829. USEDPARAM(DialogKind);
  1830. assert(DialogKind == dkOpen);
  1831. Dialog = new TOpenDialog(dynamic_cast<TComponent *>(Sender));
  1832. }
  1833. //---------------------------------------------------------------------------
  1834. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1835. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  1836. {
  1837. if (Value == 0)
  1838. {
  1839. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1840. Handled = true;
  1841. }
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1845. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  1846. {
  1847. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1848. {
  1849. Value = 0;
  1850. Handled = true;
  1851. }
  1852. }
  1853. //---------------------------------------------------------------------------
  1854. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  1855. {
  1856. bool Result;
  1857. bool Retry;
  1858. do
  1859. {
  1860. Retry = false;
  1861. Result = !AnyOtherInstanceOfSelf();
  1862. if (!Result)
  1863. {
  1864. unsigned int Answer =
  1865. MessageDialog(
  1866. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  1867. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  1868. HELP_MASTER_PASSWORD);
  1869. switch (Answer)
  1870. {
  1871. case qaRetry:
  1872. Retry = true;
  1873. break;
  1874. case qaIgnore:
  1875. Result = true;
  1876. break;
  1877. case qaCancel:
  1878. default:
  1879. // noop
  1880. break;
  1881. }
  1882. }
  1883. }
  1884. while (Retry && !Result);
  1885. return Result;
  1886. }
  1887. //---------------------------------------------------------------------------
  1888. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  1889. UnicodeString Message, TStrings * RecryptPasswordErrors)
  1890. {
  1891. // Save master password.
  1892. // This is unlikely to fail, as storage is written explicitly already
  1893. // when writing the recrypted passwords
  1894. Configuration->SaveExplicit();
  1895. TQueryType QueryType = qtInformation;
  1896. if (RecryptPasswordErrors->Count > 0)
  1897. {
  1898. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  1899. QueryType = qtWarning;
  1900. }
  1901. MoreMessageDialog(
  1902. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  1903. }
  1904. //---------------------------------------------------------------------------
  1905. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  1906. {
  1907. UnicodeString NewPassword;
  1908. if (DoChangeMasterPasswordDialog(NewPassword))
  1909. {
  1910. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  1911. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  1912. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  1913. }
  1914. }
  1915. //---------------------------------------------------------------------------
  1916. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  1917. TObject * /*Sender*/)
  1918. {
  1919. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  1920. {
  1921. try
  1922. {
  1923. if (CanSetMasterPassword())
  1924. {
  1925. if (UseMasterPasswordCheck->Checked)
  1926. {
  1927. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  1928. }
  1929. else
  1930. {
  1931. if (DoMasterPasswordDialog())
  1932. {
  1933. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  1934. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  1935. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  1936. }
  1937. }
  1938. }
  1939. }
  1940. __finally
  1941. {
  1942. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  1943. UpdateControls();
  1944. }
  1945. }
  1946. }
  1947. //---------------------------------------------------------------------------
  1948. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  1949. TObject * /*Sender*/)
  1950. {
  1951. if (CanSetMasterPassword())
  1952. {
  1953. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  1954. }
  1955. }
  1956. //---------------------------------------------------------------------------
  1957. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  1958. {
  1959. std::unique_ptr<TStrings> Data(TextToStringList(GetUsageData()));
  1960. UnicodeString Message =
  1961. Data->Text.IsEmpty() ? MainInstructions(LoadStr(USAGE_DATA_NONE)) : LoadStr(USAGE_DATA2);
  1962. MoreMessageDialog(Message, Data.get(), qtInformation, qaOK, HELP_USAGE);
  1963. }
  1964. //---------------------------------------------------------------------------
  1965. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  1966. {
  1967. if (EditCopyParamButton->Enabled)
  1968. {
  1969. AddEditCopyParam(cpmEdit);
  1970. }
  1971. }
  1972. //---------------------------------------------------------------------------
  1973. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  1974. TCustomListView * Sender, TListItem * Item,
  1975. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  1976. {
  1977. if (Item->Index == 0)
  1978. {
  1979. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  1980. }
  1981. }
  1982. //---------------------------------------------------------------------------
  1983. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  1984. {
  1985. PuttyRegistryStorageKeyEdit->ItemIndex =
  1986. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  1987. }
  1988. //---------------------------------------------------------------------------
  1989. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  1990. {
  1991. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1992. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  1993. {
  1994. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  1995. }
  1996. else if (ContainsText(PuttyPath, KittyExecutable))
  1997. {
  1998. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  1999. }
  2000. UpdateControls();
  2001. }
  2002. //---------------------------------------------------------------------------
  2003. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2004. TTreeNode * Node, bool & /*AllowChange*/)
  2005. {
  2006. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2007. // delay load as this can be time consuming
  2008. if (Sheet == LanguagesSheet)
  2009. {
  2010. LoadLanguages();
  2011. }
  2012. }
  2013. //---------------------------------------------------------------------------
  2014. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2015. {
  2016. OpenBrowser(LoadStr(LOCALES_URL));
  2017. }
  2018. //---------------------------------------------------------------------------
  2019. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2020. {
  2021. CommanderInterfaceButton2->SetFocus();
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2025. {
  2026. ExplorerInterfaceButton2->SetFocus();
  2027. }
  2028. //---------------------------------------------------------------------------
  2029. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2030. {
  2031. PanelFontButtonClick(Sender);
  2032. }
  2033. //---------------------------------------------------------------------------