Click here to Skip to main content
15,894,540 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.3K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
#include "stdafx.h"
#include "Resource.h"

#include "ESBServer.h"
#include "VSWorkspaceLoader.h"

#include <Model/Simulators/HierarchyLoaderSimulator.h>
#include <Model/CTags/CTagsHierarchyLoader.h>
#include <Renderer/MFC/Browsers/OutlineBrowserRenderer.h>

using namespace std;
using namespace CTags;

ESBServer::ESBServer()
: mRenderer(this), mMethodBrowser("Method/Function"), mTypeBrowser("Type") 
{  
  getOutlineBrowser().setRenderer(make_smart_ptr(new OutlineBrowserDialog()));
  getOutlineBrowser().setESBServer(this);
  
  smart_ptr<SingleSelectionListener> listener = make_smart_ptr(new DefaultSingleSelectionListener());
  getOutlineBrowser().addSelectionListener(listener);
  getHierarchyBrowser().addSelectionListener(listener);
}

void ESBServer::run() 
{ 
	mRenderer.DoModal(); 
}

void ESBServer::showTypes() 
{
 	smart_ptr<TypeBrowserModel> model(new TypeBrowserModel(getTypeInfoLoader()->load("")));

  getTypeBrowser().setModel(model);
	getTypeBrowser().show();	
}

void ESBServer::showMethods()
{
 	smart_ptr<MethodBrowserModel> model(new MethodBrowserModel(getMethodLoader()->load()));

  getMethodBrowser().setModel(model);
	getMethodBrowser().show();	
}


void ESBServer::showWorkspace()
{
  smart_ptr<ScopedNameBrowserModel> model(new WorkspaceBrowserModel(*getWorkspace()));

  getWorkspaceBrowser().setModel(model);
  getWorkspaceBrowser().show();
}

void ESBServer::showFileOutline(const std::string &file, bool enforceModelReload)
{
  if(!file.empty()) {
    string x = file_path_is::pathof(file) + file_name_is::nameof(file);
    string y = file_path_is::pathof(getOutlineBrowser().getModelName()) + file_name_is::nameof(getOutlineBrowser().getModelName());
    
    bool reload = enforceModelReload || x != y;

    if(reload) {
      getOutlineBrowser().setModel(getFileOutlineLoader()->load(file), file);
      getOutlineBrowser().show();
    }  
  }
}

void ESBServer::showHierarchy(const Inheritable &type)
{
  TagCloner cloner;
  const_cast<Inheritable&>(type).acceptVisitor(&cloner);

  smart_ptr<Inheritable> clone = Dynamic_cast<Inheritable>(cloner.getClone());
  clone->setHierarchyLoader(make_smart_ptr(new CTags::HierarchyLoader(getWorkspace())));
  
  getHierarchyBrowser().setModel(clone);
  getHierarchyBrowser().show();
}

void ESBServer::reparseFile(const std::string &file)
{
  try {
    DatabaseManager::instance().getDatabase(getWorkspace())->refreshTagsReferencingFile(file);
    showFileOutline(file, true);

  } catch(std::exception &e) {
    AfxMessageBox(e.what());
  }
}

void ESBServer::openWorkspace(const Workspace& w)
{
  try {
    VisualStudioWorkspaceLoader workspaceLoader(w.getName());
    setWorkspace(workspaceLoader.load(w.getPackages()));

  } catch(std::exception &e) {
    AfxMessageBox(e.what());
  }
}

void ESBServer::reparseWorkspace()
{
  openWorkspace(*getWorkspace());
}

void ESBServer::showBrowser(const std::string &browser)
{
  if(browser == "outline") {
    getOutlineBrowser().show();
    getOutlineBrowser().moveToForeground();

  } else if(browser == "hierarchy") {
    if(getHierarchyBrowser().getSelection() == NULL) {
      showHierarchy(Class("dummy", ePublic, TagLocation()));
      //getHierarchyBrowser().moveToForeground();
    } else {
      getHierarchyBrowser().getRenderer().moveToForeground();
    }

  } else if(browser == "types") {
    showTypes();
    getTypeBrowser().moveToForeground();

  } else if(browser == "methods") {
    showMethods();
    getMethodBrowser().moveToForeground();

  } else if(browser == "workspace") {
    showWorkspace();
    getWorkspaceBrowser().moveToForeground();

  } else {
    AfxMessageBox(("ESBServer::showBrowser():unknown browser type " + browser).c_str());
  }
}

#include "Model/Simulators/TypeInfoLoaderSimulator.h"
smart_ptr<::TypeInfoLoader> ESBServer::getTypeInfoLoader()
{
  //return smart_ptr<TypeInfoLoaderSimulator>(new TypeInfoLoaderSimulator());
  return smart_ptr<::TypeInfoLoader>(new CTags::TypeInfoLoader(getWorkspace())); 
}

smart_ptr<::MethodLoader> ESBServer::getMethodLoader()
{
  return smart_ptr<::MethodLoader>(new CTags::MethodLoader(getWorkspace()));
}

smart_ptr<::FileOutlineLoader> ESBServer::getFileOutlineLoader()
{
  //return smart_ptr<FileOutlineLoaderSimulator>(new FileOutlineLoaderSimulator());
  return smart_ptr<::FileOutlineLoader>(new CTags::FileOutlineLoader(getWorkspace()));
}

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