EditorPreferences.cpp 5.2 KB

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