Preferences.cpp 103 KB

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