1
0

Preferences.cpp 100 KB

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