Preferences.cpp 49 KB

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