Preferences.cpp 116 KB

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