Staging
v0.5.1
rsync://a.cvs.sourceforge.net/cvsroot/titano/titano
Raw File
Tip revision: caf6b08e7ee50ea57b401dbf73c67715c80ad881 authored by amid on 31 January 2001, 05:11:03 UTC
*** empty log message ***
Tip revision: caf6b08
projects.h
/* projects.h - Project classes -*- C++ -*-
 * Copyright (C) 2000 Malenko Dmitry <maldim@mail.ru>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.  
 */
 
#ifndef _PROJECTS_H
#define _PROJECTS_H 

#include <string>
#include <hash_map>
#include <list>

#include "dialogs.h"
#include "files.h"
#include "tree.h"

//xpm for internal use
#include "xpm/fold_cls.xpm"
#include "xpm/file.xpm"
#include "xpm/file_h.xpm"
#include "xpm/file_c.xpm"

struct str_hasher
{
	size_t operator()(const string &str) const
	{
		hash<char *> hasher;
		return hasher(str.c_str());
	};
};

typedef hash_map<string,File *,str_hasher> files_map;
typedef list<string> files_list;

typedef enum {UNKNOWN,C_HEADER,C_SOURCE} FileType;

class Project
{
protected:
	string filename;
	string name,dir,version;

	files_map file_map;
	files_list file_list;
	File *cur_file;

	GtkNotebook *notebook;

	const Application &parent;

	Tree tree;

	bool modified;

	FileType get_file_type(const string &name);
	
	virtual void load(void);

	virtual void add_am_file(const string &file);
	virtual void remove_am_file(const string &file);

	virtual void create_item(const string &name);
	virtual void remove_item(const string &name);

	string adjust_file_name(const string &fullname);

	virtual string get_file_tree_item(const string &name) = 0;
	virtual char **get_file_tree_icon(const string &name)
	{
		return NULL;
	};
public:
	Project(const string &file,const Application &_app) :
		parent(_app),
		tree(GTK_TREE(_app.get_widget("proj_tree")))
	{
		filename = file;
		cur_file = NULL;
		modified = false;

		notebook = GTK_NOTEBOOK(gtk_notebook_new());
		gtk_notebook_set_scrollable(notebook,true);
		gtk_paned_add2(GTK_PANED(parent.get_widget("mainhpaned")),GTK_WIDGET(notebook));
		gtk_signal_connect(GTK_OBJECT(notebook),"switch_page",GTK_SIGNAL_FUNC(on_file_switch),this);
		gtk_widget_show(GTK_WIDGET(notebook));
	};
	virtual ~Project();

	string get_name(void) const
	{
		return name;
	};
	string get_dir(void) const
	{
		return dir;
	};
	string get_filename(void) const
	{
		return dir + "/" + name + ".titano";
	};
	string get_version(void) const
	{
		return version;
	};
	
	virtual bool get_modified(void) const
	{
		return modified;
	};

	bool has_file(void) const
	{
		return cur_file;
	};

	File &get_file(void)
	{
		return *cur_file;
	};

	const files_list &get_files(void)
	{
		return file_list;
	};
	
	virtual void save(void);
	virtual void save_as(const string &newname);

	virtual void new_file(void) = 0;
	virtual void add_file(const string &fullname);
	virtual void remove_file(const string &name);
	virtual void open_file(const string &name);
	virtual void close_file(void);
	virtual void close_file(const string &name);
	virtual void save_file_as(const string &name);
	virtual void save_all_files(void);

	virtual File *operator[](const string &name);

	virtual bool file_in_project(const string &name);
	virtual bool file_is_opened(const string &name);

	//Shell routines
	virtual void autogen(void);
	virtual void configure(void);
	virtual void make(void);
	virtual void make_dist(void);
	
	//callbacks
	static void on_file_switch(GtkNotebook *nb,gpointer data,gint n,Project *project);
	static void proj_item_selected(GtkItem *item,Project *project);
};

class CppProject : public Project
{
protected:
	virtual string get_file_tree_item(const string &name);
	virtual char **get_file_tree_icon(const string &name);
public:
	CppProject(const string &file,const Application &_app) :
		Project(file,_app)
	{
		tree.add_item("/Headers",fold_cls_xpm);
		tree.add_item("/Sources",fold_cls_xpm);
		tree.add_item("/Others",fold_cls_xpm);
		
		load();
		
		parent.set_title(" - [C/C++] " + name);
	};
	virtual ~CppProject();

	virtual void new_file(void);
};

#endif
back to top