Click here to Skip to main content
15,891,687 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 184.1K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
#include "stdafx.h"
#include "Resource.h"

#include "ScopedNameBrowser.h"
#include "ScopedNameBrowserRenderer.h"


#include "StringTokenizer.h"
#include "RegExpr.h"
#include "stl_ext.h"

using namespace std;

struct NameSorter
{
  bool operator()(smart_ptr<ScopedNameBrowserItem> lhs, smart_ptr<ScopedNameBrowserItem> rhs)
  {  return lhs->getNameLabel() < rhs->getNameLabel(); }
};

struct ScopeSorter
{
  bool operator()(smart_ptr<ScopedNameBrowserItem> lhs, smart_ptr<ScopedNameBrowserItem> rhs)
  {  return lhs->getScopeLabel() < rhs->getScopeLabel(); }
};


ScopedNameBrowser::ScopedNameBrowser()
: mSelection(0)
{
	mRenderer = smart_ptr<RendererType>(new RendererType(this));
}

ScopedNameBrowser::~ScopedNameBrowser()
{
}

bool ScopedNameBrowser::show(bool isModal)
{
	if(isModal) {
    if(getRenderer().DoModal() == S_OK) {
      typeSelected(getSelection());
      return true;
    }
    return false;

	} else {
    if(!getRenderer().m_hWnd) {
		  getRenderer().Create(IDD_SCOPEDNAME_BROWSER,CWnd::GetDesktopWindow());
    }
    getRenderer().renderNames(getModel().getDatastore().begin(), getModel().getDatastore().end());
		getRenderer().ShowWindow(SW_SHOW);
		return true;
	}
}

void ScopedNameBrowser::filterChanged(const std::string &newFilter)
{
  typedef std::set<smart_ptr<ModelItemType>, NameSorter> NameSet;

	NameSet result;

  //copy_if(getModel().begin(), getModel().end(), inserter(result, result.end()), RegExpr(newFilter));
	
	RegExpr regExpr(to_lower(newFilter));
  for(ModelType::DatastoreType::const_iterator type = getModel().getDatastore().begin(); type != getModel().getDatastore().end(); type++) {
    if(regExpr.hasMatch(to_lower((*type)->getNameLabel()))) {
      result.insert(*type);
    }
  }

  getRenderer().renderNames(result.begin(), result.end());
}

void ScopedNameBrowser::typeSelected(ModelItemType *selection)
{
	setSelection(selection);
	//getRenderer().OnOK();
}

void ScopedNameBrowser::typeSelectionChanged(ModelItemType *selection)
{
	setSelection(selection);

  typedef std::multiset<smart_ptr<ModelItemType>, ScopeSorter> ScopeSet;

  ScopeSet scopes;

	//TypeList::iterator t = getModel().find(smart_ptr<CppType>(selection));
	//copy_if(getModel().getDatastore().begin(), getModel().getDatastore().end(), bind());
  for(ModelType::DatastoreType::iterator t = getModel().getDatastore().begin(); t != getModel().getDatastore().end(); t++) {
		if((*t)->getNameLabel() == selection->getNameLabel()) {
			scopes.insert(*t);
		}
	}

	getRenderer().renderScopes(scopes.begin(), scopes.end());
}

void ScopedNameBrowser::qualifierSelectionChanged(ModelItemType *selection)
{
	setSelection(selection);
}


ScopedNameBrowser::RendererType& ScopedNameBrowser::getRenderer() 
{ 
  return *mRenderer; 
}

void ScopedNameBrowser::setRenderer(const smart_ptr<ScopedNameBrowser::RendererType> &r) 
{ 
  mRenderer = r; 
  mRenderer->setController(this); 
}

void ScopedNameBrowser::moveToForeground()
{
  getRenderer().moveToForeground();
}

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


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions