Log.cpp 5.3 KB

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