Preferences.cpp 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182
  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. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  33. TPreferencesDialogData * DialogData)
  34. {
  35. bool Result;
  36. TPreferencesDialog * PreferencesDialog =
  37. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  38. try
  39. {
  40. Result = PreferencesDialog->Execute(DialogData);
  41. if (Result)
  42. {
  43. CheckConfigurationForceSave();
  44. Configuration->SaveExplicit();
  45. }
  46. }
  47. __finally
  48. {
  49. delete PreferencesDialog;
  50. }
  51. return Result;
  52. }
  53. //---------------------------------------------------------------------
  54. __fastcall TPreferencesDialog::TPreferencesDialog(
  55. TComponent* AOwner, TPreferencesMode PreferencesMode)
  56. : TForm(AOwner)
  57. {
  58. SetCorrectFormParent(this);
  59. FNoUpdate = 0;
  60. FPreferencesMode = PreferencesMode;
  61. FEditorFont.reset(new TFont());
  62. FEditorFont->Color = clWindowText;
  63. FPanelFont.reset(new TFont());
  64. FPanelFont->Color = clWindowText;
  65. // currently useless
  66. FAfterFilenameEditDialog = false;
  67. FCustomCommandList = new TCustomCommandList();
  68. FCustomCommandChanging = false;
  69. FExtensionList = new TCustomCommandList();
  70. FListViewDragDest = -1;
  71. FCopyParamList = new TCopyParamList();
  72. FEditorList = new TEditorList();
  73. FAutomaticUpdatesPossible = IsInstalled();
  74. FCustomCommandsHintItem = NULL;
  75. FAddedExtensions.reset(CreateSortedStringList());
  76. FCustomCommandOptions.reset(new TStringList());
  77. UseSystemSettings(this);
  78. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  79. FixListColumnWidth(CustomCommandsView, -1);
  80. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  81. FixListColumnWidth(CopyParamListView, -1);
  82. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  83. FixListColumnWidth(EditorListView3, -1);
  84. FFileColorScrollOnDragOver = new TListViewScrollOnDragOver(FileColorsView, true);
  85. FOrigCustomCommandsViewWindowProc = CustomCommandsView->WindowProc;
  86. CustomCommandsView->WindowProc = CustomCommandsViewWindowProc;
  87. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  88. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta && !IsUWP());
  89. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  90. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  91. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  92. HintLabel(ShellIconsText2);
  93. HotTrackLabel(CopyParamLabel);
  94. HintLabel(PuttyPathHintText, LoadStr(PUTTY_PATTERNS_HINT2));
  95. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  96. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  97. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  98. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  99. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  100. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  101. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  102. MenuButton(RegisterAsUrlHandlersButton);
  103. MenuButton(EditorFontColorButton);
  104. MenuButton(EditorBackgroundColorButton);
  105. LoadDialogImage(CommanderInterfacePicture, L"Commander");
  106. LoadDialogImage(ExplorerInterfacePicture, L"Explorer");
  107. LinkLabel(UpdatesLink);
  108. LinkAppLabel(BackgroundConfirmationsLink);
  109. AutoSizeButton(UsageViewButton);
  110. AutomaticIniFileStorageLabel->Caption = ExpandEnvironmentVariables(Configuration->GetAutomaticIniFileStorageName(false));
  111. if (IsUWP())
  112. {
  113. UpdatesSheet->Caption = LoadStr(PREFERENCES_STATISTICS_CAPTION);
  114. int ProxyOffset = UpdatesProxyGroup->Top - UpdatesOptionsGroup->Top - UpdatesOptionsGroup->Height;
  115. UpdatesGroup2->Visible = false;
  116. UpdatesOptionsGroup->Top = UpdatesGroup2->Top;
  117. UpdatesBetaVersionsCombo->Visible = false;
  118. UpdatesBetaVersionsLabel->Visible = false;
  119. int Offset = UsageViewButton->Top - UpdatesBetaVersionsCombo->Top;
  120. CollectUsageCheck->Top = CollectUsageCheck->Top - Offset;
  121. UsageViewButton->Top = UsageViewButton->Top - Offset;
  122. UpdatesOptionsGroup->Height = UpdatesOptionsGroup->Height - Offset;
  123. UpdatesProxyGroup->Top = UpdatesOptionsGroup->Top + UpdatesOptionsGroup->Height + ProxyOffset;
  124. }
  125. HideComponentsPanel(this);
  126. }
  127. //---------------------------------------------------------------------------
  128. __fastcall TPreferencesDialog::~TPreferencesDialog()
  129. {
  130. SAFE_DESTROY(FFileColorScrollOnDragOver);
  131. SAFE_DESTROY(FEditorScrollOnDragOver);
  132. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  133. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  134. delete FCustomCommandList;
  135. FCustomCommandList = NULL;
  136. delete FExtensionList;
  137. FExtensionList = NULL;
  138. delete FCopyParamList;
  139. FCopyParamList = NULL;
  140. delete FEditorList;
  141. FEditorList = NULL;
  142. }
  143. //---------------------------------------------------------------------
  144. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  145. {
  146. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  147. FDialogData = DialogData;
  148. bool Result = (ShowModal() == DefaultResult(this));
  149. if (Result)
  150. {
  151. SaveConfiguration();
  152. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  153. }
  154. else
  155. {
  156. for (int Index = 0; Index < FAddedExtensions->Count; Index++)
  157. {
  158. DeleteFile(ApiPath(FAddedExtensions->Strings[Index]));
  159. }
  160. }
  161. return Result;
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TPreferencesDialog::LoadLanguages()
  165. {
  166. if (!FLanguagesLoaded)
  167. {
  168. LanguagesView->Items->Clear();
  169. LCID Locale = GUIConfiguration->Locale;
  170. if (Locale == NULL)
  171. {
  172. DebugAssert(GUIConfiguration->AppliedLocale == WinConfiguration->DefaultLocale);
  173. Locale = WinConfiguration->DefaultLocale;
  174. }
  175. TObjectList * Locales = GUIConfiguration->Locales;
  176. for (int Index = 0; Index < Locales->Count; Index++)
  177. {
  178. TListItem * Item = LanguagesView->Items->Add();
  179. TLocaleInfo * LocaleInfo = DebugNotNull(dynamic_cast<TLocaleInfo *>(Locales->Items[Index]));
  180. Item->Caption = LocaleInfo->Name;
  181. Item->Data = LocaleInfo;
  182. Item->Focused = (LocaleInfo->Locale == Locale);
  183. Item->Selected = Item->Focused;
  184. }
  185. AutoSizeListColumnsWidth(LanguagesView);
  186. FLanguagesLoaded = true;
  187. }
  188. }
  189. //---------------------------------------------------------------------------
  190. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  191. {
  192. for (int pi = 0; pi < PageControl->PageCount; pi++)
  193. {
  194. TTabSheet * Sheet = PageControl->Pages[pi];
  195. if (Sheet->Tag == Node->SelectedIndex)
  196. {
  197. return Sheet;
  198. }
  199. }
  200. DebugFail();
  201. return NULL;
  202. }
  203. //---------------------------------------------------------------------------
  204. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  205. {
  206. Tree->FullExpand();
  207. int i = 0;
  208. while (i < Tree->Items->Count)
  209. {
  210. TTreeNode * Node = Tree->Items->Item[i];
  211. TTabSheet * Sheet = FindPageForTreeNode(Node);
  212. if (DebugNotNull(Sheet))
  213. {
  214. if (Sheet->Enabled)
  215. {
  216. // gets called multiple times occasionally
  217. // (e.g. when called from upload dialog invoked by /upload)
  218. if (!Sheet->Caption.IsEmpty())
  219. {
  220. Node->Text = Sheet->Caption;
  221. Sheet->Caption = L"";
  222. }
  223. }
  224. else
  225. {
  226. Tree->Items->Delete(Node);
  227. i--;
  228. }
  229. }
  230. i++;
  231. }
  232. }
  233. //---------------------------------------------------------------------------
  234. void __fastcall TPreferencesDialog::LoadConfiguration()
  235. {
  236. FNoUpdate++;
  237. try
  238. {
  239. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  240. BOOLPROP(DefaultDirIsHome);
  241. BOOLPROP(PreservePanelState);
  242. BOOLPROP(DeleteToRecycleBin);
  243. BOOLPROP(DDWarnLackOfTempSpace);
  244. BOOLPROP(ShowHiddenFiles);
  245. BOOLPROP(RenameWholeName);
  246. BOOLPROP(ShowInaccesibleDirectories);
  247. BOOLPROP(CopyOnDoubleClickConfirmation);
  248. BOOLPROP(ConfirmTransferring);
  249. BOOLPROP(ConfirmOverwriting);
  250. BOOLPROP(ConfirmResume);
  251. BOOLPROP(ConfirmDeleting);
  252. BOOLPROP(ConfirmRecycling);
  253. BOOLPROP(ConfirmExitOnCompletion);
  254. BOOLPROP(ConfirmCommandSession);
  255. BOOLPROP(ContinueOnError);
  256. BOOLPROP(SynchronizeSummary);
  257. BOOLPROP(BeepOnFinish);
  258. BOOLPROP(TemporaryDirectoryAppendSession);
  259. BOOLPROP(TemporaryDirectoryAppendPath);
  260. BOOLPROP(TemporaryDirectoryDeterministic);
  261. BOOLPROP(TemporaryDirectoryCleanup);
  262. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  263. BOOLPROP(FullRowSelect);
  264. BOOLPROP(NaturalOrderNumericalSorting);
  265. ConfirmClosingSessionCheck2->Checked = WinConfiguration->ConfirmClosingSession;
  266. if (WinConfiguration->DDTransferConfirmation == asAuto)
  267. {
  268. // allow grayed state only initially,
  269. // once the off state is confirmed, never allow returning
  270. // to the undefined state
  271. DDTransferConfirmationCheck2->AllowGrayed = true;
  272. }
  273. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck2, WinConfiguration->DDTransferConfirmation);
  274. BeepOnFinishAfterEdit->AsInteger =
  275. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  276. BOOLPROP(BalloonNotifications);
  277. DDFakeFileEnabledButton->Checked = WinConfiguration->DDFakeFile;
  278. DDFakeFileDisabledButton->Checked = !DDFakeFileEnabledButton->Checked;
  279. DDDrivesMemo->Lines->CommaText = WinConfiguration->DDDrives;
  280. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  281. {
  282. DDSystemTemporaryDirectoryButton->Checked = true;
  283. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  284. }
  285. else
  286. {
  287. DDCustomTemporaryDirectoryButton->Checked = true;
  288. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  289. }
  290. // Commander
  291. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  292. {
  293. NortonLikeModeCombo->ItemIndex = 2;
  294. }
  295. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  296. {
  297. NortonLikeModeCombo->ItemIndex = 1;
  298. }
  299. else
  300. {
  301. NortonLikeModeCombo->ItemIndex = 0;
  302. }
  303. SwappedPanelsCheck->Checked =
  304. WinConfiguration->ScpCommander.SwappedPanels;
  305. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  306. ExplorerKeyboardShortcutsCombo->ItemIndex =
  307. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  308. BOOLPROP(UseLocationProfiles);
  309. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  310. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  311. // Local panel
  312. PreserveLocalDirectoryCheck->Checked =
  313. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  314. SystemContextMenuCheck->Checked =
  315. WinConfiguration->ScpCommander.SystemContextMenu;
  316. // Explorer
  317. ShowFullAddressCheck->Checked =
  318. WinConfiguration->ScpExplorer.ShowFullAddress;
  319. // select none when stNul
  320. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  321. AutomaticIniFileStorageButton->Checked =
  322. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && Configuration->CustomIniFileStorageName.IsEmpty();
  323. CustomIniFileStorageButton->Checked =
  324. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && !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. // do not allow switching storage, when we start with stNul,
  1210. // as that would destroy the stored configuration
  1211. EnableControl(StorageGroup, Configuration->Storage != stNul);
  1212. AutomaticIniFileStorageLabel->UpdateStatus();
  1213. EnableControl(CustomIniFileStorageEdit, CustomIniFileStorageButton->Checked);
  1214. // editors
  1215. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1216. bool EditorSelected = (EditorListView3->Selected != NULL);
  1217. EnableControl(EditEditorButton, EditorSelected);
  1218. EnableControl(RemoveEditorButton, EditorSelected);
  1219. EnableControl(UpEditorButton, EditorSelected &&
  1220. (EditorListView3->ItemIndex > 0));
  1221. EnableControl(DownEditorButton, EditorSelected &&
  1222. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1223. // file colors
  1224. bool FileColorSelected = (FileColorsView->Selected != NULL);
  1225. EnableControl(EditFileColorButton, FileColorSelected);
  1226. EnableControl(RemoveFileColorButton, FileColorSelected);
  1227. EnableControl(UpFileColorButton, FileColorSelected && (FileColorsView->ItemIndex > 0));
  1228. EnableControl(DownFileColorButton, FileColorSelected && (FileColorsView->ItemIndex < FileColorsView->Items->Count - 1));
  1229. // updates
  1230. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1231. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1232. EnableControl(UpdatesShowOnStartup, !IsUWP());
  1233. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1234. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1235. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1236. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1237. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1238. bool IsSiteCommand = false;
  1239. bool IsPasswordCommand = false;
  1240. try
  1241. {
  1242. TRemoteCustomCommand RemoteCustomCommand;
  1243. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1244. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1245. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1246. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1247. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1248. }
  1249. catch (...)
  1250. {
  1251. // noop
  1252. }
  1253. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1254. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1255. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1256. EnableControl(TelnetForFtpInPuttyCheck,
  1257. AnyPuttyPath && !IsSiteCommand);
  1258. EnableControl(PuttyRegistryStorageKeyEdit,
  1259. AnyPuttyPath && !IsSiteCommand && !IsUWP());
  1260. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1261. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1262. // network
  1263. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1264. // window
  1265. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1266. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1267. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1268. !Configuration->DisablePasswordStoring &&
  1269. AutoWorkspaceCombo->Enabled);
  1270. // integration
  1271. EnableControl(ShellIconsGroup, !IsUWP());
  1272. MakeDefaultHandlerItem->Visible = IsWinVista();
  1273. // languages
  1274. LanguageChangeLabel->Visible =
  1275. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1276. (LanguagesView->ItemFocused != NULL) &&
  1277. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1278. // logging
  1279. EnableControl(LogProtocolCombo2, EnableLoggingCheck->Checked);
  1280. EnableControl(LogFileNameEdit3, LogProtocolCombo2->Enabled);
  1281. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1282. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1283. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1284. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1285. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1286. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1287. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1288. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1289. EnableControl(LogSensitiveCheck, LogProtocolCombo2->Enabled);
  1290. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1291. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1292. // interface
  1293. InterfaceChangeLabel->Visible =
  1294. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1295. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1296. }
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1300. {
  1301. if (FontDialog(FEditorFont.get()))
  1302. {
  1303. UpdateControls();
  1304. }
  1305. }
  1306. //---------------------------------------------------------------------------
  1307. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1308. {
  1309. FEditorFont->Color = Color;
  1310. UpdateControls();
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1314. {
  1315. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1316. // "internal error" when passing menu directly to unique_ptr.
  1317. // Splitting it to two statements seems to help.
  1318. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick, TOpenLocalPathHandler::Open and TSelectMaskDialog::ColorButtonClick
  1319. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1320. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1321. FColorPopupMenu.reset(Menu);
  1322. MenuPopup(Menu, EditorFontColorButton);
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1326. {
  1327. FEditorBackgroundColor = Color;
  1328. UpdateControls();
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1332. {
  1333. // See comment in EditorFontColorButtonClick.
  1334. // We are using session color (contrary to editor text color) for background
  1335. // for a consistency with color selection menu on editor toolbar.
  1336. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1337. FColorPopupMenu.reset(PopupMenu);
  1338. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1339. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1343. {
  1344. if (FontDialog(FPanelFont.get()))
  1345. {
  1346. PanelFontCheck->Checked = true;
  1347. UpdateControls();
  1348. }
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1352. bool & /*CanClose*/)
  1353. {
  1354. if (ModalResult == DefaultResult(this))
  1355. {
  1356. ExitActiveControl(this);
  1357. }
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1361. {
  1362. UnicodeString IconName, Params;
  1363. int SpecialFolder;
  1364. if (Sender == DesktopIconButton)
  1365. {
  1366. IconName = AppName;
  1367. int Result =
  1368. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1369. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1370. switch (Result)
  1371. {
  1372. case qaYes:
  1373. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1374. break;
  1375. case qaNo:
  1376. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1377. break;
  1378. default:
  1379. Abort();
  1380. break;
  1381. }
  1382. }
  1383. else if (Sender == SendToHookButton)
  1384. {
  1385. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1386. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1387. {
  1388. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1389. SpecialFolder = CSIDL_SENDTO;
  1390. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1391. }
  1392. else
  1393. {
  1394. Abort();
  1395. }
  1396. }
  1397. else
  1398. {
  1399. DebugFail();
  1400. Abort();
  1401. }
  1402. TInstantOperationVisualizer Visualizer;
  1403. CreateAppDesktopShortCut(IconName, Params, L"", SpecialFolder);
  1404. }
  1405. //---------------------------------------------------------------------------
  1406. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1407. TListItem * Item)
  1408. {
  1409. // WORKAROUND We get here on Wine after destructor is called
  1410. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1411. {
  1412. int Index = Item->Index;
  1413. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1414. UnicodeString Caption = StripHotkey(Command->Name);
  1415. Item->Caption = Caption;
  1416. DebugAssert(!Item->SubItems->Count);
  1417. Item->SubItems->Add(Command->Command);
  1418. Item->SubItems->Add(LoadStr(
  1419. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1420. }
  1421. }
  1422. //---------------------------------------------------------------------------
  1423. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1424. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1425. {
  1426. UpdateControls();
  1427. }
  1428. //---------------------------------------------------------------------------
  1429. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1430. {
  1431. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1432. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1433. CustomCommandsView->Invalidate();
  1434. // particularly after command is edited/configured, make sure the hint is updated,
  1435. // even if we manage to display a hint for the same command as before the change
  1436. FCustomCommandsHintItem = NULL;
  1437. }
  1438. //---------------------------------------------------------------------------
  1439. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1440. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1441. {
  1442. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1443. {
  1444. RemoveCommandButtonClick(NULL);
  1445. }
  1446. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1447. {
  1448. AddEditCommand(false);
  1449. }
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1453. TObject * /*Sender*/)
  1454. {
  1455. if (EditCommandButton->Enabled)
  1456. {
  1457. AddEditCommand(true);
  1458. }
  1459. else if (ConfigureCommandButton->Enabled)
  1460. {
  1461. ConfigureCommand();
  1462. }
  1463. }
  1464. //---------------------------------------------------------------------------
  1465. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1466. {
  1467. if (Index >= 0)
  1468. {
  1469. List->Insert(Index, Command);
  1470. }
  1471. else
  1472. {
  1473. List->Add(Command);
  1474. Index = List->Count - 1;
  1475. }
  1476. return Index;
  1477. }
  1478. //---------------------------------------------------------------------------
  1479. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1480. {
  1481. TShortCuts ShortCuts;
  1482. if (WinConfiguration->SharedBookmarks != NULL)
  1483. {
  1484. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1485. }
  1486. FCustomCommandList->ShortCuts(ShortCuts);
  1487. FExtensionList->ShortCuts(ShortCuts);
  1488. return ShortCuts;
  1489. }
  1490. //---------------------------------------------------------------------------
  1491. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1492. {
  1493. TCustomCommandType Command;
  1494. if (Edit)
  1495. {
  1496. int Index = CustomCommandsView->ItemIndex;
  1497. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1498. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1499. }
  1500. TShortCuts ShortCuts = GetShortCuts();
  1501. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1502. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1503. {
  1504. int Index = GetListCommandIndex(FCustomCommandList);
  1505. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1506. if (Edit)
  1507. {
  1508. DebugAssert(Index < FCustomCommandList->Count);
  1509. FCustomCommandList->Change(Index, ACommand);
  1510. }
  1511. else
  1512. {
  1513. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1514. }
  1515. UpdateCustomCommandsView();
  1516. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1517. CustomCommandsView->ItemFocused->MakeVisible(false);
  1518. UpdateControls();
  1519. }
  1520. }
  1521. //---------------------------------------------------------------------------
  1522. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1523. TObject * /*Sender*/)
  1524. {
  1525. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1526. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1527. if (List == FExtensionList)
  1528. {
  1529. const TCustomCommandType * CustomComand = List->Commands[Index];
  1530. // If the extension was added in this "preferences session", remove the file
  1531. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1532. if (PathIndex >= 0)
  1533. {
  1534. FAddedExtensions->Delete(PathIndex);
  1535. DeleteFile(ApiPath(CustomComand->FileName));
  1536. }
  1537. }
  1538. List->Delete(Index);
  1539. UpdateCustomCommandsView();
  1540. UpdateControls();
  1541. }
  1542. //---------------------------------------------------------------------------
  1543. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1544. {
  1545. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1546. int SourceIndex = GetCommandIndex(Source);
  1547. int DestIndex = GetCommandIndex(Dest);
  1548. List->Move(SourceIndex, DestIndex);
  1549. CustomCommandsView->ItemIndex = Dest;
  1550. UpdateCustomCommandsView();
  1551. UpdateControls();
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1555. {
  1556. CustomCommandMove(CustomCommandsView->ItemIndex,
  1557. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1561. {
  1562. if (ListView == CopyParamListView)
  1563. {
  1564. return FCopyParamScrollOnDragOver;
  1565. }
  1566. else if (ListView == CustomCommandsView)
  1567. {
  1568. return FCustomCommandsScrollOnDragOver;
  1569. }
  1570. else if (ListView == EditorListView3)
  1571. {
  1572. return FEditorScrollOnDragOver;
  1573. }
  1574. else if (ListView == FileColorsView)
  1575. {
  1576. return FFileColorScrollOnDragOver;
  1577. }
  1578. else
  1579. {
  1580. DebugFail();
  1581. return NULL;
  1582. }
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1586. TObject * Sender, TDragObject *& /*DragObject*/)
  1587. {
  1588. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1589. FListViewDragDest = -1;
  1590. ScrollOnDragOver(Sender)->StartDrag();
  1591. }
  1592. //---------------------------------------------------------------------------
  1593. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1594. {
  1595. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1596. return Item ? Item->Index : -1;
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1600. {
  1601. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1602. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1606. TObject * Sender, TObject * Source, int X, int Y)
  1607. {
  1608. if (Source == CustomCommandsView)
  1609. {
  1610. if (AllowListViewDrag(Sender, X, Y) &&
  1611. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1612. {
  1613. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1614. }
  1615. }
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1619. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1620. {
  1621. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1622. if (Source == Sender)
  1623. {
  1624. int Dest = PointToListViewIndex(Sender, X, Y);
  1625. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1626. {
  1627. Accept = false;
  1628. }
  1629. }
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. void __fastcall TPreferencesDialog::ListViewDragOver(
  1633. TObject * Sender, TObject * Source, int X, int Y,
  1634. TDragState /*State*/, bool & Accept)
  1635. {
  1636. if (Source == Sender)
  1637. {
  1638. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1639. // (when dropped on item itself, when it was dragged over another item before,
  1640. // that another item remains highlighted forever)
  1641. Accept = true;
  1642. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1643. }
  1644. }
  1645. //---------------------------------------------------------------------------
  1646. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1647. {
  1648. if (Index == 0)
  1649. {
  1650. return &FCopyParams;
  1651. }
  1652. else
  1653. {
  1654. return FCopyParamList->CopyParams[Index - 1];
  1655. }
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1659. {
  1660. DebugAssert((Source > 0) && (Dest > 0));
  1661. FCopyParamList->Move(Source - 1, Dest - 1);
  1662. CopyParamListView->ItemIndex = Dest;
  1663. UpdateCopyParamListView();
  1664. UpdateControls();
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1668. TObject * Sender, TObject * Source, int X, int Y)
  1669. {
  1670. if (Source == CopyParamListView)
  1671. {
  1672. if ((FListViewDragSource > 0) &&
  1673. AllowListViewDrag(Sender, X, Y) &&
  1674. (FListViewDragDest > 0))
  1675. {
  1676. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1677. }
  1678. }
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TPreferencesDialog::CopyParamListViewDragOver(
  1682. TObject * Sender, TObject * Source, int X, int Y, TDragState State, bool & Accept)
  1683. {
  1684. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1685. if (Source == Sender)
  1686. {
  1687. int Dest = PointToListViewIndex(Sender, X, Y);
  1688. if ((FListViewDragSource == 0) || (Dest == 0))
  1689. {
  1690. Accept = false;
  1691. }
  1692. }
  1693. }
  1694. //---------------------------------------------------------------------------
  1695. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1696. {
  1697. CopyParamMove(CopyParamListView->ItemIndex,
  1698. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1699. }
  1700. //---------------------------------------------------------------------------
  1701. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1702. TObject * /*Sender*/)
  1703. {
  1704. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1705. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1706. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1707. UpdateCopyParamListView();
  1708. UpdateControls();
  1709. }
  1710. //---------------------------------------------------------------------------
  1711. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1712. {
  1713. int Index = CopyParamListView->ItemIndex;
  1714. bool Result;
  1715. if ((Index == 0) && (Mode == cpmEdit))
  1716. {
  1717. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1718. }
  1719. else
  1720. {
  1721. TCopyParamRuleData * CopyParamRuleData =
  1722. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1723. // negative (when default is selected) means add to the end
  1724. Index--;
  1725. TCopyParamType DefaultCopyParams;
  1726. // For cpmAdd use defaults.
  1727. if (Mode == cpmDuplicate)
  1728. {
  1729. // Only used, when duplicating default settings (Index < 0)
  1730. DefaultCopyParams = FCopyParams;
  1731. }
  1732. else if (Mode == cpmEdit)
  1733. {
  1734. // For cpmEdit, DefaultCopyParams is never used.
  1735. DebugAssert(Index >= 0);
  1736. }
  1737. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1738. if (Result)
  1739. {
  1740. UpdateCopyParamListView();
  1741. CopyParamListView->ItemIndex = Index + 1;
  1742. // when using duplicate button, focus remains on original item
  1743. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1744. }
  1745. }
  1746. if (Result)
  1747. {
  1748. UpdateControls();
  1749. }
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1753. {
  1754. AddEditCopyParam(cpmAdd);
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1758. {
  1759. AddEditCopyParam(cpmEdit);
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1763. {
  1764. AddEditCopyParam(cpmDuplicate);
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1768. TObject * /*Sender*/)
  1769. {
  1770. if (EditCopyParamButton->Enabled)
  1771. {
  1772. AddEditCopyParam(cpmEdit);
  1773. }
  1774. }
  1775. //---------------------------------------------------------------------------
  1776. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1777. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1778. {
  1779. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1780. {
  1781. RemoveCopyParamButtonClick(NULL);
  1782. }
  1783. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1784. {
  1785. AddEditCopyParam(cpmAdd);
  1786. }
  1787. }
  1788. //---------------------------------------------------------------------------
  1789. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1790. {
  1791. FEditorList->Move(Source, Dest);
  1792. EditorListView3->ItemIndex = Dest;
  1793. UpdateEditorListView();
  1794. UpdateControls();
  1795. }
  1796. //---------------------------------------------------------------------------
  1797. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1798. TObject * Source, int X, int Y)
  1799. {
  1800. if (Source == EditorListView3)
  1801. {
  1802. if (AllowListViewDrag(Sender, X, Y))
  1803. {
  1804. EditorMove(FListViewDragSource, FListViewDragDest);
  1805. }
  1806. }
  1807. }
  1808. //---------------------------------------------------------------------------
  1809. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1810. {
  1811. EditorMove(EditorListView3->ItemIndex,
  1812. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1813. }
  1814. //---------------------------------------------------------------------------
  1815. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1816. TObject * /*Sender*/)
  1817. {
  1818. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1819. EditorListView3->ItemIndex < FEditorList->Count);
  1820. FEditorList->Delete(EditorListView3->ItemIndex);
  1821. UpdateEditorListView();
  1822. UpdateControls();
  1823. }
  1824. //---------------------------------------------------------------------------
  1825. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1826. {
  1827. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1828. int Index = EditorListView3->ItemIndex;
  1829. TEditorPreferences * Editor;
  1830. if (Mode == epmEdit)
  1831. {
  1832. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1833. }
  1834. else
  1835. {
  1836. Editor = new TEditorPreferences();
  1837. }
  1838. try
  1839. {
  1840. bool DummyRemember = false;
  1841. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1842. {
  1843. if (Mode == epmEdit)
  1844. {
  1845. FEditorList->Change(Index, Editor);
  1846. }
  1847. else
  1848. {
  1849. if (Index < 0)
  1850. {
  1851. Index = FEditorList->Count;
  1852. FEditorList->Add(Editor);
  1853. }
  1854. else
  1855. {
  1856. FEditorList->Insert(Index, Editor);
  1857. }
  1858. }
  1859. // ownership of the object lost
  1860. Editor = NULL;
  1861. UpdateEditorListView();
  1862. EditorListView3->ItemIndex = Index;
  1863. UpdateControls();
  1864. }
  1865. }
  1866. __finally
  1867. {
  1868. delete Editor;
  1869. }
  1870. }
  1871. //---------------------------------------------------------------------------
  1872. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1873. {
  1874. if (EditEditorButton->Enabled)
  1875. {
  1876. AddEditEditorButtonClick(EditEditorButton);
  1877. }
  1878. }
  1879. //---------------------------------------------------------------------------
  1880. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1881. WORD & Key, TShiftState /*Shift*/)
  1882. {
  1883. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1884. {
  1885. RemoveEditorButtonClick(NULL);
  1886. }
  1887. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1888. {
  1889. AddEditEditorButtonClick(AddEditorButton);
  1890. }
  1891. }
  1892. //---------------------------------------------------------------------------
  1893. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1894. {
  1895. EditorListView3->Items->Count = FEditorList->Count;
  1896. AutoSizeListColumnsWidth(EditorListView3);
  1897. EditorListView3->Invalidate();
  1898. }
  1899. //---------------------------------------------------------------------------
  1900. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1901. TListItem * Item)
  1902. {
  1903. // WORKAROUND We get here on Wine after destructor is called
  1904. if (FEditorList != NULL)
  1905. {
  1906. int Index = Item->Index;
  1907. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1908. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1909. Item->Caption = Editor->Name;
  1910. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1911. if (Editor->Data->Editor == edExternal)
  1912. {
  1913. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1914. }
  1915. }
  1916. }
  1917. //---------------------------------------------------------------------------
  1918. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1919. TTreeNode * Node)
  1920. {
  1921. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1922. {
  1923. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1924. // reshow the accelerators, etc
  1925. ResetSystemSettings(this);
  1926. // This is particularly here to enable EditCopyParamButton,
  1927. // as for some reason CopyParamListView->Selected is NULL until
  1928. // its page is shown for the first time
  1929. UpdateControls();
  1930. }
  1931. }
  1932. //---------------------------------------------------------------------------
  1933. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1934. {
  1935. // this is probably only ever called from FormShow (explicitly)
  1936. bool Found = false;
  1937. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1938. {
  1939. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1940. {
  1941. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1942. PageControl->ActivePage->Tag)
  1943. {
  1944. NavigationTree->Items->Item[Index]->Selected = true;
  1945. Found = true;
  1946. }
  1947. }
  1948. }
  1949. if (DebugAlwaysTrue(Found))
  1950. {
  1951. UpdateControls();
  1952. }
  1953. }
  1954. //---------------------------------------------------------------------------
  1955. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1956. {
  1957. if (Message.CharCode == VK_TAB)
  1958. {
  1959. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1960. if (Shift.Contains(ssCtrl))
  1961. {
  1962. TTreeNode * Node = NavigationTree->Selected;
  1963. if (!Shift.Contains(ssShift))
  1964. {
  1965. Node = Node->GetNext();
  1966. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1967. }
  1968. else
  1969. {
  1970. if (Node->GetPrev()) Node = Node->GetPrev();
  1971. else
  1972. while (Node->GetNext()) Node = Node->GetNext();
  1973. }
  1974. Node->Selected = True;
  1975. Message.Result = 1;
  1976. return;
  1977. }
  1978. }
  1979. TForm::Dispatch(&Message);
  1980. }
  1981. //---------------------------------------------------------------------------
  1982. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1983. {
  1984. DebugAssert(Message.HelpInfo != NULL);
  1985. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1986. {
  1987. // invoke help for active page (not for whole form), regardless of focus
  1988. // (e.g. even if focus is on control outside pagecontrol)
  1989. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1990. }
  1991. TForm::Dispatch(&Message);
  1992. }
  1993. //---------------------------------------------------------------------------
  1994. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  1995. {
  1996. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  1997. // we may end up using a slightly different size, so apply it straight away for consistency
  1998. UpdateControls();
  1999. TForm::Dispatch(&Message);
  2000. }
  2001. //---------------------------------------------------------------------------
  2002. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  2003. {
  2004. TMessage * M = reinterpret_cast<TMessage*>(Message);
  2005. DebugAssert(M);
  2006. if (M->Msg == CM_DIALOGKEY)
  2007. {
  2008. CMDialogKey(*((TWMKeyDown *)Message));
  2009. }
  2010. else if (M->Msg == CM_DPICHANGED)
  2011. {
  2012. CMDpiChanged(*M);
  2013. }
  2014. else if (M->Msg == WM_HELP)
  2015. {
  2016. WMHelp(*((TWMHelp *)Message));
  2017. }
  2018. else
  2019. {
  2020. TForm::Dispatch(Message);
  2021. }
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  2025. TObject * /*Sender*/)
  2026. {
  2027. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  2028. }
  2029. //---------------------------------------------------------------------------
  2030. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  2031. {
  2032. unsigned int Result =
  2033. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  2034. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2035. if (Result == qaYes)
  2036. {
  2037. TInstantOperationVisualizer Visualizer;
  2038. RegisterForDefaultProtocols();
  2039. }
  2040. }
  2041. //---------------------------------------------------------------------------
  2042. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  2043. {
  2044. unsigned int Result =
  2045. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  2046. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2047. if (Result == qaYes)
  2048. {
  2049. TInstantOperationVisualizer Visualizer;
  2050. UnregisterForProtocols();
  2051. }
  2052. }
  2053. //---------------------------------------------------------------------------
  2054. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  2055. {
  2056. TOperationVisualizer Visualizer;
  2057. LaunchAdvancedAssociationUI();
  2058. }
  2059. //---------------------------------------------------------------------------
  2060. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  2061. {
  2062. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  2063. }
  2064. //---------------------------------------------------------------------------
  2065. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  2066. TObject * /*Sender*/)
  2067. {
  2068. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  2069. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  2070. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  2071. {
  2072. TInstantOperationVisualizer Visualizer;
  2073. AddSearchPath(AppPath);
  2074. }
  2075. }
  2076. //---------------------------------------------------------------------------
  2077. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2078. TObject * Sender)
  2079. {
  2080. EditorFontButtonClick(Sender);
  2081. }
  2082. //---------------------------------------------------------------------------
  2083. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2084. {
  2085. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2086. AutoSizeListColumnsWidth(CopyParamListView);
  2087. CopyParamListView->Invalidate();
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2091. TListItem * Item)
  2092. {
  2093. // WORKAROUND We get here on Wine after destructor is called
  2094. if (FCopyParamList != NULL)
  2095. {
  2096. UnicodeString Name;
  2097. UnicodeString Rule;
  2098. int Index = Item->Index;
  2099. if (Index == 0)
  2100. {
  2101. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2102. }
  2103. else
  2104. {
  2105. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2106. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2107. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2108. }
  2109. Item->Caption = Name;
  2110. Item->SubItems->Add(Rule);
  2111. }
  2112. }
  2113. //---------------------------------------------------------------------------
  2114. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2115. {
  2116. FormHelp(this);
  2117. }
  2118. //---------------------------------------------------------------------------
  2119. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2120. TObject * /*Sender*/)
  2121. {
  2122. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2123. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2124. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2125. }
  2126. //---------------------------------------------------------------------------
  2127. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2128. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2129. {
  2130. FBeforeDialogPath = Name;
  2131. Name = ExpandEnvironmentVariables(Name);
  2132. }
  2133. //---------------------------------------------------------------------------
  2134. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2135. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2136. {
  2137. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2138. {
  2139. Name = FBeforeDialogPath;
  2140. }
  2141. }
  2142. //---------------------------------------------------------------------------
  2143. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2144. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2145. {
  2146. AllowCollapse = false;
  2147. }
  2148. //---------------------------------------------------------------------------
  2149. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2150. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2151. {
  2152. ScrollOnDragOver(Sender)->EndDrag();
  2153. }
  2154. //---------------------------------------------------------------------------
  2155. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2156. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2157. {
  2158. if (Value == 0)
  2159. {
  2160. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2161. Handled = true;
  2162. }
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2166. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2167. {
  2168. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2169. {
  2170. Value = 0;
  2171. Handled = true;
  2172. }
  2173. }
  2174. //---------------------------------------------------------------------------
  2175. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2176. {
  2177. bool Result;
  2178. bool Retry;
  2179. do
  2180. {
  2181. Retry = false;
  2182. Result = !AnyOtherInstanceOfSelf();
  2183. if (!Result)
  2184. {
  2185. unsigned int Answer =
  2186. MessageDialog(
  2187. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2188. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2189. HELP_MASTER_PASSWORD);
  2190. switch (Answer)
  2191. {
  2192. case qaRetry:
  2193. Retry = true;
  2194. break;
  2195. case qaIgnore:
  2196. Result = true;
  2197. break;
  2198. case qaCancel:
  2199. default:
  2200. // noop
  2201. break;
  2202. }
  2203. }
  2204. }
  2205. while (Retry && !Result);
  2206. return Result;
  2207. }
  2208. //---------------------------------------------------------------------------
  2209. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2210. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2211. {
  2212. // Save master password.
  2213. // This is unlikely to fail, as storage is written explicitly already
  2214. // when writing the recrypted passwords
  2215. Configuration->SaveExplicit();
  2216. TQueryType QueryType = qtInformation;
  2217. if (RecryptPasswordErrors->Count > 0)
  2218. {
  2219. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2220. QueryType = qtWarning;
  2221. }
  2222. MoreMessageDialog(
  2223. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2224. }
  2225. //---------------------------------------------------------------------------
  2226. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2227. {
  2228. UnicodeString NewPassword;
  2229. if (DoChangeMasterPasswordDialog(NewPassword))
  2230. {
  2231. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2232. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2233. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2234. }
  2235. }
  2236. //---------------------------------------------------------------------------
  2237. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2238. TObject * /*Sender*/)
  2239. {
  2240. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2241. {
  2242. try
  2243. {
  2244. if (CanSetMasterPassword())
  2245. {
  2246. if (UseMasterPasswordCheck->Checked)
  2247. {
  2248. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2249. }
  2250. else
  2251. {
  2252. if (DoMasterPasswordDialog())
  2253. {
  2254. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2255. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2256. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2257. }
  2258. }
  2259. }
  2260. }
  2261. __finally
  2262. {
  2263. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2264. UpdateControls();
  2265. }
  2266. }
  2267. }
  2268. //---------------------------------------------------------------------------
  2269. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2270. TObject * /*Sender*/)
  2271. {
  2272. if (CanSetMasterPassword())
  2273. {
  2274. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2275. }
  2276. }
  2277. //---------------------------------------------------------------------------
  2278. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2279. {
  2280. DoUsageStatisticsDialog();
  2281. }
  2282. //---------------------------------------------------------------------------
  2283. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2284. {
  2285. if (EditCopyParamButton->Enabled)
  2286. {
  2287. AddEditCopyParam(cpmEdit);
  2288. }
  2289. }
  2290. //---------------------------------------------------------------------------
  2291. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2292. TCustomListView * Sender, TListItem * Item,
  2293. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2294. {
  2295. if (Item->Index == 0)
  2296. {
  2297. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2298. }
  2299. }
  2300. //---------------------------------------------------------------------------
  2301. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2302. {
  2303. PuttyRegistryStorageKeyEdit->ItemIndex =
  2304. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2308. {
  2309. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2310. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2311. {
  2312. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2313. }
  2314. else if (ContainsText(PuttyPath, KittyExecutable))
  2315. {
  2316. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2317. }
  2318. UpdateControls();
  2319. }
  2320. //---------------------------------------------------------------------------
  2321. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2322. TTreeNode * Node, bool & /*AllowChange*/)
  2323. {
  2324. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2325. // delay load as this can be time consuming
  2326. if (Sheet == LanguagesSheet)
  2327. {
  2328. LoadLanguages();
  2329. }
  2330. }
  2331. //---------------------------------------------------------------------------
  2332. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2333. {
  2334. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2335. }
  2336. //---------------------------------------------------------------------------
  2337. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2338. {
  2339. CommanderInterfaceButton2->SetFocus();
  2340. }
  2341. //---------------------------------------------------------------------------
  2342. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2343. {
  2344. ExplorerInterfaceButton2->SetFocus();
  2345. }
  2346. //---------------------------------------------------------------------------
  2347. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2348. {
  2349. PanelFontButtonClick(Sender);
  2350. }
  2351. //---------------------------------------------------------------------------
  2352. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2353. {
  2354. if (!IsCancelButtonBeingClicked(this))
  2355. {
  2356. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2357. {
  2358. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2359. {
  2360. TUpdatesConfiguration Updates = SaveUpdates();
  2361. {
  2362. TInstantOperationVisualizer Visualizer;
  2363. QueryUpdates(Updates);
  2364. }
  2365. UnicodeString AuthenticationError = Updates.Results.AuthenticationError;
  2366. if (!AuthenticationError.IsEmpty())
  2367. {
  2368. AuthenticationError = FormatUpdatesMessage(AuthenticationError);
  2369. if (HasParagraphs(AuthenticationError))
  2370. {
  2371. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2372. }
  2373. else
  2374. {
  2375. AuthenticationError = MainInstructions(AuthenticationError);
  2376. }
  2377. unsigned int Result =
  2378. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HELP_AUTOMATIC_UPDATE);
  2379. if (Result == qaAbort)
  2380. {
  2381. Abort();
  2382. }
  2383. }
  2384. }
  2385. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2386. }
  2387. }
  2388. }
  2389. //---------------------------------------------------------------------------
  2390. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2391. {
  2392. EnableAutomaticUpdates();
  2393. }
  2394. //---------------------------------------------------------------------------
  2395. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2396. {
  2397. FOrigCustomCommandsViewWindowProc(Message);
  2398. if (Message.Msg == CN_NOTIFY)
  2399. {
  2400. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2401. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2402. {
  2403. // request CDDS_ITEMPOSTPAINT notification
  2404. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2405. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2406. int Index = CustomDraw->nmcd.dwItemSpec;
  2407. int CommandIndex = GetCommandIndex(Index);
  2408. TCustomCommandList * List = GetCommandList(Index);
  2409. // after end of every list, except for the last last list
  2410. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2411. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2412. {
  2413. TRect Rect;
  2414. Rect.Top = CustomDraw->iSubItem;
  2415. Rect.Left = LVIR_BOUNDS;
  2416. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2417. HDC DC = CustomDraw->nmcd.hdc;
  2418. SelectObject(DC, GetStockObject(DC_PEN));
  2419. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2420. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2421. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2422. }
  2423. }
  2424. }
  2425. }
  2426. //---------------------------------------------------------------------------
  2427. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2428. {
  2429. if ((Status / 10) == 49)
  2430. {
  2431. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2432. throw Exception(Message);
  2433. }
  2434. }
  2435. //---------------------------------------------------------------------------
  2436. void __fastcall TPreferencesDialog::AddExtension()
  2437. {
  2438. const UnicodeString HistoryKey(L"ExtensionPath");
  2439. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2440. UnicodeString Path;
  2441. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2442. HELP_NONE, History.get(), true) &&
  2443. !Path.IsEmpty())
  2444. {
  2445. CustomWinConfiguration->History[HistoryKey] = History.get();
  2446. bool Trusted;
  2447. bool Latest;
  2448. UnicodeString FileName;
  2449. UnicodeString ExtensionPath;
  2450. std::unique_ptr<TStringList> Lines(new TStringList());
  2451. std::unique_ptr<TCustomCommandType> CustomCommand;
  2452. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2453. try
  2454. {
  2455. UnicodeString ProvisionaryId;
  2456. if (IsUrl)
  2457. {
  2458. UnicodeString Url = Path;
  2459. Url = SecureUrl(Url);
  2460. bool WinSCPURL = IsWinSCPUrl(Url);
  2461. if (WinSCPURL)
  2462. {
  2463. Url = ProgramUrl(Url);
  2464. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2465. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2466. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2467. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2468. Url = CampaignUrl(Url);
  2469. }
  2470. TOperationVisualizer Visualizer;
  2471. std::unique_ptr<THttp> Http(CreateHttp());
  2472. Http->URL = Url;
  2473. std::unique_ptr<TStrings> Headers(new TStringList());
  2474. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2475. Http->RequestHeaders = Headers.get();
  2476. Http->OnError = ExtensionHttpError;
  2477. Http->Get();
  2478. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2479. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2480. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2481. if (FileName.IsEmpty())
  2482. {
  2483. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2484. }
  2485. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2486. Lines->Text = Http->Response;
  2487. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2488. }
  2489. else
  2490. {
  2491. if (!FileExists(ApiPath(Path)))
  2492. {
  2493. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2494. }
  2495. Trusted = true;
  2496. Latest = true;
  2497. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2498. FileName = ExtractFileName(Path);
  2499. if (!Id.IsEmpty())
  2500. {
  2501. ExtensionPath = Path;
  2502. ProvisionaryId = Id;
  2503. }
  2504. else
  2505. {
  2506. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2507. }
  2508. LoadScriptFromFile(Path, Lines.get());
  2509. }
  2510. // validate syntax
  2511. CustomCommand.reset(new TCustomCommandType());
  2512. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2513. CustomCommand->Id = ProvisionaryId;
  2514. CustomCommand->LoadExtension(Lines.get(), FileName);
  2515. }
  2516. catch (Exception & E)
  2517. {
  2518. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2519. }
  2520. if (!ExtensionPath.IsEmpty())
  2521. {
  2522. int Index = FExtensionList->FindIndexByFileName(Path);
  2523. if (Index >= 0)
  2524. {
  2525. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2526. CustomCommandsView->ItemFocused->MakeVisible(false);
  2527. CustomCommandsView->SetFocus();
  2528. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2529. }
  2530. }
  2531. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2532. {
  2533. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2534. }
  2535. if (ExtensionPath.IsEmpty())
  2536. {
  2537. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2538. {
  2539. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2540. if (FileNameOnly.IsEmpty())
  2541. {
  2542. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2543. }
  2544. else
  2545. {
  2546. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2547. }
  2548. }
  2549. }
  2550. if (Trusted ||
  2551. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2552. {
  2553. if (ExtensionPath.IsEmpty())
  2554. {
  2555. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2556. if (!DirectoryExists(UserExtensionsPath) &&
  2557. !ForceDirectories(UserExtensionsPath))
  2558. {
  2559. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2560. }
  2561. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2562. int Counter = 1;
  2563. UnicodeString OriginalExtensionPath = ExtensionPath;
  2564. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2565. while (FileExists(ApiPath(ExtensionPath)))
  2566. {
  2567. Counter++;
  2568. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2569. }
  2570. Lines->SaveToFile(ApiPath(ExtensionPath));
  2571. FAddedExtensions->Add(ExtensionPath);
  2572. }
  2573. int Index = GetListCommandIndex(FExtensionList);
  2574. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2575. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2576. CustomCommand->LoadExtension(ExtensionPath);
  2577. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2578. UpdateCustomCommandsView();
  2579. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2580. CustomCommandsView->ItemFocused->MakeVisible(false);
  2581. UpdateControls();
  2582. if (!Latest)
  2583. {
  2584. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2585. }
  2586. if (IsUrl)
  2587. {
  2588. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2589. }
  2590. else
  2591. {
  2592. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2593. }
  2594. }
  2595. }
  2596. }
  2597. //---------------------------------------------------------------------------
  2598. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2599. {
  2600. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2601. {
  2602. AddEditCommand(false);
  2603. }
  2604. else
  2605. {
  2606. AddExtension();
  2607. }
  2608. }
  2609. //---------------------------------------------------------------------------
  2610. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2611. {
  2612. AddEditCommand(false);
  2613. }
  2614. //---------------------------------------------------------------------------
  2615. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2616. {
  2617. AddExtension();
  2618. }
  2619. //---------------------------------------------------------------------------
  2620. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2621. {
  2622. AddEditCommand(true);
  2623. }
  2624. //---------------------------------------------------------------------------
  2625. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2626. {
  2627. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2628. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2629. MenuPopup(AddCommandMenu, AddCommandButton);
  2630. }
  2631. //---------------------------------------------------------------------------
  2632. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2633. {
  2634. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2635. UnicodeString Result;
  2636. if (Terminal != NULL)
  2637. {
  2638. Result = Terminal->SessionData->SessionKey;
  2639. }
  2640. return Result;
  2641. }
  2642. //---------------------------------------------------------------------------
  2643. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2644. {
  2645. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2646. int Index = (Item != NULL) ? Item->Index : -1;
  2647. if (Index != FCustomCommandsHintItem)
  2648. {
  2649. Application->CancelHint();
  2650. UnicodeString Hint;
  2651. if (Index >= 0)
  2652. {
  2653. TCustomCommandList * List = GetCommandList(Index);
  2654. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2655. Hint = StripHotkey(Command->Name);
  2656. if (Command->ShortCut != 0)
  2657. {
  2658. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2659. }
  2660. if (!Command->Description.IsEmpty())
  2661. {
  2662. Hint += L"\n" + Command->Description;
  2663. }
  2664. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2665. if (List == FExtensionList)
  2666. {
  2667. Hint += L"\n" + Command->FileName;
  2668. }
  2669. }
  2670. CustomCommandsView->Hint = Hint;
  2671. FCustomCommandsHintItem = Index;
  2672. }
  2673. }
  2674. //---------------------------------------------------------------------------
  2675. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2676. {
  2677. PageControl->ActivePage = QueueSheet;
  2678. PageControlChange(NULL);
  2679. QueueNoConfirmationCheck->SetFocus();
  2680. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2681. }
  2682. //---------------------------------------------------------------------------
  2683. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2684. {
  2685. ConfigureCommand();
  2686. }
  2687. //---------------------------------------------------------------------------
  2688. void __fastcall TPreferencesDialog::ConfigureCommand()
  2689. {
  2690. int Index = CustomCommandsView->ItemIndex;
  2691. TCustomCommandList * CommandList = GetCommandList(Index);
  2692. int CommandIndex = GetCommandIndex(Index);
  2693. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2694. UnicodeString Site = GetSessionKey();
  2695. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2696. Site.IsEmpty())
  2697. {
  2698. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2699. }
  2700. TShortCut ShortCut = Command->ShortCut;
  2701. TShortCuts ShortCuts = GetShortCuts();
  2702. if (DoCustomCommandOptionsDialog(
  2703. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2704. {
  2705. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2706. UpdatedCommand->ShortCut = ShortCut;
  2707. CommandList->Change(CommandIndex, UpdatedCommand);
  2708. UpdateCustomCommandsView();
  2709. }
  2710. }
  2711. //---------------------------------------------------------------------------
  2712. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2713. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2714. {
  2715. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2716. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2717. {
  2718. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2719. }
  2720. if (LocaleInfo->Completeness < 0)
  2721. {
  2722. Sender->Canvas->Font->Color = clRed;
  2723. }
  2724. else if (LocaleInfo->Completeness < 100)
  2725. {
  2726. Sender->Canvas->Font->Color = clGrayText;
  2727. }
  2728. }
  2729. //---------------------------------------------------------------------------
  2730. void __fastcall TPreferencesDialog::LogMaxSizeComboExit(TObject * /*Sender*/)
  2731. {
  2732. __int64 Size;
  2733. if (!IsCancelButtonBeingClicked(this))
  2734. {
  2735. if (!TryStrToSize(LogMaxSizeCombo->Text, Size))
  2736. {
  2737. LogMaxSizeCombo->SetFocus();
  2738. throw Exception(FMTLOAD(SIZE_INVALID, (LogMaxSizeCombo->Text)));
  2739. }
  2740. else
  2741. {
  2742. LogMaxSizeCombo->Text = SizeToStr(Size);
  2743. }
  2744. }
  2745. }
  2746. //---------------------------------------------------------------------------
  2747. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2748. {
  2749. if (!IsCancelButtonBeingClicked(this))
  2750. {
  2751. try
  2752. {
  2753. UnicodeString Program, AParams, Dir;
  2754. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2755. }
  2756. catch(...)
  2757. {
  2758. PuttyPathEdit->SelectAll();
  2759. PuttyPathEdit->SetFocus();
  2760. throw;
  2761. }
  2762. }
  2763. }
  2764. //---------------------------------------------------------------------------
  2765. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2766. {
  2767. Active = AutomaticIniFileStorageButton->Checked;
  2768. }
  2769. //---------------------------------------------------------------------------
  2770. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2771. {
  2772. UnicodeString Result;
  2773. if (CustomIniFileStorageButton->Checked)
  2774. {
  2775. Result = CustomIniFileStorageEdit->Text;
  2776. }
  2777. return Result;
  2778. }
  2779. //---------------------------------------------------------------------------
  2780. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2781. {
  2782. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2783. if (!CustomIniFileStorageName.IsEmpty() &&
  2784. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2785. FileExists(CustomIniFileStorageName))
  2786. {
  2787. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageName));
  2788. TMessageParams Params;
  2789. TQueryButtonAlias Aliases[2];
  2790. Aliases[0].Button = qaYes;
  2791. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2792. Aliases[1].Button = qaNo;
  2793. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2794. Params.Aliases = Aliases;
  2795. Params.AliasesCount = 2;
  2796. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2797. if (Result == qaYes)
  2798. {
  2799. // noop
  2800. }
  2801. else if (Result == qaNo)
  2802. {
  2803. Configuration->ScheduleCustomIniFileStorageUse(GetCustomIniFileStorageName());
  2804. ExecuteNewInstance(L"");
  2805. TerminateApplication();
  2806. }
  2807. else
  2808. {
  2809. Abort();
  2810. }
  2811. }
  2812. FCustomIniFileStorageName = CustomIniFileStorageName;
  2813. }
  2814. //---------------------------------------------------------------------------
  2815. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2816. {
  2817. if (!IsCancelButtonBeingClicked(this))
  2818. {
  2819. CustomIniFileStorageChanged();
  2820. }
  2821. else
  2822. {
  2823. // Reset the value to prevent accidental overwide of an INI file, in case the dialog cancel does not complete
  2824. CustomIniFileStorageEdit->Text = FCustomIniFileStorageName;
  2825. }
  2826. }
  2827. //---------------------------------------------------------------------------
  2828. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2829. {
  2830. PathEditAfterDialog(Sender, Name, Action);
  2831. if (Action)
  2832. {
  2833. CustomIniFileStorageEdit->Text = Name;
  2834. CustomIniFileStorageChanged();
  2835. }
  2836. }
  2837. //---------------------------------------------------------------------------
  2838. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2839. {
  2840. UpdateControls();
  2841. // Handler is shown also when Checked is set from LoadConfiguration
  2842. if (FNoUpdate == 0)
  2843. {
  2844. // Focus to force validation
  2845. CustomIniFileStorageEdit->SetFocus();
  2846. }
  2847. }
  2848. //---------------------------------------------------------------------------
  2849. void __fastcall TPreferencesDialog::UpdateFileColorsView()
  2850. {
  2851. FileColorsView->Items->Count = FFileColors.size();
  2852. AutoSizeListColumnsWidth(FileColorsView);
  2853. }
  2854. //---------------------------------------------------------------------------
  2855. void __fastcall TPreferencesDialog::FileColorsViewData(TObject *, TListItem * Item)
  2856. {
  2857. Item->Caption = FFileColors[Item->Index].FileMask.Masks;
  2858. }
  2859. //---------------------------------------------------------------------------
  2860. void __fastcall TPreferencesDialog::FileColorsViewCustomDrawItem(
  2861. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  2862. {
  2863. Sender->Canvas->Font->Color = FFileColors[Item->Index].Color;
  2864. }
  2865. //---------------------------------------------------------------------------
  2866. void __fastcall TPreferencesDialog::AddEditFileColor(bool Edit)
  2867. {
  2868. TFileColorData FileColorData;
  2869. int Index = FileColorsView->ItemIndex;
  2870. if (Edit)
  2871. {
  2872. FileColorData = FFileColors[Index];
  2873. }
  2874. else
  2875. {
  2876. FileColorData.FileMask = AnyMask;
  2877. }
  2878. if (DoFileColorDialog(FileColorData))
  2879. {
  2880. if (Edit)
  2881. {
  2882. FFileColors[Index] = FileColorData;
  2883. }
  2884. else
  2885. {
  2886. if (Index < 0)
  2887. {
  2888. FFileColors.push_back(FileColorData);
  2889. }
  2890. else
  2891. {
  2892. FFileColors.insert(&FFileColors[Index], FileColorData);
  2893. }
  2894. }
  2895. UpdateFileColorsView();
  2896. FileColorsView->ItemIndex = Index;
  2897. UpdateControls();
  2898. }
  2899. }
  2900. //---------------------------------------------------------------------------
  2901. void __fastcall TPreferencesDialog::AddEditFileColorButtonClick(TObject * Sender)
  2902. {
  2903. bool Edit = (Sender == EditFileColorButton);
  2904. AddEditFileColor(Edit);
  2905. }
  2906. //---------------------------------------------------------------------------
  2907. void __fastcall TPreferencesDialog::FileColorMove(int Source, int Dest)
  2908. {
  2909. FFileColors.insert(FFileColors.begin() + Dest + ((Dest > Source) ? 1 : 0), FFileColors[Source]);
  2910. FFileColors.erase(FFileColors.begin() + Source + ((Dest < Source) ? 1 : 0));
  2911. FileColorsView->ItemIndex = Dest;
  2912. UpdateFileColorsView();
  2913. UpdateControls();
  2914. }
  2915. //---------------------------------------------------------------------------
  2916. void __fastcall TPreferencesDialog::FileColorsViewDragDrop(TObject * Sender, TObject * Source, int X, int Y)
  2917. {
  2918. if (Source == FileColorsView)
  2919. {
  2920. if (AllowListViewDrag(Sender, X, Y))
  2921. {
  2922. FileColorMove(FListViewDragSource, FListViewDragDest);
  2923. }
  2924. }
  2925. }
  2926. //---------------------------------------------------------------------------
  2927. void __fastcall TPreferencesDialog::FileColorsViewKeyDown(TObject *, WORD & Key, TShiftState)
  2928. {
  2929. if (RemoveFileColorButton->Enabled && (Key == VK_DELETE))
  2930. {
  2931. RemoveFileColorButtonClick(NULL);
  2932. }
  2933. if (DebugAlwaysTrue(AddFileColorButton->Enabled) && (Key == VK_INSERT))
  2934. {
  2935. AddEditFileColor(false);
  2936. }
  2937. }
  2938. //---------------------------------------------------------------------------
  2939. void __fastcall TPreferencesDialog::RemoveFileColorButtonClick(TObject *)
  2940. {
  2941. FFileColors.erase(FFileColors.begin() + FileColorsView->ItemIndex);
  2942. UpdateFileColorsView();
  2943. UpdateControls();
  2944. }
  2945. //---------------------------------------------------------------------------
  2946. void __fastcall TPreferencesDialog::FileColorsViewDblClick(TObject *)
  2947. {
  2948. if (EditFileColorButton->Enabled)
  2949. {
  2950. AddEditFileColor(true);
  2951. }
  2952. }
  2953. //---------------------------------------------------------------------------
  2954. void __fastcall TPreferencesDialog::UpDownFileColorButtonClick(TObject * Sender)
  2955. {
  2956. int DestIndex = FileColorsView->ItemIndex + (Sender == UpFileColorButton ? -1 : 1);
  2957. FileColorMove(FileColorsView->ItemIndex, DestIndex);
  2958. }
  2959. //---------------------------------------------------------------------------