1
0

Preferences.cpp 103 KB

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