1
0

Preferences.cpp 93 KB

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