EditorPreferences.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <WinConfiguration.h>
  6. #include <WinInterface.h>
  7. #include <VCLCommon.h>
  8. #include <TextsWin.h>
  9. #include <Tools.h>
  10. #include <CoreMain.h>
  11. #include "EditorPreferences.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "HistoryComboBox"
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. bool __fastcall DoEditorPreferencesDialog(TEditorPreferences * Editor,
  18. TEditorPreferencesMode Mode)
  19. {
  20. bool Result;
  21. TEditorPreferencesDialog * Dialog = new TEditorPreferencesDialog(Application, Mode);
  22. try
  23. {
  24. Result = Dialog->Execute(Editor);
  25. }
  26. __finally
  27. {
  28. delete Dialog;
  29. }
  30. return Result;
  31. }
  32. //---------------------------------------------------------------------------
  33. __fastcall TEditorPreferencesDialog::TEditorPreferencesDialog(
  34. TComponent * Owner, TEditorPreferencesMode Mode) :
  35. TForm(Owner)
  36. {
  37. UseSystemSettings(this);
  38. FMode = Mode;
  39. Caption = LoadStr(Mode == epmEdit ? EDITOR_EDIT : EDITOR_ADD);
  40. InstallPathWordBreakProc(ExternalEditorEdit);
  41. }
  42. //---------------------------------------------------------------------------
  43. bool __fastcall TEditorPreferencesDialog::Execute(TEditorPreferences * Editor)
  44. {
  45. EditorInternalButton->Checked = (Editor->Data.Editor == edInternal);
  46. EditorExternalButton->Checked = (Editor->Data.Editor == edExternal);
  47. AnsiString ExternalEditor = Editor->Data.ExternalEditor;
  48. if (!ExternalEditor.IsEmpty())
  49. {
  50. ReformatFileNameCommand(ExternalEditor);
  51. }
  52. ExternalEditorEdit->Text = ExternalEditor;
  53. ExternalEditorEdit->Items = CustomWinConfiguration->History["ExternalEditor"];
  54. MaskEdit->Text = Editor->Data.FileMask.Masks;
  55. MaskEdit->Items = CustomWinConfiguration->History["Mask"];
  56. ExternalEditorTextCheck->Checked = Editor->Data.ExternalEditorText;
  57. MDIExternalEditorCheck->Checked = Editor->Data.MDIExternalEditor;
  58. bool Result = (ShowModal() == mrOk);
  59. if (Result)
  60. {
  61. Editor->Data.Editor = (EditorInternalButton->Checked ? edInternal : edExternal);
  62. Editor->Data.ExternalEditor = ExternalEditorEdit->Text;
  63. ExternalEditorEdit->SaveToHistory();
  64. CustomWinConfiguration->History["ExternalEditor"] = ExternalEditorEdit->Items;
  65. Editor->Data.FileMask = MaskEdit->Text;
  66. MaskEdit->SaveToHistory();
  67. CustomWinConfiguration->History["Mask"] = MaskEdit->Items;
  68. Editor->Data.ExternalEditorText = ExternalEditorTextCheck->Checked;
  69. Editor->Data.MDIExternalEditor = MDIExternalEditorCheck->Checked;
  70. }
  71. return Result;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TEditorPreferencesDialog::ExternalEditorEditExit(
  75. TObject * Sender)
  76. {
  77. // duplicated in TPreferencesDialog::FilenameEditExit
  78. THistoryComboBox * FilenameEdit = dynamic_cast<THistoryComboBox *>(Sender);
  79. try
  80. {
  81. AnsiString Filename = FilenameEdit->Text;
  82. if (!Filename.IsEmpty())
  83. {
  84. ReformatFileNameCommand(Filename);
  85. FilenameEdit->Text = Filename;
  86. }
  87. ControlChange(Sender);
  88. }
  89. catch(...)
  90. {
  91. FilenameEdit->SelectAll();
  92. FilenameEdit->SetFocus();
  93. throw;
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TEditorPreferencesDialog::ExternalEditorBrowseButtonClick(
  98. TObject * /*Sender*/)
  99. {
  100. BrowseForExecutable(ExternalEditorEdit,
  101. LoadStr(PREFERENCES_SELECT_EXTERNAL_EDITOR),
  102. LoadStr(PREFERENCES_EXTERNAL_EDITOR_FILTER), true);
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TEditorPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  106. {
  107. FormHelp(this);
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TEditorPreferencesDialog::ControlChange(TObject * /*Sender*/)
  111. {
  112. UpdateControls();
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TEditorPreferencesDialog::UpdateControls()
  116. {
  117. EnableControl(OkButton,
  118. EditorInternalButton->Checked || !ExternalEditorEdit->Text.IsEmpty());
  119. EnableControl(ExternalEditorEdit, EditorExternalButton->Checked);
  120. EnableControl(ExternalEditorBrowseButton, EditorExternalButton->Checked);
  121. EnableControl(ExternalEditorGroup, EditorExternalButton->Checked);
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TEditorPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  125. bool & /*CanClose*/)
  126. {
  127. if (ModalResult != mrCancel)
  128. {
  129. ExitActiveControl(this);
  130. }
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TEditorPreferencesDialog::MaskEditExit(TObject * /*Sender*/)
  134. {
  135. ValidateMaskEdit(MaskEdit);
  136. }
  137. //---------------------------------------------------------------------------