Preferences.cpp 92 KB

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