Preferences.cpp 102 KB

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