Preferences.cpp 91 KB

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