Preferences.cpp 109 KB

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