Preferences.cpp 101 KB

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