Preferences.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "Preferences.h"
  6. #include <ScpMain.h>
  7. #include <Terminal.h>
  8. #include "VCLCommon.h"
  9. #include "GUITools.h"
  10. #include "Tools.h"
  11. #include "TextsWin.h"
  12. #include "WinInterface.h"
  13. #include "WinConfiguration.h"
  14. //---------------------------------------------------------------------
  15. #pragma link "GeneralSettings"
  16. #pragma link "LogSettings"
  17. #pragma link "XPGroupBox"
  18. #pragma link "CopyParams"
  19. #pragma link "UpDownEdit"
  20. #pragma link "IEComboBox"
  21. #pragma resource "*.dfm"
  22. //---------------------------------------------------------------------
  23. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode)
  24. {
  25. bool Result;
  26. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
  27. try
  28. {
  29. PreferencesDialog->PreferencesMode = APreferencesMode;
  30. Result = PreferencesDialog->Execute();
  31. }
  32. __finally
  33. {
  34. delete PreferencesDialog;
  35. }
  36. return Result;
  37. }
  38. //---------------------------------------------------------------------
  39. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  40. : TForm(AOwner)
  41. {
  42. FPreferencesMode = pmDefault;
  43. LoggingFrame->OnGetDefaultLogFileName = LoggingGetDefaultLogFileName;
  44. CopyParamsFrame->Direction = pdAll;
  45. FEditorFont = new TFont();
  46. FAfterExternalEditorDialog = false;
  47. FCustomCommands = new TCustomCommands();
  48. FCustomCommandChanging = false;
  49. FCustomCommandDragDest = -1;
  50. UseSystemSettings(this);
  51. }
  52. //---------------------------------------------------------------------------
  53. __fastcall TPreferencesDialog::~TPreferencesDialog()
  54. {
  55. LoggingFrame->OnGetDefaultLogFileName = NULL;
  56. delete FEditorFont;
  57. delete FCustomCommands;
  58. }
  59. //---------------------------------------------------------------------
  60. bool __fastcall TPreferencesDialog::Execute()
  61. {
  62. LoadConfiguration();
  63. bool Result = (ShowModal() == mrOk);
  64. if (Result)
  65. {
  66. SaveConfiguration();
  67. }
  68. return Result;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  72. {
  73. Tree->FullExpand();
  74. int i = 0;
  75. while (i < Tree->Items->Count)
  76. {
  77. if ((!WinConfiguration->ExpertMode &&
  78. Tree->Items->Item[i]->SelectedIndex & 128))
  79. {
  80. Tree->Items->Delete(Tree->Items->Item[i]);
  81. }
  82. else
  83. {
  84. for (int pi = 0; pi < PageControl->PageCount; pi++)
  85. {
  86. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  87. {
  88. if (PageControl->Pages[pi]->Enabled)
  89. {
  90. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  91. }
  92. else
  93. {
  94. Tree->Items->Delete(Tree->Items->Item[i]);
  95. i--;
  96. }
  97. break;
  98. }
  99. }
  100. i++;
  101. }
  102. }
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TPreferencesDialog::LoggingGetDefaultLogFileName(
  106. TObject * /*Sender*/, AnsiString & DefaultLogFileName)
  107. {
  108. DefaultLogFileName = "";
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TPreferencesDialog::LoadConfiguration()
  112. {
  113. if (FPreferencesMode != pmLogin)
  114. {
  115. LoggingFrame->LoadConfiguration();
  116. GeneralSettingsFrame->LoadConfiguration();
  117. }
  118. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  119. BOOLPROP(DefaultDirIsHome);
  120. BOOLPROP(DeleteToRecycleBin);
  121. BOOLPROP(DDTransferConfirmation);
  122. BOOLPROP(DDWarnLackOfTempSpace);
  123. BOOLPROP(ShowHiddenFiles);
  124. BOOLPROP(ShowInaccesibleDirectories);
  125. BOOLPROP(CopyOnDoubleClick);
  126. BOOLPROP(CopyOnDoubleClickConfirmation);
  127. BOOLPROP(ConfirmOverwriting);
  128. BOOLPROP(ConfirmDeleting);
  129. BOOLPROP(ConfirmClosingSession);
  130. BOOLPROP(ConfirmExitOnCompletion);
  131. BOOLPROP(UseLocationProfiles);
  132. BOOLPROP(ContinueOnError);
  133. BOOLPROP(DDAllowMoveInit);
  134. #undef BOOLPROP
  135. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  136. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  137. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  138. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  139. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  140. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  141. {
  142. DDSystemTemporaryDirectoryButton->Checked = true;
  143. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  144. }
  145. else
  146. {
  147. DDCustomTemporaryDirectoryButton->Checked = true;
  148. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  149. }
  150. ExplorerStyleSelectionCheck->Checked =
  151. WinConfiguration->ScpCommander.ExplorerStyleSelection;
  152. PreserveLocalDirectoryCheck->Checked =
  153. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  154. ShowFullAddressCheck->Checked =
  155. WinConfiguration->ScpExplorer.ShowFullAddress;
  156. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  157. IniFileStorageButton->Checked = (Configuration->Storage == stIniFile);
  158. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  159. // editor
  160. EditorInternalButton->Checked = WinConfiguration->Editor.Editor == edInternal;
  161. EditorExternalButton->Checked = WinConfiguration->Editor.Editor == edExternal;
  162. AnsiString ExternalEditor = WinConfiguration->Editor.ExternalEditor;
  163. if (!ExternalEditor.IsEmpty())
  164. {
  165. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  166. }
  167. ExternalEditorEdit->Text = ExternalEditor;
  168. ExternalEditorTextCheck->Checked = WinConfiguration->Editor.ExternalEditorText;
  169. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  170. FEditorFont->Name = WinConfiguration->Editor.FontName;
  171. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  172. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  173. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  174. CopyParamsFrame->Params = GUIConfiguration->CopyParam;
  175. ResumeOnButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsOn;
  176. ResumeSmartButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsSmart;
  177. ResumeOffButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsOff;
  178. ResumeThresholdEdit->Value = GUIConfiguration->CopyParam.ResumeThreshold / 1024;
  179. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  180. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  181. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  182. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  183. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  184. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  185. StorageGroup->Visible = WinConfiguration->ExpertMode;
  186. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  187. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  188. FCustomCommands->Assign(WinConfiguration->CustomCommands);
  189. CustomCommandDescEdit->Text = "";
  190. CustomCommandEdit->Text = "";
  191. UpdateCustomCommandsView();
  192. PuttyPathEdit->FileName = WinConfiguration->PuttyPath;
  193. // Queue
  194. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  195. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  196. QueueCheck->Checked = GUIConfiguration->CopyParam.Queue;
  197. RememberPasswordCheck->Checked = Configuration->RememberPassword;
  198. if (WinConfiguration->QueueView.Show == qvShow)
  199. {
  200. QueueViewShowButton->Checked = true;
  201. }
  202. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  203. {
  204. QueueViewHideWhenEmptyButton->Checked = true;
  205. }
  206. else
  207. {
  208. QueueViewHideButton->Checked = true;
  209. }
  210. UpdateControls();
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TPreferencesDialog::SaveConfiguration()
  214. {
  215. Configuration->BeginUpdate();
  216. try
  217. {
  218. TGUICopyParamType CopyParam = GUIConfiguration->CopyParam;
  219. if (FPreferencesMode != pmLogin)
  220. {
  221. LoggingFrame->SaveConfiguration();
  222. GeneralSettingsFrame->SaveConfiguration();
  223. }
  224. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  225. BOOLPROP(DefaultDirIsHome);
  226. BOOLPROP(DeleteToRecycleBin);
  227. BOOLPROP(DDTransferConfirmation);
  228. BOOLPROP(DDWarnLackOfTempSpace);
  229. BOOLPROP(ShowHiddenFiles);
  230. BOOLPROP(ShowInaccesibleDirectories);
  231. BOOLPROP(CopyOnDoubleClick);
  232. BOOLPROP(CopyOnDoubleClickConfirmation);
  233. BOOLPROP(ConfirmOverwriting);
  234. BOOLPROP(ConfirmDeleting);
  235. BOOLPROP(ConfirmClosingSession);
  236. BOOLPROP(ConfirmExitOnCompletion);
  237. BOOLPROP(UseLocationProfiles);
  238. BOOLPROP(ContinueOnError);
  239. BOOLPROP(DDAllowMoveInit);
  240. #undef BOOLPROP
  241. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  242. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  243. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  244. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  245. if (DDSystemTemporaryDirectoryButton->Checked)
  246. {
  247. WinConfiguration->DDTemporaryDirectory = "";
  248. }
  249. else
  250. {
  251. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  252. }
  253. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  254. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  255. ScpCommander.ExplorerStyleSelection = ExplorerStyleSelectionCheck->Checked;
  256. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  257. WinConfiguration->ScpCommander = ScpCommander;
  258. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  259. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  260. WinConfiguration->ScpExplorer = ScpExplorer;
  261. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  262. // editor
  263. WinConfiguration->Editor.Editor =
  264. (EditorInternalButton->Checked || ExternalEditorEdit->Text.IsEmpty()) ?
  265. edInternal : edExternal;
  266. WinConfiguration->Editor.ExternalEditor = ExternalEditorEdit->Text;
  267. WinConfiguration->Editor.ExternalEditorText = ExternalEditorTextCheck->Checked;
  268. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  269. WinConfiguration->Editor.FontName = FEditorFont->Name;
  270. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  271. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  272. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  273. // overwrites only TCopyParamType fields
  274. CopyParam = CopyParamsFrame->Params;
  275. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  276. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  277. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  278. CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
  279. WinConfiguration->CustomCommands = FCustomCommands;
  280. WinConfiguration->PuttyPath = PuttyPathEdit->FileName;
  281. // Queue
  282. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  283. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  284. CopyParam.Queue = QueueCheck->Checked;
  285. Configuration->RememberPassword = RememberPasswordCheck->Checked;
  286. if (QueueViewShowButton->Checked)
  287. {
  288. WinConfiguration->QueueView.Show = qvShow;
  289. }
  290. else if (QueueViewHideWhenEmptyButton->Checked)
  291. {
  292. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  293. }
  294. else
  295. {
  296. WinConfiguration->QueueView.Show = qvHide;
  297. }
  298. GUIConfiguration->CopyParam = CopyParam;
  299. }
  300. __finally
  301. {
  302. Configuration->EndUpdate();
  303. }
  304. }
  305. //---------------------------------------------------------------------------
  306. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  307. {
  308. if (PreferencesMode != value)
  309. {
  310. FPreferencesMode = value;
  311. GeneralSheet->Enabled = (value != pmLogin);
  312. LogSheet->Enabled = (value != pmLogin);
  313. }
  314. }
  315. //---------------------------------------------------------------------------
  316. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  317. {
  318. PrepareNavigationTree(NavigationTree);
  319. for (int Index = 0; Index < PageControl->PageCount; Index++)
  320. {
  321. PageControl->Pages[Index]->TabVisible = false;
  322. }
  323. // change form height by height of hidden tabs
  324. ClientHeight -= 50;
  325. switch (PreferencesMode) {
  326. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  327. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  328. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  329. default: PageControl->ActivePage = PreferencesSheet; break;
  330. }
  331. PageControlChange(NULL);
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  335. {
  336. UpdateControls();
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TPreferencesDialog::UpdateControls()
  340. {
  341. EnableControl(CopyOnDoubleClickConfirmationCheck, CopyOnDoubleClickCheck->Checked);
  342. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  343. EditorFontLabel->Caption = FMTLOAD(EDITOR_FONT_FMT,
  344. (FEditorFont->Name, FEditorFont->Size));
  345. bool CommandComplete = !CustomCommandDescEdit->Text.IsEmpty() &&
  346. !CustomCommandEdit->Text.IsEmpty();
  347. EnableControl(AddCommandButton, CommandComplete);
  348. EnableControl(SaveCommandButton, CommandComplete &&
  349. CustomCommandsView->Selected &&
  350. (CustomCommandDescEdit->Text != FCustomCommands->Names[CustomCommandsView->ItemIndex] ||
  351. CustomCommandEdit->Text != FCustomCommands->Values[
  352. FCustomCommands->Names[CustomCommandsView->ItemIndex]] ||
  353. CustomCommandParams() != FCustomCommands->Params[
  354. FCustomCommands->Names[CustomCommandsView->ItemIndex]]));
  355. EnableControl(RemoveCommandButton, CustomCommandsView->Selected);
  356. EnableControl(UpCommandButton, CustomCommandsView->ItemIndex > 0);
  357. EnableControl(DownCommandButton, CustomCommandsView->ItemIndex >= 0 &&
  358. CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1);
  359. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  360. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  361. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  362. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  363. DDCustomTemporaryDirectoryButton->Checked);
  364. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  365. DDAllowMoveInitCheck->Checked);
  366. }
  367. //---------------------------------------------------------------------------
  368. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  369. {
  370. TFontDialog * Dialog = new TFontDialog(Application);
  371. try
  372. {
  373. Dialog->Device = fdScreen;
  374. Dialog->Options = TFontDialogOptions() << fdForceFontExist;
  375. Dialog->Font = FEditorFont;
  376. if (Dialog->Execute())
  377. {
  378. FEditorFont->Assign(Dialog->Font);
  379. UpdateControls();
  380. }
  381. }
  382. __finally
  383. {
  384. delete Dialog;
  385. }
  386. }
  387. //---------------------------------------------------------------------------
  388. void __fastcall TPreferencesDialog::ExternalEditorEditExit(TObject * /*Sender*/)
  389. {
  390. try
  391. {
  392. AnsiString ExternalEditor = ExternalEditorEdit->Text;
  393. if (!ExternalEditor.IsEmpty())
  394. {
  395. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  396. ExternalEditorEdit->Text = ExternalEditor;
  397. }
  398. }
  399. catch(...)
  400. {
  401. ExternalEditorEdit->SelectAll();
  402. ExternalEditorEdit->SetFocus();
  403. throw;
  404. }
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TPreferencesDialog::ExternalEditorEditAfterDialog(
  408. TObject * /*Sender*/, AnsiString & /*Name*/, bool & Action)
  409. {
  410. if (Action)
  411. {
  412. FAfterExternalEditorDialog = true;
  413. }
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TPreferencesDialog::ExternalEditorEditChange(
  417. TObject *Sender)
  418. {
  419. if (FAfterExternalEditorDialog)
  420. {
  421. FAfterExternalEditorDialog = false;
  422. ExternalEditorEditExit(Sender);
  423. }
  424. }
  425. //---------------------------------------------------------------------------
  426. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  427. bool & /*CanClose*/)
  428. {
  429. if (ModalResult != mrCancel && ExternalEditorEdit->Focused())
  430. {
  431. ExternalEditorEditExit(NULL);
  432. }
  433. }
  434. //---------------------------------------------------------------------------
  435. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  436. {
  437. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  438. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  439. {
  440. AnsiString IconName, Params;
  441. int SpecialFolder;
  442. if (Sender == SendToHookButton)
  443. {
  444. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppNameVersion));
  445. SpecialFolder = CSIDL_SENDTO;
  446. Params = "/upload";
  447. }
  448. else if (Sender == QuickLaunchIconButton)
  449. {
  450. IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
  451. AppNameVersion;
  452. SpecialFolder = CSIDL_APPDATA;
  453. }
  454. else
  455. {
  456. IconName = AppNameVersion;
  457. SpecialFolder = Sender == DesktopIconButton ?
  458. CSIDL_DESKTOPDIRECTORY :CSIDL_COMMON_DESKTOPDIRECTORY;
  459. }
  460. CreateDesktopShortCut(IconName,
  461. Application->ExeName, Params, "", SpecialFolder);
  462. }
  463. }
  464. //---------------------------------------------------------------------------
  465. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  466. TListItem * Item)
  467. {
  468. assert(FCustomCommands);
  469. int Index = Item->Index;
  470. assert(Index >= 0 && Index <= FCustomCommands->Count);
  471. Item->Caption = StringReplace(FCustomCommands->Names[Index], "&", "",
  472. TReplaceFlags() << rfReplaceAll);
  473. assert(!Item->SubItems->Count);
  474. AnsiString Name = FCustomCommands->Names[Index];
  475. Item->SubItems->Add(FCustomCommands->Values[Name]);
  476. int Params = FCustomCommands->Params[Name];
  477. AnsiString ParamsStr;
  478. if ((Params & ccApplyToDirectories) && (Params & ccRecursive))
  479. {
  480. ParamsStr = FMTLOAD(CUSTOM_COMMAND_PARAMFMT,
  481. (LoadStr(CUSTOM_COMMAND_DIRECTORIES), LoadStr(CUSTOM_COMMAND_RECURSE)));
  482. }
  483. else if (Params & ccApplyToDirectories)
  484. {
  485. ParamsStr = LoadStr(CUSTOM_COMMAND_DIRECTORIES);
  486. }
  487. else if (Params & ccRecursive)
  488. {
  489. ParamsStr = LoadStr(CUSTOM_COMMAND_RECURSE);
  490. }
  491. Item->SubItems->Add(ParamsStr);
  492. }
  493. //---------------------------------------------------------------------------
  494. void __fastcall TPreferencesDialog::CustomCommandsViewSelectItem(
  495. TObject * /*Sender*/, TListItem * Item, bool Selected)
  496. {
  497. if (Item && Selected)
  498. {
  499. assert(Item);
  500. int Index = Item->Index;
  501. assert(Index >= 0 && Index <= FCustomCommands->Count);
  502. CustomCommandDescEdit->Text = FCustomCommands->Names[Index];
  503. AnsiString Name = FCustomCommands->Names[Index];
  504. CustomCommandEdit->Text = FCustomCommands->Values[Name];
  505. int Params = FCustomCommands->Params[Name];
  506. CustomCommandApplyToDirectoriesCheck->Checked = Params & ccApplyToDirectories;
  507. CustomCommandRecursiveCheck->Checked = Params & ccRecursive;
  508. }
  509. UpdateControls();
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  513. {
  514. CustomCommandsView->Items->Count = FCustomCommands->Count;
  515. AdjustListColumnsWidth(CustomCommandsView);
  516. CustomCommandsView->Invalidate();
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  520. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  521. {
  522. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  523. {
  524. RemoveCommandButtonClick(NULL);
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. AnsiString __fastcall TPreferencesDialog::CustomCommandString(int Index)
  529. {
  530. if (CustomCommandDescEdit->Text.Pos("="))
  531. {
  532. throw Exception(FMTLOAD(CUSTOM_COMMAND_INVALID, ("=")));
  533. }
  534. int I = FCustomCommands->IndexOfName(CustomCommandDescEdit->Text);
  535. if (I >= 0 && (Index < 0 || I != Index))
  536. {
  537. throw Exception(FMTLOAD(CUSTOM_COMMAND_DUPLICATE, (CustomCommandDescEdit->Text)));
  538. }
  539. return FORMAT("%s=%s", (CustomCommandDescEdit->Text, CustomCommandEdit->Text));
  540. }
  541. //---------------------------------------------------------------------------
  542. int __fastcall TPreferencesDialog::CustomCommandParams()
  543. {
  544. return
  545. (CustomCommandApplyToDirectoriesCheck->Checked ? ccApplyToDirectories : 0) |
  546. (CustomCommandRecursiveCheck->Checked ? ccRecursive : 0);
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  550. {
  551. int Index;
  552. if (CustomCommandsView->ItemIndex >= 0)
  553. {
  554. FCustomCommands->Insert(CustomCommandsView->ItemIndex, CustomCommandString());
  555. Index = CustomCommandsView->ItemIndex;
  556. }
  557. else
  558. {
  559. Index = FCustomCommands->Add(CustomCommandString());
  560. }
  561. FCustomCommands->Params[CustomCommandDescEdit->Text] = CustomCommandParams();
  562. CustomCommandsView->ItemIndex = Index;
  563. UpdateCustomCommandsView();
  564. UpdateControls();
  565. }
  566. //---------------------------------------------------------------------------
  567. void __fastcall TPreferencesDialog::SaveCommandButtonClick(TObject * /*Sender*/)
  568. {
  569. assert(CustomCommandsView->ItemIndex >= 0 &&
  570. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  571. FCustomCommands->Strings[CustomCommandsView->ItemIndex] =
  572. CustomCommandString(CustomCommandsView->ItemIndex);
  573. FCustomCommands->Params[CustomCommandDescEdit->Text] = CustomCommandParams();
  574. UpdateCustomCommandsView();
  575. UpdateControls();
  576. }
  577. //---------------------------------------------------------------------------
  578. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  579. TObject * /*Sender*/)
  580. {
  581. assert(CustomCommandsView->ItemIndex >= 0 &&
  582. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  583. FCustomCommands->Delete(CustomCommandsView->ItemIndex);
  584. UpdateCustomCommandsView();
  585. UpdateControls();
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  589. {
  590. if (Source >= 0 && Source < FCustomCommands->Count &&
  591. Dest >= 0 && Dest < FCustomCommands->Count)
  592. {
  593. FCustomCommands->Move(Source, Dest);
  594. // workaround for bug in VCL
  595. CustomCommandsView->ItemIndex = -1;
  596. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  597. CustomCommandsView->ItemIndex = Dest;
  598. UpdateCustomCommandsView();
  599. UpdateControls();
  600. }
  601. }
  602. //---------------------------------------------------------------------------
  603. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  604. {
  605. CustomCommandMove(CustomCommandsView->ItemIndex,
  606. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TPreferencesDialog::CustomCommandsViewStartDrag(
  610. TObject * /*Sender*/, TDragObject *& /*DragObject*/)
  611. {
  612. FCustomCommandDragSource = CustomCommandsView->ItemIndex;
  613. FCustomCommandDragDest = -1;
  614. }
  615. //---------------------------------------------------------------------------
  616. bool __fastcall TPreferencesDialog::AllowCustomCommandsDrag(int X, int Y)
  617. {
  618. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  619. FCustomCommandDragDest = Item ? Item->Index : -1;
  620. return (FCustomCommandDragDest >= 0) && (FCustomCommandDragDest != FCustomCommandDragSource);
  621. }
  622. //---------------------------------------------------------------------------
  623. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  624. TObject * /*Sender*/, TObject * Source, int X, int Y)
  625. {
  626. if (Source == CustomCommandsView)
  627. {
  628. if (AllowCustomCommandsDrag(X, Y))
  629. {
  630. CustomCommandMove(FCustomCommandDragSource, FCustomCommandDragDest);
  631. }
  632. }
  633. }
  634. //---------------------------------------------------------------------------
  635. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  636. TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/,
  637. TDragState /*State*/, bool & Accept)
  638. {
  639. if (Source == CustomCommandsView)
  640. {
  641. // cannot use AllowCustomCommandsDrag(X, Y) because of bug in VCL
  642. // (when dropped on item itself, when it was dragged over another item before,
  643. // that another item remains highlighted forever)
  644. Accept = true;
  645. }
  646. }
  647. //---------------------------------------------------------------------------
  648. void __fastcall TPreferencesDialog::CompareByTimeCheckClick(
  649. TObject * /*Sender*/)
  650. {
  651. if (!CompareByTimeCheck->Checked)
  652. {
  653. CompareBySizeCheck->Checked = true;
  654. }
  655. UpdateControls();
  656. }
  657. //---------------------------------------------------------------------------
  658. void __fastcall TPreferencesDialog::CompareBySizeCheckClick(
  659. TObject * /*Sender*/)
  660. {
  661. if (!CompareBySizeCheck->Checked)
  662. {
  663. CompareByTimeCheck->Checked = true;
  664. }
  665. UpdateControls();
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  669. TTreeNode *Node)
  670. {
  671. if (Node->SelectedIndex)
  672. {
  673. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  674. {
  675. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  676. {
  677. PageControl->ActivePage = PageControl->Pages[Index];
  678. return;
  679. }
  680. }
  681. }
  682. assert(false);
  683. }
  684. //---------------------------------------------------------------------------
  685. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  686. {
  687. bool Found = false;
  688. if (PageControl->ActivePage->Tag)
  689. {
  690. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  691. {
  692. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  693. PageControl->ActivePage->Tag)
  694. {
  695. NavigationTree->Items->Item[Index]->Selected = true;
  696. Found = true;
  697. }
  698. }
  699. }
  700. assert(Found);
  701. if (Found)
  702. {
  703. UpdateControls();
  704. }
  705. }
  706. //---------------------------------------------------------------------------
  707. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  708. {
  709. if (Message.CharCode == VK_TAB)
  710. {
  711. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  712. if (Shift.Contains(ssCtrl))
  713. {
  714. TTreeNode * Node = NavigationTree->Selected;
  715. if (!Shift.Contains(ssShift))
  716. {
  717. Node = Node->GetNext();
  718. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  719. }
  720. else
  721. {
  722. if (Node->GetPrev()) Node = Node->GetPrev();
  723. else
  724. while (Node->GetNext()) Node = Node->GetNext();
  725. }
  726. Node->Selected = True;
  727. Message.Result = 1;
  728. return;
  729. }
  730. }
  731. TForm::Dispatch(&Message);
  732. }
  733. //---------------------------------------------------------------------------
  734. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  735. {
  736. TMessage * M = reinterpret_cast<TMessage*>(Message);
  737. assert(M);
  738. if (M->Msg == CM_DIALOGKEY)
  739. {
  740. CMDialogKey(*((TWMKeyDown *)Message));
  741. }
  742. else
  743. {
  744. TForm::Dispatch(Message);
  745. }
  746. }
  747. //---------------------------------------------------------------------------
  748. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  749. TObject * /*Sender*/)
  750. {
  751. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  752. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  753. {
  754. RegisterAsUrlHandler();
  755. }
  756. }
  757. //---------------------------------------------------------------------------
  758. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  759. {
  760. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  761. Checked = true;
  762. }
  763. //---------------------------------------------------------------------------
  764. void __fastcall TPreferencesDialog::PathEditsKeyDown(
  765. TObject * Sender, WORD & Key, TShiftState Shift)
  766. {
  767. PathEditKeyDown(dynamic_cast<TCustomEdit*>(Sender), Key, Shift, false);
  768. }
  769. //---------------------------------------------------------------------------