Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

VS File Finder

, 8 May 2005
A Visual Studio add-in to help navigate around large projects.
vsfilefindersetup.zip
VSFileFinderSetup.msi
vsfilefindersource.zip
VSFileFinder
docs
back.gif
finder.gif
menu.gif
modified
back.gif
finder.gif
home.gif
menu.gif
monster.gif
next.gif
noback.gif
nonext.gif
solutionexplorer.gif
monster.gif
next.gif
noback.gif
nonext.gif
orig
back.png
finder.png
home.png
menu.png
monster.gif
next.png
noback.png
solutionexplorer.gif
solutionexplorer.gif
VSFileFinder
AddIn.def
AddIn.rgs
VSFileFinderCtrl
icon1.ico
Options.ico
VSFileFinderCtrl.def
VSFileFinderCtrl.rgs
VSFileFinderCtrlCtrl.bmp
VSFileFinderCtrlps.def
VSFileFinderCtrlps.mk
VSFileFinderSetup
Binary
bannrbmp.bmp
completi.ico
custicon.ico
dlgbmp.bmp
exclamic.ico
info.ico
insticon.ico
New.ico
removico.ico
repairic.ico
Up.ico
Product.wxs
Text.wxs
UI.wxs
#include "StdAfx.h"
#include "Options.h"

static const TCHAR* szRootKey				= _T("Software\\VS File Finder");
static const TCHAR* szExcludedFilesKey		= _T("Excluded Files");
static const TCHAR* szHighlightedFilesKey	= _T("Highlighted Files");
static const TCHAR* szColumnWidthsKey		= _T("Column Widths");

static const TCHAR* szColumnNameValue		= _T("Name");
static const TCHAR* szColumnProjectValue	= _T("Project");
static const TCHAR* szColumnFileNameValue	= _T("File Name");

Options::Options()
	: m_ColumnWidthName(150)
	, m_ColumnWidthProject(175)
	, m_ColumnWidthFileName(175)
{
}

void Options::Load()
{
	m_ExcludedFileList.clear();
	m_HighlightedFileList.clear();

	CRegKey keyRoot;
	if (keyRoot.Open(HKEY_CURRENT_USER, szRootKey) != ERROR_SUCCESS)
		if (keyRoot.Open(HKEY_LOCAL_MACHINE, szRootKey) != ERROR_SUCCESS)
			return;

	CRegKey keyExcludedFiles;
	if (keyExcludedFiles.Open(keyRoot.m_hKey, szExcludedFilesKey) == ERROR_SUCCESS)
	{
		DWORD dwIndex = 0;
		EnumResult result;
		do
		{
			CString strName, strValue;
			result = RegEnumValueString(keyExcludedFiles.m_hKey, dwIndex++, &strName, &strValue);

			if (result == EnumGotString)
			{
				ExcludedFile f;
				f.Description = strName;
				f.Filter = strValue;
				m_ExcludedFileList.push_back(f);
			}
		} while (result != EnumNoMoreItems);
	}
	std::sort(m_ExcludedFileList.begin(), m_ExcludedFileList.end(), ExcludedFileCompare);

	CRegKey keyHighlightedFiles;
	if (keyHighlightedFiles.Open(keyRoot.m_hKey, szHighlightedFilesKey) == ERROR_SUCCESS)
	{
		DWORD dwIndex = 0;
		EnumResult result;
		do
		{
			CString strName, strValue;
			result = RegEnumValueString(keyHighlightedFiles.m_hKey, dwIndex++, &strName, &strValue);

			if (result == EnumGotString)
			{
				HighlightedFile f;
				f.Description = strName;
				UnpackHighlightString(strValue, &f.Filter, &f.Colour);
				m_HighlightedFileList.push_back(f);
			}
		} while (result != EnumNoMoreItems);
	}
	std::sort(m_HighlightedFileList.begin(), m_HighlightedFileList.end(), HighlightedFileCompare);

	CRegKey keyColumnWidths;
	if (keyColumnWidths.Open(keyRoot.m_hKey, szColumnWidthsKey) == ERROR_SUCCESS)
	{
		DWORD dw;
		if (keyColumnWidths.QueryDWORDValue(szColumnNameValue, dw) == ERROR_SUCCESS)
			m_ColumnWidthName = dw;
		if (keyColumnWidths.QueryDWORDValue(szColumnProjectValue, dw) == ERROR_SUCCESS)
			m_ColumnWidthProject = dw;
		if (keyColumnWidths.QueryDWORDValue(szColumnFileNameValue, dw) == ERROR_SUCCESS)
			m_ColumnWidthFileName = dw;
	}
}

