Preferences.cpp 93 KB

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