Preferences.cpp 109 KB

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