Preferences.cpp 108 KB

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