Preferences.cpp 113 KB

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