1
0

Preferences.cpp 112 KB

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