Preferences.cpp 108 KB

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