Click here to Skip to main content
15,895,812 members
Articles / Desktop Programming / MFC

Include File Hierarchy Viewer

Rate me:
Please Sign up or sign in to vote.
4.84/5 (108 votes)
29 Jul 2003CPOL8 min read 385.8K   4.5K   151  
A tool to view the include file hierarchy of your source code.
//====================================================================
// Although great care has gone into developing this software,
// it is provided without any guarantee of reliability, accuracy
// of information, or correctness of operation.  I am not responsible
// for any damages that may occur as a result of using this software.
// Use this software entirely at your own risk.
// Copyright 2003, Chris Richardson
//
// Description: Settings storage.
//
//====================================================================

#include "stdafx.h"
#include "IncFinder.h"
#include "Settings.h"

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

CSettings CSettings::s_oSettings;

// Registry entries.
static const TCHAR * s_pszSettings              = _T("Settings");
static const TCHAR * s_pszDirectoryX            = _T("Directory%d");
static const TCHAR * s_pszDirectories           = _T("DirectoryCount");
static const TCHAR * s_pszMaskX                 = _T("Mask%d");
static const TCHAR * s_pszMasks                 = _T("MaskCount");
static const TCHAR * s_pszIncludeDirs           = _T("IncludeDirs");
static const TCHAR * s_pszRecurse               = _T("Recurse");
static const TCHAR * s_pszPreprocess            = _T("Preprocess");
static const TCHAR * s_pszWindowX               = _T("WindowX");
static const TCHAR * s_pszWindowY               = _T("WindowY");
static const TCHAR * s_pszWindowWidth           = _T("WindowWidth");
static const TCHAR * s_pszWindowHeight          = _T("WindowHeight");
static const TCHAR * s_pszWindowMax             = _T("WindowMaximized");
static const TCHAR * s_pszCustomViewerCmd       = _T("CustomViewerCmd");
static const TCHAR * s_pszViewWithAssocViewer   = _T("ViewWithAssocViewer");
static const TCHAR * s_pszWorkspaceX            = _T("Workspace%d");
static const TCHAR * s_pszWorkspaces            = _T("WorkspaceCount");
static const TCHAR * s_pszWorkspaceMaskX        = _T("WorkspaceMask%d");
static const TCHAR * s_pszWorkspaceMasks        = _T("WorkspaceMaskCount");
static const TCHAR * s_pszActiveSearchTab       = _T("ActiveSearchTab");

//////////////////////////////////////////////////////////////////////
// CSettings Implementation.
//////////////////////////////////////////////////////////////////////

