LogSettings.cpp 5.4 KB

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