Preferences.cpp 102 KB

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