Preferences.cpp 96 KB

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