Preferences.cpp 102 KB

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