Preferences.cpp 109 KB

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