📄 keywordlist.cpp
字号:
/*
* Tail for Win32 - a Windows version of the UNIX 'tail -f' command.
*
* Author: Paul Perkins (paul@objektiv.org.uk)
*
* Copyright(c)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: Keywordlist.cpp,v 1.5 2003/11/25 08:15:13 paulperkins Exp $
*
*/
#include "stdafx.h"
#include "shlwapi.h"
#include "tail.h"
#include "keywordlist.h"
#include "plugin.h"
#include "settings.h"
#define KEYWORD_FILE "keywords.cfg"
CKeywordPlugin::CKeywordPlugin (void)
{
m_bActive = FALSE;
m_pPlugin = NULL;
}
CKeywordPlugin::CKeywordPlugin (CPlugin* pPlugin)
{
m_bActive = FALSE;
m_pPlugin = pPlugin;
}
CKeywordPlugin::~CKeywordPlugin (void)
{
}
BOOL CKeywordPlugin::Active (
void)
{
return m_bActive;
}
void CKeywordPlugin::SetActive (
BOOL bActive)
{
m_bActive = bActive;
}
const char* CKeywordPlugin::GetShortName (void)
{
return m_pPlugin->GetShortName ();
}
CKeywordListItem::CKeywordListItem (void)
{
m_bActive = FALSE;
m_dwCount = 0;
memset (m_szKeyword, 0, KEYWORD_NAME_SIZE);
m_crColour = RGB (255, 0, 0);
m_pPlugins = new CObList;
}
CKeywordListItem::CKeywordListItem (const char* pszKeyword, BOOL bActive)
{
m_bActive = bActive;
m_dwCount = 0;
m_crColour = RGB (255, 0, 0);
strcpy (m_szKeyword, pszKeyword);
m_pPlugins = new CObList;
}
CKeywordListItem::CKeywordListItem (
const char* pszKeyword,
BOOL bActive,
COLORREF cr)
{
m_bActive = bActive;
m_dwCount = 0;
m_crColour = cr;
strcpy (m_szKeyword, pszKeyword);
m_pPlugins = new CObList;
}
CKeywordListItem::~CKeywordListItem (void)
{
POSITION stPos;
for (stPos = m_pPlugins->GetHeadPosition (); stPos != NULL; )
{
delete (CKeywordPlugin*) m_pPlugins->GetNext (stPos);
}
delete m_pPlugins;
}
CKeywordPlugin* CKeywordListItem::FindPlugin (
const char* pszShortName)
{
POSITION stPos;
CKeywordPlugin* pPlugin = NULL;
for (stPos = m_pPlugins->GetHeadPosition (); stPos != NULL; )
{
pPlugin = (CKeywordPlugin*) m_pPlugins->GetNext (stPos);
if (strcmp (pPlugin->GetShortName (), pszShortName) == 0)
{
return pPlugin;
}
}
return NULL;
}
CKeywordPlugin* CKeywordListItem::FindPlugin (
CPlugin* pPlugin)
{
POSITION stPos;
CKeywordPlugin* pKeywordPlugin = NULL;
for (stPos = m_pPlugins->GetHeadPosition (); stPos != NULL; )
{
pKeywordPlugin = (CKeywordPlugin*) m_pPlugins->GetNext (stPos);
if (pKeywordPlugin->m_pPlugin == pPlugin)
{
return pKeywordPlugin;
}
}
return NULL;
}
CKeywordPlugin* CKeywordListItem::FindPlugin (
long lIndex)
{
POSITION stPos;
if ((stPos = m_pPlugins->FindIndex (lIndex)) != NULL)
{
return (CKeywordPlugin*) m_pPlugins->GetAt (stPos);
}
return NULL;
}
CKeywordPlugin* CKeywordListItem::AddPlugin (
const char* pszPlugin)
{
POSITION stPos;
CString* str = new CString (pszPlugin);
stPos = m_pPlugins->AddTail ((CObject*) str);
return (CKeywordPlugin*) m_pPlugins->GetAt (stPos);
}
CKeywordPlugin* CKeywordListItem::AddPlugin (
CPlugin* pPlugin)
{
CKeywordPlugin* pNewPlugin = NULL;
if (!(pNewPlugin = FindPlugin (pPlugin->GetShortName())))
{
pNewPlugin = new CKeywordPlugin (pPlugin);
m_pPlugins->AddTail ((CObject*) pNewPlugin);
}
return pNewPlugin;
}
BOOL CKeywordListItem::Active (void)
{
return m_bActive;
}
COLORREF CKeywordListItem::Colour (void)
{
return m_crColour;
}
const char* CKeywordListItem::Keyword (void)
{
return &m_szKeyword[0];
}
void CKeywordListItem::SetActive (BOOL bActive)
{
m_bActive = bActive;
}
void CKeywordListItem::SetColour (COLORREF cr)
{
m_crColour = cr;
}
CKeywordList::CKeywordList (
void)
{
m_pItems = new CObList;
}
CKeywordList::~CKeywordList (
void)
{
POSITION stPos;
for (stPos = m_pItems->GetHeadPosition (); stPos != NULL; )
{
delete (CKeywordListItem*) m_pItems->GetNext (stPos);
}
delete m_pItems;
}
CKeywordListItem* CKeywordList::FindKeyword (
const char* pszName)
{
POSITION stPos;
CKeywordListItem* pKeyword = NULL;
for (stPos = m_pItems->GetHeadPosition (); stPos != NULL; )
{
pKeyword = (CKeywordListItem*) m_pItems->GetNext (stPos);
if (strcmp (pKeyword->Keyword (), pszName) == 0)
{
return pKeyword;
}
}
return NULL;
}
CKeywordListItem* CKeywordList::FindKeyword (
long lIndex)
{
POSITION stPos;
if ((stPos = m_pItems->FindIndex (lIndex)) != NULL)
{
return (CKeywordListItem*) m_pItems->GetAt (stPos);
}
return NULL;
}
CKeywordListItem* CKeywordList::AddKeyword (
const char* pszKeyword)
{
CKeywordListItem* pNewKeyword = NULL;
CPlugin* pPlugin = NULL;
CTailApp* theApp = (CTailApp*) AfxGetApp ();
CSettings* pSettings = theApp->GetSettings ();
if (!(pNewKeyword = FindKeyword (pszKeyword)))
{
pNewKeyword = new CKeywordListItem (pszKeyword, TRUE);
m_pItems->AddTail ((CObject*) pNewKeyword);
// Add the plugins.
int j = 0;
while (pPlugin = pSettings->FindPlugin (j++))
{
// Add a reference to each plugin to the keywords.
pNewKeyword->AddPlugin (pPlugin);
}
}
return pNewKeyword;
}
CKeywordListItem* CKeywordList::AddKeyword (
const char* pszKeyword,
BOOL bActive)
{
CKeywordListItem* pNewKeyword = NULL;
if (!(pNewKeyword = FindKeyword (pszKeyword)))
{
pNewKeyword = new CKeywordListItem (pszKeyword, bActive);
m_pItems->AddTail ((CObject*) pNewKeyword);
}
return pNewKeyword;
}
CKeywordListItem* CKeywordList::AddKeyword (
const char* pszKeyword,
BOOL bActive,
COLORREF cr)
{
CKeywordListItem* pNewKeyword = NULL;
if (!(pNewKeyword = FindKeyword (pszKeyword)))
{
pNewKeyword = new CKeywordListItem (pszKeyword, bActive, cr);
m_pItems->AddTail ((CObject*) pNewKeyword);
}
return pNewKeyword;
}
CKeywordListItem* CKeywordList::AddKeyword (
CKeywordListItem* pKeyword)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -