Preferences.cpp 114 KB

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