Expose the command name autocompletion to the script
This commit is contained in:
parent
e4efc8b5fc
commit
1634c61512
@ -304,6 +304,7 @@
|
||||
E8C7D7B422DAF5B500F78763 /* ConsoleCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C7D7B322DAF5B400F78763 /* ConsoleCommand.cpp */; };
|
||||
E8C7D7BA22DB220300F78763 /* ConfigConsoleResponder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C7D7B822DB220200F78763 /* ConfigConsoleResponder.cpp */; };
|
||||
E8C7D7BE22DB2A4400F78763 /* ConsoleCommandCandidate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C7D7BD22DB2A4400F78763 /* ConsoleCommandCandidate.cpp */; };
|
||||
E8C7D7C022DB3AE000F78763 /* ConsoleCommandCandidate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8C7D7BF22DB3AE000F78763 /* ConsoleCommandCandidate.cpp */; };
|
||||
E8CB47CE1DE071CA00BF606A /* SWUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CB47CC1DE071CA00BF606A /* SWUtils.cpp */; };
|
||||
E8CB47D21DE07CF000BF606A /* SettingSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CB47CF1DE07CF000BF606A /* SettingSet.cpp */; };
|
||||
E8CB47D61DE084AB00BF606A /* GLSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E8CB47D41DE084AB00BF606A /* GLSettings.cpp */; };
|
||||
@ -775,6 +776,7 @@
|
||||
E8C7D7BB22DB263200F78763 /* Iterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Iterator.h; sourceTree = "<group>"; };
|
||||
E8C7D7BC22DB2A4400F78763 /* ConsoleCommandCandidate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConsoleCommandCandidate.h; sourceTree = "<group>"; };
|
||||
E8C7D7BD22DB2A4400F78763 /* ConsoleCommandCandidate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleCommandCandidate.cpp; sourceTree = "<group>"; };
|
||||
E8C7D7BF22DB3AE000F78763 /* ConsoleCommandCandidate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConsoleCommandCandidate.cpp; sourceTree = "<group>"; };
|
||||
E8C92A0A18695EA500740C9F /* SWModelRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWModelRenderer.cpp; sourceTree = "<group>"; };
|
||||
E8C92A0B18695EA500740C9F /* SWModelRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWModelRenderer.h; sourceTree = "<group>"; };
|
||||
E8C92A0D186A8D3600740C9F /* CpuID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CpuID.h; sourceTree = "<group>"; };
|
||||
@ -1400,6 +1402,7 @@
|
||||
E8B6B6E617E40AF300E35523 /* ScriptBindings */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8C7D7BF22DB3AE000F78763 /* ConsoleCommandCandidate.cpp */,
|
||||
E8C7D7B022DA35F000F78763 /* ConsoleHelper.cpp */,
|
||||
E8B6B6E717E40AF500E35523 /* MathScript.cpp */,
|
||||
E838D42018ADDE2800EE3C53 /* StringsScript.cpp */,
|
||||
@ -2100,6 +2103,7 @@
|
||||
E82E674A18EA7972004DBA18 /* as_objecttype.cpp in Sources */,
|
||||
E82E674B18EA7972004DBA18 /* as_outputbuffer.cpp in Sources */,
|
||||
E82E674C18EA7972004DBA18 /* as_parser.cpp in Sources */,
|
||||
E8C7D7C022DB3AE000F78763 /* ConsoleCommandCandidate.cpp in Sources */,
|
||||
E82E674D18EA7972004DBA18 /* as_restore.cpp in Sources */,
|
||||
E82E674E18EA7972004DBA18 /* as_scriptcode.cpp in Sources */,
|
||||
E8C7D7BE22DB2A4400F78763 /* ConsoleCommandCandidate.cpp in Sources */,
|
||||
|
@ -59,5 +59,17 @@ namespace spades {
|
||||
SPLog("An exception was thrown while executing a console command: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleCommandCandidateIterator *
|
||||
ConsoleHelper::AutocompleteCommandName(const std::string &name) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
auto parent = GetParent();
|
||||
if (!parent) {
|
||||
return new EmptyIterator<const ConsoleCommandCandidate &>();
|
||||
}
|
||||
|
||||
return parent->AutocompleteCommandName(name).Unmanage();
|
||||
}
|
||||
} // namespace gui
|
||||
} // namespace spades
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <Core/RefCountedObject.h>
|
||||
|
||||
#include "ConsoleCommandCandidate.h"
|
||||
|
||||
namespace spades {
|
||||
namespace gui {
|
||||
class ConsoleScreen;
|
||||
@ -36,6 +38,9 @@ namespace spades {
|
||||
/** Execute a console command. */
|
||||
void ExecCommand(const std::string &);
|
||||
|
||||
/** Produce a sequence of candidates for command name autocompletion. */
|
||||
ConsoleCommandCandidateIterator *AutocompleteCommandName(const std::string &name);
|
||||
|
||||
private:
|
||||
~ConsoleHelper();
|
||||
/** A weak reference to the owning `ConsoleScreen`. */
|
||||
|
@ -62,7 +62,7 @@ namespace spades {
|
||||
virtual bool ExecCommand(const Handle<ConsoleCommand> &) { return false; }
|
||||
|
||||
/**
|
||||
* Produce a sequence of candidates of command name autocompletion.
|
||||
* Produce a sequence of candidates for command name autocompletion.
|
||||
*
|
||||
* `name` is an incomplete command name. This method produces
|
||||
* a sequence of candidates starting with `name`.
|
||||
|
101
Sources/ScriptBindings/ConsoleCommandCandidate.cpp
Normal file
101
Sources/ScriptBindings/ConsoleCommandCandidate.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (c) 2019 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
OpenSpades 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenSpades is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "ScriptManager.h"
|
||||
#include <Gui/ConsoleCommandCandidate.h>
|
||||
|
||||
namespace spades {
|
||||
class ConsoleCommandCandidateRegistrar : public ScriptObjectRegistrar {
|
||||
static void ConsoleCommandCandidateFactory1(gui::ConsoleCommandCandidate *p) {
|
||||
new (p) gui::ConsoleCommandCandidate();
|
||||
}
|
||||
static void ConsoleCommandCandidateFactory2(const gui::ConsoleCommandCandidate &other,
|
||||
gui::ConsoleCommandCandidate *p) {
|
||||
new (p) gui::ConsoleCommandCandidate(other);
|
||||
}
|
||||
static void ConsoleCommandCandidateDestructor(gui::ConsoleCommandCandidate *p) {
|
||||
p->~ConsoleCommandCandidate();
|
||||
}
|
||||
|
||||
public:
|
||||
ConsoleCommandCandidateRegistrar() : ScriptObjectRegistrar("ConsoleCommandCandidate") {}
|
||||
|
||||
virtual void Register(ScriptManager *manager, Phase phase) {
|
||||
asIScriptEngine *eng = manager->GetEngine();
|
||||
int r;
|
||||
eng->SetDefaultNamespace("spades");
|
||||
switch (phase) {
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterObjectType("ConsoleCommandCandidate",
|
||||
sizeof(gui::ConsoleCommandCandidate),
|
||||
asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectType("ConsoleCommandCandidateIterator", 0, asOBJ_REF);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterObjectBehaviour(
|
||||
"ConsoleCommandCandidate", asBEHAVE_CONSTRUCT, "void f()",
|
||||
asFUNCTION(ConsoleCommandCandidateFactory1), asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour("ConsoleCommandCandidate", asBEHAVE_CONSTRUCT,
|
||||
"void f(const ConsoleCommandCandidate& in)",
|
||||
asFUNCTION(ConsoleCommandCandidateFactory2),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour(
|
||||
"ConsoleCommandCandidate", asBEHAVE_DESTRUCT, "void f()",
|
||||
asFUNCTION(ConsoleCommandCandidateDestructor), asCALL_CDECL_OBJLAST);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty("ConsoleCommandCandidate", "string Name",
|
||||
asOFFSET(gui::ConsoleCommandCandidate, name));
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectProperty(
|
||||
"ConsoleCommandCandidate", "string Description",
|
||||
asOFFSET(gui::ConsoleCommandCandidate, description));
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectBehaviour(
|
||||
"ConsoleCommandCandidateIterator", asBEHAVE_ADDREF, "void f()",
|
||||
asMETHOD(gui::ConsoleCommandCandidateIterator, AddRef), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectBehaviour(
|
||||
"ConsoleCommandCandidateIterator", asBEHAVE_RELEASE, "void f()",
|
||||
asMETHOD(gui::ConsoleCommandCandidateIterator, Release), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterObjectMethod(
|
||||
"ConsoleCommandCandidateIterator", "bool MoveNext()",
|
||||
asMETHOD(gui::ConsoleCommandCandidateIterator, MoveNext), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod(
|
||||
"ConsoleCommandCandidateIterator",
|
||||
"const ConsoleCommandCandidate &get_Current()",
|
||||
asMETHOD(gui::ConsoleCommandCandidateIterator, GetCurrent), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static ConsoleCommandCandidateRegistrar registrar;
|
||||
} // namespace spades
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2013 yvt
|
||||
Copyright (c) 2019 yvt
|
||||
|
||||
This file is part of OpenSpades.
|
||||
|
||||
@ -50,6 +50,11 @@ namespace spades {
|
||||
"ConsoleHelper", "void ExecCommand(const string& in)",
|
||||
asMETHOD(gui::ConsoleHelper, ExecCommand), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterObjectMethod(
|
||||
"ConsoleHelper",
|
||||
"ConsoleCommandCandidateIterator@ AutocompleteCommandName(const string& in)",
|
||||
asMETHOD(gui::ConsoleHelper, AutocompleteCommandName), asCALL_THISCALL);
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user