CSettings::CSettings() :
   c_bRecurse( FALSE ),
   c_bMaximized( FALSE ),
   c_bPreprocess( TRUE ),
   c_bViewWithAssociatedViewer( TRUE ),
   c_iActiveSearchTab( 0 )
{
}
//
// ------------------------------------------------------------------
//
CSettings::~CSettings()
{
}
//
// ------------------------------------------------------------------
//
void CSettings::ReadArray( CStdStringArray & p_roArray,
                           const TCHAR * p_pszNameStr,
                           const TCHAR * p_pszCountStr )
{
   CWinApp * a_poApp = AfxGetApp();
   
   int a_iCount = a_poApp->GetProfileInt( s_pszSettings, p_pszCountStr, 0 );
   for( int i = 0; i<a_iCount; ++i )
   {
      CString a_sTemp;
      a_sTemp.Format( p_pszNameStr, i );
      p_roArray.push_back( (LPCTSTR)a_poApp->GetProfileString( s_pszSettings, a_sTemp, NULL ) );
   }
}
//
// ------------------------------------------------------------------
//
void CSettings::ReadRegistry()
{
   CWinApp * a_poApp = AfxGetApp();
   
   ReadArray( s_oSettings.c_oDirectories, s_pszDirectoryX, s_pszDirectories );
   ReadArray( s_oSettings.c_oFileMasks, s_pszMaskX, s_pszMasks );
   ReadArray( s_oSettings.c_oWorkspaces, s_pszWorkspaceX, s_pszWorkspaces );
   ReadArray( s_oSettings.c_oWorkspaceFileMasks, s_pszWorkspaceMaskX, s_pszWorkspaceMasks );

   CString a_sTemp                = a_poApp->GetProfileString( s_pszSettings, s_pszIncludeDirs, NULL );
   s_oSettings.c_sIncludeDirs     = (LPCTSTR)a_sTemp;
   
   s_oSettings.c_bRecurse         = a_poApp->GetProfileInt( s_pszSettings, s_pszRecurse, FALSE );
   s_oSettings.c_bPreprocess      = a_poApp->GetProfileInt( s_pszSettings, s_pszPreprocess, TRUE );

   s_oSettings.c_oMainRect.left   = a_poApp->GetProfileInt( s_pszSettings, s_pszWindowX, -1 );
   s_oSettings.c_oMainRect.top    = a_poApp->GetProfileInt( s_pszSettings, s_pszWindowY, -1 );
   int a_iWidth                   = a_poApp->GetProfileInt( s_pszSettings, s_pszWindowWidth, 0 );
   int a_iHeight                  = a_poApp->GetProfileInt( s_pszSettings, s_pszWindowHeight, 0 );
   s_oSettings.c_oMainRect.right  = s_oSettings.c_oMainRect.left + a_iWidth;
   s_oSettings.c_oMainRect.bottom = s_oSettings.c_oMainRect.top + a_iHeight;
   
   if( s_oSettings.c_oMainRect.left != -1 && 
       s_oSettings.c_oMainRect.top != -1 &&
       s_oSettings.c_oMainRect.right != -1 && 
       s_oSettings.c_oMainRect.bottom != -1 )
   {
      // Range check the window position and dimensions.
      int a_iScreenX = GetSystemMetrics( SM_CXSCREEN );
      int a_iScreenY = GetSystemMetrics( SM_CYSCREEN );
      if( s_oSettings.c_oMainRect.left < 0 )
         s_oSettings.c_oMainRect.left = 10;
      else
      if( s_oSettings.c_oMainRect.left > a_iScreenX )
         s_oSettings.c_oMainRect.left = -1; // Will make it use the default rect.
      if( s_oSettings.c_oMainRect.top < 0 )
         s_oSettings.c_oMainRect.top = 10;
      else
      if( s_oSettings.c_oMainRect.top > a_iScreenX )
         s_oSettings.c_oMainRect.top = -1; // Will make it use the default rect.
   
      if( s_oSettings.c_oMainRect.Width() > a_iScreenX )
         s_oSettings.c_oMainRect.left = -1; // Will make it use the default rect.
      if( s_oSettings.c_oMainRect.Height() > a_iScreenY )
         s_oSettings.c_oMainRect.top = -1; // Will make it use the default rect.
   }

   s_oSettings.c_bMaximized       = a_poApp->GetProfileInt( s_pszSettings, s_pszWindowMax, FALSE );
   
   s_oSettings.c_iActiveSearchTab = a_poApp->GetProfileInt( s_pszSettings, s_pszActiveSearchTab, 0 );

   s_oSettings.c_sCustomSourceViewerCommand  = a_poApp->GetProfileString( s_pszSettings, s_pszCustomViewerCmd, NULL );
   s_oSettings.c_bViewWithAssociatedViewer   = a_poApp->GetProfileInt( s_pszSettings, s_pszViewWithAssocViewer, TRUE );
}
//
// ------------------------------------------------------------------
//
void CSettings::WriteArray( CStdStringArray & p_roArray,
                            const TCHAR * p_pszNameStr,
                            const TCHAR * p_pszCountStr )
{
   CWinApp * a_poApp = AfxGetApp();

   int a_iCount = p_roArray.size();
   a_poApp->WriteProfileInt( s_pszSettings, p_pszCountStr, a_iCount );
   for( int i = 0; i<a_iCount; ++i )
   {
      CString a_sTemp;
      a_sTemp.Format( p_pszNameStr, i );
      a_poApp->WriteProfileString( s_pszSettings, a_sTemp, p_roArray[i].c_str() );
   }
}
//
// ------------------------------------------------------------------
//
void CSettings::WriteRegistry()
{
   CWinApp * a_poApp = AfxGetApp();

   WriteArray( s_oSettings.c_oDirectories, s_pszDirectoryX, s_pszDirectories );
   WriteArray( s_oSettings.c_oFileMasks, s_pszMaskX, s_pszMasks );
   WriteArray( s_oSettings.c_oWorkspaces, s_pszWorkspaceX, s_pszWorkspaces );
   WriteArray( s_oSettings.c_oWorkspaceFileMasks, s_pszWorkspaceMaskX, s_pszWorkspaceMasks );

   a_poApp->WriteProfileString( s_pszSettings, s_pszIncludeDirs, s_oSettings.c_sIncludeDirs.c_str() );

   a_poApp->WriteProfileInt( s_pszSettings, s_pszRecurse, s_oSettings.c_bRecurse );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszPreprocess, s_oSettings.c_bPreprocess );

   a_poApp->WriteProfileInt( s_pszSettings, s_pszWindowX, s_oSettings.c_oMainRect.left );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszWindowY, s_oSettings.c_oMainRect.top );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszWindowWidth, s_oSettings.c_oMainRect.Width() );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszWindowHeight, s_oSettings.c_oMainRect.Height() );

   a_poApp->WriteProfileInt( s_pszSettings, s_pszWindowMax, s_oSettings.c_bMaximized );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszActiveSearchTab, s_oSettings.c_iActiveSearchTab );

   a_poApp->WriteProfileString( s_pszSettings, s_pszCustomViewerCmd, s_oSettings.c_sCustomSourceViewerCommand.c_str() );
   a_poApp->WriteProfileInt( s_pszSettings, s_pszViewWithAssocViewer, s_oSettings.c_bViewWithAssociatedViewer );
}
//
// ------------------------------------------------------------------
//

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
Software Developer (Senior)
United States United States
I like to program, I like to sail.

Comments and Discussions