Preferences.cpp 103 KB

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