Preferences.cpp 89 KB

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