forked from mirror/openmw-tes3mp
Merge branch 'tab_completion'
This commit is contained in:
commit
d7226fc9c2
7 changed files with 133 additions and 35 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "console.hpp"
|
#include "console.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <components/compiler/exception.hpp>
|
#include <components/compiler/exception.hpp>
|
||||||
|
|
||||||
#include "../mwscript/extensions.hpp"
|
#include "../mwscript/extensions.hpp"
|
||||||
|
@ -26,6 +28,12 @@ namespace MWGui
|
||||||
|
|
||||||
bool Console::compile (const std::string& cmd, Compiler::Output& output)
|
bool Console::compile (const std::string& cmd, Compiler::Output& output)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
listNames();
|
||||||
|
for (std::vector<std::string>::iterator iter (mNames.begin()); iter!=mNames.end(); ++iter)
|
||||||
|
std::cout << *iter << ", ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ErrorHandler::reset();
|
ErrorHandler::reset();
|
||||||
|
@ -67,6 +75,31 @@ namespace MWGui
|
||||||
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
printError ((type==ErrorMessage ? "error: " : "warning: ") + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Console::listNames()
|
||||||
|
{
|
||||||
|
if (mNames.empty())
|
||||||
|
{
|
||||||
|
// keywords
|
||||||
|
std::istringstream input ("");
|
||||||
|
|
||||||
|
Compiler::Scanner scanner (*this, input, mCompilerContext.getExtensions());
|
||||||
|
|
||||||
|
scanner.listKeywords (mNames);
|
||||||
|
|
||||||
|
// identifier
|
||||||
|
const ESMS::ESMStore& store = mEnvironment.mWorld->getStore();
|
||||||
|
|
||||||
|
for (ESMS::RecListList::const_iterator iter (store.recLists.begin());
|
||||||
|
iter!=store.recLists.end(); ++iter)
|
||||||
|
{
|
||||||
|
iter->second->listIdentifier (mNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort
|
||||||
|
std::sort (mNames.begin(), mNames.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console::Console(int w, int h, MWWorld::Environment& environment,
|
Console::Console(int w, int h, MWWorld::Environment& environment,
|
||||||
const Compiler::Extensions& extensions)
|
const Compiler::Extensions& extensions)
|
||||||
: Layout("openmw_console_layout.xml"),
|
: Layout("openmw_console_layout.xml"),
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace MWGui
|
||||||
|
|
||||||
MWScript::CompilerContext mCompilerContext;
|
MWScript::CompilerContext mCompilerContext;
|
||||||
MWWorld::Environment& mEnvironment;
|
MWWorld::Environment& mEnvironment;
|
||||||
|
std::vector<std::string> mNames;
|
||||||
|
|
||||||
bool compile (const std::string& cmd, Compiler::Output& output);
|
bool compile (const std::string& cmd, Compiler::Output& output);
|
||||||
|
|
||||||
|
@ -33,6 +34,12 @@ namespace MWGui
|
||||||
/// Report a file related error
|
/// Report a file related error
|
||||||
virtual void report (const std::string& message, Type type);
|
virtual void report (const std::string& message, Type type);
|
||||||
|
|
||||||
|
void listNames();
|
||||||
|
///< Write all valid identifiers and keywords into mNames and sort them.
|
||||||
|
/// \note If mNames is not empty, this function is a no-op.
|
||||||
|
/// \note The list may contain duplicates (if a name is a keyword and an identifier at the same
|
||||||
|
/// time).
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyGUI::EditPtr command;
|
MyGUI::EditPtr command;
|
||||||
MyGUI::EditPtr history;
|
MyGUI::EditPtr history;
|
||||||
|
|
|
@ -207,4 +207,11 @@ namespace Compiler
|
||||||
throw std::logic_error ("unsupported code segment");
|
throw std::logic_error ("unsupported code segment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Extensions::listKeywords (std::vector<std::string>& keywords) const
|
||||||
|
{
|
||||||
|
for (std::map<std::string, int>::const_iterator iter (mKeywords.begin());
|
||||||
|
iter!=mKeywords.end(); ++iter)
|
||||||
|
keywords.push_back (iter->first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,9 @@ namespace Compiler
|
||||||
void generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
|
void generateInstructionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
|
||||||
Literals& literals, const std::string& id, int optionalArguments) const;
|
Literals& literals, const std::string& id, int optionalArguments) const;
|
||||||
///< Append code for function to \a code.
|
///< Append code for function to \a code.
|
||||||
|
|
||||||
|
void listKeywords (std::vector<std::string>& keywords) const;
|
||||||
|
///< Append all known keywords to \æ kaywords.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,27 +230,27 @@ namespace Compiler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *keywords[] =
|
||||||
|
{
|
||||||
|
"begin", "end",
|
||||||
|
"short", "long", "float",
|
||||||
|
"if", "endif", "else", "elseif",
|
||||||
|
"while", "endwhile",
|
||||||
|
"return",
|
||||||
|
"messagebox",
|
||||||
|
"set", "to",
|
||||||
|
"getsquareroot",
|
||||||
|
"menumode",
|
||||||
|
"random",
|
||||||
|
"startscript", "stopscript", "scriptrunning",
|
||||||
|
"getdistance",
|
||||||
|
"getsecondspassed",
|
||||||
|
"enable", "disable", "getdisabled",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
bool Scanner::scanName (char c, Parser& parser, bool& cont)
|
bool Scanner::scanName (char c, Parser& parser, bool& cont)
|
||||||
{
|
{
|
||||||
static const char *keywords[] =
|
|
||||||
{
|
|
||||||
"begin", "end",
|
|
||||||
"short", "long", "float",
|
|
||||||
"if", "endif", "else", "elseif",
|
|
||||||
"while", "endwhile",
|
|
||||||
"return",
|
|
||||||
"messagebox",
|
|
||||||
"set", "to",
|
|
||||||
"getsquareroot",
|
|
||||||
"menumode",
|
|
||||||
"random",
|
|
||||||
"startscript", "stopscript", "scriptrunning",
|
|
||||||
"getdistance",
|
|
||||||
"getsecondspassed",
|
|
||||||
"enable", "disable", "getdisabled",
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
if (!scanName (c, name))
|
if (!scanName (c, name))
|
||||||
|
@ -513,4 +513,13 @@ namespace Compiler
|
||||||
mPutbackCode = keyword;
|
mPutbackCode = keyword;
|
||||||
mPutbackLoc = loc;
|
mPutbackLoc = loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scanner::listKeywords (std::vector<std::string>& keywords)
|
||||||
|
{
|
||||||
|
for (int i=0; Compiler::keywords[i]; ++i)
|
||||||
|
keywords.push_back (Compiler::keywords[i]);
|
||||||
|
|
||||||
|
if (mExtensions)
|
||||||
|
mExtensions->listKeywords (keywords);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "tokenloc.hpp"
|
#include "tokenloc.hpp"
|
||||||
|
|
||||||
|
@ -116,6 +117,8 @@ namespace Compiler
|
||||||
void putbackKeyword (int keyword, const TokenLoc& loc);
|
void putbackKeyword (int keyword, const TokenLoc& loc);
|
||||||
///< put back a keyword token
|
///< put back a keyword token
|
||||||
|
|
||||||
|
void listKeywords (std::vector<std::string>& keywords);
|
||||||
|
///< Append all known keywords to \æ kaywords.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "components/esm/records.hpp"
|
#include "components/esm/records.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -23,6 +24,7 @@ namespace ESMS
|
||||||
{
|
{
|
||||||
virtual void load(ESMReader &esm, const std::string &id) = 0;
|
virtual void load(ESMReader &esm, const std::string &id) = 0;
|
||||||
virtual int getSize() = 0;
|
virtual int getSize() = 0;
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const = 0;
|
||||||
|
|
||||||
static std::string toLower (const std::string& name)
|
static std::string toLower (const std::string& name)
|
||||||
{
|
{
|
||||||
|
@ -76,6 +78,12 @@ namespace ESMS
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSize() { return list.size(); }
|
int getSize() { return list.size(); }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||||
|
{
|
||||||
|
for (typename MapType::const_iterator iter (list.begin()); iter!=list.end(); ++iter)
|
||||||
|
identifier.push_back (iter->first);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Modified version of RecListT for records, that need to store their own ID
|
/// Modified version of RecListT for records, that need to store their own ID
|
||||||
|
@ -117,6 +125,12 @@ namespace ESMS
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSize() { return list.size(); }
|
int getSize() { return list.size(); }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||||
|
{
|
||||||
|
for (typename MapType::const_iterator iter (list.begin()); iter!=list.end(); ++iter)
|
||||||
|
identifier.push_back (iter->first);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The only difference to the above is a slight change to the load()
|
// The only difference to the above is a slight change to the load()
|
||||||
|
@ -163,6 +177,12 @@ namespace ESMS
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSize() { return list.size(); }
|
int getSize() { return list.size(); }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||||
|
{
|
||||||
|
for (typename MapType::const_iterator iter (list.begin()); iter!=list.end(); ++iter)
|
||||||
|
identifier.push_back (iter->first);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Land textures are indexed by an integer number
|
/* Land textures are indexed by an integer number
|
||||||
|
@ -181,6 +201,8 @@ namespace ESMS
|
||||||
|
|
||||||
int getSize() { return count; }
|
int getSize() { return count; }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const {}
|
||||||
|
|
||||||
void load(ESMReader &esm, const std::string &id)
|
void load(ESMReader &esm, const std::string &id)
|
||||||
{
|
{
|
||||||
LandTexture lt;
|
LandTexture lt;
|
||||||
|
@ -210,6 +232,8 @@ namespace ESMS
|
||||||
LandList() : count(0) {}
|
LandList() : count(0) {}
|
||||||
int getSize() { return count; }
|
int getSize() { return count; }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const {}
|
||||||
|
|
||||||
// Find land for the given coordinates. Return null if no data.
|
// Find land for the given coordinates. Return null if no data.
|
||||||
const Land *search(int x, int y) const
|
const Land *search(int x, int y) const
|
||||||
{
|
{
|
||||||
|
@ -267,6 +291,12 @@ namespace ESMS
|
||||||
typedef std::map<int, ExtCellsCol> ExtCells;
|
typedef std::map<int, ExtCellsCol> ExtCells;
|
||||||
ExtCells extCells;
|
ExtCells extCells;
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||||
|
{
|
||||||
|
for (IntCells::const_iterator iter (intCells.begin()); iter!=intCells.end(); ++iter)
|
||||||
|
identifier.push_back (iter->first);
|
||||||
|
}
|
||||||
|
|
||||||
~CellList()
|
~CellList()
|
||||||
{
|
{
|
||||||
for (IntCells::iterator it = intCells.begin(); it!=intCells.end(); ++it)
|
for (IntCells::iterator it = intCells.begin(); it!=intCells.end(); ++it)
|
||||||
|
@ -407,6 +437,12 @@ namespace ESMS
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSize() { return list.size(); }
|
int getSize() { return list.size(); }
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const
|
||||||
|
{
|
||||||
|
for (typename MapType::const_iterator iter (list.begin()); iter!=list.end(); ++iter)
|
||||||
|
identifier.push_back (iter->first);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename X>
|
template <typename X>
|
||||||
|
@ -429,6 +465,8 @@ namespace ESMS
|
||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void listIdentifier (std::vector<std::string>& identifier) const {}
|
||||||
|
|
||||||
// Find the given object ID, or return NULL if not found.
|
// Find the given object ID, or return NULL if not found.
|
||||||
const X* search (int id) const
|
const X* search (int id) const
|
||||||
{
|
{
|
||||||
|
@ -458,9 +496,7 @@ namespace ESMS
|
||||||
|
|
||||||
/* We need special lists for:
|
/* We need special lists for:
|
||||||
|
|
||||||
Land
|
|
||||||
Path grids
|
Path grids
|
||||||
Land textures
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue