Log.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <FileCtrl.hpp>
  5. #include <VCLCommon.h>
  6. #include <Common.h>
  7. #include <ScpMain.h>
  8. #include <TextsWin.h>
  9. #include "Log.h"
  10. #include "Glyphs.h"
  11. #include "NonVisual.h"
  12. #include "WinConfiguration.h"
  13. #include "Tools.h"
  14. //---------------------------------------------------------------------------
  15. #pragma package(smart_init)
  16. #pragma link "LogMemo"
  17. #pragma link "TB2Dock"
  18. #pragma link "TB2Item"
  19. #pragma link "TB2Toolbar"
  20. #pragma link "TBX"
  21. #pragma link "TBXStatusBars"
  22. #pragma resource "*.dfm"
  23. TLogForm *LogForm = NULL;
  24. //---------------------------------------------------------------------------
  25. TLogForm * __fastcall CreateLogForm(TLogMemo *ALogMemo)
  26. {
  27. assert(!LogForm);
  28. TLogForm * aLogForm = new TLogForm(Application);
  29. try
  30. {
  31. aLogForm->LogMemo = ALogMemo;
  32. aLogForm->Show();
  33. }
  34. catch (...)
  35. {
  36. delete aLogForm;
  37. throw;
  38. }
  39. LogForm = aLogForm;
  40. return aLogForm;
  41. }
  42. //---------------------------------------------------------------------------
  43. TLogForm * __fastcall RequireLogForm(TLogMemo *ALogMemo)
  44. {
  45. if (!LogForm)
  46. {
  47. CreateLogForm(ALogMemo);
  48. }
  49. return LogForm;
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall FreeLogForm()
  53. {
  54. if (LogForm)
  55. {
  56. TLogForm * PLogForm = LogForm;
  57. LogForm = NULL;
  58. // would also free form see TLogForm::FormClose()
  59. // we can't free form directly (cause exception when form is closed by
  60. // button on toolbar, beacuse it destroys the button too)
  61. PLogForm->Close();
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. __fastcall TLogForm::TLogForm(TComponent* Owner)
  66. : FFormRestored(False), TForm(Owner)
  67. {
  68. FLogMemo = NULL;
  69. FSessionLog = NULL;
  70. ShowWindow(Handle, SW_SHOWNA);
  71. UseSystemSettings(this);
  72. }
  73. //---------------------------------------------------------------------------
  74. __fastcall TLogForm::~TLogForm()
  75. {
  76. LogForm = NULL;
  77. LogMemo = NULL;
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TLogForm::SetLogMemo(TLogMemo * value)
  81. {
  82. if (LogMemo != value)
  83. {
  84. TLogMemo * OldLogMemo = LogMemo;
  85. FLogMemo = value;
  86. if (OldLogMemo)
  87. {
  88. assert((OldLogMemo->Parent == this) && (OldLogMemo->OnChange == LogMemoChange));
  89. OldLogMemo->OnChange = NULL;
  90. if (SessionLog == OldLogMemo->SessionLog) SessionLog = NULL;
  91. OldLogMemo->Parent = NULL;
  92. }
  93. if (LogMemo)
  94. {
  95. LogMemo->Align = alClient;
  96. if (!SessionLog) SessionLog = LogMemo->SessionLog;
  97. LogMemo->Parent = this;
  98. // setting Parent usually calls OnChange many times (pending changes are
  99. // inserted to TLogMemo), so we set OnChange handler after Parent.
  100. LogMemo->OnChange = LogMemoChange;
  101. LogMemoChange(LogMemo);
  102. }
  103. }
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TLogForm::LogMemoChange(TObject * /*Sender*/)
  107. {
  108. assert(LogMemo);
  109. Application->ProcessMessages();
  110. if (!ComponentState.Contains(csDestroying))
  111. {
  112. UpdateActions();
  113. }
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TLogForm::FormClose(TObject * /*Sender*/, TCloseAction & Action)
  117. {
  118. assert(Configuration);
  119. // If log window feature is turned off (log window is being closed
  120. // by turning off this feature e.g. in Preferences Window), really close it
  121. // If log window feature is turned on (log window is being closed by
  122. // close command if this window) we only disable log window feature
  123. // (this function will be than called again, see case 1)
  124. LogMemo = NULL;
  125. if (!Configuration->Logging || (WinConfiguration->LogView != lvWindow) ||
  126. Application->Terminated)
  127. {
  128. Action = caFree;
  129. }
  130. else
  131. {
  132. WinConfiguration->LogView = lvNone;
  133. Action = caFree;
  134. }
  135. WinConfiguration->LogWindowParams = StoreForm(this);
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TLogForm::SetSessionLog(TSessionLog * value)
  139. {
  140. if (FSessionLog != value)
  141. {
  142. FSessionLog = value;
  143. UpdateControls();
  144. }
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TLogForm::UpdateControls()
  148. {
  149. TTBXStatusPanel * Panel = StatusBar->Panels->Items[0];
  150. if (SessionLog)
  151. {
  152. if (SessionLog->LoggingToFile)
  153. {
  154. Panel->TextTruncation = twPathEllipsis;
  155. Panel->Caption = SessionLog->LogFileName;
  156. }
  157. else
  158. {
  159. Panel->TextTruncation = twEndEllipsis;
  160. Panel->Caption = LoadStr(LOG_NOLOGFILE);
  161. }
  162. Caption = FMTLOAD(LOG_CAPTION, (SessionLog->SessionName));
  163. }
  164. else
  165. {
  166. Panel->TextTruncation = twEndEllipsis;
  167. Panel->Caption = LoadStr(LOG_NOLOG);
  168. Caption = LoadStr(LOG_NOLOGCAPTION);
  169. }
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TLogForm::CreateParams(TCreateParams & Params)
  173. {
  174. if (!FFormRestored)
  175. {
  176. FFormRestored = True;
  177. assert(Configuration);
  178. RestoreForm(WinConfiguration->LogWindowParams, this);
  179. }
  180. TForm::CreateParams(Params);
  181. Params.WndParent = GetDesktopWindow();
  182. }