#ifndef PROJECTFILESYSTEMWIDGET_H
#define PROJECTFILESYSTEMWIDGET_H

#include "ui_projectfilesystemwidget.h"
#include "filterdialog.h"
#include <extensionsystem/iplugin.h>
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
#include <QElapsedTimer>
#include <QMenu>

extern QFileInfo projectfs_menu_target;

class ProjectsModel;

class ProjectFilesystemWidget: public QWidget, private Ui::ProjectFilesystemWidget
{
	Q_OBJECT
public:
	explicit ProjectFilesystemWidget(QWidget * parent = 0);

	FilterDialog::Filter currentFilters() const {return cur_filter;}
	QString currentSearch() const {return lineFilter->text();}

	void setCurrentFilter(const FilterDialog::Filter & v);
	void setCurrentSearch(QString v) {lineFilter->setText(v);}

protected:
	void changeEvent(QEvent * e);
	void createTree(QTreeWidgetItem * ti, const QString & dir);
	bool filterTree(QTreeWidgetItem * ti, const QString & filter);
	void filter();
	void rememberExpanded(QTreeWidgetItem * ti);
	void restoreExpanded(QTreeWidgetItem * ti);
	void setExtVariable();
	void checkProcEvents();

	bool in_proc, need_rebuild;
	ExtensionSystem::IPlugin * proj_plug;
	QMenu popup_menu;
	QMap<QString, QTreeWidgetItem*> item_map;
	QSet<QString> last_expanded;
	FilterDialog filter_dialog;
	FilterDialog::Filter cur_filter;
	QElapsedTimer tm;

public slots:
	void projectsChanged();
	void filterClicked();

private slots:
	void fileChanged();
	void startupProjectChanged();

	void on_tree_itemDoubleClicked(QTreeWidgetItem * item, int );
	void on_lineFilter_textChanged(const QString &);
	void on_tree_itemClicked(QTreeWidgetItem *item, int column);
	void on_tree_customContextMenuRequested(const QPoint & pos);
	void on_actionOpen_here_triggered();
	void on_actionOpen_external_triggered();
	void on_actionShow_external_triggered();
	void on_actionOpen_terminal_triggered();
	void on_actionCopy_name_triggered();
	void on_actionCopy_path_triggered();

};

#endif // PROJECTFILESYSTEMWIDGET_H
