Preferences.cpp 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963
  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->IsDDExtBroken())
  1102. {
  1103. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_BROKEN);
  1104. DragExtStatusLabel->Enabled = false;
  1105. DragExtStatusLabel->Font->Color = clWindowText;
  1106. }
  1107. else if (!WinConfiguration->DDExtInstalled)
  1108. {
  1109. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_INSTALLED);
  1110. DragExtStatusLabel->Enabled = false;
  1111. DragExtStatusLabel->Font->Color = clWindowText;
  1112. }
  1113. else if (!WinConfiguration->IsDDExtRunning())
  1114. {
  1115. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_RUNNING);
  1116. DragExtStatusLabel->Enabled = true;
  1117. DragExtStatusLabel->Font->Color = clGrayText;
  1118. }
  1119. else
  1120. {
  1121. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_RUNNING);
  1122. DragExtStatusLabel->Enabled = true;
  1123. DragExtStatusLabel->Font->Color = clWindowText;
  1124. }
  1125. EnableControl(DDFakeFileDisabledPanel, DDFakeFileDisabledButton->Checked);
  1126. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  1127. DDCustomTemporaryDirectoryButton->Checked);
  1128. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  1129. TemporaryDirectoryCleanupCheck->Checked);
  1130. // allow only when some of the known storages is selected,
  1131. // and particularly do not allow switching storage, when we start with stNul,
  1132. // as that would destroy the stored configuration
  1133. EnableControl(StorageGroup,
  1134. RegistryStorageButton->Checked || AutomaticIniFileStorageButton->Checked || CustomIniFileStorageButton->Checked);
  1135. AutomaticIniFileStorageLabel->UpdateStatus();
  1136. EnableControl(CustomIniFileStorageEdit, CustomIniFileStorageButton->Checked);
  1137. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1138. bool EditorSelected = (EditorListView3->Selected != NULL);
  1139. EnableControl(EditEditorButton, EditorSelected);
  1140. EnableControl(RemoveEditorButton, EditorSelected);
  1141. EnableControl(UpEditorButton, EditorSelected &&
  1142. (EditorListView3->ItemIndex > 0));
  1143. EnableControl(DownEditorButton, EditorSelected &&
  1144. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1145. // updates
  1146. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1147. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1148. EnableControl(UpdatesShowOnStartup, !IsUWP());
  1149. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1150. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1151. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1152. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1153. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1154. bool IsSiteCommand = false;
  1155. bool IsPasswordCommand = false;
  1156. try
  1157. {
  1158. TRemoteCustomCommand RemoteCustomCommand;
  1159. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1160. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1161. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1162. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1163. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1164. }
  1165. catch (...)
  1166. {
  1167. // noop
  1168. }
  1169. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1170. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1171. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1172. EnableControl(TelnetForFtpInPuttyCheck,
  1173. AnyPuttyPath && !IsSiteCommand);
  1174. EnableControl(PuttyRegistryStorageKeyEdit,
  1175. AnyPuttyPath && !IsSiteCommand && !IsUWP());
  1176. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1177. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1178. // network
  1179. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1180. // window
  1181. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1182. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1183. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1184. !Configuration->DisablePasswordStoring &&
  1185. AutoWorkspaceCombo->Enabled);
  1186. // integration
  1187. EnableControl(ShellIconsGroup, !IsUWP());
  1188. // There's no quick launch in Windows 7
  1189. EnableControl(QuickLaunchIconButton, ShellIconsGroup->Enabled && !IsWin7());
  1190. MakeDefaultHandlerItem->Visible = IsWinVista();
  1191. // languages
  1192. LanguageChangeLabel->Visible =
  1193. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1194. (LanguagesView->ItemFocused != NULL) &&
  1195. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1196. // logging
  1197. EnableControl(LogProtocolCombo, EnableLoggingCheck->Checked);
  1198. EnableControl(LogFileNameEdit3, LogProtocolCombo->Enabled);
  1199. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1200. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1201. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1202. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1203. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1204. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1205. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1206. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1207. EnableControl(LogSensitiveCheck, LogProtocolCombo->Enabled);
  1208. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1209. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1210. // interface
  1211. InterfaceChangeLabel->Visible =
  1212. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1213. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1214. }
  1215. }
  1216. //---------------------------------------------------------------------------
  1217. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1218. {
  1219. if (FontDialog(FEditorFont.get()))
  1220. {
  1221. UpdateControls();
  1222. }
  1223. }
  1224. //---------------------------------------------------------------------------
  1225. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1226. {
  1227. FEditorFont->Color = Color;
  1228. UpdateControls();
  1229. }
  1230. //---------------------------------------------------------------------------
  1231. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1232. {
  1233. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1234. // "internal error" when passing menu directly to unique_ptr.
  1235. // Splitting it to two statements seems to help.
  1236. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick and TOpenLocalPathHandler::Open
  1237. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1238. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1239. FColorPopupMenu.reset(Menu);
  1240. MenuPopup(Menu, EditorFontColorButton);
  1241. }
  1242. //---------------------------------------------------------------------------
  1243. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1244. {
  1245. FEditorBackgroundColor = Color;
  1246. UpdateControls();
  1247. }
  1248. //---------------------------------------------------------------------------
  1249. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1250. {
  1251. // See comment in EditorFontColorButtonClick.
  1252. // We are using session color (contrary to editor text color) for background
  1253. // for a consistency with color selection menu on editor toolbar.
  1254. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1255. FColorPopupMenu.reset(PopupMenu);
  1256. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1257. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1261. {
  1262. if (FontDialog(FPanelFont.get()))
  1263. {
  1264. PanelFontCheck->Checked = true;
  1265. UpdateControls();
  1266. }
  1267. }
  1268. //---------------------------------------------------------------------------
  1269. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1270. bool & /*CanClose*/)
  1271. {
  1272. if (ModalResult == DefaultResult(this))
  1273. {
  1274. ExitActiveControl(this);
  1275. }
  1276. }
  1277. //---------------------------------------------------------------------------
  1278. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1279. {
  1280. UnicodeString IconName, Params;
  1281. int SpecialFolder;
  1282. if (Sender == DesktopIconButton)
  1283. {
  1284. IconName = AppName;
  1285. int Result =
  1286. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1287. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1288. switch (Result)
  1289. {
  1290. case qaYes:
  1291. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1292. break;
  1293. case qaNo:
  1294. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1295. break;
  1296. default:
  1297. Abort();
  1298. break;
  1299. }
  1300. }
  1301. else
  1302. {
  1303. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1304. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1305. {
  1306. if (Sender == SendToHookButton)
  1307. {
  1308. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1309. SpecialFolder = CSIDL_SENDTO;
  1310. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1311. }
  1312. else if (Sender == QuickLaunchIconButton)
  1313. {
  1314. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  1315. AppName;
  1316. SpecialFolder = CSIDL_APPDATA;
  1317. }
  1318. }
  1319. else
  1320. {
  1321. Abort();
  1322. }
  1323. }
  1324. TInstantOperationVisualizer Visualizer;
  1325. CreateDesktopShortCut(IconName,
  1326. Application->ExeName, Params, L"", SpecialFolder);
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1330. TListItem * Item)
  1331. {
  1332. // WORKAROUND We get here on Wine after destructor is called
  1333. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1334. {
  1335. int Index = Item->Index;
  1336. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1337. UnicodeString Caption = StripHotkey(Command->Name);
  1338. Item->Caption = Caption;
  1339. DebugAssert(!Item->SubItems->Count);
  1340. Item->SubItems->Add(Command->Command);
  1341. Item->SubItems->Add(LoadStr(
  1342. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1343. }
  1344. }
  1345. //---------------------------------------------------------------------------
  1346. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1347. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1348. {
  1349. UpdateControls();
  1350. }
  1351. //---------------------------------------------------------------------------
  1352. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1353. {
  1354. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1355. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1356. CustomCommandsView->Invalidate();
  1357. // particularly after command is edited/configured, make sure the hint is updated,
  1358. // even if we manage to display a hint for the same command as before the change
  1359. FCustomCommandsHintItem = NULL;
  1360. }
  1361. //---------------------------------------------------------------------------
  1362. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1363. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1364. {
  1365. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1366. {
  1367. RemoveCommandButtonClick(NULL);
  1368. }
  1369. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1370. {
  1371. AddEditCommand(false);
  1372. }
  1373. }
  1374. //---------------------------------------------------------------------------
  1375. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1376. TObject * /*Sender*/)
  1377. {
  1378. if (EditCommandButton->Enabled)
  1379. {
  1380. AddEditCommand(true);
  1381. }
  1382. else if (ConfigureCommandButton->Enabled)
  1383. {
  1384. ConfigureCommand();
  1385. }
  1386. }
  1387. //---------------------------------------------------------------------------
  1388. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1389. {
  1390. if (Index >= 0)
  1391. {
  1392. List->Insert(Index, Command);
  1393. }
  1394. else
  1395. {
  1396. List->Add(Command);
  1397. Index = List->Count - 1;
  1398. }
  1399. return Index;
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1403. {
  1404. TShortCuts ShortCuts;
  1405. if (WinConfiguration->SharedBookmarks != NULL)
  1406. {
  1407. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1408. }
  1409. FCustomCommandList->ShortCuts(ShortCuts);
  1410. FExtensionList->ShortCuts(ShortCuts);
  1411. return ShortCuts;
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1415. {
  1416. TCustomCommandType Command;
  1417. if (Edit)
  1418. {
  1419. int Index = CustomCommandsView->ItemIndex;
  1420. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1421. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1422. }
  1423. TShortCuts ShortCuts = GetShortCuts();
  1424. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1425. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1426. {
  1427. int Index = GetListCommandIndex(FCustomCommandList);
  1428. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1429. if (Edit)
  1430. {
  1431. DebugAssert(Index < FCustomCommandList->Count);
  1432. FCustomCommandList->Change(Index, ACommand);
  1433. }
  1434. else
  1435. {
  1436. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1437. }
  1438. UpdateCustomCommandsView();
  1439. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1440. CustomCommandsView->ItemFocused->MakeVisible(false);
  1441. UpdateControls();
  1442. }
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1446. TObject * /*Sender*/)
  1447. {
  1448. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1449. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1450. if (List == FExtensionList)
  1451. {
  1452. const TCustomCommandType * CustomComand = List->Commands[Index];
  1453. // If the extension was added in this "preferences session", remove the file
  1454. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1455. if (PathIndex >= 0)
  1456. {
  1457. FAddedExtensions->Delete(PathIndex);
  1458. DeleteFile(ApiPath(CustomComand->FileName));
  1459. }
  1460. }
  1461. List->Delete(Index);
  1462. UpdateCustomCommandsView();
  1463. UpdateControls();
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1467. {
  1468. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1469. int SourceIndex = GetCommandIndex(Source);
  1470. int DestIndex = GetCommandIndex(Dest);
  1471. List->Move(SourceIndex, DestIndex);
  1472. // workaround for bug in VCL
  1473. CustomCommandsView->ItemIndex = -1;
  1474. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  1475. CustomCommandsView->ItemIndex = Dest;
  1476. UpdateCustomCommandsView();
  1477. UpdateControls();
  1478. }
  1479. //---------------------------------------------------------------------------
  1480. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1481. {
  1482. CustomCommandMove(CustomCommandsView->ItemIndex,
  1483. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1484. }
  1485. //---------------------------------------------------------------------------
  1486. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1487. {
  1488. if (ListView == CopyParamListView)
  1489. {
  1490. return FCopyParamScrollOnDragOver;
  1491. }
  1492. else if (ListView == CustomCommandsView)
  1493. {
  1494. return FCustomCommandsScrollOnDragOver;
  1495. }
  1496. else if (ListView == EditorListView3)
  1497. {
  1498. return FEditorScrollOnDragOver;
  1499. }
  1500. else
  1501. {
  1502. DebugFail();
  1503. return NULL;
  1504. }
  1505. }
  1506. //---------------------------------------------------------------------------
  1507. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1508. TObject * Sender, TDragObject *& /*DragObject*/)
  1509. {
  1510. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1511. FListViewDragDest = -1;
  1512. ScrollOnDragOver(Sender)->StartDrag();
  1513. }
  1514. //---------------------------------------------------------------------------
  1515. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1516. {
  1517. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1518. return Item ? Item->Index : -1;
  1519. }
  1520. //---------------------------------------------------------------------------
  1521. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1522. {
  1523. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1524. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1525. }
  1526. //---------------------------------------------------------------------------
  1527. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1528. TObject * Sender, TObject * Source, int X, int Y)
  1529. {
  1530. if (Source == CustomCommandsView)
  1531. {
  1532. if (AllowListViewDrag(Sender, X, Y) &&
  1533. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1534. {
  1535. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1536. }
  1537. }
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1541. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1542. {
  1543. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1544. if (Source == Sender)
  1545. {
  1546. int Dest = PointToListViewIndex(Sender, X, Y);
  1547. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1548. {
  1549. Accept = false;
  1550. }
  1551. }
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TPreferencesDialog::ListViewDragOver(
  1555. TObject * Sender, TObject * Source, int X, int Y,
  1556. TDragState /*State*/, bool & Accept)
  1557. {
  1558. if (Source == Sender)
  1559. {
  1560. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1561. // (when dropped on item itself, when it was dragged over another item before,
  1562. // that another item remains highlighted forever)
  1563. Accept = true;
  1564. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1565. }
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1569. {
  1570. if (Index == 0)
  1571. {
  1572. return &FCopyParams;
  1573. }
  1574. else
  1575. {
  1576. return FCopyParamList->CopyParams[Index - 1];
  1577. }
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1581. {
  1582. if (Source >= 1 && Source < (1 + FCopyParamList->Count) &&
  1583. Dest >= 0 && Dest < (1 + FCopyParamList->Count))
  1584. {
  1585. if (Dest == 0)
  1586. {
  1587. Dest = 1;
  1588. }
  1589. FCopyParamList->Move(Source - 1, Dest - 1);
  1590. // workaround for bug in VCL
  1591. CopyParamListView->ItemIndex = -1;
  1592. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1593. CopyParamListView->ItemIndex = Dest;
  1594. UpdateCopyParamListView();
  1595. UpdateControls();
  1596. }
  1597. }
  1598. //---------------------------------------------------------------------------
  1599. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1600. TObject * Sender, TObject * Source, int X, int Y)
  1601. {
  1602. if (Source == CopyParamListView)
  1603. {
  1604. if (AllowListViewDrag(Sender, X, Y))
  1605. {
  1606. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1607. }
  1608. }
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1612. {
  1613. CopyParamMove(CopyParamListView->ItemIndex,
  1614. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1618. TObject * /*Sender*/)
  1619. {
  1620. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1621. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1622. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1623. UpdateCopyParamListView();
  1624. UpdateControls();
  1625. }
  1626. //---------------------------------------------------------------------------
  1627. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1628. {
  1629. int Index = CopyParamListView->ItemIndex;
  1630. bool Result;
  1631. if ((Index == 0) && (Mode == cpmEdit))
  1632. {
  1633. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1634. }
  1635. else
  1636. {
  1637. TCopyParamRuleData * CopyParamRuleData =
  1638. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1639. // negative (when default is selected) means add to the end
  1640. Index--;
  1641. TCopyParamType DefaultCopyParams;
  1642. // For cpmAdd use defaults.
  1643. if (Mode == cpmDuplicate)
  1644. {
  1645. // Only used, when duplicating default settings (Index < 0)
  1646. DefaultCopyParams = FCopyParams;
  1647. }
  1648. else if (Mode == cpmEdit)
  1649. {
  1650. // For cpmEdit, DefaultCopyParams is never used.
  1651. DebugAssert(Index >= 0);
  1652. }
  1653. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1654. if (Result)
  1655. {
  1656. UpdateCopyParamListView();
  1657. CopyParamListView->ItemIndex = Index + 1;
  1658. // when using duplicate button, focus remains on original item
  1659. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1660. }
  1661. }
  1662. if (Result)
  1663. {
  1664. UpdateControls();
  1665. }
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1669. {
  1670. AddEditCopyParam(cpmAdd);
  1671. }
  1672. //---------------------------------------------------------------------------
  1673. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1674. {
  1675. AddEditCopyParam(cpmEdit);
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1679. {
  1680. AddEditCopyParam(cpmDuplicate);
  1681. }
  1682. //---------------------------------------------------------------------------
  1683. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1684. TObject * /*Sender*/)
  1685. {
  1686. if (EditCopyParamButton->Enabled)
  1687. {
  1688. AddEditCopyParam(cpmEdit);
  1689. }
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1693. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1694. {
  1695. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1696. {
  1697. RemoveCopyParamButtonClick(NULL);
  1698. }
  1699. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1700. {
  1701. AddEditCopyParam(cpmAdd);
  1702. }
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1706. {
  1707. if (Source >= 0 && Source < FEditorList->Count &&
  1708. Dest >= 0 && Dest < FEditorList->Count)
  1709. {
  1710. FEditorList->Move(Source, Dest);
  1711. // workaround for bug in VCL
  1712. EditorListView3->ItemIndex = -1;
  1713. EditorListView3->ItemFocused = EditorListView3->Selected;
  1714. EditorListView3->ItemIndex = Dest;
  1715. UpdateEditorListView();
  1716. UpdateControls();
  1717. }
  1718. }
  1719. //---------------------------------------------------------------------------
  1720. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1721. TObject * Source, int X, int Y)
  1722. {
  1723. if (Source == EditorListView3)
  1724. {
  1725. if (AllowListViewDrag(Sender, X, Y))
  1726. {
  1727. EditorMove(FListViewDragSource, FListViewDragDest);
  1728. }
  1729. }
  1730. }
  1731. //---------------------------------------------------------------------------
  1732. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1733. {
  1734. EditorMove(EditorListView3->ItemIndex,
  1735. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1736. }
  1737. //---------------------------------------------------------------------------
  1738. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1739. TObject * /*Sender*/)
  1740. {
  1741. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1742. EditorListView3->ItemIndex < FEditorList->Count);
  1743. FEditorList->Delete(EditorListView3->ItemIndex);
  1744. UpdateEditorListView();
  1745. UpdateControls();
  1746. }
  1747. //---------------------------------------------------------------------------
  1748. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1749. {
  1750. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1751. int Index = EditorListView3->ItemIndex;
  1752. TEditorPreferences * Editor;
  1753. if (Mode == epmEdit)
  1754. {
  1755. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1756. }
  1757. else
  1758. {
  1759. Editor = new TEditorPreferences();
  1760. }
  1761. try
  1762. {
  1763. bool DummyRemember = false;
  1764. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1765. {
  1766. if (Mode == epmEdit)
  1767. {
  1768. FEditorList->Change(Index, Editor);
  1769. }
  1770. else
  1771. {
  1772. if (Index < 0)
  1773. {
  1774. Index = FEditorList->Count;
  1775. FEditorList->Add(Editor);
  1776. }
  1777. else
  1778. {
  1779. FEditorList->Insert(Index, Editor);
  1780. }
  1781. }
  1782. // ownership of the object lost
  1783. Editor = NULL;
  1784. UpdateEditorListView();
  1785. EditorListView3->ItemIndex = Index;
  1786. UpdateControls();
  1787. }
  1788. }
  1789. __finally
  1790. {
  1791. delete Editor;
  1792. }
  1793. }
  1794. //---------------------------------------------------------------------------
  1795. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1796. {
  1797. if (EditEditorButton->Enabled)
  1798. {
  1799. AddEditEditorButtonClick(EditEditorButton);
  1800. }
  1801. }
  1802. //---------------------------------------------------------------------------
  1803. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1804. WORD & Key, TShiftState /*Shift*/)
  1805. {
  1806. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1807. {
  1808. RemoveEditorButtonClick(NULL);
  1809. }
  1810. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1811. {
  1812. AddEditEditorButtonClick(AddEditorButton);
  1813. }
  1814. }
  1815. //---------------------------------------------------------------------------
  1816. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1817. {
  1818. EditorListView3->Items->Count = FEditorList->Count;
  1819. AutoSizeListColumnsWidth(EditorListView3);
  1820. EditorListView3->Invalidate();
  1821. }
  1822. //---------------------------------------------------------------------------
  1823. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1824. TListItem * Item)
  1825. {
  1826. // WORKAROUND We get here on Wine after destructor is called
  1827. if (FEditorList != NULL)
  1828. {
  1829. int Index = Item->Index;
  1830. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1831. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1832. Item->Caption = Editor->Name;
  1833. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1834. if (Editor->Data->Editor == edExternal)
  1835. {
  1836. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1837. }
  1838. }
  1839. }
  1840. //---------------------------------------------------------------------------
  1841. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1842. TTreeNode * Node)
  1843. {
  1844. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1845. {
  1846. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1847. // reshow the accelerators, etc
  1848. ResetSystemSettings(this);
  1849. // This is particularly here to enable EditCopyParamButton,
  1850. // as for some reason CopyParamListView->Selected is NULL until
  1851. // its page is shown for the first time
  1852. UpdateControls();
  1853. }
  1854. }
  1855. //---------------------------------------------------------------------------
  1856. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1857. {
  1858. // this is probably only ever called from FormShow (explicitly)
  1859. bool Found = false;
  1860. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1861. {
  1862. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1863. {
  1864. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1865. PageControl->ActivePage->Tag)
  1866. {
  1867. NavigationTree->Items->Item[Index]->Selected = true;
  1868. Found = true;
  1869. }
  1870. }
  1871. }
  1872. if (DebugAlwaysTrue(Found))
  1873. {
  1874. UpdateControls();
  1875. }
  1876. }
  1877. //---------------------------------------------------------------------------
  1878. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1879. {
  1880. if (Message.CharCode == VK_TAB)
  1881. {
  1882. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1883. if (Shift.Contains(ssCtrl))
  1884. {
  1885. TTreeNode * Node = NavigationTree->Selected;
  1886. if (!Shift.Contains(ssShift))
  1887. {
  1888. Node = Node->GetNext();
  1889. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1890. }
  1891. else
  1892. {
  1893. if (Node->GetPrev()) Node = Node->GetPrev();
  1894. else
  1895. while (Node->GetNext()) Node = Node->GetNext();
  1896. }
  1897. Node->Selected = True;
  1898. Message.Result = 1;
  1899. return;
  1900. }
  1901. }
  1902. TForm::Dispatch(&Message);
  1903. }
  1904. //---------------------------------------------------------------------------
  1905. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1906. {
  1907. DebugAssert(Message.HelpInfo != NULL);
  1908. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1909. {
  1910. // invoke help for active page (not for whole form), regardless of focus
  1911. // (e.g. even if focus is on control outside pagecontrol)
  1912. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1913. }
  1914. TForm::Dispatch(&Message);
  1915. }
  1916. //---------------------------------------------------------------------------
  1917. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  1918. {
  1919. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  1920. // we may end up using a slightly different size, so apply it straight away for consistency
  1921. UpdateControls();
  1922. TForm::Dispatch(&Message);
  1923. }
  1924. //---------------------------------------------------------------------------
  1925. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1926. {
  1927. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1928. DebugAssert(M);
  1929. if (M->Msg == CM_DIALOGKEY)
  1930. {
  1931. CMDialogKey(*((TWMKeyDown *)Message));
  1932. }
  1933. else if (M->Msg == CM_DPICHANGED)
  1934. {
  1935. CMDpiChanged(*M);
  1936. }
  1937. else if (M->Msg == WM_HELP)
  1938. {
  1939. WMHelp(*((TWMHelp *)Message));
  1940. }
  1941. else
  1942. {
  1943. TForm::Dispatch(Message);
  1944. }
  1945. }
  1946. //---------------------------------------------------------------------------
  1947. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  1948. TObject * /*Sender*/)
  1949. {
  1950. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  1951. }
  1952. //---------------------------------------------------------------------------
  1953. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  1954. {
  1955. unsigned int Result =
  1956. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  1957. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1958. if (Result == qaYes)
  1959. {
  1960. TInstantOperationVisualizer Visualizer;
  1961. RegisterForDefaultProtocols();
  1962. }
  1963. }
  1964. //---------------------------------------------------------------------------
  1965. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  1966. {
  1967. unsigned int Result =
  1968. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  1969. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1970. if (Result == qaYes)
  1971. {
  1972. TInstantOperationVisualizer Visualizer;
  1973. UnregisterForProtocols();
  1974. }
  1975. }
  1976. //---------------------------------------------------------------------------
  1977. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  1978. {
  1979. TOperationVisualizer Visualizer;
  1980. LaunchAdvancedAssociationUI();
  1981. }
  1982. //---------------------------------------------------------------------------
  1983. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  1984. {
  1985. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  1986. }
  1987. //---------------------------------------------------------------------------
  1988. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1989. TObject * /*Sender*/)
  1990. {
  1991. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1992. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  1993. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1994. {
  1995. TInstantOperationVisualizer Visualizer;
  1996. AddSearchPath(AppPath);
  1997. }
  1998. }
  1999. //---------------------------------------------------------------------------
  2000. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2001. TObject * Sender)
  2002. {
  2003. EditorFontButtonClick(Sender);
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2007. {
  2008. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2009. AutoSizeListColumnsWidth(CopyParamListView);
  2010. CopyParamListView->Invalidate();
  2011. }
  2012. //---------------------------------------------------------------------------
  2013. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2014. TListItem * Item)
  2015. {
  2016. // WORKAROUND We get here on Wine after destructor is called
  2017. if (FCopyParamList != NULL)
  2018. {
  2019. UnicodeString Name;
  2020. UnicodeString Rule;
  2021. int Index = Item->Index;
  2022. if (Index == 0)
  2023. {
  2024. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2025. }
  2026. else
  2027. {
  2028. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2029. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2030. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2031. }
  2032. Item->Caption = Name;
  2033. Item->SubItems->Add(Rule);
  2034. }
  2035. }
  2036. //---------------------------------------------------------------------------
  2037. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2038. {
  2039. FormHelp(this);
  2040. }
  2041. //---------------------------------------------------------------------------
  2042. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2043. TObject * /*Sender*/)
  2044. {
  2045. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2046. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2047. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2048. }
  2049. //---------------------------------------------------------------------------
  2050. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2051. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2052. {
  2053. FBeforeDialogPath = Name;
  2054. Name = ExpandEnvironmentVariables(Name);
  2055. }
  2056. //---------------------------------------------------------------------------
  2057. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2058. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2059. {
  2060. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2061. {
  2062. Name = FBeforeDialogPath;
  2063. }
  2064. }
  2065. //---------------------------------------------------------------------------
  2066. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2067. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2068. {
  2069. AllowCollapse = false;
  2070. }
  2071. //---------------------------------------------------------------------------
  2072. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2073. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2074. {
  2075. ScrollOnDragOver(Sender)->EndDrag();
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2079. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2080. {
  2081. if (Value == 0)
  2082. {
  2083. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2084. Handled = true;
  2085. }
  2086. }
  2087. //---------------------------------------------------------------------------
  2088. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2089. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2090. {
  2091. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2092. {
  2093. Value = 0;
  2094. Handled = true;
  2095. }
  2096. }
  2097. //---------------------------------------------------------------------------
  2098. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2099. {
  2100. bool Result;
  2101. bool Retry;
  2102. do
  2103. {
  2104. Retry = false;
  2105. Result = !AnyOtherInstanceOfSelf();
  2106. if (!Result)
  2107. {
  2108. unsigned int Answer =
  2109. MessageDialog(
  2110. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2111. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2112. HELP_MASTER_PASSWORD);
  2113. switch (Answer)
  2114. {
  2115. case qaRetry:
  2116. Retry = true;
  2117. break;
  2118. case qaIgnore:
  2119. Result = true;
  2120. break;
  2121. case qaCancel:
  2122. default:
  2123. // noop
  2124. break;
  2125. }
  2126. }
  2127. }
  2128. while (Retry && !Result);
  2129. return Result;
  2130. }
  2131. //---------------------------------------------------------------------------
  2132. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2133. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2134. {
  2135. // Save master password.
  2136. // This is unlikely to fail, as storage is written explicitly already
  2137. // when writing the recrypted passwords
  2138. Configuration->SaveExplicit();
  2139. TQueryType QueryType = qtInformation;
  2140. if (RecryptPasswordErrors->Count > 0)
  2141. {
  2142. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2143. QueryType = qtWarning;
  2144. }
  2145. MoreMessageDialog(
  2146. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2147. }
  2148. //---------------------------------------------------------------------------
  2149. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2150. {
  2151. UnicodeString NewPassword;
  2152. if (DoChangeMasterPasswordDialog(NewPassword))
  2153. {
  2154. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2155. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2156. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2157. }
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2161. TObject * /*Sender*/)
  2162. {
  2163. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2164. {
  2165. try
  2166. {
  2167. if (CanSetMasterPassword())
  2168. {
  2169. if (UseMasterPasswordCheck->Checked)
  2170. {
  2171. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2172. }
  2173. else
  2174. {
  2175. if (DoMasterPasswordDialog())
  2176. {
  2177. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2178. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2179. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2180. }
  2181. }
  2182. }
  2183. }
  2184. __finally
  2185. {
  2186. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2187. UpdateControls();
  2188. }
  2189. }
  2190. }
  2191. //---------------------------------------------------------------------------
  2192. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2193. TObject * /*Sender*/)
  2194. {
  2195. if (CanSetMasterPassword())
  2196. {
  2197. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2198. }
  2199. }
  2200. //---------------------------------------------------------------------------
  2201. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2202. {
  2203. DoUsageStatisticsDialog();
  2204. }
  2205. //---------------------------------------------------------------------------
  2206. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2207. {
  2208. if (EditCopyParamButton->Enabled)
  2209. {
  2210. AddEditCopyParam(cpmEdit);
  2211. }
  2212. }
  2213. //---------------------------------------------------------------------------
  2214. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2215. TCustomListView * Sender, TListItem * Item,
  2216. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2217. {
  2218. if (Item->Index == 0)
  2219. {
  2220. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2221. }
  2222. }
  2223. //---------------------------------------------------------------------------
  2224. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2225. {
  2226. PuttyRegistryStorageKeyEdit->ItemIndex =
  2227. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2228. }
  2229. //---------------------------------------------------------------------------
  2230. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2231. {
  2232. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2233. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2234. {
  2235. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2236. }
  2237. else if (ContainsText(PuttyPath, KittyExecutable))
  2238. {
  2239. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2240. }
  2241. UpdateControls();
  2242. }
  2243. //---------------------------------------------------------------------------
  2244. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2245. TTreeNode * Node, bool & /*AllowChange*/)
  2246. {
  2247. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2248. // delay load as this can be time consuming
  2249. if (Sheet == LanguagesSheet)
  2250. {
  2251. LoadLanguages();
  2252. }
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2256. {
  2257. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2258. }
  2259. //---------------------------------------------------------------------------
  2260. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2261. {
  2262. CommanderInterfaceButton2->SetFocus();
  2263. }
  2264. //---------------------------------------------------------------------------
  2265. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2266. {
  2267. ExplorerInterfaceButton2->SetFocus();
  2268. }
  2269. //---------------------------------------------------------------------------
  2270. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2271. {
  2272. PanelFontButtonClick(Sender);
  2273. }
  2274. //---------------------------------------------------------------------------
  2275. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2276. {
  2277. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2278. {
  2279. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2280. {
  2281. TUpdatesConfiguration Updates = SaveUpdates();
  2282. {
  2283. TInstantOperationVisualizer Visualizer;
  2284. QueryUpdates(Updates);
  2285. }
  2286. UnicodeString AuthenticationError = Updates.Results.AuthenticationError;
  2287. if (!AuthenticationError.IsEmpty())
  2288. {
  2289. AuthenticationError = FormatUpdatesMessage(AuthenticationError);
  2290. if (HasParagraphs(AuthenticationError))
  2291. {
  2292. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2293. }
  2294. else
  2295. {
  2296. AuthenticationError = MainInstructions(AuthenticationError);
  2297. }
  2298. UnicodeString HelpUrl = GetEnableAutomaticUpdatesUrl();
  2299. unsigned int Result =
  2300. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HelpUrl);
  2301. if (Result == qaAbort)
  2302. {
  2303. Abort();
  2304. }
  2305. }
  2306. }
  2307. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2308. }
  2309. }
  2310. //---------------------------------------------------------------------------
  2311. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2312. {
  2313. EnableAutomaticUpdates();
  2314. }
  2315. //---------------------------------------------------------------------------
  2316. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2317. {
  2318. FOrigCustomCommandsViewWindowProc(Message);
  2319. if (Message.Msg == CN_NOTIFY)
  2320. {
  2321. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2322. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2323. {
  2324. // request CDDS_ITEMPOSTPAINT notification
  2325. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2326. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2327. int Index = CustomDraw->nmcd.dwItemSpec;
  2328. int CommandIndex = GetCommandIndex(Index);
  2329. TCustomCommandList * List = GetCommandList(Index);
  2330. // after end of every list, except for the last last list
  2331. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2332. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2333. {
  2334. TRect Rect;
  2335. Rect.Top = CustomDraw->iSubItem;
  2336. Rect.Left = LVIR_BOUNDS;
  2337. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2338. HDC DC = CustomDraw->nmcd.hdc;
  2339. SelectObject(DC, GetStockObject(DC_PEN));
  2340. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2341. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2342. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2343. }
  2344. }
  2345. }
  2346. }
  2347. //---------------------------------------------------------------------------
  2348. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2349. {
  2350. if ((Status / 10) == 49)
  2351. {
  2352. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2353. throw Exception(Message);
  2354. }
  2355. }
  2356. //---------------------------------------------------------------------------
  2357. void __fastcall TPreferencesDialog::AddExtension()
  2358. {
  2359. const UnicodeString HistoryKey(L"ExtensionPath");
  2360. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2361. UnicodeString Path;
  2362. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2363. HELP_NONE, History.get(), true) &&
  2364. !Path.IsEmpty())
  2365. {
  2366. CustomWinConfiguration->History[HistoryKey] = History.get();
  2367. bool Trusted;
  2368. bool Latest;
  2369. UnicodeString FileName;
  2370. UnicodeString ExtensionPath;
  2371. std::unique_ptr<TStringList> Lines(new TStringList());
  2372. std::unique_ptr<TCustomCommandType> CustomCommand;
  2373. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2374. try
  2375. {
  2376. UnicodeString ProvisionaryId;
  2377. if (IsUrl)
  2378. {
  2379. UnicodeString Url = Path;
  2380. Url = SecureUrl(Url);
  2381. bool WinSCPURL = IsWinSCPUrl(Url);
  2382. if (WinSCPURL)
  2383. {
  2384. Url = ProgramUrl(Url);
  2385. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2386. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2387. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2388. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2389. Url = CampaignUrl(Url);
  2390. }
  2391. TOperationVisualizer Visualizer;
  2392. std::unique_ptr<THttp> Http(CreateHttp());
  2393. Http->URL = Url;
  2394. std::unique_ptr<TStrings> Headers(new TStringList());
  2395. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2396. Http->RequestHeaders = Headers.get();
  2397. Http->OnError = ExtensionHttpError;
  2398. Http->Get();
  2399. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2400. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2401. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2402. if (FileName.IsEmpty())
  2403. {
  2404. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2405. }
  2406. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2407. Lines->Text = Http->Response;
  2408. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2409. }
  2410. else
  2411. {
  2412. if (!FileExists(ApiPath(Path)))
  2413. {
  2414. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2415. }
  2416. Trusted = true;
  2417. Latest = true;
  2418. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2419. FileName = ExtractFileName(Path);
  2420. if (!Id.IsEmpty())
  2421. {
  2422. ExtensionPath = Path;
  2423. ProvisionaryId = Id;
  2424. }
  2425. else
  2426. {
  2427. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2428. }
  2429. LoadScriptFromFile(Path, Lines.get());
  2430. }
  2431. // validate syntax
  2432. CustomCommand.reset(new TCustomCommandType());
  2433. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2434. CustomCommand->Id = ProvisionaryId;
  2435. CustomCommand->LoadExtension(Lines.get(), FileName);
  2436. }
  2437. catch (Exception & E)
  2438. {
  2439. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2440. }
  2441. if (!ExtensionPath.IsEmpty())
  2442. {
  2443. int Index = FExtensionList->FindIndexByFileName(Path);
  2444. if (Index >= 0)
  2445. {
  2446. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2447. CustomCommandsView->ItemFocused->MakeVisible(false);
  2448. CustomCommandsView->SetFocus();
  2449. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2450. }
  2451. }
  2452. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2453. {
  2454. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2455. }
  2456. if (ExtensionPath.IsEmpty())
  2457. {
  2458. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2459. {
  2460. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2461. if (FileNameOnly.IsEmpty())
  2462. {
  2463. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2464. }
  2465. else
  2466. {
  2467. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2468. }
  2469. }
  2470. }
  2471. if (Trusted ||
  2472. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2473. {
  2474. if (ExtensionPath.IsEmpty())
  2475. {
  2476. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2477. if (!DirectoryExists(UserExtensionsPath) &&
  2478. !ForceDirectories(UserExtensionsPath))
  2479. {
  2480. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2481. }
  2482. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2483. int Counter = 1;
  2484. UnicodeString OriginalExtensionPath = ExtensionPath;
  2485. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2486. while (FileExists(ApiPath(ExtensionPath)))
  2487. {
  2488. Counter++;
  2489. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2490. }
  2491. Lines->SaveToFile(ApiPath(ExtensionPath));
  2492. FAddedExtensions->Add(ExtensionPath);
  2493. }
  2494. int Index = GetListCommandIndex(FExtensionList);
  2495. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2496. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2497. CustomCommand->LoadExtension(ExtensionPath);
  2498. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2499. UpdateCustomCommandsView();
  2500. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2501. CustomCommandsView->ItemFocused->MakeVisible(false);
  2502. UpdateControls();
  2503. if (!Latest)
  2504. {
  2505. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2506. }
  2507. if (IsUrl)
  2508. {
  2509. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2510. }
  2511. else
  2512. {
  2513. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2514. }
  2515. }
  2516. }
  2517. }
  2518. //---------------------------------------------------------------------------
  2519. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2520. {
  2521. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2522. {
  2523. AddEditCommand(false);
  2524. }
  2525. else
  2526. {
  2527. AddExtension();
  2528. }
  2529. }
  2530. //---------------------------------------------------------------------------
  2531. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2532. {
  2533. AddEditCommand(false);
  2534. }
  2535. //---------------------------------------------------------------------------
  2536. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2537. {
  2538. AddExtension();
  2539. }
  2540. //---------------------------------------------------------------------------
  2541. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2542. {
  2543. AddEditCommand(true);
  2544. }
  2545. //---------------------------------------------------------------------------
  2546. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2547. {
  2548. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2549. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2550. MenuPopup(AddCommandMenu, AddCommandButton);
  2551. }
  2552. //---------------------------------------------------------------------------
  2553. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2554. {
  2555. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2556. UnicodeString Result;
  2557. if (Terminal != NULL)
  2558. {
  2559. Result = Terminal->SessionData->SessionKey;
  2560. }
  2561. return Result;
  2562. }
  2563. //---------------------------------------------------------------------------
  2564. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2565. {
  2566. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2567. int Index = (Item != NULL) ? Item->Index : -1;
  2568. if (Index != FCustomCommandsHintItem)
  2569. {
  2570. Application->CancelHint();
  2571. UnicodeString Hint;
  2572. if (Index >= 0)
  2573. {
  2574. TCustomCommandList * List = GetCommandList(Index);
  2575. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2576. Hint = StripHotkey(Command->Name);
  2577. if (Command->ShortCut != 0)
  2578. {
  2579. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2580. }
  2581. if (!Command->Description.IsEmpty())
  2582. {
  2583. Hint += L"\n" + Command->Description;
  2584. }
  2585. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2586. if (List == FExtensionList)
  2587. {
  2588. Hint += L"\n" + Command->FileName;
  2589. }
  2590. }
  2591. CustomCommandsView->Hint = Hint;
  2592. FCustomCommandsHintItem = Index;
  2593. }
  2594. }
  2595. //---------------------------------------------------------------------------
  2596. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2597. {
  2598. PageControl->ActivePage = QueueSheet;
  2599. PageControlChange(NULL);
  2600. QueueNoConfirmationCheck->SetFocus();
  2601. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2602. }
  2603. //---------------------------------------------------------------------------
  2604. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2605. {
  2606. ConfigureCommand();
  2607. }
  2608. //---------------------------------------------------------------------------
  2609. void __fastcall TPreferencesDialog::ConfigureCommand()
  2610. {
  2611. int Index = CustomCommandsView->ItemIndex;
  2612. TCustomCommandList * CommandList = GetCommandList(Index);
  2613. int CommandIndex = GetCommandIndex(Index);
  2614. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2615. UnicodeString Site = GetSessionKey();
  2616. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2617. Site.IsEmpty())
  2618. {
  2619. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2620. }
  2621. TShortCut ShortCut = Command->ShortCut;
  2622. TShortCuts ShortCuts = GetShortCuts();
  2623. if (DoCustomCommandOptionsDialog(
  2624. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2625. {
  2626. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2627. UpdatedCommand->ShortCut = ShortCut;
  2628. CommandList->Change(CommandIndex, UpdatedCommand);
  2629. UpdateCustomCommandsView();
  2630. }
  2631. }
  2632. //---------------------------------------------------------------------------
  2633. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2634. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2635. {
  2636. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2637. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2638. {
  2639. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2640. }
  2641. if (LocaleInfo->Completeness < 0)
  2642. {
  2643. Sender->Canvas->Font->Color = clRed;
  2644. }
  2645. else if (LocaleInfo->Completeness < 100)
  2646. {
  2647. Sender->Canvas->Font->Color = clGrayText;
  2648. }
  2649. }
  2650. //---------------------------------------------------------------------------
  2651. void __fastcall TPreferencesDialog::LogMaxSizeComboExit(TObject * /*Sender*/)
  2652. {
  2653. __int64 Size;
  2654. if (!TryStrToSize(LogMaxSizeCombo->Text, Size))
  2655. {
  2656. LogMaxSizeCombo->SetFocus();
  2657. throw Exception(FMTLOAD(SIZE_INVALID, (LogMaxSizeCombo->Text)));
  2658. }
  2659. else
  2660. {
  2661. LogMaxSizeCombo->Text = SizeToStr(Size);
  2662. }
  2663. }
  2664. //---------------------------------------------------------------------------
  2665. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2666. {
  2667. try
  2668. {
  2669. UnicodeString Program, AParams, Dir;
  2670. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2671. }
  2672. catch(...)
  2673. {
  2674. PuttyPathEdit->SelectAll();
  2675. PuttyPathEdit->SetFocus();
  2676. throw;
  2677. }
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2681. {
  2682. Active = AutomaticIniFileStorageButton->Checked;
  2683. }
  2684. //---------------------------------------------------------------------------
  2685. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2686. {
  2687. UnicodeString Result;
  2688. if (CustomIniFileStorageButton->Checked)
  2689. {
  2690. Result = CustomIniFileStorageEdit->Text;
  2691. }
  2692. return Result;
  2693. }
  2694. //---------------------------------------------------------------------------
  2695. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2696. {
  2697. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2698. if (!CustomIniFileStorageName.IsEmpty() &&
  2699. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2700. FileExists(CustomIniFileStorageName))
  2701. {
  2702. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageName));
  2703. TMessageParams Params;
  2704. TQueryButtonAlias Aliases[2];
  2705. Aliases[0].Button = qaYes;
  2706. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2707. Aliases[1].Button = qaNo;
  2708. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2709. Params.Aliases = Aliases;
  2710. Params.AliasesCount = 2;
  2711. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2712. if (Result == qaYes)
  2713. {
  2714. // noop
  2715. }
  2716. else if (Result == qaNo)
  2717. {
  2718. Configuration->ScheduleCustomIniFileStorageUse(GetCustomIniFileStorageName());
  2719. ExecuteNewInstance(L"");
  2720. TerminateApplication();
  2721. }
  2722. else
  2723. {
  2724. Abort();
  2725. }
  2726. }
  2727. FCustomIniFileStorageName = CustomIniFileStorageName;
  2728. }
  2729. //---------------------------------------------------------------------------
  2730. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2731. {
  2732. CustomIniFileStorageChanged();
  2733. }
  2734. //---------------------------------------------------------------------------
  2735. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2736. {
  2737. PathEditAfterDialog(Sender, Name, Action);
  2738. if (Action)
  2739. {
  2740. CustomIniFileStorageEdit->Text = Name;
  2741. CustomIniFileStorageChanged();
  2742. }
  2743. }
  2744. //---------------------------------------------------------------------------
  2745. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2746. {
  2747. UpdateControls();
  2748. // Handler is shown also when Checked is set from LoadConfiguration
  2749. if (FNoUpdate == 0)
  2750. {
  2751. // Focus to force validation
  2752. CustomIniFileStorageEdit->SetFocus();
  2753. }
  2754. }
  2755. //---------------------------------------------------------------------------