Preferences.cpp 133 KB

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