void Options::Save()
{
	CRegKey keyRoot;
	if (keyRoot.Create(HKEY_CURRENT_USER, szRootKey) != ERROR_SUCCESS)
		return;

	keyRoot.RecurseDeleteKey(szExcludedFilesKey);

	CRegKey keyExcludedFiles;
	if (keyExcludedFiles.Create(keyRoot.m_hKey, szExcludedFilesKey) == ERROR_SUCCESS)
	{
		for (ExcludedFileList::const_iterator i = m_ExcludedFileList.begin(); i != m_ExcludedFileList.end(); ++i)
		{
			keyExcludedFiles.SetStringValue((*i).Description, (*i).Filter);
		}
	}

	keyRoot.RecurseDeleteKey(szHighlightedFilesKey);

	CRegKey keyHighlightedFiles;
	if (keyHighlightedFiles.Create(keyRoot.m_hKey, szHighlightedFilesKey) == ERROR_SUCCESS)
	{
		for (HighlightedFileList::const_iterator i = m_HighlightedFileList.begin(); i != m_HighlightedFileList.end(); ++i)
		{
			CString s = PackHighlightString((*i).Filter, (*i).Colour);
			keyHighlightedFiles.SetStringValue((*i).Description, s);
		}
	}

	CRegKey keyColumnWidths;
	if (keyColumnWidths.Create(keyRoot.m_hKey, szColumnWidthsKey) == ERROR_SUCCESS)
	{
		keyColumnWidths.SetDWORDValue(szColumnNameValue, m_ColumnWidthName);
		keyColumnWidths.SetDWORDValue(szColumnProjectValue, m_ColumnWidthProject);
		keyColumnWidths.SetDWORDValue(szColumnFileNameValue, m_ColumnWidthFileName);
	}
}

int Options::GetExcludedFileCount() const
{
	return int(m_ExcludedFileList.size());
}

const Options::ExcludedFile& Options::GetExcludedFile(int i) const
{
	return m_ExcludedFileList[i];
}

void Options::AddExcludedFile(const ExcludedFile& file)
{
	m_ExcludedFileList.push_back(file);
	std::sort(m_ExcludedFileList.begin(), m_ExcludedFileList.end(), ExcludedFileCompare);
}

void Options::RemoveExcludedFile(int nIndex)
{
	m_ExcludedFileList.erase(m_ExcludedFileList.begin() + nIndex);
}

bool Options::ExcludedFileCompare(const ExcludedFile& a, const ExcludedFile& b)
{
	int n = a.Description.Compare(b.Description);
	if (n != 0)
		return n < 0;
	else
		return a.Filter.Compare(b.Filter) < 0;
}

int Options::GetHighlightedFileCount() const
{
	return int(m_HighlightedFileList.size());
}

const Options::HighlightedFile& Options::GetHighlightedFile(int i) const
{
	return m_HighlightedFileList[i];
}

void Options::AddHighlightedFile(const HighlightedFile& file)
{
	m_HighlightedFileList.push_back(file);
	std::sort(m_HighlightedFileList.begin(), m_HighlightedFileList.end(), HighlightedFileCompare);
}

void Options::RemoveHighlightedFile(int nIndex)
{
	m_HighlightedFileList.erase(m_HighlightedFileList.begin() + nIndex);
}

bool Options::HighlightedFileCompare(const HighlightedFile& a, const HighlightedFile& b)
{
	int n;

	n = a.Description.Compare(b.Description);
	if (n != 0)
		return n < 0;

	n = a.Filter.Compare(b.Filter) < 0;
	if (n != 0)
		return n < 0;

	return a.Colour < b.Colour;
}

CString Options::PackHighlightString(const CString& strFilter, COLORREF colour) const
{
	CString s;
	s.Format(_T("#%02x%02x%02x:%s"), GetRValue(colour), GetGValue(colour), GetBValue(colour), strFilter);
	return s;
}

void Options::UnpackHighlightString(CString s, CString* pFilter, COLORREF* pColour) const
{
	*pFilter = _T("");
	*pColour = 0;

	if (s.GetLength() < 8 || s.GetAt(0) != _T('#') || s.GetAt(7) != _T(':'))
		return;

	*pFilter = s.Mid(8);

	int r = 0, g = 0, b = 0;
	_stscanf(s.Mid(1, 6), _T("%02x%02x%02x"), &r, &g, &b);
	*pColour = RGB(r, g, b);
}

Options::EnumResult Options::RegEnumValueString(HKEY hKey, DWORD dwIndex, CString* pName, CString* pValue)
{
	*pName = _T("");
	*pValue = _T("");

	const int nBufferSize = 1024;
	TCHAR* pszName = pName->GetBuffer(nBufferSize);
	TCHAR* pszValue = pValue->GetBuffer(nBufferSize);

	DWORD dwNameChars = nBufferSize;
	DWORD dwValueChars = nBufferSize;

	DWORD dwType = 0;

	LONG nResult = RegEnumValue(
		hKey, dwIndex, pszName, &dwNameChars, 0, &dwType,
		reinterpret_cast<BYTE*>(pszValue), &dwValueChars
	);
	pszName[nBufferSize - 1] = _T('\0');
	pszValue[nBufferSize - 1] = _T('\0');

	pName->ReleaseBuffer();
	pValue->ReleaseBuffer();

	switch (nResult)
	{
	case ERROR_SUCCESS:
		if (dwType == REG_SZ)
			return EnumGotString;
		else
			return EnumWrongType;
	case ERROR_NO_MORE_ITEMS:
		return EnumNoMoreItems;
	default:
		return EnumOtherError;
	}
}

void Options::GetColumnWidths(int* pName, int* pProject, int* pFileName) const
{
	*pName = m_ColumnWidthName;
	*pProject = m_ColumnWidthProject;
	*pFileName = m_ColumnWidthFileName;
}

void Options::SetColumnWidths(int Name, int Project, int FileName)
{
	m_ColumnWidthName = Name;
	m_ColumnWidthProject = Project;
	m_ColumnWidthFileName = FileName;
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

J W Payne
Web Developer
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 May 2005
Article Copyright 2004 by J W Payne
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid