Click here to Skip to main content
15,894,825 members
Articles / Programming Languages / C++

ToDoList Add-on

Rate me:
Please Sign up or sign in to vote.
4.69/5 (6 votes)
20 Apr 2002CPOL3 min read 242.3K   2.9K   57  
A Visual Studio add-in to help navigate to TODO:, TASK: etc comments, as well as showing STL containers in debug mode such as std::string, std::list etc
/********************************************************************
  created:    2001/11/05
  created:    5:11:2001   16:24
  filename:   d:\My Projects\Own\Add-on\ToDoCached\ShtKeywords.cpp
  file path:  d:\My Projects\Own\Add-on\ToDoCached
  file base:  ShtKeywords
  file ext:   cpp
  author:     Alex Kucherenko

  purpose:    
*********************************************************************/

#include "stdafx.h"
#include "ShtKeywords.h"
#include "todohlp.h"

#ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 

IMPLEMENT_DYNCREATE(CShtKeywords, CHHPropPage)

//////////////////////////////////////////////////////////////////////////
// main constructor of dialog with help support 

CShtKeywords::CShtKeywords( CRegistryEx *pReg /*= NULL*/ ) 
  : CHHPropPage(CShtKeywords::IDD, true, IDH_PAGE_KEYWORDS )
  , CInitDialogImpl( "keywords_optdlg", pReg )
  , m_bCommModified( FALSE )
  , m_bKeyModified( FALSE )
{
  //{{AFX_DATA_INIT(CShtKeywords)
  m_strExtension = _T("");
  m_strComment = _T("");
  m_strKeyword = _T("");
  m_strKeywordList = _T("");
  //}}AFX_DATA_INIT
}

//////////////////////////////////////////////////////////////////////////
// destructor

CShtKeywords::~CShtKeywords()
{
}

//////////////////////////////////////////////////////////////////////////
// data exchange function of MFC dialog

void CShtKeywords::DoDataExchange(CDataExchange* pDX)
{
  CHHPropPage::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CShtKeywords)
  DDX_Control(pDX, IDC_KEYLIST, m_cKeys);
  DDX_Text(pDX, IDC_EXTENSIONS, m_strExtension);
	DDV_MaxChars(pDX, m_strExtension, 255);
  DDX_Text(pDX, IDC_COMMENT, m_strComment);
	DDV_MaxChars(pDX, m_strComment, 255);
  DDX_Text(pDX, IDC_KEYWORD, m_strKeyword);
	DDV_MaxChars(pDX, m_strKeyword, 255);
  DDX_LBString(pDX, IDC_KEYLIST, m_strKeywordList);
	//}}AFX_DATA_MAP
}

//////////////////////////////////////////////////////////////////////////
// message mapping 

BEGIN_MESSAGE_MAP(CShtKeywords, CHHPropPage)
  //{{AFX_MSG_MAP(CShtKeywords)
  ON_WM_DESTROY()
  ON_BN_CLICKED(IDC_DELETE, OnDelete)
  ON_BN_CLICKED(IDC_ADD, OnAdd)
  ON_LBN_SELCHANGE(IDC_KEYLIST, OnSelchangeKeylist)
  ON_EN_CHANGE(IDC_COMMENT, OnChangeComment)
  ON_EN_CHANGE(IDC_KEYWORD, OnChangeKeyword)
  ON_BN_CLICKED(IDC_APPLY, OnApplyChanges)
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Reover dialog settings from registry

void CShtKeywords::GetInitSettings()
{
  m_arrKeywords = m_pRegistry->GetArrayByTemplate( "search\\search%d" );
  m_arrComments = m_pRegistry->GetArrayByTemplate( "search\\text%d" );
  m_strExtension = GetDlgItemValue( "extensions" ).c_str();
};

//////////////////////////////////////////////////////////////////////////
// save settings to registry

void CShtKeywords::SetInitSettings()
{
  m_pRegistry->DeleteByTemplate( "search\\search%d" );
  m_pRegistry->SetValueByTemplate( "search\\search%d", m_arrKeywords );

  m_pRegistry->DeleteByTemplate( "search\\text%d" );
  m_pRegistry->SetValueByTemplate( "search\\text%d", m_arrComments );

  SetDlgItemParam( "extensions", m_strExtension );
};

//////////////////////////////////////////////////////////////////////////
// Init function of dialog

BOOL CShtKeywords::OnInitDialog() 
{
  CHHPropPage::OnInitDialog();
  GetInitSettings();

  TStrArrayIter i;

  m_cKeys.LockWindowUpdate();

  for( i = m_arrKeywords.begin(); i != m_arrKeywords.end(); i++ )
    m_cKeys.AddString( i->c_str() );

  m_cKeys.UnlockWindowUpdate();

  if( !m_arrKeywords.empty() )
  {
    ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_DELETE ), TRUE );
    m_strKeyword = m_arrKeywords[0].c_str();
  }

  if( !m_arrComments.empty() )
    m_strComment = m_arrComments[0].c_str();

  m_cKeys.SetCurSel( 0 );

  UpdateData( FALSE );
  return TRUE;
}

//////////////////////////////////////////////////////////////////////////
// save settings to registry on dialog destroy

void CShtKeywords::OnDestroy() 
{
  UpdateData();
  SetInitSettings();
  CHHPropPage::OnDestroy();
}

//////////////////////////////////////////////////////////////////////////
// delete one keyword from list

