Preferences.cpp 93 KB

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