Preferences.cpp 121 KB

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