Preferences.cpp 110 KB

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