Preferences.cpp 133 KB

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