Preferences.cpp 113 KB

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