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