LogSettings.cpp 5.5 KB

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