Preferences.cpp 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <System.IOUtils.hpp>
  6. #include <Common.h>
  7. #include <math.h>
  8. #include <limits>
  9. #include "Preferences.h"
  10. #include "Custom.h"
  11. #include <CoreMain.h>
  12. #include <Terminal.h>
  13. #include <Bookmarks.h>
  14. #include "VCLCommon.h"
  15. #include "GUITools.h"
  16. #include "Tools.h"
  17. #include "TextsCore.h"
  18. #include "TextsWin.h"
  19. #include "HelpWin.h"
  20. #include "WinInterface.h"
  21. #include "WinConfiguration.h"
  22. #include "Setup.h"
  23. #include "ProgParams.h"
  24. #include "Http.h"
  25. #include "TerminalManager.h"
  26. //---------------------------------------------------------------------
  27. #pragma link "CopyParams"
  28. #pragma link "UpDownEdit"
  29. #pragma link "ComboEdit"
  30. #pragma link "HistoryComboBox"
  31. #pragma link "PathLabel"
  32. #pragma resource "*.dfm"
  33. //---------------------------------------------------------------------
  34. const int PrivatePortMin = 49152; // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic,_private_or_ephemeral_ports
  35. //---------------------------------------------------------------------
  36. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  37. TPreferencesDialogData * DialogData)
  38. {
  39. bool Result;
  40. TPreferencesDialog * PreferencesDialog =
  41. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  42. try
  43. {
  44. Result = PreferencesDialog->Execute(DialogData);
  45. if (Result)
  46. {
  47. CheckConfigurationForceSave();
  48. Configuration->SaveExplicit();
  49. }
  50. }
  51. __finally
  52. {
  53. delete PreferencesDialog;
  54. }
  55. return Result;
  56. }
  57. //---------------------------------------------------------------------
  58. __fastcall TPreferencesDialog::TPreferencesDialog(
  59. TComponent* AOwner, TPreferencesMode PreferencesMode)
  60. : TForm(AOwner)
  61. {
  62. SetCorrectFormParent(this);
  63. FNoUpdate = 0;
  64. FPreferencesMode = PreferencesMode;
  65. FEditorFont.reset(new TFont());
  66. FEditorFont->Color = clWindowText;
  67. FPanelFont.reset(new TFont());
  68. FPanelFont->Color = clWindowText;
  69. // currently useless
  70. FAfterFilenameEditDialog = false;
  71. FCustomCommandList = new TCustomCommandList();
  72. FCustomCommandChanging = false;
  73. FExtensionList = new TCustomCommandList();
  74. FListViewDragDest = -1;
  75. FCopyParamList = new TCopyParamList();
  76. FEditorList = new TEditorList();
  77. FAutomaticUpdatesPossible = IsInstalled();
  78. FCustomCommandsHintItem = NULL;
  79. FAddedExtensions.reset(CreateSortedStringList());
  80. FCustomCommandOptions.reset(new TStringList());
  81. UseSystemSettings(this);
  82. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  83. FixListColumnWidth(CustomCommandsView, -1);
  84. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  85. FixListColumnWidth(CopyParamListView, -1);
  86. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  87. FixListColumnWidth(EditorListView3, -1);
  88. FFileColorScrollOnDragOver = new TListViewScrollOnDragOver(FileColorsView, true);
  89. FOrigCustomCommandsViewWindowProc = CustomCommandsView->WindowProc;
  90. CustomCommandsView->WindowProc = CustomCommandsViewWindowProc;
  91. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  92. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta && !IsUWP());
  93. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  94. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  95. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  96. HintLabel(ShellIconsText2);
  97. HotTrackLabel(CopyParamLabel);
  98. std::unique_ptr<TStrings> PuttyPathHintStrings(TextToStringList(LoadStr(PUTTY_PATTERNS_HINT2)));
  99. PuttyPathHintStrings->Insert(7, LoadStr(PATTERNS_HINT_K));
  100. HintLabel(PuttyPathHintText, TrimRight(StringsToText(PuttyPathHintStrings.get())));
  101. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  102. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  103. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  104. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  105. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  106. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  107. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  108. MenuButton(RegisterAsUrlHandlersButton);
  109. MenuButton(EditorFontColorButton);
  110. MenuButton(EditorBackgroundColorButton);
  111. LoadDialogImage(CommanderInterfacePicture, L"Commander");
  112. LoadDialogImage(ExplorerInterfacePicture, L"Explorer");
  113. LinkLabel(UpdatesLink);
  114. LinkAppLabel(BackgroundConfirmationsLink);
  115. AutoSizeButton(UsageViewButton);
  116. AutomaticIniFileStorageLabel->Caption = ExpandEnvironmentVariables(Configuration->GetAutomaticIniFileStorageName(false));
  117. QueueTransferLimitEdit->MaxValue = WinConfiguration->QueueTransferLimitMax;
  118. CommanderDescriptionLabel2->Caption = Bullet(CommanderDescriptionLabel2->Caption);
  119. ExplorerDescriptionLabel->Caption = Bullet(ExplorerDescriptionLabel->Caption);
  120. if (IsUWP())
  121. {
  122. UpdatesSheet->Caption = LoadStr(PREFERENCES_STATISTICS_CAPTION);
  123. int ProxyOffset = UpdatesProxyGroup->Top - UpdatesOptionsGroup->Top - UpdatesOptionsGroup->Height;
  124. UpdatesGroup2->Visible = false;
  125. UpdatesOptionsGroup->Top = UpdatesGroup2->Top;
  126. UpdatesBetaVersionsCombo->Visible = false;
  127. UpdatesBetaVersionsLabel->Visible = false;
  128. int Offset = UsageViewButton->Top - UpdatesBetaVersionsCombo->Top;
  129. CollectUsageCheck->Top = CollectUsageCheck->Top - Offset;
  130. UsageViewButton->Top = UsageViewButton->Top - Offset;
  131. UpdatesOptionsGroup->Height = UpdatesOptionsGroup->Height - Offset;
  132. UpdatesProxyGroup->Top = UpdatesOptionsGroup->Top + UpdatesOptionsGroup->Height + ProxyOffset;
  133. }
  134. HideComponentsPanel(this);
  135. }
  136. //---------------------------------------------------------------------------
  137. __fastcall TPreferencesDialog::~TPreferencesDialog()
  138. {
  139. SAFE_DESTROY(FFileColorScrollOnDragOver);
  140. SAFE_DESTROY(FEditorScrollOnDragOver);
  141. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  142. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  143. delete FCustomCommandList;
  144. FCustomCommandList = NULL;
  145. delete FExtensionList;
  146. FExtensionList = NULL;
  147. delete FCopyParamList;
  148. FCopyParamList = NULL;
  149. delete FEditorList;
  150. FEditorList = NULL;
  151. }
  152. //---------------------------------------------------------------------
  153. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  154. {
  155. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  156. FDialogData = DialogData;
  157. bool Result = (ShowModal() == DefaultResult(this));
  158. if (Result)
  159. {
  160. SaveConfiguration();
  161. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  162. }
  163. else
  164. {
  165. for (int Index = 0; Index < FAddedExtensions->Count; Index++)
  166. {
  167. DeleteFile(ApiPath(FAddedExtensions->Strings[Index]));
  168. }
  169. }
  170. return Result;
  171. }
  172. //---------------------------------------------------------------------------
  173. void __fastcall TPreferencesDialog::LoadLanguages()
  174. {
  175. if (!FLanguagesLoaded)
  176. {
  177. LanguagesView->Items->Clear();
  178. LCID Locale = GUIConfiguration->Locale;
  179. if (Locale == NULL)
  180. {
  181. DebugAssert(GUIConfiguration->AppliedLocale == WinConfiguration->DefaultLocale);
  182. Locale = WinConfiguration->DefaultLocale;
  183. }
  184. TObjectList * Locales = GUIConfiguration->Locales;
  185. for (int Index = 0; Index < Locales->Count; Index++)
  186. {
  187. TListItem * Item = LanguagesView->Items->Add();
  188. TLocaleInfo * LocaleInfo = DebugNotNull(dynamic_cast<TLocaleInfo *>(Locales->Items[Index]));
  189. Item->Caption = LocaleInfo->Name;
  190. Item->Data = LocaleInfo;
  191. Item->Focused = (LocaleInfo->Locale == Locale);
  192. Item->Selected = Item->Focused;
  193. }
  194. AutoSizeListColumnsWidth(LanguagesView);
  195. FLanguagesLoaded = true;
  196. }
  197. }
  198. //---------------------------------------------------------------------------
  199. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  200. {
  201. for (int pi = 0; pi < PageControl->PageCount; pi++)
  202. {
  203. TTabSheet * Sheet = PageControl->Pages[pi];
  204. if (Sheet->Tag == Node->SelectedIndex)
  205. {
  206. return Sheet;
  207. }
  208. }
  209. DebugFail();
  210. return NULL;
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  214. {
  215. Tree->FullExpand();
  216. int i = 0;
  217. while (i < Tree->Items->Count)
  218. {
  219. TTreeNode * Node = Tree->Items->Item[i];
  220. TTabSheet * Sheet = FindPageForTreeNode(Node);
  221. if (DebugNotNull(Sheet))
  222. {
  223. if (Sheet->Enabled)
  224. {
  225. // gets called multiple times occasionally
  226. // (e.g. when called from upload dialog invoked by /upload)
  227. if (!Sheet->Caption.IsEmpty())
  228. {
  229. Node->Text = Sheet->Caption;
  230. Sheet->Caption = L"";
  231. }
  232. }
  233. else
  234. {
  235. Tree->Items->Delete(Node);
  236. i--;
  237. }
  238. }
  239. i++;
  240. }
  241. }
  242. //---------------------------------------------------------------------------
  243. void __fastcall TPreferencesDialog::LoadConfiguration()
  244. {
  245. FNoUpdate++;
  246. try
  247. {
  248. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  249. BOOLPROP(DefaultDirIsHome);
  250. BOOLPROP(PreservePanelState);
  251. BOOLPROP(DeleteToRecycleBin);
  252. BOOLPROP(DDWarnLackOfTempSpace);
  253. BOOLPROP(ShowHiddenFiles);
  254. BOOLPROP(RenameWholeName);
  255. BOOLPROP(ShowInaccesibleDirectories);
  256. BOOLPROP(CopyOnDoubleClickConfirmation);
  257. BOOLPROP(ConfirmTransferring);
  258. BOOLPROP(ConfirmOverwriting);
  259. BOOLPROP(ConfirmResume);
  260. BOOLPROP(ConfirmDeleting);
  261. BOOLPROP(ConfirmRecycling);
  262. BOOLPROP(ConfirmExitOnCompletion);
  263. BOOLPROP(ConfirmCommandSession);
  264. BOOLPROP(ContinueOnError);
  265. BOOLPROP(SynchronizeSummary);
  266. BOOLPROP(BeepOnFinish);
  267. BOOLPROP(TemporaryDirectoryAppendSession);
  268. BOOLPROP(TemporaryDirectoryAppendPath);
  269. BOOLPROP(TemporaryDirectoryDeterministic);
  270. BOOLPROP(TemporaryDirectoryCleanup);
  271. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  272. BOOLPROP(FullRowSelect);
  273. BOOLPROP(NaturalOrderNumericalSorting);
  274. BOOLPROP(AlwaysSortDirectoriesByName);
  275. ConfirmClosingSessionCheck2->Checked = WinConfiguration->ConfirmClosingSession;
  276. if (WinConfiguration->DDTransferConfirmation == asAuto)
  277. {
  278. // allow grayed state only initially,
  279. // once the off state is confirmed, never allow returning
  280. // to the undefined state
  281. DDTransferConfirmationCheck2->AllowGrayed = true;
  282. }
  283. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck2, WinConfiguration->DDTransferConfirmation);
  284. BeepOnFinishAfterEdit->AsInteger =
  285. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  286. BOOLPROP(BalloonNotifications);
  287. DDFakeFileEnabledButton->Checked = WinConfiguration->DDFakeFile;
  288. DDFakeFileDisabledButton->Checked = !DDFakeFileEnabledButton->Checked;
  289. DDDrivesMemo->Lines->CommaText = WinConfiguration->DDDrives;
  290. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  291. {
  292. DDSystemTemporaryDirectoryButton->Checked = true;
  293. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  294. }
  295. else
  296. {
  297. DDCustomTemporaryDirectoryButton->Checked = true;
  298. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  299. }
  300. // Commander
  301. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  302. {
  303. NortonLikeModeCombo->ItemIndex = 2;
  304. }
  305. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  306. {
  307. NortonLikeModeCombo->ItemIndex = 1;
  308. }
  309. else
  310. {
  311. NortonLikeModeCombo->ItemIndex = 0;
  312. }
  313. SwappedPanelsCheck->Checked =
  314. WinConfiguration->ScpCommander.SwappedPanels;
  315. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  316. ExplorerKeyboardShortcutsCombo->ItemIndex =
  317. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  318. BOOLPROP(UseLocationProfiles);
  319. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  320. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  321. // Local panel
  322. PreserveLocalDirectoryCheck->Checked =
  323. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  324. SystemContextMenuCheck->Checked =
  325. WinConfiguration->ScpCommander.SystemContextMenu;
  326. // Explorer
  327. ShowFullAddressCheck->Checked =
  328. WinConfiguration->ScpExplorer.ShowFullAddress;
  329. // select none when stNul
  330. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  331. AutomaticIniFileStorageButton->Checked =
  332. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && Configuration->CustomIniFileStorageName.IsEmpty();
  333. CustomIniFileStorageButton->Checked =
  334. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && !Configuration->CustomIniFileStorageName.IsEmpty();
  335. CustomIniFileStorageEdit->Text = Configuration->CustomIniFileStorageName;
  336. if (Configuration->CustomIniFileStorageName.IsEmpty())
  337. {
  338. CustomIniFileStorageEdit->Text = Configuration->GetDefaultIniFileExportPath();
  339. }
  340. else
  341. {
  342. CustomIniFileStorageEdit->Text = Configuration->CustomIniFileStorageName;
  343. }
  344. FCustomIniFileStorageName = GetCustomIniFileStorageName();
  345. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  346. // editor
  347. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  348. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  349. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  350. {
  351. EditorEncodingCombo->ItemIndex = 1;
  352. }
  353. else
  354. {
  355. EditorEncodingCombo->ItemIndex = 0;
  356. }
  357. TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
  358. FEditorFont->Color = WinConfiguration->Editor.FontColor;
  359. FEditorBackgroundColor = WinConfiguration->Editor.BackgroundColor;
  360. (*FEditorList) = *WinConfiguration->EditorList;
  361. UpdateEditorListView();
  362. BOOLPROP(EditorCheckNotModified);
  363. FCopyParams = GUIConfiguration->DefaultCopyParam;
  364. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  365. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  366. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  367. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  368. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  369. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  370. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  371. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  372. SessionReopenAutoIdleEdit->Value = (GUIConfiguration->SessionReopenAutoIdle > 0 ?
  373. (GUIConfiguration->SessionReopenAutoIdle / MSecsPerSec) : 5);
  374. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  375. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  376. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  377. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  378. GeneralSheet->Enabled = WinConfiguration->ExpertMode;
  379. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  380. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  381. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  382. StorageGroup->Visible = WinConfiguration->ExpertMode;
  383. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  384. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  385. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  386. FExtensionList->Assign(WinConfiguration->ExtensionList);
  387. UpdateCustomCommandsView();
  388. FCustomCommandOptions->Assign(WinConfiguration->CustomCommandOptions);
  389. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  390. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  391. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  392. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  393. SelectPuttyRegistryStorageKey(GUIConfiguration->PuttyRegistryStorageKey);
  394. // Queue
  395. QueueTransferLimitEdit->AsInteger = Configuration->QueueTransfersLimit;
  396. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  397. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  398. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  399. QueueParallelCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueParallel;
  400. ParallelTransferCheck->Checked = (Configuration->ParallelTransferThreshold > 0);
  401. __int64 ParallelTransferThreshold = static_cast<__int64>(Configuration->ParallelTransferThreshold) * 1024;
  402. ParallelTransferThresholdCombo->Text =
  403. SizeToStr((ParallelTransferThreshold > 0) ? ParallelTransferThreshold : 100*1024*1024);
  404. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  405. if (!GUIConfiguration->QueueKeepDoneItems)
  406. {
  407. QueueKeepDoneItemsForCombo->ItemIndex = 0;
  408. }
  409. else if (GUIConfiguration->QueueKeepDoneItemsFor < 0)
  410. {
  411. QueueKeepDoneItemsForCombo->ItemIndex = 5;
  412. }
  413. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15)
  414. {
  415. QueueKeepDoneItemsForCombo->ItemIndex = 1;
  416. }
  417. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60)
  418. {
  419. QueueKeepDoneItemsForCombo->ItemIndex = 2;
  420. }
  421. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15 * 60)
  422. {
  423. QueueKeepDoneItemsForCombo->ItemIndex = 3;
  424. }
  425. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60 * 60)
  426. {
  427. QueueKeepDoneItemsForCombo->ItemIndex = 4;
  428. }
  429. if (WinConfiguration->QueueView.Show == qvShow)
  430. {
  431. QueueViewShowButton->Checked = true;
  432. }
  433. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  434. {
  435. QueueViewHideWhenEmptyButton->Checked = true;
  436. }
  437. else
  438. {
  439. QueueViewHideButton->Checked = true;
  440. }
  441. // window
  442. AutoSaveWorkspaceCheck->Checked = WinConfiguration->AutoSaveWorkspace;
  443. AutoWorkspaceCombo->Text =
  444. DefaultStr(WinConfiguration->AutoWorkspace,
  445. // It will rarely happen that LastWorkspace is set, while AutoWorkspace not.
  446. // It can happen only when user saved workspace before opening the Preferences
  447. // dialog for the first time
  448. DefaultStr(WinConfiguration->LastWorkspace, LoadStr(NEW_WORKSPACE)));
  449. AutoSaveWorkspacePasswordsCheck->Checked = WinConfiguration->AutoSaveWorkspacePasswords;
  450. if (WinConfiguration->PathInCaption == picFull)
  451. {
  452. PathInCaptionFullButton->Checked = true;
  453. }
  454. else if (WinConfiguration->PathInCaption == picShort)
  455. {
  456. PathInCaptionShortButton->Checked = true;
  457. }
  458. else
  459. {
  460. PathInCaptionNoneButton->Checked = true;
  461. }
  462. BOOLPROP(MinimizeToTray);
  463. BOOLPROP(ExternalSessionInExistingInstance);
  464. BOOLPROP(ShowLoginWhenNoSession);
  465. BOOLPROP(KeepOpenWhenNoSession);
  466. BOOLPROP(ShowTips);
  467. // panels
  468. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  469. BOOLPROP(AutoReadDirectoryAfterOp);
  470. BOOLPROP(RefreshRemotePanel);
  471. RefreshRemotePanelIntervalEdit->Value =
  472. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  473. switch (WinConfiguration->FormatSizeBytes)
  474. {
  475. case fbNone:
  476. FormatSizeBytesCombo->ItemIndex = 0;
  477. break;
  478. case fbKilobytes:
  479. FormatSizeBytesCombo->ItemIndex = 1;
  480. break;
  481. case fbShort:
  482. FormatSizeBytesCombo->ItemIndex = 2;
  483. break;
  484. default:
  485. DebugFail();
  486. }
  487. switch (WinConfiguration->PanelSearch)
  488. {
  489. case isOff:
  490. PanelSearchCombo->ItemIndex = -1;
  491. break;
  492. case isNameStartOnly:
  493. PanelSearchCombo->ItemIndex = 0;
  494. break;
  495. case isName:
  496. PanelSearchCombo->ItemIndex = 1;
  497. break;
  498. case isAll:
  499. PanelSearchCombo->ItemIndex = 2;
  500. break;
  501. default:
  502. DebugFail();
  503. }
  504. bool CustomPanelFont = !WinConfiguration->PanelFont.FontName.IsEmpty();
  505. PanelFontCheck->Checked = CustomPanelFont;
  506. if (CustomPanelFont)
  507. {
  508. TWinConfiguration::RestoreFont(WinConfiguration->PanelFont, FPanelFont.get());
  509. }
  510. else
  511. {
  512. // Default to system icon font, when starting customization
  513. FPanelFont->Assign(Screen->IconFont);
  514. }
  515. // file colors
  516. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  517. UpdateFileColorsView();
  518. // updates
  519. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  520. if (int(Updates.Period) <= 0)
  521. {
  522. UpdatesPeriodCombo->ItemIndex = 0;
  523. }
  524. else if (int(Updates.Period) <= 1)
  525. {
  526. UpdatesPeriodCombo->ItemIndex = 1;
  527. }
  528. else if (int(Updates.Period) <= 7)
  529. {
  530. UpdatesPeriodCombo->ItemIndex = 2;
  531. }
  532. else
  533. {
  534. UpdatesPeriodCombo->ItemIndex = 3;
  535. }
  536. UpdatesShowOnStartup->Checked = Updates.ShowOnStartup;
  537. UpdatesAuthenticationEmailEdit->Text = Updates.AuthenticationEmail;
  538. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  539. CollectUsageCheck->Checked = Configuration->CollectUsage;
  540. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  541. switch (Updates.ConnectionType)
  542. {
  543. case ctDirect:
  544. default:
  545. UpdatesDirectCheck->Checked = true;
  546. break;
  547. case ctAuto:
  548. UpdatesAutoCheck->Checked = true;
  549. break;
  550. case ctProxy:
  551. UpdatesProxyCheck->Checked = true;
  552. break;
  553. }
  554. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  555. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  556. // presets
  557. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  558. UpdateCopyParamListView();
  559. CopyParamListView->ItemIndex = 0;
  560. BOOLPROP(CopyParamAutoSelectNotice);
  561. // interface
  562. ComboAutoSwitchLoad(ThemeCombo, WinConfiguration->DarkTheme);
  563. switch (CustomWinConfiguration->Interface)
  564. {
  565. case ifCommander:
  566. CommanderInterfaceButton2->Checked = true;
  567. break;
  568. case ifExplorer:
  569. ExplorerInterfaceButton2->Checked = true;
  570. break;
  571. default:
  572. DebugFail();
  573. break;
  574. }
  575. // security
  576. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  577. SessionRememberPasswordCheck->Checked = GUIConfiguration->SessionRememberPassword;
  578. FSshHostCAPlainList = Configuration->SshHostCAList->GetList();
  579. // network
  580. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  581. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  582. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  583. LocalPortNumberCheck->Checked = Configuration->HasLocalPortNumberLimits();
  584. LocalPortNumberMinEdit->AsInteger =
  585. (Configuration->LocalPortNumberMin > 0 ? Configuration->LocalPortNumberMin : PrivatePortMin);
  586. LocalPortNumberMaxEdit->AsInteger =
  587. (Configuration->LocalPortNumberMax >= LocalPortNumberMinEdit->AsInteger ? Configuration->LocalPortNumberMax : static_cast<int>(LocalPortNumberMaxEdit->MaxValue));
  588. TryFtpWhenSshFailsCheck->Checked = Configuration->TryFtpWhenSshFails;
  589. // logging
  590. EnableLoggingCheck->Checked = Configuration->Logging;
  591. LogProtocolCombo2->ItemIndex = Configuration->LogProtocol + BelowNormalLogLevels;
  592. LogFileNameEdit3->Text =
  593. !Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
  594. if (Configuration->LogFileAppend)
  595. {
  596. LogFileAppendButton->Checked = true;
  597. }
  598. else
  599. {
  600. LogFileOverwriteButton->Checked = true;
  601. }
  602. LogMaxSizeCheck->Checked = (Configuration->LogMaxSize > 0);
  603. LogMaxSizeCombo->Text = SizeToStr((Configuration->LogMaxSize > 0) ? Configuration->LogMaxSize : (1 * 1024 * 1024));
  604. LogMaxSizeCountCheck->Checked = (Configuration->LogMaxCount > 0);
  605. LogMaxSizeCountEdit->AsInteger = ((Configuration->LogMaxCount > 0) ? Configuration->LogMaxCount : 5);
  606. BOOLPROP(LogSensitive);
  607. EnableActionsLoggingCheck->Checked = Configuration->LogActions;
  608. ActionsLogFileNameEdit->Text = Configuration->ActionsLogFileName;
  609. #undef BOOLPROP
  610. }
  611. __finally
  612. {
  613. FNoUpdate--;
  614. }
  615. UpdateControls();
  616. }
  617. //---------------------------------------------------------------------------
  618. void __fastcall TPreferencesDialog::SaveConfiguration()
  619. {
  620. Configuration->BeginUpdate();
  621. try
  622. {
  623. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  624. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  625. BOOLPROP(DefaultDirIsHome);
  626. BOOLPROP(PreservePanelState);
  627. BOOLPROP(DeleteToRecycleBin);
  628. BOOLPROP(DDWarnLackOfTempSpace);
  629. BOOLPROP(ShowHiddenFiles);
  630. BOOLPROP(RenameWholeName);
  631. BOOLPROP(ShowInaccesibleDirectories);
  632. BOOLPROP(CopyOnDoubleClickConfirmation);
  633. BOOLPROP(ConfirmTransferring);
  634. BOOLPROP(ConfirmOverwriting);
  635. BOOLPROP(ConfirmResume);
  636. BOOLPROP(ConfirmDeleting);
  637. BOOLPROP(ConfirmRecycling);
  638. BOOLPROP(ConfirmExitOnCompletion);
  639. BOOLPROP(ConfirmCommandSession);
  640. BOOLPROP(ContinueOnError);
  641. BOOLPROP(SynchronizeSummary);
  642. BOOLPROP(BeepOnFinish);
  643. BOOLPROP(TemporaryDirectoryAppendSession);
  644. BOOLPROP(TemporaryDirectoryAppendPath);
  645. BOOLPROP(TemporaryDirectoryDeterministic);
  646. BOOLPROP(TemporaryDirectoryCleanup);
  647. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  648. BOOLPROP(FullRowSelect);
  649. BOOLPROP(NaturalOrderNumericalSorting);
  650. BOOLPROP(AlwaysSortDirectoriesByName);
  651. WinConfiguration->ConfirmClosingSession = ConfirmClosingSessionCheck2->Checked;
  652. WinConfiguration->DDTransferConfirmation =
  653. CheckBoxAutoSwitchSave(DDTransferConfirmationCheck2);
  654. GUIConfiguration->BeepOnFinishAfter =
  655. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  656. BOOLPROP(BalloonNotifications);
  657. WinConfiguration->DDFakeFile = DDFakeFileEnabledButton->Checked;
  658. WinConfiguration->DDDrives = DDDrivesMemo->Lines->CommaText;
  659. if (DDSystemTemporaryDirectoryButton->Checked)
  660. {
  661. WinConfiguration->DDTemporaryDirectory = L"";
  662. }
  663. else
  664. {
  665. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  666. }
  667. // Commander
  668. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  669. if (NortonLikeModeCombo->ItemIndex == 2)
  670. {
  671. ScpCommander.NortonLikeMode = nlOff;
  672. }
  673. else if (NortonLikeModeCombo->ItemIndex == 1)
  674. {
  675. ScpCommander.NortonLikeMode = nlKeyboard;
  676. }
  677. else
  678. {
  679. ScpCommander.NortonLikeMode = nlOn;
  680. }
  681. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  682. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  683. ScpCommander.ExplorerKeyboardShortcuts =
  684. (ExplorerKeyboardShortcutsCombo->ItemIndex != 0);
  685. BOOLPROP(UseLocationProfiles);
  686. ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  687. ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  688. // Local panel
  689. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  690. ScpCommander.SystemContextMenu = SystemContextMenuCheck->Checked;
  691. WinConfiguration->ScpCommander = ScpCommander;
  692. // Explorer
  693. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  694. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  695. WinConfiguration->ScpExplorer = ScpExplorer;
  696. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  697. // editor
  698. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  699. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  700. switch (EditorEncodingCombo->ItemIndex)
  701. {
  702. case 1:
  703. WinConfiguration->Editor.Encoding = CP_UTF8;
  704. break;
  705. default:
  706. WinConfiguration->Editor.Encoding = CP_ACP;
  707. break;
  708. }
  709. TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
  710. WinConfiguration->Editor.FontColor = FEditorFont->Color;
  711. WinConfiguration->Editor.BackgroundColor = FEditorBackgroundColor;
  712. WinConfiguration->EditorList = FEditorList;
  713. BOOLPROP(EditorCheckNotModified);
  714. // overwrites only TCopyParamType fields
  715. CopyParam = FCopyParams;
  716. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  717. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  718. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  719. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  720. Configuration->SessionReopenAuto =
  721. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  722. GUIConfiguration->SessionReopenAutoIdle =
  723. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoIdleEdit->AsInteger * MSecsPerSec) : 0);
  724. Configuration->SessionReopenAutoStall =
  725. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  726. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  727. WinConfiguration->CustomCommandList = FCustomCommandList;
  728. WinConfiguration->ExtensionList = FExtensionList;
  729. WinConfiguration->CustomCommandOptions = FCustomCommandOptions.get();
  730. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  731. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  732. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  733. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  734. // do not overwrite custom keys
  735. if (PuttyRegistryStorageKeyEdit->ItemIndex >= 0)
  736. {
  737. GUIConfiguration->PuttyRegistryStorageKey = PuttyRegistryStorageKeyEdit->Text;
  738. }
  739. // Queue
  740. Configuration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  741. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  742. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  743. CopyParam.Queue = QueueCheck->Checked;
  744. CopyParam.QueueParallel = QueueParallelCheck->Checked;
  745. __int64 ParallelTransferThreshold;
  746. if (ParallelTransferCheck->Checked && TryStrToSize(ParallelTransferThresholdCombo->Text, ParallelTransferThreshold))
  747. {
  748. Configuration->ParallelTransferThreshold = std::min(ParallelTransferThreshold / 1024, static_cast<__int64>(std::numeric_limits<int>::max()));
  749. }
  750. else
  751. {
  752. // In future, we might set it to 0, if -1 will actually mean some default threshold
  753. Configuration->ParallelTransferThreshold = -1;
  754. }
  755. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  756. GUIConfiguration->QueueKeepDoneItems = (QueueKeepDoneItemsForCombo->ItemIndex != 0);
  757. switch (QueueKeepDoneItemsForCombo->ItemIndex)
  758. {
  759. case 0:
  760. GUIConfiguration->QueueKeepDoneItemsFor = 0;
  761. break;
  762. case 1:
  763. GUIConfiguration->QueueKeepDoneItemsFor = 15;
  764. break;
  765. case 2:
  766. GUIConfiguration->QueueKeepDoneItemsFor = 60;
  767. break;
  768. case 3:
  769. GUIConfiguration->QueueKeepDoneItemsFor = 15 * 60;
  770. break;
  771. case 4:
  772. GUIConfiguration->QueueKeepDoneItemsFor = 60 * 60;
  773. break;
  774. default:
  775. GUIConfiguration->QueueKeepDoneItemsFor = -1;
  776. break;
  777. }
  778. if (QueueViewShowButton->Checked)
  779. {
  780. WinConfiguration->QueueView.Show = qvShow;
  781. }
  782. else if (QueueViewHideWhenEmptyButton->Checked)
  783. {
  784. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  785. }
  786. else
  787. {
  788. WinConfiguration->QueueView.Show = qvHide;
  789. }
  790. GUIConfiguration->DefaultCopyParam = CopyParam;
  791. // window
  792. WinConfiguration->AutoSaveWorkspace =
  793. !AutoWorkspaceCombo->Text.IsEmpty() &&
  794. AutoSaveWorkspaceCheck->Checked;
  795. if (!AutoWorkspaceCombo->Text.IsEmpty())
  796. {
  797. WinConfiguration->AutoWorkspace = AutoWorkspaceCombo->Text;
  798. }
  799. WinConfiguration->AutoSaveWorkspacePasswords = AutoSaveWorkspacePasswordsCheck->Checked;
  800. if (PathInCaptionFullButton->Checked)
  801. {
  802. WinConfiguration->PathInCaption = picFull;
  803. }
  804. else if (PathInCaptionShortButton->Checked)
  805. {
  806. WinConfiguration->PathInCaption = picShort;
  807. }
  808. else
  809. {
  810. WinConfiguration->PathInCaption = picNone;
  811. }
  812. BOOLPROP(MinimizeToTray);
  813. BOOLPROP(ExternalSessionInExistingInstance);
  814. BOOLPROP(ShowLoginWhenNoSession);
  815. BOOLPROP(KeepOpenWhenNoSession);
  816. BOOLPROP(ShowTips);
  817. // panels
  818. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  819. BOOLPROP(AutoReadDirectoryAfterOp);
  820. BOOLPROP(RefreshRemotePanel);
  821. WinConfiguration->RefreshRemotePanelInterval =
  822. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  823. switch (FormatSizeBytesCombo->ItemIndex)
  824. {
  825. case 0:
  826. WinConfiguration->FormatSizeBytes = fbNone;
  827. break;
  828. case 1:
  829. WinConfiguration->FormatSizeBytes = fbKilobytes;
  830. break;
  831. case 2:
  832. WinConfiguration->FormatSizeBytes = fbShort;
  833. break;
  834. default:
  835. DebugFail();
  836. }
  837. switch (PanelSearchCombo->ItemIndex)
  838. {
  839. case -1:
  840. WinConfiguration->PanelSearch = isOff;
  841. break;
  842. case 0:
  843. WinConfiguration->PanelSearch = isNameStartOnly;
  844. break;
  845. case 1:
  846. WinConfiguration->PanelSearch = isName;
  847. break;
  848. case 2:
  849. WinConfiguration->PanelSearch = isAll;
  850. break;
  851. default:
  852. DebugFail();
  853. }
  854. TFontConfiguration PanelFontConfiguration;
  855. if (PanelFontCheck->Checked)
  856. {
  857. TWinConfiguration::StoreFont(FPanelFont.get(), PanelFontConfiguration);
  858. }
  859. WinConfiguration->PanelFont = PanelFontConfiguration;
  860. // file colors
  861. WinConfiguration->FileColors = TFileColorData::SaveList(FFileColors);
  862. // updates
  863. TUpdatesConfiguration Updates = SaveUpdates();
  864. if ((Configuration->CollectUsage != CollectUsageCheck->Checked) && IsUWP())
  865. {
  866. if (CollectUsageCheck->Checked)
  867. {
  868. if (Updates.Period == TDateTime(0))
  869. {
  870. Updates.Period = DefaultUpdatesPeriod;
  871. }
  872. }
  873. else
  874. {
  875. Updates.Period = 0;
  876. }
  877. }
  878. WinConfiguration->Updates = Updates;
  879. Configuration->CollectUsage = CollectUsageCheck->Checked;
  880. // presets
  881. WinConfiguration->CopyParamList = FCopyParamList;
  882. BOOLPROP(CopyParamAutoSelectNotice);
  883. // interface
  884. WinConfiguration->DarkTheme = ComboAutoSwitchSave(ThemeCombo);
  885. if (GetInterface() != CustomWinConfiguration->Interface)
  886. {
  887. Configuration->Usage->Inc(L"InterfaceChanges");
  888. }
  889. CustomWinConfiguration->Interface = GetInterface();
  890. // network
  891. Configuration->ExternalIpAddress =
  892. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  893. Configuration->LocalPortNumberMin = LocalPortNumberCheck->Checked ? LocalPortNumberMinEdit->AsInteger : 0;
  894. Configuration->LocalPortNumberMax = LocalPortNumberCheck->Checked ? LocalPortNumberMaxEdit->AsInteger : 0;
  895. Configuration->TryFtpWhenSshFails = TryFtpWhenSshFailsCheck->Checked;
  896. // security
  897. GUIConfiguration->SessionRememberPassword = SessionRememberPasswordCheck->Checked;
  898. std::unique_ptr<TSshHostCAList> SshHostCAList(new TSshHostCAList(FSshHostCAPlainList));
  899. Configuration->SshHostCAList = SshHostCAList.get();
  900. // logging
  901. Configuration->Logging = EnableLoggingCheck->Checked && !LogFileNameEdit3->Text.IsEmpty();
  902. Configuration->LogProtocol = LogProtocolCombo2->ItemIndex - BelowNormalLogLevels;
  903. Configuration->LogFileName = LogFileNameEdit3->Text;
  904. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  905. __int64 LogMaxSize;
  906. // TryStrToSize can fail, only if LogMaxSizeComboExit is bypassed due to IsCancelButtonBeingClicked
  907. if (LogMaxSizeCheck->Checked && TryStrToSize(LogMaxSizeCombo->Text, LogMaxSize))
  908. {
  909. Configuration->LogMaxSize = LogMaxSize;
  910. }
  911. else
  912. {
  913. Configuration->LogMaxSize = 0;
  914. }
  915. Configuration->LogMaxCount = (LogMaxSizeCountCheck->Checked ? LogMaxSizeCountEdit->AsInteger : 0);
  916. BOOLPROP(LogSensitive);
  917. Configuration->LogActions = EnableActionsLoggingCheck->Checked;
  918. Configuration->ActionsLogFileName = ActionsLogFileNameEdit->Text;
  919. // languages
  920. if (LanguagesView->ItemFocused != NULL)
  921. {
  922. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data);
  923. LCID Locale;
  924. // Do not change the locale settings, unless changed explicitly by user
  925. // to allow an automatic upgrade to new translation once the UI language translation
  926. // becomes available
  927. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  928. {
  929. Locale = NULL;
  930. }
  931. else
  932. {
  933. Locale = LocaleInfo->Locale;
  934. }
  935. GUIConfiguration->Locale = Locale;
  936. }
  937. #undef BOOLPROP
  938. }
  939. __finally
  940. {
  941. Configuration->EndUpdate();
  942. }
  943. bool MoveStorage = true;
  944. TStorage Storage;
  945. if (RegistryStorageButton->Checked)
  946. {
  947. Storage = stRegistry;
  948. }
  949. else if (AutomaticIniFileStorageButton->Checked)
  950. {
  951. Storage = stIniFile;
  952. }
  953. else if (CustomIniFileStorageButton->Checked)
  954. {
  955. Storage = stIniFile;
  956. }
  957. else
  958. {
  959. MoveStorage = false;
  960. }
  961. if (MoveStorage)
  962. {
  963. Configuration->MoveStorage(Storage, GetCustomIniFileStorageName());
  964. }
  965. }
  966. //---------------------------------------------------------------------------
  967. TUpdatesConfiguration __fastcall TPreferencesDialog::SaveUpdates()
  968. {
  969. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  970. if (UpdatesPeriodCombo->ItemIndex == 0)
  971. {
  972. Updates.Period = 0;
  973. }
  974. else if (UpdatesPeriodCombo->ItemIndex == 1)
  975. {
  976. Updates.Period = 1;
  977. }
  978. else if (UpdatesPeriodCombo->ItemIndex == 2)
  979. {
  980. Updates.Period = 7;
  981. }
  982. else
  983. {
  984. Updates.Period = 30;
  985. }
  986. Updates.ShowOnStartup = UpdatesShowOnStartup->Checked;
  987. Updates.AuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  988. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  989. if (UpdatesDirectCheck->Checked)
  990. {
  991. Updates.ConnectionType = ctDirect;
  992. }
  993. else if (UpdatesAutoCheck->Checked)
  994. {
  995. Updates.ConnectionType = ctAuto;
  996. }
  997. else if (UpdatesProxyCheck->Checked)
  998. {
  999. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  1000. {
  1001. Updates.ConnectionType = ctProxy;
  1002. }
  1003. else
  1004. {
  1005. Updates.ConnectionType = ctDirect;
  1006. }
  1007. }
  1008. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  1009. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  1010. return Updates;
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. TInterface __fastcall TPreferencesDialog::GetInterface()
  1014. {
  1015. return CommanderInterfaceButton2->Checked ? ifCommander : ifExplorer;
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  1019. {
  1020. // Load only now, particularly so that we have handles allocated already.
  1021. // If called before ShowModal, we end up recreating the handles,
  1022. // what causes flicker of the currently focused window
  1023. LoadConfiguration();
  1024. InstallPathWordBreakProc(RandomSeedFileEdit);
  1025. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  1026. InstallPathWordBreakProc(PuttyPathEdit);
  1027. InstallPathWordBreakProc(LogFileNameEdit3);
  1028. InstallPathWordBreakProc(ActionsLogFileNameEdit);
  1029. ListView_SetExtendedListViewStyle(CustomCommandsView->Handle, (ListView_GetExtendedListViewStyle(CustomCommandsView->Handle) & ~LVS_EX_INFOTIP));
  1030. PrepareNavigationTree(NavigationTree);
  1031. switch (FPreferencesMode) {
  1032. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  1033. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  1034. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  1035. case pmLogging: PageControl->ActivePage = LogSheet; break;
  1036. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  1037. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  1038. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  1039. case pmCommander: PageControl->ActivePage = CommanderSheet; break;
  1040. case pmEditorInternal: PageControl->ActivePage = EditorInternalSheet; break;
  1041. case pmFileColors: PageControl->ActivePage = FileColorsSheet; break;
  1042. default: PageControl->ActivePage = PreferencesSheet; break;
  1043. }
  1044. PageControlChange(NULL);
  1045. ActiveControl = NavigationTree;
  1046. }
  1047. //---------------------------------------------------------------------------
  1048. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  1049. {
  1050. UpdateControls();
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  1054. {
  1055. UnicodeString Result;
  1056. for (int Index = 1; Index <= Values.Length(); Index++)
  1057. {
  1058. if (Index > 1)
  1059. {
  1060. Result += L' ';
  1061. if (EditorTabSizeEdit->AsInteger > 2)
  1062. {
  1063. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  1064. }
  1065. }
  1066. Result += Values[Index];
  1067. }
  1068. return Result;
  1069. }
  1070. //---------------------------------------------------------------------------
  1071. TCustomCommandList * __fastcall TPreferencesDialog::GetCommandList(int Index)
  1072. {
  1073. if (Index < FCustomCommandList->Count)
  1074. {
  1075. return FCustomCommandList;
  1076. }
  1077. else
  1078. {
  1079. return FExtensionList;
  1080. }
  1081. }
  1082. //---------------------------------------------------------------------------
  1083. int __fastcall TPreferencesDialog::GetCommandIndex(int Index)
  1084. {
  1085. if (Index >= FCustomCommandList->Count)
  1086. {
  1087. Index -= FCustomCommandList->Count;
  1088. }
  1089. return Index;
  1090. }
  1091. //---------------------------------------------------------------------------
  1092. int __fastcall TPreferencesDialog::GetListCommandIndex(TCustomCommandList * List)
  1093. {
  1094. int Index;
  1095. if (GetCommandList(CustomCommandsView->ItemIndex) == List)
  1096. {
  1097. Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1098. }
  1099. else
  1100. {
  1101. Index = -1;
  1102. }
  1103. return Index;
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. int __fastcall TPreferencesDialog::GetCommandListIndex(TCustomCommandList * List, int Index)
  1107. {
  1108. if (List == FExtensionList)
  1109. {
  1110. Index += FCustomCommandList->Count;
  1111. }
  1112. return Index;
  1113. }
  1114. //---------------------------------------------------------------------------
  1115. void __fastcall TPreferencesDialog::UpdateControls()
  1116. {
  1117. if (FNoUpdate == 0)
  1118. {
  1119. EnableControl(DDTransferConfirmationCheck2, ConfirmTransferringCheck->Checked);
  1120. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  1121. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  1122. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  1123. EnableControl(ResumeThresholdUnitLabel2, ResumeThresholdEdit->Enabled);
  1124. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  1125. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  1126. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  1127. EnableControl(SessionReopenAutoIdleEdit, SessionReopenAutoIdleCheck->Checked);
  1128. EnableControl(SessionReopenAutoIdleLabel, SessionReopenAutoIdleEdit->Enabled);
  1129. EnableControl(SessionReopenAutoIdleSecLabel, SessionReopenAutoIdleEdit->Enabled);
  1130. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  1131. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  1132. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  1133. EnableControl(SessionReopenTimeoutEdit,
  1134. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  1135. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  1136. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  1137. EnableControl(CopyOnDoubleClickConfirmationCheck,
  1138. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  1139. TFont * ActualPanelFont = PanelFontCheck->Checked ? FPanelFont.get() : Screen->IconFont;
  1140. std::unique_ptr<TFont> PanelFont(new TFont());
  1141. PanelFont->Assign(ActualPanelFont);
  1142. if (PanelFontCheck->Checked)
  1143. {
  1144. PanelFont->Height = ScaleByPixelsPerInchFromSystem(PanelFont->Height, this);
  1145. }
  1146. else
  1147. {
  1148. PanelFont->Height = ScaleByPixelsPerInchFromSystem(PanelFont->Height, this);
  1149. }
  1150. UnicodeString PanelFontLabelText;
  1151. PanelFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  1152. (ActualPanelFont->Name, ActualPanelFont->Size));
  1153. PanelFontLabel->Caption = PanelFontLabelText;
  1154. if (!SameFont(PanelFontLabel->Font, PanelFont.get()))
  1155. {
  1156. PanelFontLabel->Font = PanelFont.get();
  1157. }
  1158. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  1159. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  1160. UnicodeString EditorFontLabelText;
  1161. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  1162. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  1163. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  1164. EditorFontLabelText += TabSample(L"1234");
  1165. EditorFontLabel->Caption = EditorFontLabelText;
  1166. EditorFontLabel->Color = GetWindowColor(FEditorBackgroundColor);
  1167. std::unique_ptr<TFont> EditorFont(new TFont());
  1168. EditorFont->Assign(FEditorFont.get());
  1169. EditorFont->Color = GetWindowTextColor(EditorFontLabel->Color, FEditorFont->Color);
  1170. EditorFont->Size = ScaleByPixelsPerInchFromSystem(FEditorFont->Size, this);
  1171. if (!SameFont(EditorFontLabel->Font, EditorFont.get()) ||
  1172. (EditorFontLabel->Font->Color != EditorFont->Color))
  1173. {
  1174. EditorFontLabel->Font = EditorFont.get();
  1175. }
  1176. TCustomCommandList * CommandList = GetCommandList(CustomCommandsView->ItemIndex);
  1177. int CommandIndex = GetCommandIndex(CustomCommandsView->ItemIndex);
  1178. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  1179. bool CustomCommandSelected = CommandSelected && (CommandList == FCustomCommandList);
  1180. bool ExtensionSelected = CommandSelected && (CommandList == FExtensionList);
  1181. EnableControl(EditCommandButton, CustomCommandSelected);
  1182. EditCommandButton->Visible = !ExtensionSelected;
  1183. EnableControl(ConfigureCommandButton, ExtensionSelected);
  1184. ConfigureCommandButton->Visible = ExtensionSelected;
  1185. EnableControl(RemoveCommandButton, CommandSelected);
  1186. EnableControl(UpCommandButton, CommandSelected && (CommandIndex > 0));
  1187. EnableControl(DownCommandButton, CommandSelected && (CommandIndex < CommandList->Count - 1));
  1188. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  1189. EnableControl(EditCopyParamButton, CopyParamSelected);
  1190. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  1191. EnableControl(RemoveCopyParamButton,
  1192. CopyParamSelected && (CopyParamListView->ItemIndex >= 1));
  1193. EnableControl(UpCopyParamButton,
  1194. CopyParamSelected && (CopyParamListView->ItemIndex > 1));
  1195. EnableControl(DownCopyParamButton,
  1196. CopyParamSelected &&
  1197. (CopyParamListView->ItemIndex >= 1) &&
  1198. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  1199. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  1200. UnicodeString InfoStr;
  1201. if (CopyParamSelected)
  1202. {
  1203. const TCopyParamType * SelectedCopyParam = GetCopyParam(CopyParamListView->ItemIndex);
  1204. InfoStr = SelectedCopyParam->GetInfoStr(L"; ", 0);
  1205. if (CopyParamListView->ItemIndex >= 1)
  1206. {
  1207. const TCopyParamRule * Rule = FCopyParamList->Rules[CopyParamListView->ItemIndex - 1];
  1208. if (Rule != NULL)
  1209. {
  1210. InfoStr += L"\n" + FORMAT(ReplaceStr(LoadStr(COPY_PARAM_RULE), L"\n", L" "), (Rule->GetInfoStr(L"; ")));
  1211. }
  1212. }
  1213. }
  1214. SetLabelHintPopup(CopyParamLabel, InfoStr);
  1215. if (WinConfiguration->IsDDExtBroken())
  1216. {
  1217. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_BROKEN);
  1218. DragExtStatusLabel->Enabled = false;
  1219. DragExtStatusLabel->Font->Color = clWindowText;
  1220. }
  1221. else if (!WinConfiguration->DDExtInstalled)
  1222. {
  1223. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_INSTALLED);
  1224. DragExtStatusLabel->Enabled = false;
  1225. DragExtStatusLabel->Font->Color = clWindowText;
  1226. }
  1227. else if (!WinConfiguration->IsDDExtRunning())
  1228. {
  1229. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_RUNNING);
  1230. DragExtStatusLabel->Enabled = DDFakeFileEnabledButton->Checked;
  1231. DragExtStatusLabel->Font->Color = clGrayText;
  1232. }
  1233. else
  1234. {
  1235. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_RUNNING);
  1236. DragExtStatusLabel->Enabled = DDFakeFileEnabledButton->Checked;
  1237. DragExtStatusLabel->Font->Color = clWindowText;
  1238. }
  1239. EnableControl(DDDrivesMemo, DDFakeFileEnabledButton->Checked);
  1240. EnableControl(DDDrivesLabel, DDDrivesMemo->Enabled);
  1241. EnableControl(DDFakeFileDisabledPanel, DDFakeFileDisabledButton->Checked);
  1242. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  1243. DDCustomTemporaryDirectoryButton->Checked);
  1244. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  1245. TemporaryDirectoryCleanupCheck->Checked);
  1246. // do not allow switching storage, when we start with stNul,
  1247. // as that would destroy the stored configuration
  1248. EnableControl(StorageGroup, Configuration->Storage != stNul);
  1249. AutomaticIniFileStorageLabel->UpdateStatus();
  1250. EnableControl(CustomIniFileStorageEdit, CustomIniFileStorageButton->Checked);
  1251. // editors
  1252. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1253. bool EditorSelected = (EditorListView3->Selected != NULL);
  1254. EnableControl(EditEditorButton, EditorSelected);
  1255. EnableControl(RemoveEditorButton, EditorSelected);
  1256. EnableControl(UpEditorButton, EditorSelected &&
  1257. (EditorListView3->ItemIndex > 0));
  1258. EnableControl(DownEditorButton, EditorSelected &&
  1259. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1260. // file colors
  1261. bool FileColorSelected = (FileColorsView->Selected != NULL);
  1262. EnableControl(EditFileColorButton, FileColorSelected);
  1263. EnableControl(RemoveFileColorButton, FileColorSelected);
  1264. EnableControl(UpFileColorButton, FileColorSelected && (FileColorsView->ItemIndex > 0));
  1265. EnableControl(DownFileColorButton, FileColorSelected && (FileColorsView->ItemIndex < FileColorsView->Items->Count - 1));
  1266. // updates
  1267. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1268. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1269. EnableControl(UpdatesShowOnStartup, !IsUWP());
  1270. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1271. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1272. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1273. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1274. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1275. bool IsSiteCommand = false;
  1276. bool IsPasswordCommand = false;
  1277. try
  1278. {
  1279. TRemoteCustomCommand RemoteCustomCommand;
  1280. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1281. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1282. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1283. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1284. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1285. }
  1286. catch (...)
  1287. {
  1288. // noop
  1289. }
  1290. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1291. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1292. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1293. EnableControl(TelnetForFtpInPuttyCheck,
  1294. AnyPuttyPath && !IsSiteCommand);
  1295. EnableControl(PuttyRegistryStorageKeyEdit,
  1296. AnyPuttyPath && !IsSiteCommand && !IsUWP());
  1297. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1298. // security
  1299. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1300. UpdateSshHostCAsViewView();
  1301. bool SshHostCASelected = (SshHostCAsView->Selected != NULL);
  1302. EnableControl(EditSshHostCAButton, SshHostCASelected);
  1303. EnableControl(RemoveSshHostCAButton, SshHostCASelected);
  1304. // network
  1305. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1306. EnableControl(LocalPortNumberMinEdit, LocalPortNumberCheck->Checked);
  1307. EnableControl(LocalPortNumberMaxEdit, LocalPortNumberCheck->Checked);
  1308. EnableControl(LocalPortNumberRangeLabel, LocalPortNumberCheck->Checked);
  1309. // window
  1310. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1311. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1312. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1313. !Configuration->DisablePasswordStoring &&
  1314. AutoWorkspaceCombo->Enabled);
  1315. EnableControl(ShowTipsCheck, AnyTips());
  1316. // integration
  1317. EnableControl(ShellIconsGroup, !IsUWP());
  1318. MakeDefaultHandlerItem->Visible = IsWinVista();
  1319. // languages
  1320. LanguageChangeLabel->Visible =
  1321. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1322. (LanguagesView->ItemFocused != NULL) &&
  1323. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1324. // logging
  1325. EnableControl(LogProtocolCombo2, EnableLoggingCheck->Checked);
  1326. EnableControl(LogFileNameEdit3, LogProtocolCombo2->Enabled);
  1327. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1328. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1329. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1330. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1331. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1332. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1333. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1334. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1335. EnableControl(LogSensitiveCheck, LogProtocolCombo2->Enabled);
  1336. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1337. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1338. LogProtocolHintLabel->Visible = (LogProtocolCombo2->ItemIndex - BelowNormalLogLevels >= 2);
  1339. // interface
  1340. InterfaceChangeLabel->Visible =
  1341. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1342. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1343. // background
  1344. EnableControl(ParallelTransferCheck, QueueParallelCheck->Checked);
  1345. EnableControl(ParallelTransferThresholdCombo, ParallelTransferCheck->Enabled && ParallelTransferCheck->Checked);
  1346. EnableControl(ParallelTransferThresholdUnitLabel, ParallelTransferThresholdCombo->Enabled);
  1347. }
  1348. }
  1349. //---------------------------------------------------------------------------
  1350. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1351. {
  1352. if (FontDialog(FEditorFont.get()))
  1353. {
  1354. UpdateControls();
  1355. }
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1359. {
  1360. FEditorFont->Color = Color;
  1361. UpdateControls();
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1365. {
  1366. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1367. // "internal error" when passing menu directly to unique_ptr.
  1368. // Splitting it to two statements seems to help.
  1369. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick, TOpenLocalPathHandler::Open and TSelectMaskDialog::ColorButtonClick
  1370. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1371. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1372. FColorPopupMenu.reset(Menu);
  1373. MenuPopup(Menu, EditorFontColorButton);
  1374. }
  1375. //---------------------------------------------------------------------------
  1376. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1377. {
  1378. FEditorBackgroundColor = Color;
  1379. UpdateControls();
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1383. {
  1384. // See comment in EditorFontColorButtonClick.
  1385. // We are using session color (contrary to editor text color) for background
  1386. // for a consistency with color selection menu on editor toolbar.
  1387. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1388. FColorPopupMenu.reset(PopupMenu);
  1389. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1390. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1391. }
  1392. //---------------------------------------------------------------------------
  1393. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1394. {
  1395. if (FontDialog(FPanelFont.get()))
  1396. {
  1397. PanelFontCheck->Checked = true;
  1398. UpdateControls();
  1399. }
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1403. bool & /*CanClose*/)
  1404. {
  1405. if (ModalResult == DefaultResult(this))
  1406. {
  1407. ExitActiveControl(this);
  1408. }
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1412. {
  1413. UnicodeString IconName, Params;
  1414. int SpecialFolder;
  1415. if (Sender == DesktopIconButton)
  1416. {
  1417. IconName = AppName;
  1418. int Result =
  1419. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1420. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1421. switch (Result)
  1422. {
  1423. case qaYes:
  1424. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1425. break;
  1426. case qaNo:
  1427. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1428. break;
  1429. default:
  1430. Abort();
  1431. break;
  1432. }
  1433. }
  1434. else if (Sender == SendToHookButton)
  1435. {
  1436. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1437. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1438. {
  1439. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1440. SpecialFolder = CSIDL_SENDTO;
  1441. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1442. }
  1443. else
  1444. {
  1445. Abort();
  1446. }
  1447. }
  1448. else
  1449. {
  1450. DebugFail();
  1451. Abort();
  1452. }
  1453. TInstantOperationVisualizer Visualizer;
  1454. CreateAppDesktopShortCut(IconName, Params, L"", SpecialFolder);
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1458. TListItem * Item)
  1459. {
  1460. // WORKAROUND We get here on Wine after destructor is called
  1461. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1462. {
  1463. int Index = Item->Index;
  1464. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1465. UnicodeString Caption = StripHotkey(Command->Name);
  1466. Item->Caption = Caption;
  1467. DebugAssert(!Item->SubItems->Count);
  1468. Item->SubItems->Add(Command->Command);
  1469. Item->SubItems->Add(LoadStr(
  1470. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1471. }
  1472. }
  1473. //---------------------------------------------------------------------------
  1474. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1475. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1476. {
  1477. UpdateControls();
  1478. }
  1479. //---------------------------------------------------------------------------
  1480. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1481. {
  1482. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1483. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1484. CustomCommandsView->Invalidate();
  1485. // particularly after command is edited/configured, make sure the hint is updated,
  1486. // even if we manage to display a hint for the same command as before the change
  1487. FCustomCommandsHintItem = NULL;
  1488. }
  1489. //---------------------------------------------------------------------------
  1490. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1491. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1492. {
  1493. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1494. {
  1495. RemoveCommandButtonClick(NULL);
  1496. }
  1497. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1498. {
  1499. AddEditCommand(false);
  1500. }
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1504. TObject * /*Sender*/)
  1505. {
  1506. if (EditCommandButton->Enabled)
  1507. {
  1508. AddEditCommand(true);
  1509. }
  1510. else if (ConfigureCommandButton->Enabled)
  1511. {
  1512. ConfigureCommand();
  1513. }
  1514. }
  1515. //---------------------------------------------------------------------------
  1516. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1517. {
  1518. if (Index >= 0)
  1519. {
  1520. List->Insert(Index, Command);
  1521. }
  1522. else
  1523. {
  1524. List->Add(Command);
  1525. Index = List->Count - 1;
  1526. }
  1527. return Index;
  1528. }
  1529. //---------------------------------------------------------------------------
  1530. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1531. {
  1532. TShortCuts ShortCuts;
  1533. if (WinConfiguration->SharedBookmarks != NULL)
  1534. {
  1535. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1536. }
  1537. FCustomCommandList->ShortCuts(ShortCuts);
  1538. FExtensionList->ShortCuts(ShortCuts);
  1539. return ShortCuts;
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1543. {
  1544. TCustomCommandType Command;
  1545. if (Edit)
  1546. {
  1547. int Index = CustomCommandsView->ItemIndex;
  1548. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1549. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1550. }
  1551. TShortCuts ShortCuts = GetShortCuts();
  1552. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1553. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1554. {
  1555. int Index = GetListCommandIndex(FCustomCommandList);
  1556. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1557. if (Edit)
  1558. {
  1559. DebugAssert(Index < FCustomCommandList->Count);
  1560. FCustomCommandList->Change(Index, ACommand);
  1561. }
  1562. else
  1563. {
  1564. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1565. }
  1566. UpdateCustomCommandsView();
  1567. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1568. CustomCommandsView->ItemFocused->MakeVisible(false);
  1569. UpdateControls();
  1570. }
  1571. }
  1572. //---------------------------------------------------------------------------
  1573. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1574. TObject * /*Sender*/)
  1575. {
  1576. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1577. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1578. if (List == FExtensionList)
  1579. {
  1580. const TCustomCommandType * CustomComand = List->Commands[Index];
  1581. // If the extension was added in this "preferences session", remove the file
  1582. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1583. if (PathIndex >= 0)
  1584. {
  1585. FAddedExtensions->Delete(PathIndex);
  1586. DeleteFile(ApiPath(CustomComand->FileName));
  1587. }
  1588. }
  1589. List->Delete(Index);
  1590. UpdateCustomCommandsView();
  1591. UpdateControls();
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1595. {
  1596. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1597. int SourceIndex = GetCommandIndex(Source);
  1598. int DestIndex = GetCommandIndex(Dest);
  1599. List->Move(SourceIndex, DestIndex);
  1600. CustomCommandsView->ItemIndex = Dest;
  1601. UpdateCustomCommandsView();
  1602. UpdateControls();
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1606. {
  1607. CustomCommandMove(CustomCommandsView->ItemIndex,
  1608. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1612. {
  1613. if (ListView == CopyParamListView)
  1614. {
  1615. return FCopyParamScrollOnDragOver;
  1616. }
  1617. else if (ListView == CustomCommandsView)
  1618. {
  1619. return FCustomCommandsScrollOnDragOver;
  1620. }
  1621. else if (ListView == EditorListView3)
  1622. {
  1623. return FEditorScrollOnDragOver;
  1624. }
  1625. else if (ListView == FileColorsView)
  1626. {
  1627. return FFileColorScrollOnDragOver;
  1628. }
  1629. else
  1630. {
  1631. DebugFail();
  1632. return NULL;
  1633. }
  1634. }
  1635. //---------------------------------------------------------------------------
  1636. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1637. TObject * Sender, TDragObject *& /*DragObject*/)
  1638. {
  1639. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1640. FListViewDragDest = -1;
  1641. ScrollOnDragOver(Sender)->StartDrag();
  1642. }
  1643. //---------------------------------------------------------------------------
  1644. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1645. {
  1646. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1647. return Item ? Item->Index : -1;
  1648. }
  1649. //---------------------------------------------------------------------------
  1650. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1651. {
  1652. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1653. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1654. }
  1655. //---------------------------------------------------------------------------
  1656. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1657. TObject * Sender, TObject * Source, int X, int Y)
  1658. {
  1659. if (Source == CustomCommandsView)
  1660. {
  1661. if (AllowListViewDrag(Sender, X, Y) &&
  1662. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1663. {
  1664. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1665. }
  1666. }
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1670. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1671. {
  1672. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1673. if (Source == Sender)
  1674. {
  1675. int Dest = PointToListViewIndex(Sender, X, Y);
  1676. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1677. {
  1678. Accept = false;
  1679. }
  1680. }
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TPreferencesDialog::ListViewDragOver(
  1684. TObject * Sender, TObject * Source, int X, int Y,
  1685. TDragState /*State*/, bool & Accept)
  1686. {
  1687. if (Source == Sender)
  1688. {
  1689. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1690. // (when dropped on item itself, when it was dragged over another item before,
  1691. // that another item remains highlighted forever)
  1692. Accept = true;
  1693. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1694. }
  1695. }
  1696. //---------------------------------------------------------------------------
  1697. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1698. {
  1699. if (Index == 0)
  1700. {
  1701. return &FCopyParams;
  1702. }
  1703. else
  1704. {
  1705. return FCopyParamList->CopyParams[Index - 1];
  1706. }
  1707. }
  1708. //---------------------------------------------------------------------------
  1709. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1710. {
  1711. DebugAssert((Source > 0) && (Dest > 0));
  1712. FCopyParamList->Move(Source - 1, Dest - 1);
  1713. CopyParamListView->ItemIndex = Dest;
  1714. UpdateCopyParamListView();
  1715. UpdateControls();
  1716. }
  1717. //---------------------------------------------------------------------------
  1718. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1719. TObject * Sender, TObject * Source, int X, int Y)
  1720. {
  1721. if (Source == CopyParamListView)
  1722. {
  1723. if ((FListViewDragSource > 0) &&
  1724. AllowListViewDrag(Sender, X, Y) &&
  1725. (FListViewDragDest > 0))
  1726. {
  1727. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1728. }
  1729. }
  1730. }
  1731. //---------------------------------------------------------------------------
  1732. void __fastcall TPreferencesDialog::CopyParamListViewDragOver(
  1733. TObject * Sender, TObject * Source, int X, int Y, TDragState State, bool & Accept)
  1734. {
  1735. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1736. if (Source == Sender)
  1737. {
  1738. int Dest = PointToListViewIndex(Sender, X, Y);
  1739. if ((FListViewDragSource == 0) || (Dest == 0))
  1740. {
  1741. Accept = false;
  1742. }
  1743. }
  1744. }
  1745. //---------------------------------------------------------------------------
  1746. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1747. {
  1748. CopyParamMove(CopyParamListView->ItemIndex,
  1749. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1753. TObject * /*Sender*/)
  1754. {
  1755. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1756. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1757. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1758. UpdateCopyParamListView();
  1759. UpdateControls();
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1763. {
  1764. int Index = CopyParamListView->ItemIndex;
  1765. bool Result;
  1766. if ((Index == 0) && (Mode == cpmEdit))
  1767. {
  1768. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1769. }
  1770. else
  1771. {
  1772. TCopyParamRuleData * CopyParamRuleData =
  1773. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1774. // negative (when default is selected) means add to the end
  1775. Index--;
  1776. TCopyParamType DefaultCopyParams;
  1777. // For cpmAdd use defaults.
  1778. if (Mode == cpmDuplicate)
  1779. {
  1780. // Only used, when duplicating default settings (Index < 0)
  1781. DefaultCopyParams = FCopyParams;
  1782. }
  1783. else if (Mode == cpmEdit)
  1784. {
  1785. // For cpmEdit, DefaultCopyParams is never used.
  1786. DebugAssert(Index >= 0);
  1787. }
  1788. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1789. if (Result)
  1790. {
  1791. UpdateCopyParamListView();
  1792. CopyParamListView->ItemIndex = Index + 1;
  1793. // when using duplicate button, focus remains on original item
  1794. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1795. }
  1796. }
  1797. if (Result)
  1798. {
  1799. UpdateControls();
  1800. }
  1801. }
  1802. //---------------------------------------------------------------------------
  1803. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1804. {
  1805. AddEditCopyParam(cpmAdd);
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1809. {
  1810. AddEditCopyParam(cpmEdit);
  1811. }
  1812. //---------------------------------------------------------------------------
  1813. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1814. {
  1815. AddEditCopyParam(cpmDuplicate);
  1816. }
  1817. //---------------------------------------------------------------------------
  1818. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1819. TObject * /*Sender*/)
  1820. {
  1821. if (EditCopyParamButton->Enabled)
  1822. {
  1823. AddEditCopyParam(cpmEdit);
  1824. }
  1825. }
  1826. //---------------------------------------------------------------------------
  1827. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1828. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1829. {
  1830. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1831. {
  1832. RemoveCopyParamButtonClick(NULL);
  1833. }
  1834. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1835. {
  1836. AddEditCopyParam(cpmAdd);
  1837. }
  1838. }
  1839. //---------------------------------------------------------------------------
  1840. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1841. {
  1842. FEditorList->Move(Source, Dest);
  1843. EditorListView3->ItemIndex = Dest;
  1844. UpdateEditorListView();
  1845. UpdateControls();
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1849. TObject * Source, int X, int Y)
  1850. {
  1851. if (Source == EditorListView3)
  1852. {
  1853. if (AllowListViewDrag(Sender, X, Y))
  1854. {
  1855. EditorMove(FListViewDragSource, FListViewDragDest);
  1856. }
  1857. }
  1858. }
  1859. //---------------------------------------------------------------------------
  1860. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1861. {
  1862. EditorMove(EditorListView3->ItemIndex,
  1863. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1864. }
  1865. //---------------------------------------------------------------------------
  1866. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1867. TObject * /*Sender*/)
  1868. {
  1869. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1870. EditorListView3->ItemIndex < FEditorList->Count);
  1871. FEditorList->Delete(EditorListView3->ItemIndex);
  1872. UpdateEditorListView();
  1873. UpdateControls();
  1874. }
  1875. //---------------------------------------------------------------------------
  1876. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1877. {
  1878. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1879. int Index = EditorListView3->ItemIndex;
  1880. TEditorPreferences * Editor;
  1881. if (Mode == epmEdit)
  1882. {
  1883. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1884. }
  1885. else
  1886. {
  1887. Editor = new TEditorPreferences();
  1888. }
  1889. try
  1890. {
  1891. bool DummyRemember = false;
  1892. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1893. {
  1894. if (Mode == epmEdit)
  1895. {
  1896. FEditorList->Change(Index, Editor);
  1897. }
  1898. else
  1899. {
  1900. if (Index < 0)
  1901. {
  1902. Index = FEditorList->Count;
  1903. FEditorList->Add(Editor);
  1904. }
  1905. else
  1906. {
  1907. FEditorList->Insert(Index, Editor);
  1908. }
  1909. }
  1910. // ownership of the object lost
  1911. Editor = NULL;
  1912. UpdateEditorListView();
  1913. EditorListView3->ItemIndex = Index;
  1914. UpdateControls();
  1915. }
  1916. }
  1917. __finally
  1918. {
  1919. delete Editor;
  1920. }
  1921. }
  1922. //---------------------------------------------------------------------------
  1923. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1924. {
  1925. if (EditEditorButton->Enabled)
  1926. {
  1927. AddEditEditorButtonClick(EditEditorButton);
  1928. }
  1929. }
  1930. //---------------------------------------------------------------------------
  1931. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1932. WORD & Key, TShiftState /*Shift*/)
  1933. {
  1934. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1935. {
  1936. RemoveEditorButtonClick(NULL);
  1937. }
  1938. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1939. {
  1940. AddEditEditorButtonClick(AddEditorButton);
  1941. }
  1942. }
  1943. //---------------------------------------------------------------------------
  1944. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1945. {
  1946. EditorListView3->Items->Count = FEditorList->Count;
  1947. AutoSizeListColumnsWidth(EditorListView3);
  1948. EditorListView3->Invalidate();
  1949. }
  1950. //---------------------------------------------------------------------------
  1951. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1952. TListItem * Item)
  1953. {
  1954. // WORKAROUND We get here on Wine after destructor is called
  1955. if (FEditorList != NULL)
  1956. {
  1957. int Index = Item->Index;
  1958. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1959. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1960. Item->Caption = Editor->Name;
  1961. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1962. if (Editor->Data->Editor == edExternal)
  1963. {
  1964. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1965. }
  1966. }
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1970. TTreeNode * Node)
  1971. {
  1972. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1973. {
  1974. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1975. // reshow the accelerators, etc
  1976. ResetSystemSettings(this);
  1977. // This is particularly here to enable EditCopyParamButton,
  1978. // as for some reason CopyParamListView->Selected is NULL until
  1979. // its page is shown for the first time
  1980. UpdateControls();
  1981. }
  1982. }
  1983. //---------------------------------------------------------------------------
  1984. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1985. {
  1986. // this is probably only ever called from FormShow (explicitly)
  1987. bool Found = false;
  1988. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1989. {
  1990. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1991. {
  1992. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1993. PageControl->ActivePage->Tag)
  1994. {
  1995. NavigationTree->Items->Item[Index]->Selected = true;
  1996. Found = true;
  1997. }
  1998. }
  1999. }
  2000. if (DebugAlwaysTrue(Found))
  2001. {
  2002. UpdateControls();
  2003. }
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  2007. {
  2008. if (Message.CharCode == VK_TAB)
  2009. {
  2010. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  2011. if (Shift.Contains(ssCtrl))
  2012. {
  2013. TTreeNode * Node = NavigationTree->Selected;
  2014. if (!Shift.Contains(ssShift))
  2015. {
  2016. Node = Node->GetNext();
  2017. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  2018. }
  2019. else
  2020. {
  2021. if (Node->GetPrev()) Node = Node->GetPrev();
  2022. else
  2023. while (Node->GetNext()) Node = Node->GetNext();
  2024. }
  2025. Node->Selected = True;
  2026. Message.Result = 1;
  2027. return;
  2028. }
  2029. }
  2030. TForm::Dispatch(&Message);
  2031. }
  2032. //---------------------------------------------------------------------------
  2033. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  2034. {
  2035. DebugAssert(Message.HelpInfo != NULL);
  2036. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  2037. {
  2038. // invoke help for active page (not for whole form), regardless of focus
  2039. // (e.g. even if focus is on control outside pagecontrol)
  2040. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  2041. }
  2042. TForm::Dispatch(&Message);
  2043. }
  2044. //---------------------------------------------------------------------------
  2045. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  2046. {
  2047. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  2048. // we may end up using a slightly different size, so apply it straight away for consistency
  2049. UpdateControls();
  2050. TForm::Dispatch(&Message);
  2051. }
  2052. //---------------------------------------------------------------------------
  2053. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  2054. {
  2055. TMessage * M = reinterpret_cast<TMessage*>(Message);
  2056. DebugAssert(M);
  2057. if (M->Msg == CM_DIALOGKEY)
  2058. {
  2059. CMDialogKey(*((TWMKeyDown *)Message));
  2060. }
  2061. else if (M->Msg == CM_DPICHANGED)
  2062. {
  2063. CMDpiChanged(*M);
  2064. }
  2065. else if (M->Msg == WM_HELP)
  2066. {
  2067. WMHelp(*((TWMHelp *)Message));
  2068. }
  2069. else
  2070. {
  2071. TForm::Dispatch(Message);
  2072. }
  2073. }
  2074. //---------------------------------------------------------------------------
  2075. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  2076. TObject * /*Sender*/)
  2077. {
  2078. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  2079. }
  2080. //---------------------------------------------------------------------------
  2081. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  2082. {
  2083. unsigned int Result =
  2084. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  2085. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2086. if (Result == qaYes)
  2087. {
  2088. TInstantOperationVisualizer Visualizer;
  2089. RegisterForDefaultProtocols();
  2090. }
  2091. }
  2092. //---------------------------------------------------------------------------
  2093. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  2094. {
  2095. unsigned int Result =
  2096. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  2097. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2098. if (Result == qaYes)
  2099. {
  2100. TInstantOperationVisualizer Visualizer;
  2101. UnregisterForProtocols();
  2102. }
  2103. }
  2104. //---------------------------------------------------------------------------
  2105. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  2106. {
  2107. TOperationVisualizer Visualizer;
  2108. LaunchAdvancedAssociationUI();
  2109. }
  2110. //---------------------------------------------------------------------------
  2111. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  2112. {
  2113. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  2114. }
  2115. //---------------------------------------------------------------------------
  2116. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  2117. TObject * /*Sender*/)
  2118. {
  2119. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  2120. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  2121. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  2122. {
  2123. TInstantOperationVisualizer Visualizer;
  2124. AddSearchPath(AppPath);
  2125. }
  2126. }
  2127. //---------------------------------------------------------------------------
  2128. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2129. TObject * Sender)
  2130. {
  2131. EditorFontButtonClick(Sender);
  2132. }
  2133. //---------------------------------------------------------------------------
  2134. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2135. {
  2136. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2137. AutoSizeListColumnsWidth(CopyParamListView);
  2138. CopyParamListView->Invalidate();
  2139. }
  2140. //---------------------------------------------------------------------------
  2141. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2142. TListItem * Item)
  2143. {
  2144. // WORKAROUND We get here on Wine after destructor is called
  2145. if (FCopyParamList != NULL)
  2146. {
  2147. UnicodeString Name;
  2148. UnicodeString Rule;
  2149. int Index = Item->Index;
  2150. if (Index == 0)
  2151. {
  2152. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2153. }
  2154. else
  2155. {
  2156. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2157. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2158. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2159. }
  2160. Item->Caption = Name;
  2161. Item->SubItems->Add(Rule);
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2166. {
  2167. FormHelp(this);
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2171. TObject * /*Sender*/)
  2172. {
  2173. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2174. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2175. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2176. }
  2177. //---------------------------------------------------------------------------
  2178. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2179. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2180. {
  2181. FBeforeDialogPath = Name;
  2182. Name = ExpandEnvironmentVariables(Name);
  2183. }
  2184. //---------------------------------------------------------------------------
  2185. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2186. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2187. {
  2188. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2189. {
  2190. Name = FBeforeDialogPath;
  2191. }
  2192. }
  2193. //---------------------------------------------------------------------------
  2194. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2195. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2196. {
  2197. AllowCollapse = false;
  2198. }
  2199. //---------------------------------------------------------------------------
  2200. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2201. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2202. {
  2203. ScrollOnDragOver(Sender)->EndDrag();
  2204. }
  2205. //---------------------------------------------------------------------------
  2206. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2207. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2208. {
  2209. if (Value == 0)
  2210. {
  2211. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2212. Handled = true;
  2213. }
  2214. }
  2215. //---------------------------------------------------------------------------
  2216. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2217. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2218. {
  2219. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2220. {
  2221. Value = 0;
  2222. Handled = true;
  2223. }
  2224. }
  2225. //---------------------------------------------------------------------------
  2226. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2227. {
  2228. bool Result;
  2229. bool Retry;
  2230. do
  2231. {
  2232. Retry = false;
  2233. Result = !AnyOtherInstanceOfSelf();
  2234. if (!Result)
  2235. {
  2236. unsigned int Answer =
  2237. MessageDialog(
  2238. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2239. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2240. HELP_MASTER_PASSWORD);
  2241. switch (Answer)
  2242. {
  2243. case qaRetry:
  2244. Retry = true;
  2245. break;
  2246. case qaIgnore:
  2247. Result = true;
  2248. break;
  2249. case qaCancel:
  2250. default:
  2251. // noop
  2252. break;
  2253. }
  2254. }
  2255. }
  2256. while (Retry && !Result);
  2257. return Result;
  2258. }
  2259. //---------------------------------------------------------------------------
  2260. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2261. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2262. {
  2263. // Save master password.
  2264. // This is unlikely to fail, as storage is written explicitly already
  2265. // when writing the recrypted passwords
  2266. Configuration->SaveExplicit();
  2267. TQueryType QueryType = qtInformation;
  2268. if (RecryptPasswordErrors->Count > 0)
  2269. {
  2270. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2271. QueryType = qtWarning;
  2272. }
  2273. MoreMessageDialog(
  2274. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2278. {
  2279. UnicodeString NewPassword;
  2280. if (DoChangeMasterPasswordDialog(NewPassword))
  2281. {
  2282. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2283. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2284. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2285. }
  2286. }
  2287. //---------------------------------------------------------------------------
  2288. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2289. TObject * /*Sender*/)
  2290. {
  2291. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2292. {
  2293. try
  2294. {
  2295. if (CanSetMasterPassword())
  2296. {
  2297. if (UseMasterPasswordCheck->Checked)
  2298. {
  2299. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2300. }
  2301. else
  2302. {
  2303. if (DoMasterPasswordDialog())
  2304. {
  2305. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2306. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2307. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2308. }
  2309. }
  2310. }
  2311. }
  2312. __finally
  2313. {
  2314. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2315. UpdateControls();
  2316. }
  2317. }
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2321. TObject * /*Sender*/)
  2322. {
  2323. if (CanSetMasterPassword())
  2324. {
  2325. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2326. }
  2327. }
  2328. //---------------------------------------------------------------------------
  2329. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2330. {
  2331. DoUsageStatisticsDialog();
  2332. }
  2333. //---------------------------------------------------------------------------
  2334. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2335. {
  2336. if (EditCopyParamButton->Enabled)
  2337. {
  2338. AddEditCopyParam(cpmEdit);
  2339. }
  2340. }
  2341. //---------------------------------------------------------------------------
  2342. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2343. TCustomListView * Sender, TListItem * Item,
  2344. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2345. {
  2346. if (Item->Index == 0)
  2347. {
  2348. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2349. }
  2350. }
  2351. //---------------------------------------------------------------------------
  2352. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2353. {
  2354. PuttyRegistryStorageKeyEdit->ItemIndex =
  2355. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2356. }
  2357. //---------------------------------------------------------------------------
  2358. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2359. {
  2360. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2361. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2362. {
  2363. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2364. }
  2365. else if (ContainsText(PuttyPath, KittyExecutable))
  2366. {
  2367. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2368. }
  2369. UpdateControls();
  2370. }
  2371. //---------------------------------------------------------------------------
  2372. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2373. TTreeNode * Node, bool & /*AllowChange*/)
  2374. {
  2375. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2376. // delay load as this can be time consuming
  2377. if (Sheet == LanguagesSheet)
  2378. {
  2379. LoadLanguages();
  2380. }
  2381. }
  2382. //---------------------------------------------------------------------------
  2383. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2384. {
  2385. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2386. }
  2387. //---------------------------------------------------------------------------
  2388. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2389. {
  2390. CommanderInterfaceButton2->SetFocus();
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2394. {
  2395. ExplorerInterfaceButton2->SetFocus();
  2396. }
  2397. //---------------------------------------------------------------------------
  2398. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2399. {
  2400. PanelFontButtonClick(Sender);
  2401. }
  2402. //---------------------------------------------------------------------------
  2403. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2404. {
  2405. if (!IsCancelButtonBeingClicked(this))
  2406. {
  2407. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2408. {
  2409. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2410. {
  2411. TUpdatesConfiguration Updates = SaveUpdates();
  2412. {
  2413. TInstantOperationVisualizer Visualizer;
  2414. QueryUpdates(Updates);
  2415. }
  2416. if (!Updates.Results.AuthenticationError.IsEmpty())
  2417. {
  2418. UnicodeString AuthenticationError;
  2419. FormatUpdatesMessage(AuthenticationError, Updates.Results.AuthenticationError, Updates);
  2420. if (HasParagraphs(AuthenticationError))
  2421. {
  2422. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2423. }
  2424. else
  2425. {
  2426. AuthenticationError = MainInstructions(AuthenticationError);
  2427. }
  2428. unsigned int Result =
  2429. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HELP_AUTOMATIC_UPDATE);
  2430. if (Result == qaAbort)
  2431. {
  2432. Abort();
  2433. }
  2434. }
  2435. }
  2436. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2437. }
  2438. }
  2439. }
  2440. //---------------------------------------------------------------------------
  2441. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2442. {
  2443. EnableAutomaticUpdates();
  2444. }
  2445. //---------------------------------------------------------------------------
  2446. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2447. {
  2448. FOrigCustomCommandsViewWindowProc(Message);
  2449. if (Message.Msg == CN_NOTIFY)
  2450. {
  2451. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2452. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2453. {
  2454. // request CDDS_ITEMPOSTPAINT notification
  2455. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2456. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2457. int Index = CustomDraw->nmcd.dwItemSpec;
  2458. int CommandIndex = GetCommandIndex(Index);
  2459. TCustomCommandList * List = GetCommandList(Index);
  2460. // after end of every list, except for the last last list
  2461. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2462. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2463. {
  2464. TRect Rect;
  2465. Rect.Top = CustomDraw->iSubItem;
  2466. Rect.Left = LVIR_BOUNDS;
  2467. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2468. HDC DC = CustomDraw->nmcd.hdc;
  2469. SelectObject(DC, GetStockObject(DC_PEN));
  2470. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2471. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2472. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2473. }
  2474. }
  2475. }
  2476. }
  2477. //---------------------------------------------------------------------------
  2478. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2479. {
  2480. if ((Status / 10) == 49)
  2481. {
  2482. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2483. throw Exception(Message);
  2484. }
  2485. }
  2486. //---------------------------------------------------------------------------
  2487. void __fastcall TPreferencesDialog::AddExtension()
  2488. {
  2489. const UnicodeString HistoryKey(L"ExtensionPath");
  2490. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2491. UnicodeString Path;
  2492. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2493. HELP_ADD_EXTENSION, History.get(), true, NULL, true, 400) &&
  2494. !Path.IsEmpty())
  2495. {
  2496. CustomWinConfiguration->History[HistoryKey] = History.get();
  2497. bool Trusted;
  2498. bool Latest;
  2499. UnicodeString FileName;
  2500. UnicodeString ExtensionPath;
  2501. UnicodeString LinesSourcePath;
  2502. std::unique_ptr<TStringList> Lines(new TStringList());
  2503. std::unique_ptr<TCustomCommandType> CustomCommand;
  2504. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2505. try
  2506. {
  2507. UnicodeString ProvisionaryId;
  2508. if (IsUrl)
  2509. {
  2510. UnicodeString Url = Path;
  2511. Url = SecureUrl(Url);
  2512. bool WinSCPURL = IsWinSCPUrl(Url);
  2513. if (WinSCPURL)
  2514. {
  2515. Url = ProgramUrl(Url);
  2516. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2517. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2518. Url = AppendUrlParams(Url, FORMAT(L"netcore=%s", (EncodeUrlString(GetNetCoreVersionStr()))));
  2519. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2520. Url = AppendUrlParams(Url, FORMAT(L"pwsh=%s", (EncodeUrlString(GetPowerShellCoreVersionStr()))));
  2521. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2522. Url = CampaignUrl(Url);
  2523. }
  2524. TOperationVisualizer Visualizer;
  2525. std::unique_ptr<THttp> Http(CreateHttp());
  2526. Http->URL = Url;
  2527. std::unique_ptr<TStrings> Headers(new TStringList());
  2528. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2529. Http->RequestHeaders = Headers.get();
  2530. Http->OnError = ExtensionHttpError;
  2531. Http->Get();
  2532. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2533. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2534. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2535. if (FileName.IsEmpty())
  2536. {
  2537. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2538. }
  2539. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2540. Lines->Text = Http->Response;
  2541. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2542. }
  2543. else
  2544. {
  2545. if (!FileExists(ApiPath(Path)))
  2546. {
  2547. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2548. }
  2549. Trusted = true;
  2550. Latest = true;
  2551. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2552. FileName = ExtractFileName(Path);
  2553. if (!Id.IsEmpty())
  2554. {
  2555. ExtensionPath = Path;
  2556. ProvisionaryId = Id;
  2557. }
  2558. else
  2559. {
  2560. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2561. }
  2562. LinesSourcePath = Path;
  2563. LoadScriptFromFile(Path, Lines.get());
  2564. }
  2565. // validate syntax
  2566. CustomCommand.reset(new TCustomCommandType());
  2567. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2568. CustomCommand->Id = ProvisionaryId;
  2569. CustomCommand->LoadExtension(Lines.get(), FileName);
  2570. }
  2571. catch (Exception & E)
  2572. {
  2573. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2574. }
  2575. if (!ExtensionPath.IsEmpty())
  2576. {
  2577. int Index = FExtensionList->FindIndexByFileName(Path);
  2578. if (Index >= 0)
  2579. {
  2580. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2581. CustomCommandsView->ItemFocused->MakeVisible(false);
  2582. CustomCommandsView->SetFocus();
  2583. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2584. }
  2585. }
  2586. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2587. {
  2588. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2589. }
  2590. if (ExtensionPath.IsEmpty())
  2591. {
  2592. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2593. {
  2594. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2595. if (FileNameOnly.IsEmpty())
  2596. {
  2597. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2598. }
  2599. else
  2600. {
  2601. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2602. }
  2603. }
  2604. }
  2605. if (Trusted ||
  2606. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2607. {
  2608. if (ExtensionPath.IsEmpty())
  2609. {
  2610. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2611. if (!DirectoryExists(UserExtensionsPath) &&
  2612. !ForceDirectories(UserExtensionsPath))
  2613. {
  2614. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2615. }
  2616. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2617. int Counter = 1;
  2618. UnicodeString OriginalExtensionPath = ExtensionPath;
  2619. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2620. while (FileExists(ApiPath(ExtensionPath)))
  2621. {
  2622. Counter++;
  2623. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2624. }
  2625. if (!LinesSourcePath.IsEmpty())
  2626. {
  2627. // Copy as is, exactly preserving the file encoding
  2628. TFile::Copy(ApiPath(LinesSourcePath), ApiPath(ExtensionPath));
  2629. }
  2630. else
  2631. {
  2632. Lines->WriteBOM = false;
  2633. Lines->SaveToFile(ApiPath(ExtensionPath));
  2634. }
  2635. FAddedExtensions->Add(ExtensionPath);
  2636. }
  2637. int Index = GetListCommandIndex(FExtensionList);
  2638. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2639. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2640. CustomCommand->LoadExtension(ExtensionPath);
  2641. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2642. UpdateCustomCommandsView();
  2643. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2644. CustomCommandsView->ItemFocused->MakeVisible(false);
  2645. UpdateControls();
  2646. if (!Latest)
  2647. {
  2648. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2649. }
  2650. if (IsUrl)
  2651. {
  2652. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2653. }
  2654. else
  2655. {
  2656. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2657. }
  2658. }
  2659. }
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2663. {
  2664. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2665. {
  2666. AddEditCommand(false);
  2667. }
  2668. else
  2669. {
  2670. AddExtension();
  2671. }
  2672. }
  2673. //---------------------------------------------------------------------------
  2674. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2675. {
  2676. AddEditCommand(false);
  2677. }
  2678. //---------------------------------------------------------------------------
  2679. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2680. {
  2681. AddExtension();
  2682. }
  2683. //---------------------------------------------------------------------------
  2684. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2685. {
  2686. AddEditCommand(true);
  2687. }
  2688. //---------------------------------------------------------------------------
  2689. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2690. {
  2691. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2692. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2693. MenuPopup(AddCommandMenu, AddCommandButton);
  2694. }
  2695. //---------------------------------------------------------------------------
  2696. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2697. {
  2698. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2699. UnicodeString Result;
  2700. if (Terminal != NULL)
  2701. {
  2702. Result = Terminal->SessionData->SessionKey;
  2703. }
  2704. return Result;
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2708. {
  2709. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2710. int Index = (Item != NULL) ? Item->Index : -1;
  2711. if (Index != FCustomCommandsHintItem)
  2712. {
  2713. Application->CancelHint();
  2714. UnicodeString Hint;
  2715. if (Index >= 0)
  2716. {
  2717. TCustomCommandList * List = GetCommandList(Index);
  2718. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2719. Hint = StripHotkey(Command->Name);
  2720. if (Command->ShortCut != 0)
  2721. {
  2722. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2723. }
  2724. if (!Command->Description.IsEmpty())
  2725. {
  2726. Hint += L"\n" + Command->Description;
  2727. }
  2728. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2729. if (List == FExtensionList)
  2730. {
  2731. Hint += L"\n" + Command->FileName;
  2732. }
  2733. }
  2734. CustomCommandsView->Hint = Hint;
  2735. FCustomCommandsHintItem = Index;
  2736. }
  2737. }
  2738. //---------------------------------------------------------------------------
  2739. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2740. {
  2741. PageControl->ActivePage = QueueSheet;
  2742. PageControlChange(NULL);
  2743. QueueNoConfirmationCheck->SetFocus();
  2744. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2745. }
  2746. //---------------------------------------------------------------------------
  2747. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2748. {
  2749. ConfigureCommand();
  2750. }
  2751. //---------------------------------------------------------------------------
  2752. void __fastcall TPreferencesDialog::ConfigureCommand()
  2753. {
  2754. int Index = CustomCommandsView->ItemIndex;
  2755. TCustomCommandList * CommandList = GetCommandList(Index);
  2756. int CommandIndex = GetCommandIndex(Index);
  2757. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2758. UnicodeString Site = GetSessionKey();
  2759. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2760. Site.IsEmpty())
  2761. {
  2762. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2763. }
  2764. TShortCut ShortCut = Command->ShortCut;
  2765. TShortCuts ShortCuts = GetShortCuts();
  2766. if (DoCustomCommandOptionsDialog(
  2767. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2768. {
  2769. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2770. UpdatedCommand->ShortCut = ShortCut;
  2771. CommandList->Change(CommandIndex, UpdatedCommand);
  2772. UpdateCustomCommandsView();
  2773. }
  2774. }
  2775. //---------------------------------------------------------------------------
  2776. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2777. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2778. {
  2779. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2780. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2781. {
  2782. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2783. }
  2784. if (LocaleInfo->Completeness < 0)
  2785. {
  2786. Sender->Canvas->Font->Color = clRed;
  2787. }
  2788. else if (LocaleInfo->Completeness < 100)
  2789. {
  2790. Sender->Canvas->Font->Color = clGrayText;
  2791. }
  2792. }
  2793. //---------------------------------------------------------------------------
  2794. void __fastcall TPreferencesDialog::SizeComboExit(TObject * Sender)
  2795. {
  2796. __int64 Size;
  2797. if (!IsCancelButtonBeingClicked(this))
  2798. {
  2799. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Sender));
  2800. if (!TryStrToSize(ComboBox->Text, Size))
  2801. {
  2802. ComboBox->SetFocus();
  2803. throw Exception(FMTLOAD(SIZE_INVALID, (ComboBox->Text)));
  2804. }
  2805. else
  2806. {
  2807. ComboBox->Text = SizeToStr(Size);
  2808. }
  2809. }
  2810. }
  2811. //---------------------------------------------------------------------------
  2812. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2813. {
  2814. if (!IsCancelButtonBeingClicked(this))
  2815. {
  2816. try
  2817. {
  2818. UnicodeString Program, AParams, Dir;
  2819. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2820. }
  2821. catch(...)
  2822. {
  2823. PuttyPathEdit->SelectAll();
  2824. PuttyPathEdit->SetFocus();
  2825. throw;
  2826. }
  2827. }
  2828. }
  2829. //---------------------------------------------------------------------------
  2830. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2831. {
  2832. Active = AutomaticIniFileStorageButton->Checked;
  2833. }
  2834. //---------------------------------------------------------------------------
  2835. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2836. {
  2837. UnicodeString Result;
  2838. if (CustomIniFileStorageButton->Checked)
  2839. {
  2840. Result = CustomIniFileStorageEdit->Text;
  2841. }
  2842. return Result;
  2843. }
  2844. //---------------------------------------------------------------------------
  2845. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2846. {
  2847. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2848. UnicodeString CustomIniFileStorageNameExpanded = ExpandEnvironmentVariables(CustomIniFileStorageName);
  2849. if (!CustomIniFileStorageName.IsEmpty() &&
  2850. // Not expanding, as we want to allow change from explicit path to path with variables and vice versa
  2851. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2852. FileExists(CustomIniFileStorageNameExpanded))
  2853. {
  2854. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageNameExpanded));
  2855. TMessageParams Params;
  2856. TQueryButtonAlias Aliases[2];
  2857. Aliases[0].Button = qaYes;
  2858. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2859. Aliases[1].Button = qaNo;
  2860. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2861. Params.Aliases = Aliases;
  2862. Params.AliasesCount = 2;
  2863. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2864. if (Result == qaYes)
  2865. {
  2866. // noop
  2867. }
  2868. else if (Result == qaNo)
  2869. {
  2870. // Similar to TLoginDialog::ImportActionExecute
  2871. Configuration->ScheduleCustomIniFileStorageUse(CustomIniFileStorageName);
  2872. ExecuteSelf(EmptyStr);
  2873. TerminateApplication();
  2874. }
  2875. else
  2876. {
  2877. Abort();
  2878. }
  2879. }
  2880. FCustomIniFileStorageName = CustomIniFileStorageName;
  2881. }
  2882. //---------------------------------------------------------------------------
  2883. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2884. {
  2885. if (!IsCancelButtonBeingClicked(this))
  2886. {
  2887. CustomIniFileStorageChanged();
  2888. }
  2889. else
  2890. {
  2891. // Reset the value to prevent accidental overwrite of an INI file, in case the dialog cancel does not complete
  2892. CustomIniFileStorageEdit->Text = FCustomIniFileStorageName;
  2893. }
  2894. }
  2895. //---------------------------------------------------------------------------
  2896. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2897. {
  2898. PathEditAfterDialog(Sender, Name, Action);
  2899. if (Action)
  2900. {
  2901. CustomIniFileStorageEdit->Text = Name;
  2902. CustomIniFileStorageChanged();
  2903. }
  2904. }
  2905. //---------------------------------------------------------------------------
  2906. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2907. {
  2908. UpdateControls();
  2909. // Handler is called also when Checked is set from LoadConfiguration
  2910. if (FNoUpdate == 0)
  2911. {
  2912. // Focus to force validation
  2913. CustomIniFileStorageEdit->SetFocus();
  2914. }
  2915. }
  2916. //---------------------------------------------------------------------------
  2917. void __fastcall TPreferencesDialog::UpdateFileColorsView()
  2918. {
  2919. FileColorsView->Items->Count = FFileColors.size();
  2920. AutoSizeListColumnsWidth(FileColorsView);
  2921. }
  2922. //---------------------------------------------------------------------------
  2923. void __fastcall TPreferencesDialog::FileColorsViewData(TObject *, TListItem * Item)
  2924. {
  2925. Item->Caption = FFileColors[Item->Index].FileMask.Masks;
  2926. }
  2927. //---------------------------------------------------------------------------
  2928. void __fastcall TPreferencesDialog::FileColorsViewCustomDrawItem(
  2929. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  2930. {
  2931. Sender->Canvas->Font->Color = FFileColors[Item->Index].Color;
  2932. }
  2933. //---------------------------------------------------------------------------
  2934. void __fastcall TPreferencesDialog::AddEditFileColor(bool Edit)
  2935. {
  2936. TFileColorData FileColorData;
  2937. int Index = FileColorsView->ItemIndex;
  2938. if (Edit)
  2939. {
  2940. FileColorData = FFileColors[Index];
  2941. }
  2942. else
  2943. {
  2944. FileColorData.FileMask = AnyMask;
  2945. }
  2946. if (DoFileColorDialog(FileColorData))
  2947. {
  2948. if (Edit)
  2949. {
  2950. FFileColors[Index] = FileColorData;
  2951. }
  2952. else
  2953. {
  2954. if (Index < 0)
  2955. {
  2956. FFileColors.push_back(FileColorData);
  2957. }
  2958. else
  2959. {
  2960. FFileColors.insert(&FFileColors[Index], FileColorData);
  2961. }
  2962. }
  2963. UpdateFileColorsView();
  2964. FileColorsView->ItemIndex = Index;
  2965. UpdateControls();
  2966. }
  2967. }
  2968. //---------------------------------------------------------------------------
  2969. void __fastcall TPreferencesDialog::AddEditFileColorButtonClick(TObject * Sender)
  2970. {
  2971. bool Edit = (Sender == EditFileColorButton);
  2972. AddEditFileColor(Edit);
  2973. }
  2974. //---------------------------------------------------------------------------
  2975. void __fastcall TPreferencesDialog::FileColorMove(int Source, int Dest)
  2976. {
  2977. FFileColors.insert(FFileColors.begin() + Dest + ((Dest > Source) ? 1 : 0), FFileColors[Source]);
  2978. FFileColors.erase(FFileColors.begin() + Source + ((Dest < Source) ? 1 : 0));
  2979. FileColorsView->ItemIndex = Dest;
  2980. UpdateFileColorsView();
  2981. UpdateControls();
  2982. }
  2983. //---------------------------------------------------------------------------
  2984. void __fastcall TPreferencesDialog::FileColorsViewDragDrop(TObject * Sender, TObject * Source, int X, int Y)
  2985. {
  2986. if (Source == FileColorsView)
  2987. {
  2988. if (AllowListViewDrag(Sender, X, Y))
  2989. {
  2990. FileColorMove(FListViewDragSource, FListViewDragDest);
  2991. }
  2992. }
  2993. }
  2994. //---------------------------------------------------------------------------
  2995. void __fastcall TPreferencesDialog::FileColorsViewKeyDown(TObject *, WORD & Key, TShiftState)
  2996. {
  2997. if (RemoveFileColorButton->Enabled && (Key == VK_DELETE))
  2998. {
  2999. RemoveFileColorButtonClick(NULL);
  3000. }
  3001. if (DebugAlwaysTrue(AddFileColorButton->Enabled) && (Key == VK_INSERT))
  3002. {
  3003. AddEditFileColor(false);
  3004. }
  3005. }
  3006. //---------------------------------------------------------------------------
  3007. void __fastcall TPreferencesDialog::RemoveFileColorButtonClick(TObject *)
  3008. {
  3009. FFileColors.erase(FFileColors.begin() + FileColorsView->ItemIndex);
  3010. UpdateFileColorsView();
  3011. UpdateControls();
  3012. }
  3013. //---------------------------------------------------------------------------
  3014. void __fastcall TPreferencesDialog::FileColorsViewDblClick(TObject *)
  3015. {
  3016. if (EditFileColorButton->Enabled)
  3017. {
  3018. AddEditFileColor(true);
  3019. }
  3020. }
  3021. //---------------------------------------------------------------------------
  3022. void __fastcall TPreferencesDialog::UpDownFileColorButtonClick(TObject * Sender)
  3023. {
  3024. int DestIndex = FileColorsView->ItemIndex + (Sender == UpFileColorButton ? -1 : 1);
  3025. FileColorMove(FileColorsView->ItemIndex, DestIndex);
  3026. }
  3027. //---------------------------------------------------------------------------
  3028. void __fastcall TPreferencesDialog::LocalPortNumberMinEditExit(TObject *)
  3029. {
  3030. if (LocalPortNumberMinEdit->AsInteger > LocalPortNumberMaxEdit->AsInteger)
  3031. {
  3032. LocalPortNumberMaxEdit->Value = LocalPortNumberMaxEdit->MaxValue;
  3033. }
  3034. }
  3035. //---------------------------------------------------------------------------
  3036. void __fastcall TPreferencesDialog::LocalPortNumberMaxEditExit(TObject *)
  3037. {
  3038. if (LocalPortNumberMaxEdit->AsInteger < LocalPortNumberMinEdit->AsInteger)
  3039. {
  3040. if (LocalPortNumberMaxEdit->AsInteger >= PrivatePortMin)
  3041. {
  3042. LocalPortNumberMinEdit->AsInteger = PrivatePortMin;
  3043. }
  3044. else
  3045. {
  3046. LocalPortNumberMinEdit->Value = LocalPortNumberMinEdit->MinValue;
  3047. }
  3048. }
  3049. }
  3050. //---------------------------------------------------------------------------
  3051. UnicodeString TPreferencesDialog::Bullet(const UnicodeString & S)
  3052. {
  3053. // Keep in sync with similar function in installer
  3054. UnicodeString Result = S;
  3055. UnicodeString Dash(L"-");
  3056. UnicodeString Bullet(L"\u2022 ");
  3057. if (StartsStr(Dash, Result))
  3058. {
  3059. Result = Bullet + Result.SubString(Dash.Length() + 1, Result.Length() - Dash.Length());
  3060. }
  3061. Result = ReplaceStr(Result, sLineBreak + Dash, sLineBreak + Bullet);
  3062. return Result;
  3063. }
  3064. //---------------------------------------------------------------------------
  3065. void __fastcall TPreferencesDialog::SshHostCAsViewDblClick(TObject *)
  3066. {
  3067. if (EditSshHostCAButton->Enabled)
  3068. {
  3069. EditSshHostCAButtonClick(NULL);
  3070. }
  3071. }
  3072. //---------------------------------------------------------------------------
  3073. void __fastcall TPreferencesDialog::SshHostCAsViewKeyDown(TObject *, WORD & Key, TShiftState)
  3074. {
  3075. if (RemoveSshHostCAButton->Enabled && (Key == VK_DELETE))
  3076. {
  3077. RemoveSshHostCAButtonClick(NULL);
  3078. }
  3079. if (AddSshHostCAButton->Enabled && (Key == VK_INSERT))
  3080. {
  3081. AddSshHostCAButtonClick(NULL);
  3082. }
  3083. }
  3084. //---------------------------------------------------------------------------
  3085. void TPreferencesDialog::UpdateSshHostCAsViewView()
  3086. {
  3087. SshHostCAsView->Items->Count = FSshHostCAPlainList.size();
  3088. AutoSizeListColumnsWidth(SshHostCAsView, 1);
  3089. SshHostCAsView->Invalidate();
  3090. }
  3091. //---------------------------------------------------------------------------
  3092. void __fastcall TPreferencesDialog::AddSshHostCAButtonClick(TObject *)
  3093. {
  3094. TSshHostCA SshHostCA;
  3095. if (DoSshHostCADialog(true, SshHostCA))
  3096. {
  3097. FSshHostCAPlainList.push_back(SshHostCA);
  3098. UpdateSshHostCAsViewView();
  3099. SshHostCAsView->ItemIndex = FSshHostCAPlainList.size() - 1;
  3100. SshHostCAsView->ItemFocused->MakeVisible(false);
  3101. UpdateControls();
  3102. }
  3103. }
  3104. //---------------------------------------------------------------------------
  3105. void __fastcall TPreferencesDialog::SshHostCAsViewData(TObject *, TListItem * Item)
  3106. {
  3107. TSshHostCA & SshHostCA = FSshHostCAPlainList[Item->Index];
  3108. Item->Caption = SshHostCA.Name;
  3109. Item->SubItems->Add(SshHostCA.ValidityExpression);
  3110. }
  3111. //---------------------------------------------------------------------------
  3112. void __fastcall TPreferencesDialog::EditSshHostCAButtonClick(TObject *)
  3113. {
  3114. if (DoSshHostCADialog(true, FSshHostCAPlainList[SshHostCAsView->ItemIndex]))
  3115. {
  3116. UpdateSshHostCAsViewView();
  3117. UpdateControls();
  3118. }
  3119. }
  3120. //---------------------------------------------------------------------------
  3121. void __fastcall TPreferencesDialog::RemoveSshHostCAButtonClick(TObject *)
  3122. {
  3123. FSshHostCAPlainList.erase(FSshHostCAPlainList.begin() + SshHostCAsView->ItemIndex);
  3124. UpdateSshHostCAsViewView();
  3125. UpdateControls();
  3126. }
  3127. //---------------------------------------------------------------------------