Preferences.cpp 104 KB

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