LogSettings.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "LogSettings.h"
  6. #include <CoreMain.h>
  7. #include <TextsWin.h>
  8. #include <VCLCommon.h>
  9. #include <Tools.h>
  10. #include "CustomWinConfiguration.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "ComboEdit"
  14. #pragma link "UpDownEdit"
  15. #ifndef NO_RESOURCES
  16. #pragma resource "*.dfm"
  17. #endif
  18. TLoggingFrame *LoggingFrame;
  19. //---------------------------------------------------------------------------
  20. __fastcall TLoggingFrame::TLoggingFrame(TComponent* Owner)
  21. : TFrame(Owner)
  22. {
  23. FEnableLogWindow = true;
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TLoggingFrame::Init()
  27. {
  28. InstallPathWordBreakProc(LogFileNameEdit);
  29. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT2));
  30. // anchors does not apply for some reason to this particular control
  31. LogFileNameHintText->Left = LogFileNameEdit->Left + LogFileNameEdit->Width -
  32. LogFileNameHintText->Width;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TLoggingFrame::LoadConfiguration()
  36. {
  37. //Log tab
  38. LoggingCheck->Checked = Configuration->Logging;
  39. LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
  40. LogToFileCheck->Checked = Configuration->LogToFile;
  41. LogFileNameEdit->Text = Configuration->LogFileName;
  42. if (Configuration->LogFileAppend)
  43. LogFileAppendButton->Checked = True;
  44. else
  45. LogFileOverwriteButton->Checked = True;
  46. LogShowWindowCheck->Checked = (CustomWinConfiguration->LogView == lvWindow);
  47. if (Configuration->LogWindowComplete)
  48. LogWindowCompleteButton->Checked = True;
  49. else
  50. LogWindowLinesButton->Checked = True;
  51. if (!Configuration->LogWindowComplete)
  52. LogWindowLinesEdit->AsInteger = Configuration->LogWindowLines;
  53. else
  54. LogWindowLinesEdit->AsInteger = 500;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TLoggingFrame::SaveConfiguration()
  58. {
  59. Configuration->BeginUpdate();
  60. try
  61. {
  62. Configuration->Logging = LoggingCheck->Checked;
  63. Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
  64. Configuration->LogToFile = LogToFileCheck->Checked;
  65. if (LogToFileCheck->Checked)
  66. {
  67. Configuration->LogFileName = LogFileNameEdit->Text;
  68. }
  69. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  70. if (EnableLogWindow)
  71. {
  72. CustomWinConfiguration->LogView = LogShowWindowCheck->Checked ? lvWindow : lvNone;
  73. Configuration->LogWindowComplete = LogWindowCompleteButton->Checked;
  74. if (!LogWindowCompleteButton->Checked)
  75. {
  76. Configuration->LogWindowLines = LogWindowLinesEdit->AsInteger;
  77. }
  78. }
  79. }
  80. __finally
  81. {
  82. Configuration->EndUpdate();
  83. }
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TLoggingFrame::UpdateControls()
  87. {
  88. if (!LoggingCheck->Checked)
  89. {
  90. EnableControl(LoggingGroup, False);
  91. }
  92. else
  93. {
  94. LoggingGroup->Enabled = True;
  95. EnableControl(LogToFileCheck, True);
  96. EnableControl(LogProtocolLabel, True);
  97. EnableControl(LogProtocolCombo, True);
  98. EnableControl(LogFileNameEdit, LogToFileCheck->Checked);
  99. EnableControl(LogFileNameHintText, LogFileNameEdit->Enabled);
  100. EnableControl(LogFilePanel, LogToFileCheck->Checked);
  101. EnableControl(LogShowWindowCheck, True && EnableLogWindow);
  102. EnableControl(LogWindowCompleteButton, LogShowWindowCheck->Checked && EnableLogWindow);
  103. EnableControl(LogWindowLinesButton, LogShowWindowCheck->Checked && EnableLogWindow);
  104. EnableControl(LogWindowLinesText, LogShowWindowCheck->Checked && EnableLogWindow);
  105. EnableControl(LogWindowLinesEdit, LogShowWindowCheck->Checked &&
  106. LogWindowLinesButton->Checked && EnableLogWindow);
  107. }
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TLoggingFrame::LogToFileCheckChange(TObject *Sender)
  111. {
  112. if (LogToFileCheck->Checked && LogFileNameEdit->Text.IsEmpty())
  113. {
  114. LogFileNameEdit->Text = DefaultLogFileName;
  115. }
  116. DataChange(Sender);
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TLoggingFrame::DataChange(TObject * /*Sender*/)
  120. {
  121. UpdateControls();
  122. }
  123. //---------------------------------------------------------------------------
  124. AnsiString __fastcall TLoggingFrame::GetDefaultLogFileName()
  125. {
  126. return IncludeTrailingBackslash(SystemTemporaryDirectory()) + "!s.log";
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TLoggingFrame::SetEnableLogWindow(bool value)
  130. {
  131. if (EnableLogWindow != value)
  132. {
  133. FEnableLogWindow = value;
  134. UpdateControls();
  135. }
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TLoggingFrame::LogFileNameEditBeforeDialog(TObject * /*Sender*/,
  139. AnsiString & Name, bool & /*Action*/)
  140. {
  141. FBeforeDialogPath = Name;
  142. Name = ExpandEnvironmentVariables(Name);
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TLoggingFrame::LogFileNameEditAfterDialog(TObject * /*Sender*/,
  146. AnsiString & Name, bool & /*Action*/)
  147. {
  148. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  149. {
  150. Name = FBeforeDialogPath;
  151. }
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TLoggingFrame::LogFileNameEditCreateEditDialog(
  155. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  156. {
  157. USEDPARAM(DialogKind);
  158. assert(DialogKind == dkOpen);
  159. Dialog = CreateOpenDialog(dynamic_cast<TComponent *>(Sender));
  160. }
  161. //---------------------------------------------------------------------------