Preferences.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <Common.h>
  6. #include "Preferences.h"
  7. #include <CoreMain.h>
  8. #include <Terminal.h>
  9. #include <Bookmarks.h>
  10. #include "VCLCommon.h"
  11. #include "GUITools.h"
  12. #include "Tools.h"
  13. #include "TextsWin.h"
  14. #include "HelpWin.h"
  15. #include "WinInterface.h"
  16. #include "WinConfiguration.h"
  17. #include "Setup.h"
  18. //---------------------------------------------------------------------
  19. #pragma link "GeneralSettings"
  20. #pragma link "LogSettings"
  21. #pragma link "CopyParams"
  22. #pragma link "UpDownEdit"
  23. #ifndef NO_RESOURCES
  24. #pragma resource "*.dfm"
  25. #endif
  26. //---------------------------------------------------------------------
  27. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  28. TPreferencesDialogData * DialogData)
  29. {
  30. bool Result;
  31. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
  32. try
  33. {
  34. PreferencesDialog->PreferencesMode = APreferencesMode;
  35. Result = PreferencesDialog->Execute(DialogData);
  36. }
  37. __finally
  38. {
  39. delete PreferencesDialog;
  40. }
  41. return Result;
  42. }
  43. //---------------------------------------------------------------------
  44. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  45. : TForm(AOwner)
  46. {
  47. SetCorrectFormParent(this);
  48. FNoUpdate = 0;
  49. FPreferencesMode = pmDefault;
  50. FEditorFont = new TFont();
  51. FEditorFont->Color = clWindowText;
  52. // color tends to reset in object inspector
  53. EditorFontLabel->Color = clWindow;
  54. // currently useless
  55. FAfterFilenameEditDialog = false;
  56. FCustomCommandList = new TCustomCommandList();
  57. FCustomCommandChanging = false;
  58. FListViewDragDest = -1;
  59. FCopyParamList = new TCopyParamList();
  60. FEditorList = new TEditorList();
  61. UseSystemSettings(this);
  62. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  63. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  64. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView2, true);
  65. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  66. LoggingFrame->Init();
  67. InstallPathWordBreakProc(RandomSeedFileEdit);
  68. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  69. InstallPathWordBreakProc(PuttyPathEdit);
  70. HintLabel(ShellIconsText);
  71. }
  72. //---------------------------------------------------------------------------
  73. __fastcall TPreferencesDialog::~TPreferencesDialog()
  74. {
  75. SAFE_DESTROY(FEditorScrollOnDragOver);
  76. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  77. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  78. delete FEditorFont;
  79. delete FCustomCommandList;
  80. delete FCopyParamList;
  81. delete FEditorList;
  82. }
  83. //---------------------------------------------------------------------
  84. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  85. {
  86. FDialogData = DialogData;
  87. LoadConfiguration();
  88. CopyParamsFrame->BeforeExecute();
  89. bool Result = (ShowModal() == mrOk);
  90. if (Result)
  91. {
  92. CopyParamsFrame->AfterExecute();
  93. SaveConfiguration();
  94. }
  95. return Result;
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  99. {
  100. Tree->FullExpand();
  101. int i = 0;
  102. while (i < Tree->Items->Count)
  103. {
  104. if ((!WinConfiguration->ExpertMode &&
  105. Tree->Items->Item[i]->SelectedIndex & 128))
  106. {
  107. Tree->Items->Delete(Tree->Items->Item[i]);
  108. }
  109. else
  110. {
  111. for (int pi = 0; pi < PageControl->PageCount; pi++)
  112. {
  113. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  114. {
  115. if (PageControl->Pages[pi]->Enabled)
  116. {
  117. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  118. PageControl->Pages[pi]->Hint = "";
  119. }
  120. else
  121. {
  122. Tree->Items->Delete(Tree->Items->Item[i]);
  123. i--;
  124. }
  125. break;
  126. }
  127. }
  128. i++;
  129. }
  130. }
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TPreferencesDialog::LoadConfiguration()
  134. {
  135. FNoUpdate++;
  136. try
  137. {
  138. if (FPreferencesMode != pmLogin)
  139. {
  140. LoggingFrame->LoadConfiguration();
  141. GeneralSettingsFrame->LoadConfiguration();
  142. }
  143. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  144. BOOLPROP(DefaultDirIsHome);
  145. BOOLPROP(PreservePanelState);
  146. BOOLPROP(DeleteToRecycleBin);
  147. BOOLPROP(DDTransferConfirmation);
  148. BOOLPROP(DDWarnLackOfTempSpace);
  149. BOOLPROP(ShowHiddenFiles);
  150. BOOLPROP(RenameWholeName);
  151. BOOLPROP(ShowInaccesibleDirectories);
  152. BOOLPROP(CopyOnDoubleClickConfirmation);
  153. BOOLPROP(ConfirmTransferring);
  154. BOOLPROP(ConfirmOverwriting);
  155. BOOLPROP(ConfirmResume);
  156. BOOLPROP(ConfirmDeleting);
  157. BOOLPROP(ConfirmRecycling);
  158. BOOLPROP(ConfirmClosingSession);
  159. BOOLPROP(ConfirmExitOnCompletion);
  160. BOOLPROP(UseLocationProfiles);
  161. BOOLPROP(ConfirmCommandSession);
  162. BOOLPROP(ContinueOnError);
  163. BOOLPROP(DDAllowMoveInit);
  164. BOOLPROP(BeepOnFinish);
  165. BOOLPROP(TemporaryDirectoryAppendSession);
  166. BOOLPROP(TemporaryDirectoryAppendPath);
  167. BOOLPROP(TemporaryDirectoryCleanup);
  168. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  169. BeepOnFinishAfterEdit->AsInteger =
  170. static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * (24*60*60);
  171. BOOLPROP(BalloonNotifications);
  172. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  173. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  174. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  175. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  176. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  177. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  178. {
  179. DDSystemTemporaryDirectoryButton->Checked = true;
  180. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  181. }
  182. else
  183. {
  184. DDCustomTemporaryDirectoryButton->Checked = true;
  185. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  186. }
  187. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  188. {
  189. NortonLikeModeCombo->ItemIndex = 2;
  190. }
  191. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  192. {
  193. NortonLikeModeCombo->ItemIndex = 1;
  194. }
  195. else
  196. {
  197. NortonLikeModeCombo->ItemIndex = 0;
  198. }
  199. PreserveLocalDirectoryCheck->Checked =
  200. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  201. SwappedPanelsCheck->Checked =
  202. WinConfiguration->ScpCommander.SwappedPanels;
  203. FullRowSelectCheck->Checked = WinConfiguration->ScpCommander.FullRowSelect;
  204. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  205. ShowFullAddressCheck->Checked =
  206. WinConfiguration->ScpExplorer.ShowFullAddress;
  207. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  208. IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
  209. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  210. // editor
  211. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  212. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  213. FEditorFont->Name = WinConfiguration->Editor.FontName;
  214. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  215. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  216. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  217. (*FEditorList) = *WinConfiguration->EditorList;
  218. UpdateEditorListView();
  219. CopyParamsFrame->Params = GUIConfiguration->DefaultCopyParam;
  220. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  221. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  222. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  223. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  224. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  225. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  226. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  227. (Configuration->SessionReopenAuto / 1000) : 5);
  228. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / 1000);
  229. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  230. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  231. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  232. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  233. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  234. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  235. StorageGroup->Visible = WinConfiguration->ExpertMode;
  236. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  237. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  238. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  239. UpdateCustomCommandsView();
  240. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  241. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  242. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  243. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  244. // Queue
  245. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  246. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  247. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  248. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  249. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  250. RememberPasswordCheck->Checked = GUIConfiguration->QueueRememberPassword;
  251. if (WinConfiguration->QueueView.Show == qvShow)
  252. {
  253. QueueViewShowButton->Checked = true;
  254. }
  255. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  256. {
  257. QueueViewHideWhenEmptyButton->Checked = true;
  258. }
  259. else
  260. {
  261. QueueViewHideButton->Checked = true;
  262. }
  263. // window
  264. if (WinConfiguration->PathInCaption == picFull)
  265. {
  266. PathInCaptionFullButton->Checked = true;
  267. }
  268. else if (WinConfiguration->PathInCaption == picShort)
  269. {
  270. PathInCaptionShortButton->Checked = true;
  271. }
  272. else
  273. {
  274. PathInCaptionNoneButton->Checked = true;
  275. }
  276. BOOLPROP(MinimizeToTray);
  277. // panels
  278. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  279. BOOLPROP(AutoReadDirectoryAfterOp);
  280. // updates
  281. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  282. if (int(Updates.Period) <= 0)
  283. {
  284. UpdatesNeverButton->Checked = true;
  285. }
  286. else if (int(Updates.Period) <= 1)
  287. {
  288. UpdatesDailyButton->Checked = true;
  289. }
  290. else if (int(Updates.Period) <= 7)
  291. {
  292. UpdatesWeeklyButton->Checked = true;
  293. }
  294. else
  295. {
  296. UpdatesMonthlyButton->Checked = true;
  297. }
  298. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  299. switch (Updates.ConnectionType)
  300. {
  301. case ctDirect:
  302. default:
  303. UpdatesDirectCheck->Checked = true;
  304. break;
  305. case ctAuto:
  306. UpdatesAutoCheck->Checked = true;
  307. break;
  308. case ctProxy:
  309. UpdatesProxyCheck->Checked = true;
  310. break;
  311. }
  312. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  313. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  314. // presets
  315. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  316. UpdateCopyParamListView();
  317. BOOLPROP(CopyParamAutoSelectNotice);
  318. // interface
  319. if (WinConfiguration->Theme == "OfficeXP")
  320. {
  321. ThemeCombo->ItemIndex = 1;
  322. }
  323. else if (WinConfiguration->Theme == "Office2003")
  324. {
  325. ThemeCombo->ItemIndex = 2;
  326. }
  327. else
  328. {
  329. ThemeCombo->ItemIndex = 0;
  330. }
  331. // security
  332. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  333. #undef BOOLPROP
  334. }
  335. __finally
  336. {
  337. FNoUpdate--;
  338. }
  339. UpdateControls();
  340. }
  341. //---------------------------------------------------------------------------
  342. void __fastcall TPreferencesDialog::SaveConfiguration()
  343. {
  344. Configuration->BeginUpdate();
  345. try
  346. {
  347. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  348. if (FPreferencesMode != pmLogin)
  349. {
  350. LoggingFrame->SaveConfiguration();
  351. GeneralSettingsFrame->SaveConfiguration();
  352. }
  353. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  354. BOOLPROP(DefaultDirIsHome);
  355. BOOLPROP(PreservePanelState);
  356. BOOLPROP(DeleteToRecycleBin);
  357. BOOLPROP(DDTransferConfirmation);
  358. BOOLPROP(DDWarnLackOfTempSpace);
  359. BOOLPROP(ShowHiddenFiles);
  360. BOOLPROP(RenameWholeName);
  361. BOOLPROP(ShowInaccesibleDirectories);
  362. BOOLPROP(CopyOnDoubleClickConfirmation);
  363. BOOLPROP(ConfirmTransferring);
  364. BOOLPROP(ConfirmOverwriting);
  365. BOOLPROP(ConfirmResume);
  366. BOOLPROP(ConfirmDeleting);
  367. BOOLPROP(ConfirmRecycling);
  368. BOOLPROP(ConfirmClosingSession);
  369. BOOLPROP(ConfirmExitOnCompletion);
  370. BOOLPROP(UseLocationProfiles);
  371. BOOLPROP(ConfirmCommandSession);
  372. BOOLPROP(ContinueOnError);
  373. BOOLPROP(DDAllowMoveInit);
  374. BOOLPROP(BeepOnFinish);
  375. BOOLPROP(TemporaryDirectoryAppendSession);
  376. BOOLPROP(TemporaryDirectoryAppendPath);
  377. BOOLPROP(TemporaryDirectoryCleanup);
  378. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  379. GUIConfiguration->BeepOnFinishAfter =
  380. static_cast<double>(BeepOnFinishAfterEdit->Value / (24*60*60));
  381. BOOLPROP(BalloonNotifications);
  382. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  383. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  384. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  385. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  386. if (DDSystemTemporaryDirectoryButton->Checked)
  387. {
  388. WinConfiguration->DDTemporaryDirectory = "";
  389. }
  390. else
  391. {
  392. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  393. }
  394. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  395. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  396. if (NortonLikeModeCombo->ItemIndex == 2)
  397. {
  398. ScpCommander.NortonLikeMode = nlOff;
  399. }
  400. else if (NortonLikeModeCombo->ItemIndex == 1)
  401. {
  402. ScpCommander.NortonLikeMode = nlKeyboard;
  403. }
  404. else
  405. {
  406. ScpCommander.NortonLikeMode = nlOn;
  407. }
  408. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  409. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  410. ScpCommander.FullRowSelect = FullRowSelectCheck->Checked;
  411. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  412. WinConfiguration->ScpCommander = ScpCommander;
  413. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  414. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  415. WinConfiguration->ScpExplorer = ScpExplorer;
  416. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  417. // editor
  418. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  419. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  420. WinConfiguration->Editor.FontName = FEditorFont->Name;
  421. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  422. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  423. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  424. WinConfiguration->EditorList = FEditorList;
  425. // overwrites only TCopyParamType fields
  426. CopyParam = CopyParamsFrame->Params;
  427. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  428. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  429. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  430. CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
  431. Configuration->SessionReopenAuto =
  432. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->Value * 1000) : 0);
  433. GUIConfiguration->SessionReopenAutoIdle =
  434. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoEdit->Value * 1000) : 0);
  435. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->Value * 1000);
  436. WinConfiguration->CustomCommandList = FCustomCommandList;
  437. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  438. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  439. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  440. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  441. // Queue
  442. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  443. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  444. CopyParam.Queue = QueueCheck->Checked;
  445. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  446. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  447. GUIConfiguration->QueueRememberPassword = RememberPasswordCheck->Checked;
  448. if (QueueViewShowButton->Checked)
  449. {
  450. WinConfiguration->QueueView.Show = qvShow;
  451. }
  452. else if (QueueViewHideWhenEmptyButton->Checked)
  453. {
  454. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  455. }
  456. else
  457. {
  458. WinConfiguration->QueueView.Show = qvHide;
  459. }
  460. GUIConfiguration->DefaultCopyParam = CopyParam;
  461. // window
  462. if (PathInCaptionFullButton->Checked)
  463. {
  464. WinConfiguration->PathInCaption = picFull;
  465. }
  466. else if (PathInCaptionShortButton->Checked)
  467. {
  468. WinConfiguration->PathInCaption = picShort;
  469. }
  470. else
  471. {
  472. WinConfiguration->PathInCaption = picNone;
  473. }
  474. BOOLPROP(MinimizeToTray);
  475. // panels
  476. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  477. BOOLPROP(AutoReadDirectoryAfterOp);
  478. // updates
  479. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  480. if (UpdatesNeverButton->Checked)
  481. {
  482. Updates.Period = 0;
  483. }
  484. else if (UpdatesDailyButton->Checked)
  485. {
  486. Updates.Period = 1;
  487. }
  488. else if (UpdatesWeeklyButton->Checked)
  489. {
  490. Updates.Period = 7;
  491. }
  492. else
  493. {
  494. Updates.Period = 30;
  495. }
  496. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  497. if (UpdatesDirectCheck->Checked)
  498. {
  499. Updates.ConnectionType = ctDirect;
  500. }
  501. else if (UpdatesAutoCheck->Checked)
  502. {
  503. Updates.ConnectionType = ctAuto;
  504. }
  505. else if (UpdatesProxyCheck->Checked)
  506. {
  507. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  508. {
  509. Updates.ConnectionType = ctProxy;
  510. }
  511. else
  512. {
  513. Updates.ConnectionType = ctDirect;
  514. }
  515. }
  516. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  517. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  518. WinConfiguration->Updates = Updates;
  519. // presets
  520. WinConfiguration->CopyParamList = FCopyParamList;
  521. BOOLPROP(CopyParamAutoSelectNotice);
  522. // interface
  523. if (ThemeCombo->ItemIndex == 1)
  524. {
  525. WinConfiguration->Theme = "OfficeXP";
  526. }
  527. else if (ThemeCombo->ItemIndex == 2)
  528. {
  529. WinConfiguration->Theme = "Office2003";
  530. }
  531. else
  532. {
  533. WinConfiguration->Theme = "Default";
  534. }
  535. #undef BOOLPROP
  536. }
  537. __finally
  538. {
  539. Configuration->EndUpdate();
  540. }
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  544. {
  545. if (PreferencesMode != value)
  546. {
  547. FPreferencesMode = value;
  548. GeneralSheet->Enabled = (value != pmLogin);
  549. LogSheet->Enabled = (value != pmLogin);
  550. }
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  554. {
  555. PrepareNavigationTree(NavigationTree);
  556. switch (PreferencesMode) {
  557. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  558. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  559. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  560. case pmTransfer: PageControl->ActivePage = TransferSheet; break;
  561. case pmLogging: PageControl->ActivePage = LogSheet; break;
  562. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  563. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  564. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  565. default: PageControl->ActivePage = PreferencesSheet; break;
  566. }
  567. PageControlChange(NULL);
  568. }
  569. //---------------------------------------------------------------------------
  570. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  571. {
  572. UpdateControls();
  573. }
  574. //---------------------------------------------------------------------------
  575. AnsiString __fastcall TPreferencesDialog::TabSample(AnsiString Values)
  576. {
  577. AnsiString Result;
  578. for (int Index = 1; Index <= Values.Length(); Index++)
  579. {
  580. if (Index > 1)
  581. {
  582. Result += ' ';
  583. if (EditorTabSizeEdit->AsInteger > 2)
  584. {
  585. Result += AnsiString::StringOfChar(' ', EditorTabSizeEdit->AsInteger - 2);
  586. }
  587. }
  588. Result += Values[Index];
  589. }
  590. return Result;
  591. }
  592. //---------------------------------------------------------------------------
  593. void __fastcall TPreferencesDialog::UpdateControls()
  594. {
  595. if (FNoUpdate == 0)
  596. {
  597. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  598. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  599. EnableControl(BalloonNotificationsCheck, TTrayIcon::SupportsBalloons());
  600. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  601. EnableControl(ResumeThresholdUnitLabel, ResumeThresholdEdit->Enabled);
  602. EnableControl(SessionReopenAutoEdit,
  603. SessionReopenAutoCheck->Checked || SessionReopenAutoIdleCheck->Checked);
  604. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  605. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  606. EnableControl(SessionReopenTimeoutEdit, SessionReopenAutoEdit->Enabled);
  607. EnableControl(SessionReopenTimeoutLabel, SessionReopenAutoEdit->Enabled);
  608. EnableControl(SessionReopenTimeoutSecLabel, SessionReopenAutoEdit->Enabled);
  609. EnableControl(CopyOnDoubleClickConfirmationCheck,
  610. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  611. AnsiString EditorFontLabelText;
  612. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  613. (FEditorFont->Name, FEditorFont->Size)) + "\n\n";
  614. EditorFontLabelText += TabSample("ABCD") + "\n";
  615. EditorFontLabelText += TabSample("1234");
  616. EditorFontLabel->Caption = EditorFontLabelText;
  617. EditorFontLabel->Font = FEditorFont;
  618. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  619. EnableControl(EditCommandButton, CommandSelected);
  620. EnableControl(RemoveCommandButton, CommandSelected);
  621. EnableControl(UpCommandButton, CommandSelected &&
  622. CustomCommandsView->ItemIndex > 0);
  623. EnableControl(DownCommandButton, CommandSelected &&
  624. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  625. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  626. EnableControl(EditCopyParamButton, CopyParamSelected);
  627. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  628. EnableControl(RemoveCopyParamButton, CopyParamSelected);
  629. EnableControl(UpCopyParamButton, CopyParamSelected &&
  630. (CopyParamListView->ItemIndex > 0));
  631. EnableControl(DownCopyParamButton, CopyParamSelected &&
  632. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  633. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  634. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  635. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  636. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  637. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  638. DDCustomTemporaryDirectoryButton->Checked);
  639. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  640. DDAllowMoveInitCheck->Checked);
  641. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  642. TemporaryDirectoryCleanupCheck->Checked);
  643. IniFileStorageButton2->Caption =
  644. AnsiReplaceStr(IniFileStorageButton2->Caption, "winscp.ini",
  645. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName)));
  646. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  647. bool EditorSelected = (EditorListView2->Selected != NULL);
  648. EnableControl(EditEditorButton, EditorSelected);
  649. EnableControl(RemoveEditorButton, EditorSelected);
  650. EnableControl(UpEditorButton, EditorSelected &&
  651. (EditorListView2->ItemIndex > 0));
  652. EnableControl(DownEditorButton, EditorSelected &&
  653. (EditorListView2->ItemIndex < EditorListView2->Items->Count - 1));
  654. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  655. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  656. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  657. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  658. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  659. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  660. EnableControl(TelnetForFtpInPuttyCheck, PuttyPasswordCheck2->Enabled);
  661. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  662. }
  663. }
  664. //---------------------------------------------------------------------------
  665. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  666. {
  667. if (FontDialog(FEditorFont))
  668. {
  669. UpdateControls();
  670. }
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TPreferencesDialog::FilenameEditExit(TObject * Sender)
  674. {
  675. // duplicated in TExternalEditorDialog::FilenameEditExit
  676. THistoryComboBox * FilenameEdit = dynamic_cast<THistoryComboBox *>(Sender);
  677. try
  678. {
  679. AnsiString Filename = FilenameEdit->Text;
  680. if (!Filename.IsEmpty())
  681. {
  682. ReformatFileNameCommand(Filename);
  683. FilenameEdit->Text = Filename;
  684. }
  685. ControlChange(Sender);
  686. }
  687. catch(...)
  688. {
  689. FilenameEdit->SelectAll();
  690. FilenameEdit->SetFocus();
  691. throw;
  692. }
  693. }
  694. //---------------------------------------------------------------------------
  695. void __fastcall TPreferencesDialog::FilenameEditChange(
  696. TObject * Sender)
  697. {
  698. // duplicated in TExternalEditorDialog::FilenameEditChange
  699. if (FAfterFilenameEditDialog)
  700. {
  701. FAfterFilenameEditDialog = false;
  702. FilenameEditExit(Sender);
  703. }
  704. else
  705. {
  706. ControlChange(Sender);
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  711. bool & /*CanClose*/)
  712. {
  713. if (ModalResult != mrCancel)
  714. {
  715. ExitActiveControl(this);
  716. }
  717. }
  718. //---------------------------------------------------------------------------
  719. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  720. {
  721. AnsiString IconName, Params;
  722. int SpecialFolder;
  723. if (Sender == DesktopIconButton)
  724. {
  725. IconName = AppName;
  726. int Result =
  727. MessageDialog(LoadStr(CREATE_DESKTOP_ICON), qtConfirmation,
  728. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  729. switch (Result)
  730. {
  731. case qaYes:
  732. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  733. break;
  734. case qaNo:
  735. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  736. break;
  737. default:
  738. Abort();
  739. break;
  740. }
  741. }
  742. else
  743. {
  744. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  745. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  746. {
  747. if (Sender == SendToHookButton)
  748. {
  749. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppName));
  750. SpecialFolder = CSIDL_SENDTO;
  751. Params = "/upload";
  752. }
  753. else if (Sender == QuickLaunchIconButton)
  754. {
  755. IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
  756. AppName;
  757. SpecialFolder = CSIDL_APPDATA;
  758. }
  759. }
  760. else
  761. {
  762. Abort();
  763. }
  764. }
  765. CreateDesktopShortCut(IconName,
  766. Application->ExeName, Params, "", SpecialFolder);
  767. }
  768. //---------------------------------------------------------------------------
  769. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  770. TListItem * Item)
  771. {
  772. assert(FCustomCommandList != NULL);
  773. int Index = Item->Index;
  774. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  775. const TCustomCommandType * Command = FCustomCommandList->Commands[Index];
  776. AnsiString Caption = StringReplace(Command->Name, "&", "", TReplaceFlags() << rfReplaceAll);
  777. if (Command->ShortCut != 0)
  778. {
  779. Caption = FORMAT("%s (%s)", (Caption, ShortCutToText(Command->ShortCut)));
  780. }
  781. Item->Caption = Caption;
  782. assert(!Item->SubItems->Count);
  783. Item->SubItems->Add(Command->Command);
  784. int Params = Command->Params;
  785. Item->SubItems->Add(LoadStr(
  786. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  787. AnsiString ParamsStr;
  788. #define ADDPARAM(PARAM, STR) \
  789. if (FLAGSET(Params, PARAM)) \
  790. ParamsStr += (ParamsStr.IsEmpty() ? "" : "/") + LoadStr(STR);
  791. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  792. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  793. #undef ADDPARAM
  794. Item->SubItems->Add(ParamsStr);
  795. }
  796. //---------------------------------------------------------------------------
  797. void __fastcall TPreferencesDialog::ListViewSelectItem(
  798. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  799. {
  800. UpdateControls();
  801. }
  802. //---------------------------------------------------------------------------
  803. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  804. {
  805. CustomCommandsView->Items->Count = FCustomCommandList->Count;
  806. AdjustListColumnsWidth(CustomCommandsView, FCustomCommandList->Count);
  807. CustomCommandsView->Invalidate();
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  811. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  812. {
  813. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  814. {
  815. RemoveCommandButtonClick(NULL);
  816. }
  817. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  818. {
  819. AddEditCommandButtonClick(AddCommandButton);
  820. }
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  824. TObject * /*Sender*/)
  825. {
  826. if (EditCommandButton->Enabled)
  827. {
  828. AddEditCommandButtonClick(EditCommandButton);
  829. }
  830. }
  831. //---------------------------------------------------------------------------
  832. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  833. {
  834. bool Edit = (Sender == EditCommandButton);
  835. TCustomCommandType Command;
  836. if (Edit)
  837. {
  838. int Index = CustomCommandsView->ItemIndex;
  839. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  840. Command = *FCustomCommandList->Commands[Index];
  841. }
  842. TShortCuts ShortCuts;
  843. if (WinConfiguration->SharedBookmarks != NULL)
  844. {
  845. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  846. }
  847. FCustomCommandList->ShortCuts(ShortCuts);
  848. if (DoCustomCommandDialog(Command, FCustomCommandList,
  849. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  850. {
  851. int Index = CustomCommandsView->ItemIndex;
  852. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  853. if (Edit)
  854. {
  855. FCustomCommandList->Change(Index, ACommand);
  856. }
  857. else
  858. {
  859. if (Index >= 0)
  860. {
  861. FCustomCommandList->Insert(Index, ACommand);
  862. }
  863. else
  864. {
  865. FCustomCommandList->Add(ACommand);
  866. Index = FCustomCommandList->Count - 1;
  867. }
  868. }
  869. UpdateCustomCommandsView();
  870. CustomCommandsView->ItemIndex = Index;
  871. UpdateControls();
  872. }
  873. }
  874. //---------------------------------------------------------------------------
  875. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  876. TObject * /*Sender*/)
  877. {
  878. assert(CustomCommandsView->ItemIndex >= 0 &&
  879. CustomCommandsView->ItemIndex < FCustomCommandList->Count);
  880. FCustomCommandList->Delete(CustomCommandsView->ItemIndex);
  881. UpdateCustomCommandsView();
  882. UpdateControls();
  883. }
  884. //---------------------------------------------------------------------------
  885. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  886. {
  887. if (Source >= 0 && Source < FCustomCommandList->Count &&
  888. Dest >= 0 && Dest < FCustomCommandList->Count)
  889. {
  890. FCustomCommandList->Move(Source, Dest);
  891. // workaround for bug in VCL
  892. CustomCommandsView->ItemIndex = -1;
  893. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  894. CustomCommandsView->ItemIndex = Dest;
  895. UpdateCustomCommandsView();
  896. UpdateControls();
  897. }
  898. }
  899. //---------------------------------------------------------------------------
  900. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  901. {
  902. CustomCommandMove(CustomCommandsView->ItemIndex,
  903. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  904. }
  905. //---------------------------------------------------------------------------
  906. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  907. {
  908. if (ListView == CopyParamListView)
  909. {
  910. return FCopyParamScrollOnDragOver;
  911. }
  912. else if (ListView == CustomCommandsView)
  913. {
  914. return FCustomCommandsScrollOnDragOver;
  915. }
  916. else if (ListView == EditorListView2)
  917. {
  918. return FEditorScrollOnDragOver;
  919. }
  920. else
  921. {
  922. assert(false);
  923. return NULL;
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TPreferencesDialog::ListViewStartDrag(
  928. TObject * Sender, TDragObject *& /*DragObject*/)
  929. {
  930. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  931. FListViewDragDest = -1;
  932. ScrollOnDragOver(Sender)->StartDrag();
  933. }
  934. //---------------------------------------------------------------------------
  935. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  936. {
  937. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  938. FListViewDragDest = Item ? Item->Index : -1;
  939. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  943. TObject * Sender, TObject * Source, int X, int Y)
  944. {
  945. if (Source == CustomCommandsView)
  946. {
  947. if (AllowListViewDrag(Sender, X, Y))
  948. {
  949. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  950. }
  951. }
  952. }
  953. //---------------------------------------------------------------------------
  954. void __fastcall TPreferencesDialog::ListViewDragOver(
  955. TObject * Sender, TObject * Source, int X, int Y,
  956. TDragState /*State*/, bool & Accept)
  957. {
  958. if (Source == Sender)
  959. {
  960. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  961. // (when dropped on item itself, when it was dragged over another item before,
  962. // that another item remains highlighted forever)
  963. Accept = true;
  964. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  965. }
  966. }
  967. //---------------------------------------------------------------------------
  968. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  969. {
  970. if (Source >= 0 && Source < FCopyParamList->Count &&
  971. Dest >= 0 && Dest < FCopyParamList->Count)
  972. {
  973. FCopyParamList->Move(Source, Dest);
  974. // workaround for bug in VCL
  975. CopyParamListView->ItemIndex = -1;
  976. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  977. CopyParamListView->ItemIndex = Dest;
  978. UpdateCopyParamListView();
  979. UpdateControls();
  980. }
  981. }
  982. //---------------------------------------------------------------------------
  983. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  984. TObject * Sender, TObject * Source, int X, int Y)
  985. {
  986. if (Source == CopyParamListView)
  987. {
  988. if (AllowListViewDrag(Sender, X, Y))
  989. {
  990. CopyParamMove(FListViewDragSource, FListViewDragDest);
  991. }
  992. }
  993. }
  994. //---------------------------------------------------------------------------
  995. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  996. {
  997. CopyParamMove(CopyParamListView->ItemIndex,
  998. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1002. TObject * /*Sender*/)
  1003. {
  1004. assert(CopyParamListView->ItemIndex >= 0 &&
  1005. CopyParamListView->ItemIndex < FCopyParamList->Count);
  1006. FCopyParamList->Delete(CopyParamListView->ItemIndex);
  1007. UpdateCopyParamListView();
  1008. UpdateControls();
  1009. }
  1010. //---------------------------------------------------------------------------
  1011. void __fastcall TPreferencesDialog::AddEditCopyParamButtonClick(
  1012. TObject * Sender)
  1013. {
  1014. TCopyParamPresetMode Mode;
  1015. if (Sender == EditCopyParamButton)
  1016. {
  1017. Mode = cpmEdit;
  1018. }
  1019. else if (Sender == DuplicateCopyParamButton)
  1020. {
  1021. Mode = cpmDuplicate;
  1022. }
  1023. else
  1024. {
  1025. Mode = cpmAdd;
  1026. }
  1027. int Index = CopyParamListView->ItemIndex;
  1028. TCopyParamRuleData * CopyParamRuleData =
  1029. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1030. if (DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData))
  1031. {
  1032. UpdateCopyParamListView();
  1033. CopyParamListView->ItemIndex = Index;
  1034. // when using duplicate button, focu remains on original item
  1035. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1036. UpdateControls();
  1037. }
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1041. TObject * /*Sender*/)
  1042. {
  1043. if (EditCopyParamButton->Enabled)
  1044. {
  1045. AddEditCopyParamButtonClick(EditCopyParamButton);
  1046. }
  1047. }
  1048. //---------------------------------------------------------------------------
  1049. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1050. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1051. {
  1052. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1053. {
  1054. RemoveCopyParamButtonClick(NULL);
  1055. }
  1056. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1057. {
  1058. AddEditCopyParamButtonClick(AddCopyParamButton);
  1059. }
  1060. }
  1061. //---------------------------------------------------------------------------
  1062. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1063. {
  1064. if (Source >= 0 && Source < FEditorList->Count &&
  1065. Dest >= 0 && Dest < FEditorList->Count)
  1066. {
  1067. FEditorList->Move(Source, Dest);
  1068. // workaround for bug in VCL
  1069. EditorListView2->ItemIndex = -1;
  1070. EditorListView2->ItemFocused = EditorListView2->Selected;
  1071. EditorListView2->ItemIndex = Dest;
  1072. UpdateEditorListView();
  1073. UpdateControls();
  1074. }
  1075. }
  1076. //---------------------------------------------------------------------------
  1077. void __fastcall TPreferencesDialog::EditorListView2DragDrop(TObject * Sender,
  1078. TObject * Source, int X, int Y)
  1079. {
  1080. if (Source == EditorListView2)
  1081. {
  1082. if (AllowListViewDrag(Sender, X, Y))
  1083. {
  1084. EditorMove(FListViewDragSource, FListViewDragDest);
  1085. }
  1086. }
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1090. {
  1091. EditorMove(EditorListView2->ItemIndex,
  1092. EditorListView2->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1096. TObject * /*Sender*/)
  1097. {
  1098. assert(EditorListView2->ItemIndex >= 0 &&
  1099. EditorListView2->ItemIndex < FEditorList->Count);
  1100. FEditorList->Delete(EditorListView2->ItemIndex);
  1101. UpdateEditorListView();
  1102. UpdateControls();
  1103. }
  1104. //---------------------------------------------------------------------------
  1105. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1106. {
  1107. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1108. int Index = EditorListView2->ItemIndex;
  1109. TEditorPreferences * Editor;
  1110. if (Mode == epmEdit)
  1111. {
  1112. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1113. }
  1114. else
  1115. {
  1116. Editor = new TEditorPreferences();
  1117. }
  1118. try
  1119. {
  1120. bool DummyRemember = false;
  1121. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1122. {
  1123. if (Mode == epmEdit)
  1124. {
  1125. FEditorList->Change(Index, Editor);
  1126. }
  1127. else
  1128. {
  1129. if (Index < 0)
  1130. {
  1131. Index = FEditorList->Count;
  1132. FEditorList->Add(Editor);
  1133. }
  1134. else
  1135. {
  1136. FEditorList->Insert(Index, Editor);
  1137. }
  1138. }
  1139. // ownership of the object lost
  1140. Editor = NULL;
  1141. UpdateEditorListView();
  1142. EditorListView2->ItemIndex = Index;
  1143. UpdateControls();
  1144. }
  1145. }
  1146. __finally
  1147. {
  1148. delete Editor;
  1149. }
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TPreferencesDialog::EditorListView2DblClick(TObject * /*Sender*/)
  1153. {
  1154. if (EditEditorButton->Enabled)
  1155. {
  1156. AddEditEditorButtonClick(EditEditorButton);
  1157. }
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TPreferencesDialog::EditorListView2KeyDown(TObject * /*Sender*/,
  1161. WORD & Key, TShiftState /*Shift*/)
  1162. {
  1163. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1164. {
  1165. RemoveEditorButtonClick(NULL);
  1166. }
  1167. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1168. {
  1169. AddEditEditorButtonClick(AddEditorButton);
  1170. }
  1171. }
  1172. //---------------------------------------------------------------------------
  1173. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1174. {
  1175. EditorListView2->Items->Count = FEditorList->Count;
  1176. AdjustListColumnsWidth(EditorListView2, FEditorList->Count);
  1177. EditorListView2->Invalidate();
  1178. }
  1179. //---------------------------------------------------------------------------
  1180. void __fastcall TPreferencesDialog::EditorListView2Data(TObject * /*Sender*/,
  1181. TListItem * Item)
  1182. {
  1183. int Index = Item->Index;
  1184. assert(Index >= 0 && Index <= FEditorList->Count);
  1185. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1186. Item->Caption = Editor->Data->FileMask.Masks;
  1187. Item->SubItems->Add(Editor->Name);
  1188. if (Editor->Data->Editor == edExternal)
  1189. {
  1190. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1191. }
  1192. }
  1193. //---------------------------------------------------------------------------
  1194. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1195. TTreeNode *Node)
  1196. {
  1197. if (Node->SelectedIndex)
  1198. {
  1199. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  1200. {
  1201. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  1202. {
  1203. PageControl->ActivePage = PageControl->Pages[Index];
  1204. // reshow the accelerators, etc
  1205. ResetSystemSettings(this);
  1206. return;
  1207. }
  1208. }
  1209. }
  1210. assert(false);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1214. {
  1215. bool Found = false;
  1216. if (PageControl->ActivePage->Tag)
  1217. {
  1218. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1219. {
  1220. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  1221. PageControl->ActivePage->Tag)
  1222. {
  1223. NavigationTree->Items->Item[Index]->Selected = true;
  1224. Found = true;
  1225. }
  1226. }
  1227. }
  1228. assert(Found);
  1229. if (Found)
  1230. {
  1231. UpdateControls();
  1232. }
  1233. }
  1234. //---------------------------------------------------------------------------
  1235. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1236. {
  1237. if (Message.CharCode == VK_TAB)
  1238. {
  1239. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1240. if (Shift.Contains(ssCtrl))
  1241. {
  1242. TTreeNode * Node = NavigationTree->Selected;
  1243. if (!Shift.Contains(ssShift))
  1244. {
  1245. Node = Node->GetNext();
  1246. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1247. }
  1248. else
  1249. {
  1250. if (Node->GetPrev()) Node = Node->GetPrev();
  1251. else
  1252. while (Node->GetNext()) Node = Node->GetNext();
  1253. }
  1254. Node->Selected = True;
  1255. Message.Result = 1;
  1256. return;
  1257. }
  1258. }
  1259. TForm::Dispatch(&Message);
  1260. }
  1261. //---------------------------------------------------------------------------
  1262. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1263. {
  1264. assert(Message.HelpInfo != NULL);
  1265. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1266. {
  1267. // invoke help for active page (not for whole form), regardless of focus
  1268. // (e.g. even if focus is on control outside pagecontrol)
  1269. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1270. }
  1271. TForm::Dispatch(&Message);
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1275. {
  1276. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1277. assert(M);
  1278. if (M->Msg == CM_DIALOGKEY)
  1279. {
  1280. CMDialogKey(*((TWMKeyDown *)Message));
  1281. }
  1282. else if (M->Msg == WM_HELP)
  1283. {
  1284. WMHelp(*((TWMHelp *)Message));
  1285. }
  1286. else
  1287. {
  1288. TForm::Dispatch(Message);
  1289. }
  1290. }
  1291. //---------------------------------------------------------------------------
  1292. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  1293. TObject * /*Sender*/)
  1294. {
  1295. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  1296. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL) == qaYes)
  1297. {
  1298. RegisterAsUrlHandler();
  1299. }
  1300. }
  1301. //---------------------------------------------------------------------------
  1302. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1303. {
  1304. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1305. SetFocus();
  1306. }
  1307. //---------------------------------------------------------------------------
  1308. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1309. TObject * /*Sender*/)
  1310. {
  1311. AnsiString AppPath = ExtractFilePath(Application->ExeName);
  1312. if (MessageDialog(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath)),
  1313. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1314. {
  1315. AddSearchPath(AppPath);
  1316. }
  1317. }
  1318. //---------------------------------------------------------------------------
  1319. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1320. TObject * Sender)
  1321. {
  1322. EditorFontButtonClick(Sender);
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1326. {
  1327. CopyParamListView->Items->Count = FCopyParamList->Count;
  1328. AdjustListColumnsWidth(CopyParamListView, FCopyParamList->Count);
  1329. CopyParamListView->Invalidate();
  1330. }
  1331. //---------------------------------------------------------------------------
  1332. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1333. TListItem * Item)
  1334. {
  1335. int Index = Item->Index;
  1336. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1337. Item->Caption = StringReplace(FCopyParamList->Names[Index], "&", "",
  1338. TReplaceFlags() << rfReplaceAll);
  1339. Item->SubItems->Add(BooleanToStr(FCopyParamList->Rules[Index] != NULL));
  1340. }
  1341. //---------------------------------------------------------------------------
  1342. void __fastcall TPreferencesDialog::CopyParamListViewInfoTip(
  1343. TObject * /*Sender*/, TListItem * Item, AnsiString & InfoTip)
  1344. {
  1345. int Index = Item->Index;
  1346. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1347. const TCopyParamType * CopyParam = FCopyParamList->CopyParams[Index];
  1348. const TCopyParamRule * Rule = FCopyParamList->Rules[Index];
  1349. InfoTip = CopyParam->GetInfoStr("; ", 0);
  1350. if (Rule != NULL)
  1351. {
  1352. InfoTip += "\n-\n" + Rule->GetInfoStr("; ");
  1353. }
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1357. {
  1358. FormHelp(this);
  1359. }
  1360. //---------------------------------------------------------------------------
  1361. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1362. TObject * /*Sender*/)
  1363. {
  1364. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY),
  1365. LoadStr(PREFERENCES_PUTTY_FILTER), false, false);
  1366. }
  1367. //---------------------------------------------------------------------------
  1368. void __fastcall TPreferencesDialog::PuttyPathResetButtonClick(
  1369. TObject * /*Sender*/)
  1370. {
  1371. PuttyPathEdit->Text = WinConfiguration->DefaultPuttyPath;
  1372. }
  1373. //---------------------------------------------------------------------------
  1374. void __fastcall TPreferencesDialog::ExportButtonClick(TObject * /*Sender*/)
  1375. {
  1376. AnsiString PersonalDirectory;
  1377. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
  1378. AnsiString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1379. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
  1380. if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), "ini", FileName))
  1381. {
  1382. Configuration->Export(FileName);
  1383. }
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1387. TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
  1388. {
  1389. FBeforeDialogPath = Name;
  1390. Name = ExpandEnvironmentVariables(Name);
  1391. }
  1392. //---------------------------------------------------------------------------
  1393. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1394. TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
  1395. {
  1396. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1397. {
  1398. Name = FBeforeDialogPath;
  1399. }
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1403. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1404. {
  1405. AllowCollapse = false;
  1406. }
  1407. //---------------------------------------------------------------------------
  1408. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1409. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1410. {
  1411. ScrollOnDragOver(Sender)->EndDrag();
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TPreferencesDialog::RandomSeedFileEditCreateEditDialog(
  1415. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1416. {
  1417. USEDPARAM(DialogKind);
  1418. assert(DialogKind == dkOpen);
  1419. Dialog = CreateOpenDialog(dynamic_cast<TComponent *>(Sender));
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1423. TObject * /*Sender*/, Extended Value, AnsiString & Text, bool & Handled)
  1424. {
  1425. if (Value == 0)
  1426. {
  1427. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1428. Handled = true;
  1429. }
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1433. TObject * /*Sender*/, AnsiString Text, Extended & Value, bool & Handled)
  1434. {
  1435. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1436. {
  1437. Value = 0;
  1438. Handled = true;
  1439. }
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  1443. TObject * /*Sender*/)
  1444. {
  1445. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  1446. {
  1447. try
  1448. {
  1449. if (UseMasterPasswordCheck->Checked)
  1450. {
  1451. if (DoChangeMasterPasswordDialog())
  1452. {
  1453. MessageDialog(LoadStr(MASTER_PASSWORD_SET), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1454. }
  1455. }
  1456. else
  1457. {
  1458. if (DoMasterPasswordDialog())
  1459. {
  1460. WinConfiguration->ClearMasterPassword();
  1461. MessageDialog(LoadStr(MASTER_PASSWORD_CLEARED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1462. }
  1463. }
  1464. }
  1465. __finally
  1466. {
  1467. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  1468. UpdateControls();
  1469. }
  1470. }
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  1474. TObject * /*Sender*/)
  1475. {
  1476. DoChangeMasterPasswordDialog();
  1477. MessageDialog(LoadStr(MASTER_PASSWORD_CHANGED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1478. }
  1479. //---------------------------------------------------------------------------