Click here to Skip to main content
15,881,882 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 183.6K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
#ifndef OutlineBrowser_H
#define OutlineBrowser_H

#include <Utilities/smart_ptr.h>
#include <Model/FileOutlineLoader.h>
#include <Controller/Browsers/SelectionListener.h>

#include <Renderer/OutlineRenderer.h>

#include "Editor.h"

class ESBServer;
class MouseEvent;


struct OutlineFilter : public CppTagVisitorAdaptor
{
	OutlineFilter()
	: sortByName(false), publicMembersOnly(false), noStaticMembers(false), noFields(false){}
	
	bool sortByName;
	bool publicMembersOnly;
	bool noStaticMembers;
	bool noFields;

  std::list<smart_ptr<CppTag> > apply(const std::list<smart_ptr<CppTag> > &);

  bool isFiltered(const CppTag&);
  bool isFiltered(const Field &);
  bool isFiltered(const Method&);

private:
  bool mIsFiltered;
  bool mChildrenVisible;
  bool isFiltered() const { return mIsFiltered; }
  std::list<smart_ptr<CppTag> > selectTags(const std::list<smart_ptr<CppTag> >&, size_t type) const;

  virtual void visitTag(CppTag*);
  virtual void visitNamespace(Namespace*);
  virtual void visitField(Field*);
  virtual void visitMethod(Method*);
};


class OutlineBrowser
{
protected:
	smart_ptr<OutlineRenderer> mRenderer;
	FileOutlineLoader::TagList mModel;
	OutlineFilter mFilter;
  std::string mOutlineName;
  CppTag *mSelection;
  ESBServer *mESBServer;

  std::list<smart_ptr<SelectionListener> > mSelectionListeners;

public:
	OutlineBrowser();
	~OutlineBrowser();
  
  void addSelectionListener(const smart_ptr<SelectionListener>& listener)
  { mSelectionListeners.push_back(listener); }

  void removeSelectionListener(const smart_ptr<SelectionListener>& listener)
  { mSelectionListeners.remove_if(std::bind2nd(std::equal_to<smart_ptr<SelectionListener> >(), listener)); }

  const std::string& getModelName() { return mOutlineName; }
  
	FileOutlineLoader::TagList& getModel() { return mModel; }
  void setModel(const FileOutlineLoader::TagList &model, const std::string &fn = "");
  
	OutlineRenderer& getRenderer() { return *mRenderer; }
  void setRenderer(const smart_ptr<OutlineRenderer> &r) { mRenderer = r; mRenderer->registerListener(this); };

  ESBServer* getESBServer() { if(!mESBServer) {throw NullPointerException("getESBServer"); }; return mESBServer; }
  void setESBServer(ESBServer *srv) { mESBServer = srv; }

  void show();
  void moveToForeground();

  void gotoHeader();
  void gotoSource();
  void gotoHierarchy();
  void inspect();

	void tagSelectionChanged(CppTag*,  const MouseEvent &);
  void tagSelectionChanged(const std::list<CppTag*>&);
	
  void sortOrderChanged(bool);
	void publicMemberFilterChanged(bool);
	void staticMemberFilterChanged(bool);
	void fieldFilterChanged(bool);

  std::list<smart_ptr<CppTag> > getChildrenOf(CppTag*);


protected:
	OutlineFilter& getFilter() { return mFilter; }
  //void gotoFile(const TagLocation&);

  void setSelection(CppTag *s);
  CppTag* getSelection() { return mSelection; }

  std::string makeCaption(const std::string &);

};


#endif

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