void CShtKeywords::OnDelete() 
{
  UpdateData();
  
  int iSel = m_cKeys.GetCurSel();

  if( !m_arrComments.empty() )
  {
    TStrArrayIter i = m_arrKeywords.begin();
    TStrArrayIter k = m_arrComments.begin();

    std::advance( i, iSel );
    std::advance( k, iSel );

    m_arrKeywords.erase( i );
    m_arrComments.erase( k );

    UpdateListControl();

    if( m_arrKeywords.empty() )
    {
      ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_DELETE ), FALSE );
      m_strKeyword = "";
      m_strComment = "";
      UpdateData( FALSE );
    }
  }
  else
  {
    ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_DELETE ), FALSE );
  }
}

//////////////////////////////////////////////////////////////////////////
// Sort items of list control 

void CShtKeywords::SortListItems(void)
{
  // Sort and unique values in list control
  TKeyMap mapTemp;
  
  for( UINT i = 0 ; i < m_arrKeywords.size(); i++ )
    mapTemp.insert( TKeyMap::value_type( m_arrKeywords[i], m_arrComments[i] ) );
  
  m_arrKeywords.clear();
  m_arrComments.clear();
  
  TKeyMap::iterator j;
  
  for( j = mapTemp.begin(); j != mapTemp.end(); j++ )
  {
    m_arrKeywords.push_back( j->first );
    m_arrComments.push_back( j->second );
  }
  
  mapTemp.clear();
}

//////////////////////////////////////////////////////////////////////////
// add new keyword to list

void CShtKeywords::OnAdd() 
{
  UpdateData();

  if( m_strKeyword.IsEmpty() ) return;

  string temp = m_strKeyword;
  m_arrKeywords.push_back( temp );

  temp = m_strComment;
  m_arrComments.push_back( temp );

  SortListItems();
  UpdateListControl();
  
  ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_APPLY ), FALSE );
  ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_DELETE ), TRUE );

  UpdateData( FALSE );
}

//////////////////////////////////////////////////////////////////////////
// on selection change in list change data in edit boxes

void CShtKeywords::OnSelchangeKeylist() 
{
  UpdateData();
  
  int iSel = m_cKeys.GetCurSel();
  
  if( !m_arrKeywords.empty() )
    m_strKeyword = m_arrKeywords[ iSel ].c_str();

  if( !m_arrComments.empty() )
    m_strComment = m_arrComments[ iSel ].c_str();
  
  UpdateData( FALSE );
}

//////////////////////////////////////////////////////////////////////////
// user change some comments

void CShtKeywords::OnChangeComment() 
{
  if( !m_arrKeywords.empty() )
  {
    m_bCommModified = TRUE;
    ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_APPLY ), TRUE );
  }
}

//////////////////////////////////////////////////////////////////////////
// user change keyword

void CShtKeywords::OnChangeKeyword() 
{
  if( !m_arrKeywords.empty() )
  {
    m_bKeyModified = TRUE;
    ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_APPLY ), TRUE );
  }
}

//////////////////////////////////////////////////////////////////////////
// Store changes into current keyowrd item

void CShtKeywords::OnApplyChanges() 
{
  UpdateData();
  
  int iSel = m_cKeys.GetCurSel();
  string temp = m_strKeyword;

  TStrArrayIter k = std::find( m_arrKeywords.begin(), m_arrKeywords.end(), temp );

  if( k != m_arrKeywords.end() && m_bKeyModified == TRUE )
  {
    ::MessageBox( NULL, "Keyword must be unique. Please change keyword", "Error", MB_OK );
    return;
  }

  if( !m_arrKeywords.empty() )
  {
    m_arrKeywords[ iSel ] = m_strKeyword;
    m_arrComments[ iSel ] = m_strComment;
  }
  
  SortListItems();
  UpdateListControl();

  ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_APPLY ), FALSE );
  
  m_bCommModified = FALSE;
  m_bKeyModified = FALSE;

  UpdateData( FALSE );
}

//////////////////////////////////////////////////////////////////////////
// Create keyword list from the vector list

void CShtKeywords::UpdateListControl( int iSel /*= 0*/ )
{
  TStrArrayIter i;
  
  m_cKeys.LockWindowUpdate();
  
  m_cKeys.ResetContent();
  
  for( i = m_arrKeywords.begin(); i != m_arrKeywords.end(); i++ )
    m_cKeys.AddString( i->c_str() );
  
  m_cKeys.SetCurSel( iSel );
  
  m_cKeys.UnlockWindowUpdate();
};

//:> end of file

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO ArtfulBits Inc.
Ukraine Ukraine
Name:Kucherenko Oleksandr

Born:September 20, 1979

Platforms: Win32, Linux; - well known and MS-DOS; Win16; OS/2 - old time not touched;

Hardware: IBM PC

Programming Languages: Assembler (for Intel 80386); Borland C/C++; Borland Pascal; Object Pascal; Borland C++Builder; Delphi; Perl; Java; Visual C++; Visual J++; UML; XML/XSL; C#; VB.NET; T-SQL; PL/SQL; and etc.

Development Environments: MS Visual Studio 2001-2008; MS Visual C++; Borland Delphi; Borland C++Builder; C/C++ any; Rational Rose; GDPro; Together and etc.

Libraries: STL, ATL, WTL, MFC, NuMega Driver Works, VCL; .NET 1.0, 1.1, 2.0, 3.5; and etc.

Technologies: Client/Server; COM; DirectX; DirectX Media; BDE; HTML/DHTML; ActiveX; Java Servlets; DCOM; COM+; ADO; CORBA; .NET; Windows Forms; GDI/GDI+; and etc.

Application Skills: Databases - design and maintain, support, programming; GUI Design; System Programming, Security; Business Software Development. Win/Web Services development and etc.

Comments and Discussions