Preferences.cpp 103 KB

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