Preferences.cpp 111 KB

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