Preferences.cpp 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187
  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. #ifndef NO_RESOURCES
  31. #pragma resource "*.dfm"
  32. #endif
  33. //---------------------------------------------------------------------
  34. const int BelowNormalLogLevels = 1;
  35. //---------------------------------------------------------------------
  36. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  37. TPreferencesDialogData * DialogData)
  38. {
  39. bool Result;
  40. TPreferencesDialog * PreferencesDialog =
  41. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  42. try
  43. {
  44. Result = PreferencesDialog->Execute(DialogData);
  45. if (Result)
  46. {
  47. CheckConfigurationForceSave();
  48. Configuration->SaveExplicit();
  49. }
  50. }
  51. __finally
  52. {
  53. delete PreferencesDialog;
  54. }
  55. return Result;
  56. }
  57. //---------------------------------------------------------------------
  58. __fastcall TPreferencesDialog::TPreferencesDialog(
  59. TComponent* AOwner, TPreferencesMode PreferencesMode)
  60. : TForm(AOwner)
  61. {
  62. SetCorrectFormParent(this);
  63. FNoUpdate = 0;
  64. FPreferencesMode = PreferencesMode;
  65. FEditorFont.reset(new TFont());
  66. FEditorFont->Color = clWindowText;
  67. FPanelFont.reset(new TFont());
  68. FPanelFont->Color = clWindowText;
  69. // currently useless
  70. FAfterFilenameEditDialog = false;
  71. FCustomCommandList = new TCustomCommandList();
  72. FCustomCommandChanging = false;
  73. FExtensionList = new TCustomCommandList();
  74. FListViewDragDest = -1;
  75. FCopyParamList = new TCopyParamList();
  76. FEditorList = new TEditorList();
  77. FAutomaticUpdatesPossible = IsInstalled();
  78. FCustomCommandsHintItem = NULL;
  79. FAddedExtensions.reset(CreateSortedStringList());
  80. FCustomCommandOptions.reset(new TStringList());
  81. UseSystemSettings(this);
  82. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  83. FixListColumnWidth(CustomCommandsView, -1);
  84. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  85. FixListColumnWidth(CopyParamListView, -1);
  86. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  87. FixListColumnWidth(EditorListView3, -1);
  88. FFileColorScrollOnDragOver = new TListViewScrollOnDragOver(FileColorsView, true);
  89. FOrigCustomCommandsViewWindowProc = CustomCommandsView->WindowProc;
  90. CustomCommandsView->WindowProc = CustomCommandsViewWindowProc;
  91. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  92. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta && !IsUWP());
  93. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  94. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  95. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  96. HintLabel(ShellIconsText2);
  97. HotTrackLabel(CopyParamLabel);
  98. HintLabel(PuttyPathHintText, LoadStr(PUTTY_PATTERNS_HINT2));
  99. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  100. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  101. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  102. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  103. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  104. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  105. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  106. MenuButton(RegisterAsUrlHandlersButton);
  107. MenuButton(EditorFontColorButton);
  108. MenuButton(EditorBackgroundColorButton);
  109. LoadDialogImage(CommanderInterfacePicture, L"Commander");
  110. LoadDialogImage(ExplorerInterfacePicture, L"Explorer");
  111. LinkLabel(UpdatesLink);
  112. LinkAppLabel(BackgroundConfirmationsLink);
  113. AutoSizeButton(UsageViewButton);
  114. AutomaticIniFileStorageLabel->Caption = ExpandEnvironmentVariables(Configuration->GetAutomaticIniFileStorageName(false));
  115. if (IsUWP())
  116. {
  117. UpdatesSheet->Caption = LoadStr(PREFERENCES_STATISTICS_CAPTION);
  118. int ProxyOffset = UpdatesProxyGroup->Top - UpdatesOptionsGroup->Top - UpdatesOptionsGroup->Height;
  119. UpdatesGroup2->Visible = false;
  120. UpdatesOptionsGroup->Top = UpdatesGroup2->Top;
  121. UpdatesBetaVersionsCombo->Visible = false;
  122. UpdatesBetaVersionsLabel->Visible = false;
  123. int Offset = UsageViewButton->Top - UpdatesBetaVersionsCombo->Top;
  124. CollectUsageCheck->Top = CollectUsageCheck->Top - Offset;
  125. UsageViewButton->Top = UsageViewButton->Top - Offset;
  126. UpdatesOptionsGroup->Height = UpdatesOptionsGroup->Height - Offset;
  127. UpdatesProxyGroup->Top = UpdatesOptionsGroup->Top + UpdatesOptionsGroup->Height + ProxyOffset;
  128. }
  129. HideComponentsPanel(this);
  130. }
  131. //---------------------------------------------------------------------------
  132. __fastcall TPreferencesDialog::~TPreferencesDialog()
  133. {
  134. SAFE_DESTROY(FFileColorScrollOnDragOver);
  135. SAFE_DESTROY(FEditorScrollOnDragOver);
  136. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  137. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  138. delete FCustomCommandList;
  139. FCustomCommandList = NULL;
  140. delete FExtensionList;
  141. FExtensionList = NULL;
  142. delete FCopyParamList;
  143. FCopyParamList = NULL;
  144. delete FEditorList;
  145. FEditorList = NULL;
  146. }
  147. //---------------------------------------------------------------------
  148. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  149. {
  150. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  151. FDialogData = DialogData;
  152. bool Result = (ShowModal() == DefaultResult(this));
  153. if (Result)
  154. {
  155. SaveConfiguration();
  156. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  157. }
  158. else
  159. {
  160. for (int Index = 0; Index < FAddedExtensions->Count; Index++)
  161. {
  162. DeleteFile(ApiPath(FAddedExtensions->Strings[Index]));
  163. }
  164. }
  165. return Result;
  166. }
  167. //---------------------------------------------------------------------------
  168. void __fastcall TPreferencesDialog::LoadLanguages()
  169. {
  170. if (!FLanguagesLoaded)
  171. {
  172. LanguagesView->Items->Clear();
  173. LCID Locale = GUIConfiguration->Locale;
  174. if (Locale == NULL)
  175. {
  176. DebugAssert(GUIConfiguration->AppliedLocale == WinConfiguration->DefaultLocale);
  177. Locale = WinConfiguration->DefaultLocale;
  178. }
  179. TObjectList * Locales = GUIConfiguration->Locales;
  180. for (int Index = 0; Index < Locales->Count; Index++)
  181. {
  182. TListItem * Item = LanguagesView->Items->Add();
  183. TLocaleInfo * LocaleInfo = DebugNotNull(dynamic_cast<TLocaleInfo *>(Locales->Items[Index]));
  184. Item->Caption = LocaleInfo->Name;
  185. Item->Data = LocaleInfo;
  186. Item->Focused = (LocaleInfo->Locale == Locale);
  187. Item->Selected = Item->Focused;
  188. }
  189. AutoSizeListColumnsWidth(LanguagesView);
  190. FLanguagesLoaded = true;
  191. }
  192. }
  193. //---------------------------------------------------------------------------
  194. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  195. {
  196. for (int pi = 0; pi < PageControl->PageCount; pi++)
  197. {
  198. TTabSheet * Sheet = PageControl->Pages[pi];
  199. if (Sheet->Tag == Node->SelectedIndex)
  200. {
  201. return Sheet;
  202. }
  203. }
  204. DebugFail();
  205. return NULL;
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  209. {
  210. Tree->FullExpand();
  211. int i = 0;
  212. while (i < Tree->Items->Count)
  213. {
  214. TTreeNode * Node = Tree->Items->Item[i];
  215. TTabSheet * Sheet = FindPageForTreeNode(Node);
  216. if (DebugNotNull(Sheet))
  217. {
  218. if (Sheet->Enabled)
  219. {
  220. // gets called multiple times occasionally
  221. // (e.g. when called from upload dialog invoked by /upload)
  222. if (!Sheet->Caption.IsEmpty())
  223. {
  224. Node->Text = Sheet->Caption;
  225. Sheet->Caption = L"";
  226. }
  227. }
  228. else
  229. {
  230. Tree->Items->Delete(Node);
  231. i--;
  232. }
  233. }
  234. i++;
  235. }
  236. }
  237. //---------------------------------------------------------------------------
  238. void __fastcall TPreferencesDialog::LoadConfiguration()
  239. {
  240. FNoUpdate++;
  241. try
  242. {
  243. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  244. BOOLPROP(DefaultDirIsHome);
  245. BOOLPROP(PreservePanelState);
  246. BOOLPROP(DeleteToRecycleBin);
  247. BOOLPROP(DDWarnLackOfTempSpace);
  248. BOOLPROP(ShowHiddenFiles);
  249. BOOLPROP(RenameWholeName);
  250. BOOLPROP(ShowInaccesibleDirectories);
  251. BOOLPROP(CopyOnDoubleClickConfirmation);
  252. BOOLPROP(ConfirmTransferring);
  253. BOOLPROP(ConfirmOverwriting);
  254. BOOLPROP(ConfirmResume);
  255. BOOLPROP(ConfirmDeleting);
  256. BOOLPROP(ConfirmRecycling);
  257. BOOLPROP(ConfirmExitOnCompletion);
  258. BOOLPROP(ConfirmCommandSession);
  259. BOOLPROP(ContinueOnError);
  260. BOOLPROP(SynchronizeSummary);
  261. BOOLPROP(BeepOnFinish);
  262. BOOLPROP(TemporaryDirectoryAppendSession);
  263. BOOLPROP(TemporaryDirectoryAppendPath);
  264. BOOLPROP(TemporaryDirectoryDeterministic);
  265. BOOLPROP(TemporaryDirectoryCleanup);
  266. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  267. BOOLPROP(FullRowSelect);
  268. BOOLPROP(NaturalOrderNumericalSorting);
  269. ConfirmClosingSessionCheck2->Checked = WinConfiguration->ConfirmClosingSession;
  270. if (WinConfiguration->DDTransferConfirmation == asAuto)
  271. {
  272. // allow grayed state only initially,
  273. // once the off state is confirmed, never allow returning
  274. // to the undefined state
  275. DDTransferConfirmationCheck2->AllowGrayed = true;
  276. }
  277. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck2, WinConfiguration->DDTransferConfirmation);
  278. BeepOnFinishAfterEdit->AsInteger =
  279. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  280. BOOLPROP(BalloonNotifications);
  281. DDFakeFileEnabledButton->Checked = WinConfiguration->DDFakeFile;
  282. DDFakeFileDisabledButton->Checked = !DDFakeFileEnabledButton->Checked;
  283. DDDrivesMemo->Lines->CommaText = WinConfiguration->DDDrives;
  284. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  285. {
  286. DDSystemTemporaryDirectoryButton->Checked = true;
  287. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  288. }
  289. else
  290. {
  291. DDCustomTemporaryDirectoryButton->Checked = true;
  292. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  293. }
  294. // Commander
  295. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  296. {
  297. NortonLikeModeCombo->ItemIndex = 2;
  298. }
  299. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  300. {
  301. NortonLikeModeCombo->ItemIndex = 1;
  302. }
  303. else
  304. {
  305. NortonLikeModeCombo->ItemIndex = 0;
  306. }
  307. SwappedPanelsCheck->Checked =
  308. WinConfiguration->ScpCommander.SwappedPanels;
  309. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  310. ExplorerKeyboardShortcutsCombo->ItemIndex =
  311. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  312. BOOLPROP(UseLocationProfiles);
  313. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  314. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  315. // Local panel
  316. PreserveLocalDirectoryCheck->Checked =
  317. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  318. SystemContextMenuCheck->Checked =
  319. WinConfiguration->ScpCommander.SystemContextMenu;
  320. // Explorer
  321. ShowFullAddressCheck->Checked =
  322. WinConfiguration->ScpExplorer.ShowFullAddress;
  323. // select none when stNul
  324. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  325. AutomaticIniFileStorageButton->Checked = (Configuration->Storage == stIniFile) && Configuration->CustomIniFileStorageName.IsEmpty();
  326. CustomIniFileStorageButton->Checked = (Configuration->Storage == stIniFile) && !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. // allow only when some of the known storages is selected,
  1212. // and particularly do not allow switching storage, when we start with stNul,
  1213. // as that would destroy the stored configuration
  1214. EnableControl(StorageGroup,
  1215. RegistryStorageButton->Checked || AutomaticIniFileStorageButton->Checked || CustomIniFileStorageButton->Checked);
  1216. AutomaticIniFileStorageLabel->UpdateStatus();
  1217. EnableControl(CustomIniFileStorageEdit, CustomIniFileStorageButton->Checked);
  1218. // editors
  1219. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1220. bool EditorSelected = (EditorListView3->Selected != NULL);
  1221. EnableControl(EditEditorButton, EditorSelected);
  1222. EnableControl(RemoveEditorButton, EditorSelected);
  1223. EnableControl(UpEditorButton, EditorSelected &&
  1224. (EditorListView3->ItemIndex > 0));
  1225. EnableControl(DownEditorButton, EditorSelected &&
  1226. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1227. // file colors
  1228. bool FileColorSelected = (FileColorsView->Selected != NULL);
  1229. EnableControl(EditFileColorButton, FileColorSelected);
  1230. EnableControl(RemoveFileColorButton, FileColorSelected);
  1231. EnableControl(UpFileColorButton, FileColorSelected && (FileColorsView->ItemIndex > 0));
  1232. EnableControl(DownFileColorButton, FileColorSelected && (FileColorsView->ItemIndex < FileColorsView->Items->Count - 1));
  1233. // updates
  1234. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1235. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1236. EnableControl(UpdatesShowOnStartup, !IsUWP());
  1237. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1238. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1239. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1240. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1241. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1242. bool IsSiteCommand = false;
  1243. bool IsPasswordCommand = false;
  1244. try
  1245. {
  1246. TRemoteCustomCommand RemoteCustomCommand;
  1247. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1248. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1249. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1250. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1251. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1252. }
  1253. catch (...)
  1254. {
  1255. // noop
  1256. }
  1257. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1258. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1259. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1260. EnableControl(TelnetForFtpInPuttyCheck,
  1261. AnyPuttyPath && !IsSiteCommand);
  1262. EnableControl(PuttyRegistryStorageKeyEdit,
  1263. AnyPuttyPath && !IsSiteCommand && !IsUWP());
  1264. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1265. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1266. // network
  1267. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1268. // window
  1269. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1270. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1271. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1272. !Configuration->DisablePasswordStoring &&
  1273. AutoWorkspaceCombo->Enabled);
  1274. // integration
  1275. EnableControl(ShellIconsGroup, !IsUWP());
  1276. MakeDefaultHandlerItem->Visible = IsWinVista();
  1277. // languages
  1278. LanguageChangeLabel->Visible =
  1279. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1280. (LanguagesView->ItemFocused != NULL) &&
  1281. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1282. // logging
  1283. EnableControl(LogProtocolCombo2, EnableLoggingCheck->Checked);
  1284. EnableControl(LogFileNameEdit3, LogProtocolCombo2->Enabled);
  1285. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1286. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1287. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1288. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1289. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1290. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1291. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1292. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1293. EnableControl(LogSensitiveCheck, LogProtocolCombo2->Enabled);
  1294. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1295. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1296. // interface
  1297. InterfaceChangeLabel->Visible =
  1298. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1299. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1300. }
  1301. }
  1302. //---------------------------------------------------------------------------
  1303. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1304. {
  1305. if (FontDialog(FEditorFont.get()))
  1306. {
  1307. UpdateControls();
  1308. }
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1312. {
  1313. FEditorFont->Color = Color;
  1314. UpdateControls();
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1318. {
  1319. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1320. // "internal error" when passing menu directly to unique_ptr.
  1321. // Splitting it to two statements seems to help.
  1322. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick, TOpenLocalPathHandler::Open and TSelectMaskDialog::ColorButtonClick
  1323. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1324. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1325. FColorPopupMenu.reset(Menu);
  1326. MenuPopup(Menu, EditorFontColorButton);
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1330. {
  1331. FEditorBackgroundColor = Color;
  1332. UpdateControls();
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1336. {
  1337. // See comment in EditorFontColorButtonClick.
  1338. // We are using session color (contrary to editor text color) for background
  1339. // for a consistency with color selection menu on editor toolbar.
  1340. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1341. FColorPopupMenu.reset(PopupMenu);
  1342. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1343. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1344. }
  1345. //---------------------------------------------------------------------------
  1346. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1347. {
  1348. if (FontDialog(FPanelFont.get()))
  1349. {
  1350. PanelFontCheck->Checked = true;
  1351. UpdateControls();
  1352. }
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1356. bool & /*CanClose*/)
  1357. {
  1358. if (ModalResult == DefaultResult(this))
  1359. {
  1360. ExitActiveControl(this);
  1361. }
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1365. {
  1366. UnicodeString IconName, Params;
  1367. int SpecialFolder;
  1368. if (Sender == DesktopIconButton)
  1369. {
  1370. IconName = AppName;
  1371. int Result =
  1372. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1373. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1374. switch (Result)
  1375. {
  1376. case qaYes:
  1377. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1378. break;
  1379. case qaNo:
  1380. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1381. break;
  1382. default:
  1383. Abort();
  1384. break;
  1385. }
  1386. }
  1387. else if (Sender == SendToHookButton)
  1388. {
  1389. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1390. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1391. {
  1392. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1393. SpecialFolder = CSIDL_SENDTO;
  1394. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1395. }
  1396. else
  1397. {
  1398. Abort();
  1399. }
  1400. }
  1401. else
  1402. {
  1403. DebugFail();
  1404. Abort();
  1405. }
  1406. TInstantOperationVisualizer Visualizer;
  1407. CreateDesktopShortCut(IconName,
  1408. Application->ExeName, Params, L"", SpecialFolder);
  1409. }
  1410. //---------------------------------------------------------------------------
  1411. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1412. TListItem * Item)
  1413. {
  1414. // WORKAROUND We get here on Wine after destructor is called
  1415. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1416. {
  1417. int Index = Item->Index;
  1418. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1419. UnicodeString Caption = StripHotkey(Command->Name);
  1420. Item->Caption = Caption;
  1421. DebugAssert(!Item->SubItems->Count);
  1422. Item->SubItems->Add(Command->Command);
  1423. Item->SubItems->Add(LoadStr(
  1424. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1425. }
  1426. }
  1427. //---------------------------------------------------------------------------
  1428. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1429. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1430. {
  1431. UpdateControls();
  1432. }
  1433. //---------------------------------------------------------------------------
  1434. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1435. {
  1436. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1437. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1438. CustomCommandsView->Invalidate();
  1439. // particularly after command is edited/configured, make sure the hint is updated,
  1440. // even if we manage to display a hint for the same command as before the change
  1441. FCustomCommandsHintItem = NULL;
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1445. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1446. {
  1447. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1448. {
  1449. RemoveCommandButtonClick(NULL);
  1450. }
  1451. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1452. {
  1453. AddEditCommand(false);
  1454. }
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1458. TObject * /*Sender*/)
  1459. {
  1460. if (EditCommandButton->Enabled)
  1461. {
  1462. AddEditCommand(true);
  1463. }
  1464. else if (ConfigureCommandButton->Enabled)
  1465. {
  1466. ConfigureCommand();
  1467. }
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1471. {
  1472. if (Index >= 0)
  1473. {
  1474. List->Insert(Index, Command);
  1475. }
  1476. else
  1477. {
  1478. List->Add(Command);
  1479. Index = List->Count - 1;
  1480. }
  1481. return Index;
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1485. {
  1486. TShortCuts ShortCuts;
  1487. if (WinConfiguration->SharedBookmarks != NULL)
  1488. {
  1489. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1490. }
  1491. FCustomCommandList->ShortCuts(ShortCuts);
  1492. FExtensionList->ShortCuts(ShortCuts);
  1493. return ShortCuts;
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1497. {
  1498. TCustomCommandType Command;
  1499. if (Edit)
  1500. {
  1501. int Index = CustomCommandsView->ItemIndex;
  1502. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1503. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1504. }
  1505. TShortCuts ShortCuts = GetShortCuts();
  1506. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1507. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1508. {
  1509. int Index = GetListCommandIndex(FCustomCommandList);
  1510. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1511. if (Edit)
  1512. {
  1513. DebugAssert(Index < FCustomCommandList->Count);
  1514. FCustomCommandList->Change(Index, ACommand);
  1515. }
  1516. else
  1517. {
  1518. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1519. }
  1520. UpdateCustomCommandsView();
  1521. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1522. CustomCommandsView->ItemFocused->MakeVisible(false);
  1523. UpdateControls();
  1524. }
  1525. }
  1526. //---------------------------------------------------------------------------
  1527. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1528. TObject * /*Sender*/)
  1529. {
  1530. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1531. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1532. if (List == FExtensionList)
  1533. {
  1534. const TCustomCommandType * CustomComand = List->Commands[Index];
  1535. // If the extension was added in this "preferences session", remove the file
  1536. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1537. if (PathIndex >= 0)
  1538. {
  1539. FAddedExtensions->Delete(PathIndex);
  1540. DeleteFile(ApiPath(CustomComand->FileName));
  1541. }
  1542. }
  1543. List->Delete(Index);
  1544. UpdateCustomCommandsView();
  1545. UpdateControls();
  1546. }
  1547. //---------------------------------------------------------------------------
  1548. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1549. {
  1550. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1551. int SourceIndex = GetCommandIndex(Source);
  1552. int DestIndex = GetCommandIndex(Dest);
  1553. List->Move(SourceIndex, DestIndex);
  1554. CustomCommandsView->ItemIndex = Dest;
  1555. UpdateCustomCommandsView();
  1556. UpdateControls();
  1557. }
  1558. //---------------------------------------------------------------------------
  1559. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1560. {
  1561. CustomCommandMove(CustomCommandsView->ItemIndex,
  1562. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1563. }
  1564. //---------------------------------------------------------------------------
  1565. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1566. {
  1567. if (ListView == CopyParamListView)
  1568. {
  1569. return FCopyParamScrollOnDragOver;
  1570. }
  1571. else if (ListView == CustomCommandsView)
  1572. {
  1573. return FCustomCommandsScrollOnDragOver;
  1574. }
  1575. else if (ListView == EditorListView3)
  1576. {
  1577. return FEditorScrollOnDragOver;
  1578. }
  1579. else if (ListView == FileColorsView)
  1580. {
  1581. return FFileColorScrollOnDragOver;
  1582. }
  1583. else
  1584. {
  1585. DebugFail();
  1586. return NULL;
  1587. }
  1588. }
  1589. //---------------------------------------------------------------------------
  1590. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1591. TObject * Sender, TDragObject *& /*DragObject*/)
  1592. {
  1593. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1594. FListViewDragDest = -1;
  1595. ScrollOnDragOver(Sender)->StartDrag();
  1596. }
  1597. //---------------------------------------------------------------------------
  1598. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1599. {
  1600. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1601. return Item ? Item->Index : -1;
  1602. }
  1603. //---------------------------------------------------------------------------
  1604. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1605. {
  1606. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1607. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1608. }
  1609. //---------------------------------------------------------------------------
  1610. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1611. TObject * Sender, TObject * Source, int X, int Y)
  1612. {
  1613. if (Source == CustomCommandsView)
  1614. {
  1615. if (AllowListViewDrag(Sender, X, Y) &&
  1616. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1617. {
  1618. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1619. }
  1620. }
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1624. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1625. {
  1626. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1627. if (Source == Sender)
  1628. {
  1629. int Dest = PointToListViewIndex(Sender, X, Y);
  1630. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1631. {
  1632. Accept = false;
  1633. }
  1634. }
  1635. }
  1636. //---------------------------------------------------------------------------
  1637. void __fastcall TPreferencesDialog::ListViewDragOver(
  1638. TObject * Sender, TObject * Source, int X, int Y,
  1639. TDragState /*State*/, bool & Accept)
  1640. {
  1641. if (Source == Sender)
  1642. {
  1643. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1644. // (when dropped on item itself, when it was dragged over another item before,
  1645. // that another item remains highlighted forever)
  1646. Accept = true;
  1647. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1648. }
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1652. {
  1653. if (Index == 0)
  1654. {
  1655. return &FCopyParams;
  1656. }
  1657. else
  1658. {
  1659. return FCopyParamList->CopyParams[Index - 1];
  1660. }
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1664. {
  1665. DebugAssert((Source > 0) && (Dest > 0));
  1666. FCopyParamList->Move(Source - 1, Dest - 1);
  1667. CopyParamListView->ItemIndex = Dest;
  1668. UpdateCopyParamListView();
  1669. UpdateControls();
  1670. }
  1671. //---------------------------------------------------------------------------
  1672. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1673. TObject * Sender, TObject * Source, int X, int Y)
  1674. {
  1675. if (Source == CopyParamListView)
  1676. {
  1677. if ((FListViewDragSource > 0) &&
  1678. AllowListViewDrag(Sender, X, Y) &&
  1679. (FListViewDragDest > 0))
  1680. {
  1681. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1682. }
  1683. }
  1684. }
  1685. //---------------------------------------------------------------------------
  1686. void __fastcall TPreferencesDialog::CopyParamListViewDragOver(
  1687. TObject * Sender, TObject * Source, int X, int Y, TDragState State, bool & Accept)
  1688. {
  1689. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1690. if (Source == Sender)
  1691. {
  1692. int Dest = PointToListViewIndex(Sender, X, Y);
  1693. if ((FListViewDragSource == 0) || (Dest == 0))
  1694. {
  1695. Accept = false;
  1696. }
  1697. }
  1698. }
  1699. //---------------------------------------------------------------------------
  1700. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1701. {
  1702. CopyParamMove(CopyParamListView->ItemIndex,
  1703. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1704. }
  1705. //---------------------------------------------------------------------------
  1706. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1707. TObject * /*Sender*/)
  1708. {
  1709. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1710. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1711. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1712. UpdateCopyParamListView();
  1713. UpdateControls();
  1714. }
  1715. //---------------------------------------------------------------------------
  1716. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1717. {
  1718. int Index = CopyParamListView->ItemIndex;
  1719. bool Result;
  1720. if ((Index == 0) && (Mode == cpmEdit))
  1721. {
  1722. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1723. }
  1724. else
  1725. {
  1726. TCopyParamRuleData * CopyParamRuleData =
  1727. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1728. // negative (when default is selected) means add to the end
  1729. Index--;
  1730. TCopyParamType DefaultCopyParams;
  1731. // For cpmAdd use defaults.
  1732. if (Mode == cpmDuplicate)
  1733. {
  1734. // Only used, when duplicating default settings (Index < 0)
  1735. DefaultCopyParams = FCopyParams;
  1736. }
  1737. else if (Mode == cpmEdit)
  1738. {
  1739. // For cpmEdit, DefaultCopyParams is never used.
  1740. DebugAssert(Index >= 0);
  1741. }
  1742. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1743. if (Result)
  1744. {
  1745. UpdateCopyParamListView();
  1746. CopyParamListView->ItemIndex = Index + 1;
  1747. // when using duplicate button, focus remains on original item
  1748. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1749. }
  1750. }
  1751. if (Result)
  1752. {
  1753. UpdateControls();
  1754. }
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1758. {
  1759. AddEditCopyParam(cpmAdd);
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1763. {
  1764. AddEditCopyParam(cpmEdit);
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1768. {
  1769. AddEditCopyParam(cpmDuplicate);
  1770. }
  1771. //---------------------------------------------------------------------------
  1772. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1773. TObject * /*Sender*/)
  1774. {
  1775. if (EditCopyParamButton->Enabled)
  1776. {
  1777. AddEditCopyParam(cpmEdit);
  1778. }
  1779. }
  1780. //---------------------------------------------------------------------------
  1781. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1782. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1783. {
  1784. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1785. {
  1786. RemoveCopyParamButtonClick(NULL);
  1787. }
  1788. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1789. {
  1790. AddEditCopyParam(cpmAdd);
  1791. }
  1792. }
  1793. //---------------------------------------------------------------------------
  1794. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1795. {
  1796. FEditorList->Move(Source, Dest);
  1797. EditorListView3->ItemIndex = Dest;
  1798. UpdateEditorListView();
  1799. UpdateControls();
  1800. }
  1801. //---------------------------------------------------------------------------
  1802. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1803. TObject * Source, int X, int Y)
  1804. {
  1805. if (Source == EditorListView3)
  1806. {
  1807. if (AllowListViewDrag(Sender, X, Y))
  1808. {
  1809. EditorMove(FListViewDragSource, FListViewDragDest);
  1810. }
  1811. }
  1812. }
  1813. //---------------------------------------------------------------------------
  1814. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1815. {
  1816. EditorMove(EditorListView3->ItemIndex,
  1817. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1818. }
  1819. //---------------------------------------------------------------------------
  1820. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1821. TObject * /*Sender*/)
  1822. {
  1823. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1824. EditorListView3->ItemIndex < FEditorList->Count);
  1825. FEditorList->Delete(EditorListView3->ItemIndex);
  1826. UpdateEditorListView();
  1827. UpdateControls();
  1828. }
  1829. //---------------------------------------------------------------------------
  1830. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1831. {
  1832. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1833. int Index = EditorListView3->ItemIndex;
  1834. TEditorPreferences * Editor;
  1835. if (Mode == epmEdit)
  1836. {
  1837. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1838. }
  1839. else
  1840. {
  1841. Editor = new TEditorPreferences();
  1842. }
  1843. try
  1844. {
  1845. bool DummyRemember = false;
  1846. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1847. {
  1848. if (Mode == epmEdit)
  1849. {
  1850. FEditorList->Change(Index, Editor);
  1851. }
  1852. else
  1853. {
  1854. if (Index < 0)
  1855. {
  1856. Index = FEditorList->Count;
  1857. FEditorList->Add(Editor);
  1858. }
  1859. else
  1860. {
  1861. FEditorList->Insert(Index, Editor);
  1862. }
  1863. }
  1864. // ownership of the object lost
  1865. Editor = NULL;
  1866. UpdateEditorListView();
  1867. EditorListView3->ItemIndex = Index;
  1868. UpdateControls();
  1869. }
  1870. }
  1871. __finally
  1872. {
  1873. delete Editor;
  1874. }
  1875. }
  1876. //---------------------------------------------------------------------------
  1877. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1878. {
  1879. if (EditEditorButton->Enabled)
  1880. {
  1881. AddEditEditorButtonClick(EditEditorButton);
  1882. }
  1883. }
  1884. //---------------------------------------------------------------------------
  1885. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1886. WORD & Key, TShiftState /*Shift*/)
  1887. {
  1888. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1889. {
  1890. RemoveEditorButtonClick(NULL);
  1891. }
  1892. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1893. {
  1894. AddEditEditorButtonClick(AddEditorButton);
  1895. }
  1896. }
  1897. //---------------------------------------------------------------------------
  1898. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1899. {
  1900. EditorListView3->Items->Count = FEditorList->Count;
  1901. AutoSizeListColumnsWidth(EditorListView3);
  1902. EditorListView3->Invalidate();
  1903. }
  1904. //---------------------------------------------------------------------------
  1905. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1906. TListItem * Item)
  1907. {
  1908. // WORKAROUND We get here on Wine after destructor is called
  1909. if (FEditorList != NULL)
  1910. {
  1911. int Index = Item->Index;
  1912. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1913. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1914. Item->Caption = Editor->Name;
  1915. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1916. if (Editor->Data->Editor == edExternal)
  1917. {
  1918. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1919. }
  1920. }
  1921. }
  1922. //---------------------------------------------------------------------------
  1923. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1924. TTreeNode * Node)
  1925. {
  1926. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1927. {
  1928. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1929. // reshow the accelerators, etc
  1930. ResetSystemSettings(this);
  1931. // This is particularly here to enable EditCopyParamButton,
  1932. // as for some reason CopyParamListView->Selected is NULL until
  1933. // its page is shown for the first time
  1934. UpdateControls();
  1935. }
  1936. }
  1937. //---------------------------------------------------------------------------
  1938. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1939. {
  1940. // this is probably only ever called from FormShow (explicitly)
  1941. bool Found = false;
  1942. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1943. {
  1944. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1945. {
  1946. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1947. PageControl->ActivePage->Tag)
  1948. {
  1949. NavigationTree->Items->Item[Index]->Selected = true;
  1950. Found = true;
  1951. }
  1952. }
  1953. }
  1954. if (DebugAlwaysTrue(Found))
  1955. {
  1956. UpdateControls();
  1957. }
  1958. }
  1959. //---------------------------------------------------------------------------
  1960. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1961. {
  1962. if (Message.CharCode == VK_TAB)
  1963. {
  1964. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1965. if (Shift.Contains(ssCtrl))
  1966. {
  1967. TTreeNode * Node = NavigationTree->Selected;
  1968. if (!Shift.Contains(ssShift))
  1969. {
  1970. Node = Node->GetNext();
  1971. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1972. }
  1973. else
  1974. {
  1975. if (Node->GetPrev()) Node = Node->GetPrev();
  1976. else
  1977. while (Node->GetNext()) Node = Node->GetNext();
  1978. }
  1979. Node->Selected = True;
  1980. Message.Result = 1;
  1981. return;
  1982. }
  1983. }
  1984. TForm::Dispatch(&Message);
  1985. }
  1986. //---------------------------------------------------------------------------
  1987. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1988. {
  1989. DebugAssert(Message.HelpInfo != NULL);
  1990. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1991. {
  1992. // invoke help for active page (not for whole form), regardless of focus
  1993. // (e.g. even if focus is on control outside pagecontrol)
  1994. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1995. }
  1996. TForm::Dispatch(&Message);
  1997. }
  1998. //---------------------------------------------------------------------------
  1999. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  2000. {
  2001. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  2002. // we may end up using a slightly different size, so apply it straight away for consistency
  2003. UpdateControls();
  2004. TForm::Dispatch(&Message);
  2005. }
  2006. //---------------------------------------------------------------------------
  2007. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  2008. {
  2009. TMessage * M = reinterpret_cast<TMessage*>(Message);
  2010. DebugAssert(M);
  2011. if (M->Msg == CM_DIALOGKEY)
  2012. {
  2013. CMDialogKey(*((TWMKeyDown *)Message));
  2014. }
  2015. else if (M->Msg == CM_DPICHANGED)
  2016. {
  2017. CMDpiChanged(*M);
  2018. }
  2019. else if (M->Msg == WM_HELP)
  2020. {
  2021. WMHelp(*((TWMHelp *)Message));
  2022. }
  2023. else
  2024. {
  2025. TForm::Dispatch(Message);
  2026. }
  2027. }
  2028. //---------------------------------------------------------------------------
  2029. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  2030. TObject * /*Sender*/)
  2031. {
  2032. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  2033. }
  2034. //---------------------------------------------------------------------------
  2035. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  2036. {
  2037. unsigned int Result =
  2038. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  2039. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2040. if (Result == qaYes)
  2041. {
  2042. TInstantOperationVisualizer Visualizer;
  2043. RegisterForDefaultProtocols();
  2044. }
  2045. }
  2046. //---------------------------------------------------------------------------
  2047. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  2048. {
  2049. unsigned int Result =
  2050. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  2051. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2052. if (Result == qaYes)
  2053. {
  2054. TInstantOperationVisualizer Visualizer;
  2055. UnregisterForProtocols();
  2056. }
  2057. }
  2058. //---------------------------------------------------------------------------
  2059. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  2060. {
  2061. TOperationVisualizer Visualizer;
  2062. LaunchAdvancedAssociationUI();
  2063. }
  2064. //---------------------------------------------------------------------------
  2065. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  2066. {
  2067. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  2068. }
  2069. //---------------------------------------------------------------------------
  2070. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  2071. TObject * /*Sender*/)
  2072. {
  2073. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  2074. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  2075. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  2076. {
  2077. TInstantOperationVisualizer Visualizer;
  2078. AddSearchPath(AppPath);
  2079. }
  2080. }
  2081. //---------------------------------------------------------------------------
  2082. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2083. TObject * Sender)
  2084. {
  2085. EditorFontButtonClick(Sender);
  2086. }
  2087. //---------------------------------------------------------------------------
  2088. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2089. {
  2090. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2091. AutoSizeListColumnsWidth(CopyParamListView);
  2092. CopyParamListView->Invalidate();
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2096. TListItem * Item)
  2097. {
  2098. // WORKAROUND We get here on Wine after destructor is called
  2099. if (FCopyParamList != NULL)
  2100. {
  2101. UnicodeString Name;
  2102. UnicodeString Rule;
  2103. int Index = Item->Index;
  2104. if (Index == 0)
  2105. {
  2106. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2107. }
  2108. else
  2109. {
  2110. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2111. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2112. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2113. }
  2114. Item->Caption = Name;
  2115. Item->SubItems->Add(Rule);
  2116. }
  2117. }
  2118. //---------------------------------------------------------------------------
  2119. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2120. {
  2121. FormHelp(this);
  2122. }
  2123. //---------------------------------------------------------------------------
  2124. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2125. TObject * /*Sender*/)
  2126. {
  2127. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2128. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2129. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2130. }
  2131. //---------------------------------------------------------------------------
  2132. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2133. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2134. {
  2135. FBeforeDialogPath = Name;
  2136. Name = ExpandEnvironmentVariables(Name);
  2137. }
  2138. //---------------------------------------------------------------------------
  2139. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2140. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2141. {
  2142. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2143. {
  2144. Name = FBeforeDialogPath;
  2145. }
  2146. }
  2147. //---------------------------------------------------------------------------
  2148. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2149. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2150. {
  2151. AllowCollapse = false;
  2152. }
  2153. //---------------------------------------------------------------------------
  2154. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2155. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2156. {
  2157. ScrollOnDragOver(Sender)->EndDrag();
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2161. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2162. {
  2163. if (Value == 0)
  2164. {
  2165. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2166. Handled = true;
  2167. }
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2171. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2172. {
  2173. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2174. {
  2175. Value = 0;
  2176. Handled = true;
  2177. }
  2178. }
  2179. //---------------------------------------------------------------------------
  2180. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2181. {
  2182. bool Result;
  2183. bool Retry;
  2184. do
  2185. {
  2186. Retry = false;
  2187. Result = !AnyOtherInstanceOfSelf();
  2188. if (!Result)
  2189. {
  2190. unsigned int Answer =
  2191. MessageDialog(
  2192. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2193. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2194. HELP_MASTER_PASSWORD);
  2195. switch (Answer)
  2196. {
  2197. case qaRetry:
  2198. Retry = true;
  2199. break;
  2200. case qaIgnore:
  2201. Result = true;
  2202. break;
  2203. case qaCancel:
  2204. default:
  2205. // noop
  2206. break;
  2207. }
  2208. }
  2209. }
  2210. while (Retry && !Result);
  2211. return Result;
  2212. }
  2213. //---------------------------------------------------------------------------
  2214. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2215. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2216. {
  2217. // Save master password.
  2218. // This is unlikely to fail, as storage is written explicitly already
  2219. // when writing the recrypted passwords
  2220. Configuration->SaveExplicit();
  2221. TQueryType QueryType = qtInformation;
  2222. if (RecryptPasswordErrors->Count > 0)
  2223. {
  2224. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2225. QueryType = qtWarning;
  2226. }
  2227. MoreMessageDialog(
  2228. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2229. }
  2230. //---------------------------------------------------------------------------
  2231. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2232. {
  2233. UnicodeString NewPassword;
  2234. if (DoChangeMasterPasswordDialog(NewPassword))
  2235. {
  2236. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2237. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2238. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2239. }
  2240. }
  2241. //---------------------------------------------------------------------------
  2242. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2243. TObject * /*Sender*/)
  2244. {
  2245. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2246. {
  2247. try
  2248. {
  2249. if (CanSetMasterPassword())
  2250. {
  2251. if (UseMasterPasswordCheck->Checked)
  2252. {
  2253. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2254. }
  2255. else
  2256. {
  2257. if (DoMasterPasswordDialog())
  2258. {
  2259. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2260. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2261. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2262. }
  2263. }
  2264. }
  2265. }
  2266. __finally
  2267. {
  2268. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2269. UpdateControls();
  2270. }
  2271. }
  2272. }
  2273. //---------------------------------------------------------------------------
  2274. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2275. TObject * /*Sender*/)
  2276. {
  2277. if (CanSetMasterPassword())
  2278. {
  2279. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2280. }
  2281. }
  2282. //---------------------------------------------------------------------------
  2283. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2284. {
  2285. DoUsageStatisticsDialog();
  2286. }
  2287. //---------------------------------------------------------------------------
  2288. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2289. {
  2290. if (EditCopyParamButton->Enabled)
  2291. {
  2292. AddEditCopyParam(cpmEdit);
  2293. }
  2294. }
  2295. //---------------------------------------------------------------------------
  2296. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2297. TCustomListView * Sender, TListItem * Item,
  2298. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2299. {
  2300. if (Item->Index == 0)
  2301. {
  2302. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2303. }
  2304. }
  2305. //---------------------------------------------------------------------------
  2306. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2307. {
  2308. PuttyRegistryStorageKeyEdit->ItemIndex =
  2309. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2310. }
  2311. //---------------------------------------------------------------------------
  2312. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2313. {
  2314. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2315. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2316. {
  2317. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2318. }
  2319. else if (ContainsText(PuttyPath, KittyExecutable))
  2320. {
  2321. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2322. }
  2323. UpdateControls();
  2324. }
  2325. //---------------------------------------------------------------------------
  2326. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2327. TTreeNode * Node, bool & /*AllowChange*/)
  2328. {
  2329. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2330. // delay load as this can be time consuming
  2331. if (Sheet == LanguagesSheet)
  2332. {
  2333. LoadLanguages();
  2334. }
  2335. }
  2336. //---------------------------------------------------------------------------
  2337. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2338. {
  2339. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2340. }
  2341. //---------------------------------------------------------------------------
  2342. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2343. {
  2344. CommanderInterfaceButton2->SetFocus();
  2345. }
  2346. //---------------------------------------------------------------------------
  2347. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2348. {
  2349. ExplorerInterfaceButton2->SetFocus();
  2350. }
  2351. //---------------------------------------------------------------------------
  2352. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2353. {
  2354. PanelFontButtonClick(Sender);
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2358. {
  2359. if (!IsCancelButtonBeingClicked(this))
  2360. {
  2361. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2362. {
  2363. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2364. {
  2365. TUpdatesConfiguration Updates = SaveUpdates();
  2366. {
  2367. TInstantOperationVisualizer Visualizer;
  2368. QueryUpdates(Updates);
  2369. }
  2370. UnicodeString AuthenticationError = Updates.Results.AuthenticationError;
  2371. if (!AuthenticationError.IsEmpty())
  2372. {
  2373. AuthenticationError = FormatUpdatesMessage(AuthenticationError);
  2374. if (HasParagraphs(AuthenticationError))
  2375. {
  2376. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2377. }
  2378. else
  2379. {
  2380. AuthenticationError = MainInstructions(AuthenticationError);
  2381. }
  2382. unsigned int Result =
  2383. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HELP_AUTOMATIC_UPDATE);
  2384. if (Result == qaAbort)
  2385. {
  2386. Abort();
  2387. }
  2388. }
  2389. }
  2390. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2391. }
  2392. }
  2393. }
  2394. //---------------------------------------------------------------------------
  2395. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2396. {
  2397. EnableAutomaticUpdates();
  2398. }
  2399. //---------------------------------------------------------------------------
  2400. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2401. {
  2402. FOrigCustomCommandsViewWindowProc(Message);
  2403. if (Message.Msg == CN_NOTIFY)
  2404. {
  2405. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2406. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2407. {
  2408. // request CDDS_ITEMPOSTPAINT notification
  2409. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2410. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2411. int Index = CustomDraw->nmcd.dwItemSpec;
  2412. int CommandIndex = GetCommandIndex(Index);
  2413. TCustomCommandList * List = GetCommandList(Index);
  2414. // after end of every list, except for the last last list
  2415. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2416. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2417. {
  2418. TRect Rect;
  2419. Rect.Top = CustomDraw->iSubItem;
  2420. Rect.Left = LVIR_BOUNDS;
  2421. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2422. HDC DC = CustomDraw->nmcd.hdc;
  2423. SelectObject(DC, GetStockObject(DC_PEN));
  2424. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2425. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2426. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2427. }
  2428. }
  2429. }
  2430. }
  2431. //---------------------------------------------------------------------------
  2432. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2433. {
  2434. if ((Status / 10) == 49)
  2435. {
  2436. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2437. throw Exception(Message);
  2438. }
  2439. }
  2440. //---------------------------------------------------------------------------
  2441. void __fastcall TPreferencesDialog::AddExtension()
  2442. {
  2443. const UnicodeString HistoryKey(L"ExtensionPath");
  2444. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2445. UnicodeString Path;
  2446. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2447. HELP_NONE, History.get(), true) &&
  2448. !Path.IsEmpty())
  2449. {
  2450. CustomWinConfiguration->History[HistoryKey] = History.get();
  2451. bool Trusted;
  2452. bool Latest;
  2453. UnicodeString FileName;
  2454. UnicodeString ExtensionPath;
  2455. std::unique_ptr<TStringList> Lines(new TStringList());
  2456. std::unique_ptr<TCustomCommandType> CustomCommand;
  2457. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2458. try
  2459. {
  2460. UnicodeString ProvisionaryId;
  2461. if (IsUrl)
  2462. {
  2463. UnicodeString Url = Path;
  2464. Url = SecureUrl(Url);
  2465. bool WinSCPURL = IsWinSCPUrl(Url);
  2466. if (WinSCPURL)
  2467. {
  2468. Url = ProgramUrl(Url);
  2469. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2470. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2471. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2472. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2473. Url = CampaignUrl(Url);
  2474. }
  2475. TOperationVisualizer Visualizer;
  2476. std::unique_ptr<THttp> Http(CreateHttp());
  2477. Http->URL = Url;
  2478. std::unique_ptr<TStrings> Headers(new TStringList());
  2479. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2480. Http->RequestHeaders = Headers.get();
  2481. Http->OnError = ExtensionHttpError;
  2482. Http->Get();
  2483. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2484. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2485. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2486. if (FileName.IsEmpty())
  2487. {
  2488. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2489. }
  2490. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2491. Lines->Text = Http->Response;
  2492. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2493. }
  2494. else
  2495. {
  2496. if (!FileExists(ApiPath(Path)))
  2497. {
  2498. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2499. }
  2500. Trusted = true;
  2501. Latest = true;
  2502. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2503. FileName = ExtractFileName(Path);
  2504. if (!Id.IsEmpty())
  2505. {
  2506. ExtensionPath = Path;
  2507. ProvisionaryId = Id;
  2508. }
  2509. else
  2510. {
  2511. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2512. }
  2513. LoadScriptFromFile(Path, Lines.get());
  2514. }
  2515. // validate syntax
  2516. CustomCommand.reset(new TCustomCommandType());
  2517. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2518. CustomCommand->Id = ProvisionaryId;
  2519. CustomCommand->LoadExtension(Lines.get(), FileName);
  2520. }
  2521. catch (Exception & E)
  2522. {
  2523. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2524. }
  2525. if (!ExtensionPath.IsEmpty())
  2526. {
  2527. int Index = FExtensionList->FindIndexByFileName(Path);
  2528. if (Index >= 0)
  2529. {
  2530. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2531. CustomCommandsView->ItemFocused->MakeVisible(false);
  2532. CustomCommandsView->SetFocus();
  2533. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2534. }
  2535. }
  2536. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2537. {
  2538. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2539. }
  2540. if (ExtensionPath.IsEmpty())
  2541. {
  2542. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2543. {
  2544. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2545. if (FileNameOnly.IsEmpty())
  2546. {
  2547. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2548. }
  2549. else
  2550. {
  2551. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2552. }
  2553. }
  2554. }
  2555. if (Trusted ||
  2556. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2557. {
  2558. if (ExtensionPath.IsEmpty())
  2559. {
  2560. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2561. if (!DirectoryExists(UserExtensionsPath) &&
  2562. !ForceDirectories(UserExtensionsPath))
  2563. {
  2564. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2565. }
  2566. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2567. int Counter = 1;
  2568. UnicodeString OriginalExtensionPath = ExtensionPath;
  2569. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2570. while (FileExists(ApiPath(ExtensionPath)))
  2571. {
  2572. Counter++;
  2573. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2574. }
  2575. Lines->SaveToFile(ApiPath(ExtensionPath));
  2576. FAddedExtensions->Add(ExtensionPath);
  2577. }
  2578. int Index = GetListCommandIndex(FExtensionList);
  2579. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2580. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2581. CustomCommand->LoadExtension(ExtensionPath);
  2582. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2583. UpdateCustomCommandsView();
  2584. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2585. CustomCommandsView->ItemFocused->MakeVisible(false);
  2586. UpdateControls();
  2587. if (!Latest)
  2588. {
  2589. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2590. }
  2591. if (IsUrl)
  2592. {
  2593. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2594. }
  2595. else
  2596. {
  2597. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2598. }
  2599. }
  2600. }
  2601. }
  2602. //---------------------------------------------------------------------------
  2603. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2604. {
  2605. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2606. {
  2607. AddEditCommand(false);
  2608. }
  2609. else
  2610. {
  2611. AddExtension();
  2612. }
  2613. }
  2614. //---------------------------------------------------------------------------
  2615. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2616. {
  2617. AddEditCommand(false);
  2618. }
  2619. //---------------------------------------------------------------------------
  2620. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2621. {
  2622. AddExtension();
  2623. }
  2624. //---------------------------------------------------------------------------
  2625. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2626. {
  2627. AddEditCommand(true);
  2628. }
  2629. //---------------------------------------------------------------------------
  2630. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2631. {
  2632. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2633. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2634. MenuPopup(AddCommandMenu, AddCommandButton);
  2635. }
  2636. //---------------------------------------------------------------------------
  2637. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2638. {
  2639. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2640. UnicodeString Result;
  2641. if (Terminal != NULL)
  2642. {
  2643. Result = Terminal->SessionData->SessionKey;
  2644. }
  2645. return Result;
  2646. }
  2647. //---------------------------------------------------------------------------
  2648. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2649. {
  2650. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2651. int Index = (Item != NULL) ? Item->Index : -1;
  2652. if (Index != FCustomCommandsHintItem)
  2653. {
  2654. Application->CancelHint();
  2655. UnicodeString Hint;
  2656. if (Index >= 0)
  2657. {
  2658. TCustomCommandList * List = GetCommandList(Index);
  2659. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2660. Hint = StripHotkey(Command->Name);
  2661. if (Command->ShortCut != 0)
  2662. {
  2663. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2664. }
  2665. if (!Command->Description.IsEmpty())
  2666. {
  2667. Hint += L"\n" + Command->Description;
  2668. }
  2669. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2670. if (List == FExtensionList)
  2671. {
  2672. Hint += L"\n" + Command->FileName;
  2673. }
  2674. }
  2675. CustomCommandsView->Hint = Hint;
  2676. FCustomCommandsHintItem = Index;
  2677. }
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2681. {
  2682. PageControl->ActivePage = QueueSheet;
  2683. PageControlChange(NULL);
  2684. QueueNoConfirmationCheck->SetFocus();
  2685. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2686. }
  2687. //---------------------------------------------------------------------------
  2688. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2689. {
  2690. ConfigureCommand();
  2691. }
  2692. //---------------------------------------------------------------------------
  2693. void __fastcall TPreferencesDialog::ConfigureCommand()
  2694. {
  2695. int Index = CustomCommandsView->ItemIndex;
  2696. TCustomCommandList * CommandList = GetCommandList(Index);
  2697. int CommandIndex = GetCommandIndex(Index);
  2698. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2699. UnicodeString Site = GetSessionKey();
  2700. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2701. Site.IsEmpty())
  2702. {
  2703. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2704. }
  2705. TShortCut ShortCut = Command->ShortCut;
  2706. TShortCuts ShortCuts = GetShortCuts();
  2707. if (DoCustomCommandOptionsDialog(
  2708. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2709. {
  2710. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2711. UpdatedCommand->ShortCut = ShortCut;
  2712. CommandList->Change(CommandIndex, UpdatedCommand);
  2713. UpdateCustomCommandsView();
  2714. }
  2715. }
  2716. //---------------------------------------------------------------------------
  2717. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2718. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2719. {
  2720. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2721. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2722. {
  2723. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2724. }
  2725. if (LocaleInfo->Completeness < 0)
  2726. {
  2727. Sender->Canvas->Font->Color = clRed;
  2728. }
  2729. else if (LocaleInfo->Completeness < 100)
  2730. {
  2731. Sender->Canvas->Font->Color = clGrayText;
  2732. }
  2733. }
  2734. //---------------------------------------------------------------------------
  2735. void __fastcall TPreferencesDialog::LogMaxSizeComboExit(TObject * /*Sender*/)
  2736. {
  2737. __int64 Size;
  2738. if (!IsCancelButtonBeingClicked(this))
  2739. {
  2740. if (!TryStrToSize(LogMaxSizeCombo->Text, Size))
  2741. {
  2742. LogMaxSizeCombo->SetFocus();
  2743. throw Exception(FMTLOAD(SIZE_INVALID, (LogMaxSizeCombo->Text)));
  2744. }
  2745. else
  2746. {
  2747. LogMaxSizeCombo->Text = SizeToStr(Size);
  2748. }
  2749. }
  2750. }
  2751. //---------------------------------------------------------------------------
  2752. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2753. {
  2754. if (!IsCancelButtonBeingClicked(this))
  2755. {
  2756. try
  2757. {
  2758. UnicodeString Program, AParams, Dir;
  2759. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2760. }
  2761. catch(...)
  2762. {
  2763. PuttyPathEdit->SelectAll();
  2764. PuttyPathEdit->SetFocus();
  2765. throw;
  2766. }
  2767. }
  2768. }
  2769. //---------------------------------------------------------------------------
  2770. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2771. {
  2772. Active = AutomaticIniFileStorageButton->Checked;
  2773. }
  2774. //---------------------------------------------------------------------------
  2775. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2776. {
  2777. UnicodeString Result;
  2778. if (CustomIniFileStorageButton->Checked)
  2779. {
  2780. Result = CustomIniFileStorageEdit->Text;
  2781. }
  2782. return Result;
  2783. }
  2784. //---------------------------------------------------------------------------
  2785. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2786. {
  2787. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2788. if (!CustomIniFileStorageName.IsEmpty() &&
  2789. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2790. FileExists(CustomIniFileStorageName))
  2791. {
  2792. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageName));
  2793. TMessageParams Params;
  2794. TQueryButtonAlias Aliases[2];
  2795. Aliases[0].Button = qaYes;
  2796. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2797. Aliases[1].Button = qaNo;
  2798. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2799. Params.Aliases = Aliases;
  2800. Params.AliasesCount = 2;
  2801. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2802. if (Result == qaYes)
  2803. {
  2804. // noop
  2805. }
  2806. else if (Result == qaNo)
  2807. {
  2808. Configuration->ScheduleCustomIniFileStorageUse(GetCustomIniFileStorageName());
  2809. ExecuteNewInstance(L"");
  2810. TerminateApplication();
  2811. }
  2812. else
  2813. {
  2814. Abort();
  2815. }
  2816. }
  2817. FCustomIniFileStorageName = CustomIniFileStorageName;
  2818. }
  2819. //---------------------------------------------------------------------------
  2820. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2821. {
  2822. if (!IsCancelButtonBeingClicked(this))
  2823. {
  2824. CustomIniFileStorageChanged();
  2825. }
  2826. else
  2827. {
  2828. // Reset the value to prevent accidental overwide of an INI file, in case the dialog cancel does not complete
  2829. CustomIniFileStorageEdit->Text = FCustomIniFileStorageName;
  2830. }
  2831. }
  2832. //---------------------------------------------------------------------------
  2833. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2834. {
  2835. PathEditAfterDialog(Sender, Name, Action);
  2836. if (Action)
  2837. {
  2838. CustomIniFileStorageEdit->Text = Name;
  2839. CustomIniFileStorageChanged();
  2840. }
  2841. }
  2842. //---------------------------------------------------------------------------
  2843. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2844. {
  2845. UpdateControls();
  2846. // Handler is shown also when Checked is set from LoadConfiguration
  2847. if (FNoUpdate == 0)
  2848. {
  2849. // Focus to force validation
  2850. CustomIniFileStorageEdit->SetFocus();
  2851. }
  2852. }
  2853. //---------------------------------------------------------------------------
  2854. void __fastcall TPreferencesDialog::UpdateFileColorsView()
  2855. {
  2856. FileColorsView->Items->Count = FFileColors.size();
  2857. AutoSizeListColumnsWidth(FileColorsView);
  2858. }
  2859. //---------------------------------------------------------------------------
  2860. void __fastcall TPreferencesDialog::FileColorsViewData(TObject *, TListItem * Item)
  2861. {
  2862. Item->Caption = FFileColors[Item->Index].FileMask.Masks;
  2863. }
  2864. //---------------------------------------------------------------------------
  2865. void __fastcall TPreferencesDialog::FileColorsViewCustomDrawItem(
  2866. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  2867. {
  2868. Sender->Canvas->Font->Color = FFileColors[Item->Index].Color;
  2869. }
  2870. //---------------------------------------------------------------------------
  2871. void __fastcall TPreferencesDialog::AddEditFileColor(bool Edit)
  2872. {
  2873. TFileColorData FileColorData;
  2874. int Index = FileColorsView->ItemIndex;
  2875. if (Edit)
  2876. {
  2877. FileColorData = FFileColors[Index];
  2878. }
  2879. else
  2880. {
  2881. FileColorData.FileMask = AnyMask;
  2882. }
  2883. if (DoFileColorDialog(FileColorData))
  2884. {
  2885. if (Edit)
  2886. {
  2887. FFileColors[Index] = FileColorData;
  2888. }
  2889. else
  2890. {
  2891. if (Index < 0)
  2892. {
  2893. FFileColors.push_back(FileColorData);
  2894. }
  2895. else
  2896. {
  2897. FFileColors.insert(&FFileColors[Index], FileColorData);
  2898. }
  2899. }
  2900. UpdateFileColorsView();
  2901. FileColorsView->ItemIndex = Index;
  2902. UpdateControls();
  2903. }
  2904. }
  2905. //---------------------------------------------------------------------------
  2906. void __fastcall TPreferencesDialog::AddEditFileColorButtonClick(TObject * Sender)
  2907. {
  2908. bool Edit = (Sender == EditFileColorButton);
  2909. AddEditFileColor(Edit);
  2910. }
  2911. //---------------------------------------------------------------------------
  2912. void __fastcall TPreferencesDialog::FileColorMove(int Source, int Dest)
  2913. {
  2914. FFileColors.insert(FFileColors.begin() + Dest + ((Dest > Source) ? 1 : 0), FFileColors[Source]);
  2915. FFileColors.erase(FFileColors.begin() + Source + ((Dest < Source) ? 1 : 0));
  2916. FileColorsView->ItemIndex = Dest;
  2917. UpdateFileColorsView();
  2918. UpdateControls();
  2919. }
  2920. //---------------------------------------------------------------------------
  2921. void __fastcall TPreferencesDialog::FileColorsViewDragDrop(TObject * Sender, TObject * Source, int X, int Y)
  2922. {
  2923. if (Source == FileColorsView)
  2924. {
  2925. if (AllowListViewDrag(Sender, X, Y))
  2926. {
  2927. FileColorMove(FListViewDragSource, FListViewDragDest);
  2928. }
  2929. }
  2930. }
  2931. //---------------------------------------------------------------------------
  2932. void __fastcall TPreferencesDialog::FileColorsViewKeyDown(TObject *, WORD & Key, TShiftState)
  2933. {
  2934. if (RemoveFileColorButton->Enabled && (Key == VK_DELETE))
  2935. {
  2936. RemoveFileColorButtonClick(NULL);
  2937. }
  2938. if (DebugAlwaysTrue(AddFileColorButton->Enabled) && (Key == VK_INSERT))
  2939. {
  2940. AddEditFileColor(false);
  2941. }
  2942. }
  2943. //---------------------------------------------------------------------------
  2944. void __fastcall TPreferencesDialog::RemoveFileColorButtonClick(TObject *)
  2945. {
  2946. FFileColors.erase(FFileColors.begin() + FileColorsView->ItemIndex);
  2947. UpdateFileColorsView();
  2948. UpdateControls();
  2949. }
  2950. //---------------------------------------------------------------------------
  2951. void __fastcall TPreferencesDialog::FileColorsViewDblClick(TObject *)
  2952. {
  2953. if (EditFileColorButton->Enabled)
  2954. {
  2955. AddEditFileColor(true);
  2956. }
  2957. }
  2958. //---------------------------------------------------------------------------
  2959. void __fastcall TPreferencesDialog::UpDownFileColorButtonClick(TObject * Sender)
  2960. {
  2961. int DestIndex = FileColorsView->ItemIndex + (Sender == UpFileColorButton ? -1 : 1);
  2962. FileColorMove(FileColorsView->ItemIndex, DestIndex);
  2963. }
  2964. //---------------------------------------------------------------------------