mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-15 00:54:38 +00:00
added help on auto completer
This commit is contained in:
parent
33dbf09005
commit
fd33cbd061
@ -323,7 +323,7 @@ void PluginManager::loadXMLPlugin( const QString& fileName )
|
||||
if (pname != "")
|
||||
{
|
||||
QString plugnamespace = pluginNameSpace() + "." + pname;
|
||||
pluginnamespaces << plugnamespace;
|
||||
//pluginnamespaces << plugnamespace;
|
||||
scriptplugcode += pluginNameSpace() + "." + pname + " = { };\n";
|
||||
QStringList filters = pluginfo->filterNames();
|
||||
foreach(QString filter,filters)
|
||||
@ -336,10 +336,13 @@ void PluginManager::loadXMLPlugin( const QString& fileName )
|
||||
filterFunction = gen.funCodeGenerator(filter,*pluginfo);
|
||||
QString jname = pluginfo->filterAttribute(filter,MLXMLElNames::filterScriptFunctName);
|
||||
completename += "." + jname;
|
||||
filterscriptnames << completename;
|
||||
//filterscriptnames << completename;
|
||||
scriptplugcode += completename + " = " + filterFunction + "\n";
|
||||
completename += "(" + gen.parNames(filter,*pluginfo) + ")";
|
||||
filtersign << completename;
|
||||
LibraryElementInfo li;
|
||||
li.completename = completename;
|
||||
li.help = pluginfo->filterHelp(filter);
|
||||
libinfolist << li;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "interfaces.h"
|
||||
#include "xmlfilterinfo.h"
|
||||
#include "scriptinterface.h"
|
||||
#include "scriptsyntax.h"
|
||||
|
||||
class QScriptEngine;
|
||||
/**
|
||||
@ -89,9 +90,9 @@ public:
|
||||
|
||||
static QString pluginNameSpace();
|
||||
//highlight and autocomplete
|
||||
QStringList pluginnamespaces;
|
||||
QStringList filterscriptnames;
|
||||
QStringList filtersign;
|
||||
/*QStringList pluginnamespaces;
|
||||
QStringList filterscriptnames;*/
|
||||
QList<LibraryElementInfo> libinfolist;
|
||||
//Env env;
|
||||
|
||||
//void updateDocumentScriptBindings(MeshDocument& doc);
|
||||
|
||||
@ -372,22 +372,22 @@ SyntaxTreeModel* MLScriptLanguage::functionsLibrary()
|
||||
return libraries;
|
||||
}
|
||||
|
||||
void MLScriptLanguage::addFunctionsLibrary( const QStringList& funsigns )
|
||||
void MLScriptLanguage::addLibrary( const QList<LibraryElementInfo>& funsigns )
|
||||
{
|
||||
if (libraries != NULL)
|
||||
{
|
||||
SyntaxTreeNode* root = libraries->getItem(QModelIndex());
|
||||
foreach(QString st,funsigns)
|
||||
foreach(LibraryElementInfo st,funsigns)
|
||||
addBranch(st,root);
|
||||
}
|
||||
}
|
||||
|
||||
void MLScriptLanguage::addBranch( const QString& funname,SyntaxTreeNode* parent )
|
||||
void MLScriptLanguage::addBranch( const LibraryElementInfo& mi,SyntaxTreeNode* parent )
|
||||
{
|
||||
if (funname.isEmpty() || (parent == NULL))
|
||||
if (mi.completename.isEmpty() || (parent == NULL))
|
||||
return;
|
||||
QString st = funname;
|
||||
QVector<QVariant> dt(3,QVariant(QString()));
|
||||
QString st = mi.completename;
|
||||
QVector<QVariant> dt(5,QVariant(QString()));
|
||||
int indexpoint = st.indexOf(wordsjoiner);
|
||||
if (indexpoint == -1)
|
||||
{
|
||||
@ -396,12 +396,16 @@ void MLScriptLanguage::addBranch( const QString& funname,SyntaxTreeNode* parent
|
||||
{
|
||||
//is a member
|
||||
dt[0] = st;
|
||||
dt[1] = mi.help;
|
||||
dt[4] = QString::number(MLScriptLanguage::CONSTANT);
|
||||
}
|
||||
else
|
||||
{
|
||||
//is a function. I will add the name of the function and the signature for the tooltip
|
||||
dt[0] = st.left(indexpar);
|
||||
dt[1] = st;
|
||||
dt[1] = mi.help;
|
||||
dt[3] = st;
|
||||
dt[4] = QString::number(MLScriptLanguage::FUNCTION);
|
||||
}
|
||||
SyntaxTreeNode* ch = parent->findChild(dt);
|
||||
|
||||
@ -410,8 +414,8 @@ void MLScriptLanguage::addBranch( const QString& funname,SyntaxTreeNode* parent
|
||||
{
|
||||
parent->insertChildren(parent->childCount(),1,parent->columnCount());
|
||||
ch = parent->child(parent->childCount() - 1);
|
||||
ch->setData(0,dt[0]);
|
||||
ch->setData(1,dt[1]);
|
||||
for(int ii = 0;ii < 5;++ii)
|
||||
ch->setData(ii,dt[ii]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -424,16 +428,20 @@ void MLScriptLanguage::addBranch( const QString& funname,SyntaxTreeNode* parent
|
||||
tmp.remove(wordsjoiner);
|
||||
dt[0] = tmp;
|
||||
dt[2] = specificsep;
|
||||
dt[4] = QString::number(MLScriptLanguage::NAMESPACE);
|
||||
SyntaxTreeNode* ch = parent->findChild(dt);
|
||||
//Search if the node is already in the tree
|
||||
if (ch == NULL)
|
||||
{
|
||||
parent->insertChildren(parent->childCount(),1,parent->columnCount());
|
||||
ch = parent->child(parent->childCount() - 1);
|
||||
ch->setData(0,dt[0]);
|
||||
ch->setData(2,dt[2]);
|
||||
for(int ii = 0;ii < 5;++ii)
|
||||
ch->setData(ii,dt[ii]);
|
||||
}
|
||||
addBranch(st,ch);
|
||||
LibraryElementInfo minext;
|
||||
minext.completename = st;
|
||||
minext.help = mi.help;
|
||||
addBranch(minext,ch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,18 +465,20 @@ void MLScriptLanguage::initLibrary()
|
||||
delete libraries;
|
||||
QVector<QVariant> v;
|
||||
v.push_back("partial function ID");
|
||||
v.push_back("tooltip");
|
||||
v.push_back("help");
|
||||
v.push_back("separator");
|
||||
v.push_back("signature");
|
||||
v.push_back("token");
|
||||
SyntaxTreeNode* root = new SyntaxTreeNode(v,NULL);
|
||||
libraries = new SyntaxTreeModel(root,NULL);
|
||||
}
|
||||
|
||||
QStringList MLScriptLanguage::getExternalLibrariesFunctionsSignature()
|
||||
QList<LibraryElementInfo> MLScriptLanguage::getExternalLibrariesMembersInfo() const
|
||||
{
|
||||
QStringList res;
|
||||
QList<LibraryElementInfo> res;
|
||||
QList<ExternalLib*> liblist = this->scriptLibraryFiles();
|
||||
for(int ii = 0;ii <liblist.size();++ii)
|
||||
res.append(liblist[ii]->functionsSignatures());
|
||||
res.append(liblist[ii]->libraryMembersInfo());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -547,7 +557,7 @@ JavaScriptLanguage::JavaScriptLanguage()
|
||||
//comp.setModel(&mod);
|
||||
}
|
||||
|
||||
const QList<ExternalLib*> JavaScriptLanguage::scriptLibraryFiles()
|
||||
const QList<ExternalLib*> JavaScriptLanguage::scriptLibraryFiles() const
|
||||
{
|
||||
QList<ExternalLib*> res;
|
||||
SGLMathLib* lib = new SGLMathLib();
|
||||
@ -589,22 +599,36 @@ SGLMathLib::SGLMathLib()
|
||||
|
||||
}
|
||||
|
||||
QStringList SGLMathLib::functionsSignatures() const
|
||||
QList<LibraryElementInfo> SGLMathLib::libraryMembersInfo() const
|
||||
{
|
||||
QString code = libCode();
|
||||
QStringList res;
|
||||
QList<LibraryElementInfo> res;
|
||||
int index = 0;
|
||||
QRegExp parameter("\\w*");
|
||||
QRegExp parameterlist(parameter.pattern() + "(\\s*,\\s*" + parameter.pattern() + ")*");
|
||||
QRegExp namespacelist(parameter.pattern() + "(\\s*\\.\\s*" + parameter.pattern() + ")*\\$?");
|
||||
QRegExp exp(namespacelist.pattern() + "\\s*=\\s*function\\s*\\(" + parameterlist.pattern() + "\\)");
|
||||
while(index >= 0)
|
||||
QRegExp help("/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/");
|
||||
QRegExp exp("(" + help.pattern() + ")?" + "\\s*" + namespacelist.pattern() + "\\s*=\\s*function\\s*\\(" + parameterlist.pattern() + "\\)");
|
||||
int ii = 0;
|
||||
do
|
||||
{
|
||||
index = code.indexOf(exp,index) + exp.matchedLength();
|
||||
QString fun = exp.cap();
|
||||
fun.remove(QRegExp("\\s*")).remove("=").remove("function");
|
||||
res << fun;
|
||||
}
|
||||
if (index >= 0)
|
||||
{
|
||||
QString fun = exp.cap();
|
||||
LibraryElementInfo mi;
|
||||
int helpind = fun.indexOf(help);
|
||||
if (helpind >= 0)
|
||||
{
|
||||
mi.help = help.cap();
|
||||
fun.remove(help.cap());
|
||||
}
|
||||
fun.remove(QRegExp("\\s*")).remove("=").remove("function");
|
||||
mi.completename = fun;
|
||||
res << mi;
|
||||
++ii;
|
||||
}
|
||||
}while(index >= 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -66,12 +66,18 @@ private:
|
||||
SyntaxTreeNode *rootItem;
|
||||
};
|
||||
|
||||
struct LibraryElementInfo
|
||||
{
|
||||
QString completename;
|
||||
QString help;
|
||||
};
|
||||
|
||||
class ExternalLib
|
||||
{
|
||||
public:
|
||||
ExternalLib(const QString& filename);
|
||||
QString name;
|
||||
virtual QStringList functionsSignatures() const = 0;
|
||||
virtual QList<LibraryElementInfo> libraryMembersInfo() const = 0;
|
||||
QString libCode() const;
|
||||
};
|
||||
|
||||
@ -79,17 +85,19 @@ class SGLMathLib : public ExternalLib
|
||||
{
|
||||
public:
|
||||
SGLMathLib();
|
||||
QStringList functionsSignatures() const;
|
||||
QList<LibraryElementInfo> libraryMembersInfo() const;
|
||||
};
|
||||
|
||||
class MLScriptLanguage
|
||||
{
|
||||
public:
|
||||
enum LANG_TOKEN {NAMESPACE,FUNCTION,CONSTANT};
|
||||
|
||||
MLScriptLanguage();
|
||||
~MLScriptLanguage();
|
||||
//a Library of functions is a list of functions expressed as NameSpace0.NameSpace1.----.NameSpaceN.fun(par0,par1,....,park) (if sep = "." openpar = "(") with NameSpace0 common to all the functions of a single library
|
||||
//the function will generate a SyntaxTree in order to easy manage SyntaxHighlighting and Auto-Completing.
|
||||
void addFunctionsLibrary(const QStringList& funsigns);
|
||||
void addLibrary(const QList<LibraryElementInfo>& funsigns);
|
||||
const SyntaxTreeModel* functionsLibrary() const;
|
||||
SyntaxTreeModel* functionsLibrary();
|
||||
QStringList reserved;
|
||||
@ -108,14 +116,14 @@ public:
|
||||
QRegExp matchIdentifiersButNotReservedWords() const;
|
||||
QRegExp matchOnlyReservedWords() const;
|
||||
|
||||
virtual const QList<ExternalLib*> scriptLibraryFiles() = 0;
|
||||
virtual const QList<ExternalLib*> scriptLibraryFiles() const = 0;
|
||||
QString getExternalLibrariesCode();
|
||||
QStringList getExternalLibrariesFunctionsSignature();
|
||||
QList<LibraryElementInfo> getExternalLibrariesMembersInfo() const;
|
||||
//QStringList splitTextInWords(const QString& st) const;
|
||||
|
||||
private:
|
||||
void initLibrary();
|
||||
void addBranch(const QString& funname,SyntaxTreeNode* parent);
|
||||
void addBranch(const LibraryElementInfo& mi,SyntaxTreeNode* parent);
|
||||
SyntaxTreeModel* libraries;
|
||||
};
|
||||
|
||||
@ -123,7 +131,7 @@ class JavaScriptLanguage : public MLScriptLanguage
|
||||
{
|
||||
public:
|
||||
JavaScriptLanguage();
|
||||
const QList<ExternalLib*> scriptLibraryFiles();
|
||||
const QList<ExternalLib*> scriptLibraryFiles() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user