#ifndef SCRIPT_EDIT_H
#define SCRIPT_EDIT_H

#include <qcodeedit.h>
#include <QMetaEnum>
#include "SH_types.h"

class ScriptHighlighter;

class ScriptEdit: public QCodeEdit {
	Q_OBJECT
public:
	explicit ScriptEdit(QWidget * parent = 0);

	QWidget * form_ui;
	QObjectList ac_plugins;
	QStringList variables;

	void updateACObjects();
	void updateACPlugins();
	void setBlockObjects();
	void setCreatableObjects(QList<QMetaObject> col);
	void setVariables(const QStringList & vl);
	void setPlugins(const QMap<QString, SHS::Object> & pol);
	void rehighlight();

	static QString docPath (const QTextDocument * doc);
	static QString docTitle(const QTextDocument * doc);
	static void setDocPath(QTextDocument * doc, const QString & path);

protected:
	virtual ACList autoCompletitionList(const QStringList & scope, const QString & written) const;
	virtual void parse();
	virtual void documentUnset();
	virtual void documentChanged(QTextDocument * d);
	virtual void linkClicked(ACEntry e);
	virtual bool linkValidate(ACEntry e);
	void parseDocument(const QTextDocument * d);
	QList<ACEntry> findFunctions(const QString & content, const QString & docpath);
	QList<ACEntry> findVariables(const QString & content, const QString & docpath);
	QList<ACEntry> findClasses(const QString & content, const QString & docpath);
	QList<ACSection> compFromMeta(QMetaObject mo, QString written) const;
	QList<ACSection> compFromBuiltin(const QList<ACSection> & aclist, QString written) const;

	ScriptHighlighter * highlighter;
	int hid_blocks, hid_widgets, hid_variables, hid_plugins, hid_project, hid_funcs, hid_gvars, hid_classes;
	QObject ac_project;
	QSet<QString> parsed_includes;
	QList<ACEntry> ac_keywords, ac_functions, ac_objects, ac_number_func, ac_number_const;
	QList<ACEntry> ac_namespaces, ac_math_func, ac_math_const, ac_json_func;
	QList<ACEntry> ac_glob_vars, ac_rt_functions, ac_classes;
	QMap<QString, QList<ACSection> > builtin_types;
	QList<QMetaObject> new_mol;
	QMap<QString, SHS::Object> plugins_objects;
	QMap<QString, QList<QMetaEnum> > auto_comp_enums;

signals:
	void requestDocByPath(QString path, QTextDocument ** ret);
	void gotoDoc(QString path, int pos);

};

#endif // SCRIPT_EDIT_H
