Preferences.cpp 102 KB

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