Preferences.cpp 133 KB

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