summaryrefslogtreecommitdiffstats
path: root/src/kile/kileprojectview.h
blob: 6871422aed8846c6039f4cd2ea27e3750212a4d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/***************************************************************************
    begin                : Tue Aug 12 2003
    copyright            : (C) 2003 by Jeroen Wijnhout
                           (C) 2006 by Michel Ludwig
    email                : Jeroen.Wijnhout@kdemail.net
                           michel.ludwig@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef KILEPROJECTVIEW_H
#define KILEPROJECTVIEW_H

#include <ktrader.h>
#include <tdelistview.h>

#include "kileproject.h"

class KURL;
class TDEPopupMenu;
class TDEToggleAction;
namespace KileDocument {
    class Info;
}
class KileInfo;

namespace KileType {enum ProjectView { Project=0, ProjectItem, ProjectExtra, File, Folder};}

class KileProjectViewItem : public TQObject, public TDEListViewItem
{
	Q_OBJECT
  

public:
	KileProjectViewItem (TQListView *parent, KileProjectItem *item, bool ar = false) : TDEListViewItem(parent, item->url().fileName()), m_folder(-1), m_projectItem(item) { setArchiveState(ar);}
	KileProjectViewItem (TQListView *parent, TQListViewItem *after, KileProjectItem *item, bool ar = false) : TDEListViewItem(parent, after, item->url().fileName()), m_folder(-1), m_projectItem(item) { setArchiveState(ar);}
	KileProjectViewItem (TQListViewItem *parent, KileProjectItem *item, bool ar = false) : TDEListViewItem(parent, item->url().fileName()), m_folder(-1), m_projectItem(item) { setArchiveState(ar);}

	//use this to create folders
	KileProjectViewItem (TQListViewItem *parent, const TQString & name) : TDEListViewItem(parent, name), m_folder(-1), m_projectItem(0L) {}

	//use this to create non-project files
	KileProjectViewItem (TQListView *parent, const TQString & name) : TDEListViewItem(parent, name), m_folder(-1), m_projectItem(0L) {}
	
	KileProjectViewItem (TQListView *parent, const KileProject *project) : TDEListViewItem(parent, project->name()), m_folder(-1), m_projectItem(0L) {}
	

	~KileProjectViewItem() {KILE_DEBUG() << "DELETING PROJVIEWITEM " << m_url.fileName() << endl;}

	KileProjectItem* projectItem() { return m_projectItem; }

	KileProjectViewItem* parent() { return dynamic_cast<KileProjectViewItem*>(TDEListViewItem::parent()); }
	KileProjectViewItem* firstChild() { return dynamic_cast<KileProjectViewItem*>(TDEListViewItem::firstChild()); }
	KileProjectViewItem* nextSibling() { return dynamic_cast<KileProjectViewItem*>(TDEListViewItem::nextSibling()); }

	void setInfo(KileDocument::Info *docinfo) { m_docinfo = docinfo;}
	KileDocument::Info * getInfo() { return m_docinfo;}

	void setType(KileType::ProjectView type) {m_type = type;}
	KileType::ProjectView type() const { return m_type;}

	int compare(TQListViewItem * i, int col, bool ascending) const;

	void setURL(const KURL & url) { m_url=url;}
	const KURL& url() { return m_url;}

	void setArchiveState(bool ar) { setText(1,ar ? "*" : "");}

	void setFolder(int folder) { m_folder = folder; }
	int folder() { return m_folder; }

public slots:
	/**
	 * @warning Does nothing if "url" is empty !
	 **/ 
	void urlChanged(const KURL & url);
	void nameChanged(const TQString & name);
	void isrootChanged(bool isroot);

private slots:
	/**
	 * Dummy slot, simply forwarding to urlChanged(const KURL& url).
	 **/
	void slotURLChanged(KileDocument::Info*, const KURL & url);


private:
	KURL	m_url;
	KileType::ProjectView	m_type;
	KileDocument::Info	*m_docinfo;
	int   m_folder;
	KileProjectItem *m_projectItem;
};

class KileProjectView : public TDEListView
{
	Q_OBJECT
  

public:
	KileProjectView(TQWidget *parent, KileInfo *ki);

signals:
	void fileSelected(const KileProjectItem *);
	void fileSelected(const KURL &);
	void saveURL(const KURL&);
	void closeURL(const KURL&);
	void projectOptions(const KURL &);
	void projectArchive(const KURL &);
	void addFiles(const KURL &);
	void openAllFiles(const KURL &);
	void toggleArchive(KileProjectItem *);
	void closeProject(const KURL &);
	void addToProject(const KURL &);
	void removeFromProject(const KileProjectItem *);
	void buildProjectTree(const KURL &);

public slots:
	void slotClicked(TQListViewItem * item = 0);

	void slotFile(int id);
	void slotProjectItem(int id);
	void slotProject(int id);

	void slotRun(int id);

	void refreshProjectTree(const KileProject *);
	void add(const KURL & url);
	void add(const KileProject *project);
	void remove(const KURL & url);
	void remove(const KileProject *project);
	void removeItem(const KileProjectItem *, bool);
	KileProjectViewItem* add(KileProjectItem *item, KileProjectViewItem * projvi  = 0);

public:
	void addTree(KileProjectItem *item, KileProjectViewItem * projvi );

	KileProjectViewItem* projectViewItemFor(const KURL &);
	KileProjectViewItem* itemFor(const KURL &);
	KileProjectViewItem* parentFor(const KileProjectItem *projitem, KileProjectViewItem *projvi);

protected:
	virtual bool acceptDrag(TQDropEvent *e) const;

private slots:
	void popup(TDEListView *, TQListViewItem *, const TQPoint &);

private:
	void makeTheConnection(KileProjectViewItem *);
	KileProjectViewItem* folder(const KileProjectItem *item, KileProjectViewItem *);

private:
	KileInfo					*m_ki;
	TDEPopupMenu		*m_popup;
	uint						m_nProjects;
	TDEToggleAction		*m_toggle;

	TDETrader::OfferList m_offerList;
};

#endif