Preferences.cpp 120 KB

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