Preferences.cpp 70 KB

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