📄 tailview.cpp
字号:
lKeywordCount = m_pSettings->GetNumKeywords();
if (lKeywordCount)
{
i = 0;
LogMessage ("Debug: Found %ld keywords in memory.", lKeywordCount);
ppszNewList = (char**) malloc ((lKeywordCount + 1) * sizeof (char*));
pstNewKeywordList = (KEYWORD_LIST*) malloc (lKeywordCount * sizeof (KEYWORD_LIST));
memset (pstNewKeywordList, 0, (lKeywordCount * sizeof (KEYWORD_LIST)));
while (i < lKeywordCount)
{
strcpy (szLine, m_pSettings->FindKeyword(i)->Keyword());
ppszNewList[i] = (char*) malloc (sizeof (szLine));
*ppszNewList[i] = '\0';
strcpy (pstNewKeywordList[i].szKeyword, szLine);
pstNewKeywordList[i].bExclude = TRUE;
strcpy (ppszNewList[i], szLine);
// Copy the previous list members.
if (m_ppszList)
{
for (int j = 0; j < m_lNumKeywords; j++)
{
if (m_ppszList[j])
{
if (strcmp (m_ppszList[j], pstNewKeywordList[i].szKeyword) == 0)
{
pstNewKeywordList[i].dwMatches = m_pstKeywordList[i].dwMatches;
strcpy (pstNewKeywordList[i].szTimestamp, m_pstKeywordList[i].szTimestamp);
}
}
}
}
i++;
}
}
LogMessage ("Debug: There were %ld keywords, now %ld.",
m_dwNumKeywords,
lKeywordCount);
// Delete the old list.
if (m_ppszList)
{
for (int i = 0; i < m_lNumKeywords; i++)
{
if (m_ppszList[i])
{
free (m_ppszList[i]);
m_ppszList[i] = NULL;
}
}
free (m_pstKeywordList);
m_pstKeywordList = NULL;
free (m_ppszList);
m_ppszList = NULL;
}
// And re-assign.
m_dwNumKeywords = lKeywordCount;
m_lNumKeywords = m_dwNumKeywords;
m_pstKeywordList = pstNewKeywordList;
m_ppszList = ppszNewList;
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::LoadKeywords (
void)
{
char* pszItem = NULL;
char szLine[MAX_KEYWORD_LEN + 1] = "";
if (m_lNumKeywords = m_pSettings->GetNumKeywords())
{
int i = 0;
LogMessage ("Debug: Found %ld keywords in memory.", m_lNumKeywords);
m_ppszList = (char**) malloc ((m_lNumKeywords + 1) * sizeof (char*));
m_dwNumKeywords = m_lNumKeywords;
m_pstKeywordList = (KEYWORD_LIST*) malloc (m_lNumKeywords * sizeof (KEYWORD_LIST));
memset (m_pstKeywordList, 0, (m_lNumKeywords * sizeof (KEYWORD_LIST)));
while (i < m_lNumKeywords)
{
strcpy (szLine, m_pSettings->FindKeyword(i)->Keyword());
m_ppszList[i] = (char*) malloc (sizeof (szLine));
*m_ppszList[i] = '\0';
strcpy (m_pstKeywordList[i].szKeyword, szLine);
m_pstKeywordList[i].bExclude = TRUE;
strcpy (m_ppszList[i++], szLine);
}
}
}
BOOL CTailView::LoadPlugins (
void)
{
HINSTANCE hMod = NULL;
char szAppPath[_MAX_PATH] = "";
char szPlugin[_MAX_PATH] = "";
struct _finddata_t file_info;
char szFileSpec[_MAX_FNAME] = "";
long hFind = 0;
CPlugin* pPlugin = NULL;
GetAppPath (szAppPath);
strcat (szAppPath, PLUGIN_DIR);
LogMessage ("Looking for plugins in '%s'", szAppPath);
sprintf (szFileSpec, "%s*.%s", szAppPath, PLUGIN_EXT);
// Get the first file.
if (-1L != (hFind = _findfirst (szFileSpec, &file_info)))
{
sprintf (szPlugin, "%s%s", szAppPath, file_info.name);
pPlugin = new CPlugin;
LogMessage ("Loading plugin at '%s'", szPlugin);
if (!pPlugin->Load (szPlugin))
{
delete pPlugin;
pPlugin = NULL;
}
else
{
m_Plugins.AddPlugin (pPlugin);
}
while (_findnext (hFind, &file_info) == 0)
{
pPlugin = new CPlugin;
sprintf (szPlugin, "%s%s", szAppPath, file_info.name);
LogMessage ("Loading plugin at '%s'", szPlugin);
if (!pPlugin->Load (szPlugin))
{
delete pPlugin;
pPlugin = NULL;
}
else
{
m_Plugins.AddPlugin (pPlugin);
}
}
}
_findclose (hFind);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnDisplayHotlist()
{
CHotListDisplay stDlg;
stDlg.ppszList = m_ppszList;
stDlg.lNumKeywords = m_lNumKeywords;
stDlg.m_pPlugins = &m_Plugins;
stDlg.DoModal ();
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnSetfont()
{
CFontDialog stFontDlg;
// CTailApp* theApp = NULL;
CHARFORMAT stCF;
LOGFONT lf;
int nPoint; // Warlock
// theApp = (CTailApp*) AfxGetApp ();
m_ctlEdit.GetDefaultCharFormat (stCF);
lf = m_pSettings->GetLogFont ();
// Warlock, added font size changing capability
nPoint = MulDiv( stCF.yHeight, 72, 1440 );
lf.lfHeight = -MulDiv(nPoint, m_ctlEdit.GetDC()->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfCharSet = stCF.bCharSet;
lf.lfPitchAndFamily = stCF.bPitchAndFamily;
strcpy (lf.lfFaceName, stCF.szFaceName);
stFontDlg.m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
stFontDlg.m_cf.lpLogFont = &lf;
if (IDOK == stFontDlg.DoModal ())
{
// Warlock
// Point = 72 / PPI * -Height
// Twips = Point * 1440 / 72
nPoint = -MulDiv( 72, stFontDlg.m_cf.lpLogFont->lfHeight, m_ctlEdit.GetDC()->GetDeviceCaps(LOGPIXELSY) );
stCF.yHeight= MulDiv( nPoint, 1440, 72 ); // Twips
stCF.bCharSet = stFontDlg.m_cf.lpLogFont->lfCharSet;
stCF.bPitchAndFamily = stFontDlg.m_cf.lpLogFont->lfPitchAndFamily;
strcpy (stCF.szFaceName, stFontDlg.m_cf.lpLogFont->lfFaceName);
stCF.dwMask |= CFM_UNDERLINE | CFM_BOLD | CFM_ITALIC | CFM_FACE;
if (stFontDlg.m_cf.lpLogFont->lfUnderline)
{
stCF.dwEffects |= CFE_UNDERLINE;
}
else
{
stCF.dwEffects &= ~CFE_UNDERLINE;
}
if (stFontDlg.m_cf.lpLogFont->lfItalic)
{
stCF.dwEffects |= CFE_ITALIC;
}
else
{
stCF.dwEffects &= ~CFE_ITALIC;
}
if (stFontDlg.m_cf.lpLogFont->lfWeight > 500)
{
stCF.dwEffects |= CFE_BOLD;
}
else
{
stCF.dwEffects &= ~CFE_BOLD;
}
m_ctlEdit.SetDefaultCharFormat (stCF);
m_pSettings->SetLogFont (lf);
m_pSettings->SetGotFont (TRUE);
}
}
/////////////////////////////////////////////////////////////////////////////
//
//
BOOL CTailView::AddEvent (
char* pszEvent,
char* pszSeverity,
long lLine)
{
if (m_bEventsVisible)
{
return FALSE;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnConfigPlugins()
{
CPluginConfig stDlg;
stDlg.m_pPlugins = m_pSettings->GetPlugins ();
stDlg.DoModal ();
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnTally()
{
if (!m_bTallyVisible || (!AfxIsValidAddress (m_pTallyWindow, sizeof (TallyWindow))) || (!m_pTallyWindow->GetSafeHwnd ()))
{
m_pTallyWindow = new TallyWindow ();
m_pTallyWindow->Create (IDD_TALLY, this);
m_pTallyWindow->Update (m_lNumKeywords, &m_stParams.szFileName[0], m_pstKeywordList);
m_pTallyWindow->ShowWindow (SW_SHOW);
m_bTallyVisible = TRUE;
}
else
{
if (AfxIsValidAddress (m_pTallyWindow, sizeof (TallyWindow)) && m_pTallyWindow->GetSafeHwnd ())
{
m_pTallyWindow->ShowWindow (SW_SHOW);
}
}
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnIgnoreStartup()
{
m_pSettings->SetIgnoreHotStartup (!m_pSettings->GetIgnoreHotStartup());
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnUpdateIgnoreStartup(CCmdUI* pCmdUI)
{
if (pCmdUI->m_pMenu)
pCmdUI->SetCheck (m_pSettings->GetIgnoreHotStartup() ? MF_CHECKED : MF_UNCHECKED);
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnViewGo()
{
this->m_bPaused = FALSE;
ScrollToBottom (m_ctlEdit.GetSafeHwnd ());
UpdateStatusBarPause (&this->m_ctlStatusBar, this->m_bPaused);
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnViewStop()
{
this->m_bPaused = TRUE;
UpdateStatusBarPause (&this->m_ctlStatusBar, this->m_bPaused);
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnHiglightLine()
{
m_pSettings->SetHighlightLine (!m_pSettings->GetHighlightLine());
}
/////////////////////////////////////////////////////////////////////////////
//
//
void CTailView::OnUpdateHiglightLine(CCmdUI* pCmdUI)
{
if (pCmdUI->m_pMenu)
{
pCmdUI->SetCheck (m_pSettings->GetHighlightLine() ? MF_CHECKED : MF_UNCHECKED);
}
}
/////////////////////////////////////////////////////////////////////////////
//
//
void ReloadKeywords (
CTailView* pView)
{
if (pView)
{
pView->ReloadKeywords ();
if (AfxIsValidAddress (pView->m_pTallyWindow, sizeof (TallyWindow)) && pView->m_pTallyWindow->GetSafeHwnd ())
{
pView->m_pTallyWindow->Update (pView->m_lNumKeywords,
&pView->m_stParams.szFileName[0],
pView->m_pstKeywordList);
}
}
}
void CTailView::OnWordwrap()
{
m_pSettings->SetWordWrap (!m_pSettings->GetWordWrap());
m_ctlEdit.SetTargetDevice (NULL, m_pSettings->GetWordWrap() ? 0 : 1);
}
void CTailView::OnUpdateWordwrap(CCmdUI* pCmdUI)
{
if (pCmdUI->m_pMenu)
pCmdUI->SetCheck (m_pSettings->GetWordWrap() ? MF_CHECKED : MF_UNCHECKED);
}
void CTailView::OnDestroy()
{
// Kill the worker thread.
HANDLE hDie;
hDie = OpenEvent (EVENT_ALL_ACCESS, FALSE, m_szDieEvent);
SetEvent (hDie);
// Wait for the die to occur.
if (m_pThread && (WAIT_TIMEOUT == WaitForSingleObject (m_pThread->m_hThread, 2000)))
{
AfxMessageBox ("(Debug Warning) Could Not Kill Thread!");
}
CloseHandle (hDie);
CView::OnDestroy();
// Remove ourself from the workspace dialog.
theApp.m_pWorkspace->RemoveWorkspaceFile (this);
}
void CTailView::OnSetBackground()
{
CColorDialog dlg (m_pSettings->GetBackGroundColour(), CC_FULLOPEN);
if (IDOK == dlg.DoModal())
{
m_pSettings->SetBackGroundColour(dlg.GetColor ());
m_ctlEdit.SetBackgroundColor (FALSE, m_pSettings->GetBackGroundColour());
}
}
void CTailView::OnSetHighlightColour()
{
CColorDialog dlg (m_pSettings->GetHighlightColour(), CC_FULLOPEN);
if (IDOK == dlg.DoModal())
{
m_pSettings->SetHighlightColour(dlg.GetColor ());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -