Preferences.cpp 48 KB

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