Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tempKeys, & lua hooks for tempKeys/permKeys #472

Merged
merged 33 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f91858d
Added tempKeys, & lua hooks for tempKeys/permKeys
SecareLupus Mar 30, 2017
f0b3478
Removed unnecessary typedefs from KeyUnit
SecareLupus Mar 31, 2017
4f30400
Improved error messages on new kebinding functions
SecareLupus Mar 31, 2017
dbb4b3e
Improved error messages on new kebinding functions
SecareLupus Mar 31, 2017
966abe9
Merge branch 'development' of https://github.com/SecareLupus/Mudlet i…
SecareLupus Mar 31, 2017
392a320
Added check for pHost nullity in keybind functions
SecareLupus Apr 1, 2017
b4f6722
luaSendText (keybind) audit and string init
SecareLupus Apr 1, 2017
52a0c15
Simplified exists() checks, using count()
SecareLupus Apr 1, 2017
da58f33
Merge branch 'development' into development
SecareLupus Apr 1, 2017
c810ae7
Minor style fixes
SecareLupus Apr 4, 2017
e5bbb0c
Exists() now works with keybinds
SecareLupus Apr 4, 2017
145236e
Merge branch 'development' of https://github.com/SecareLupus/Mudlet i…
SecareLupus Apr 4, 2017
c1356fa
Moved isTempKey check in XMLexport.cpp
SecareLupus Apr 4, 2017
532127d
Added Keybind stats to TConsole::showStatistics
SecareLupus Apr 15, 2017
bec4ce6
Merge branch 'development' into development
vadi2 Apr 21, 2017
70e6d75
Post-merge fixes.
vadi2 Apr 21, 2017
ee64b0a
Added Lua data structure representing key code values.
SecareLupus May 28, 2017
9386eed
Refactored tempKey() and permKey() functions to be Mod-Key order
SecareLupus May 28, 2017
4ac562b
Made KeyModifier codes optional for permKey() and tempKey()
SecareLupus May 28, 2017
048a659
Merge branch 'development' into development
vadi2 May 28, 2017
4dd0ad5
Fixed merge error
vadi2 May 28, 2017
52ef8f0
Merge branch 'development' into development
vadi2 May 28, 2017
7b212d8
Fix merge error
vadi2 May 29, 2017
1a40807
Simplified key codes loading
vadi2 May 29, 2017
52183fb
Removed redundant space as result of deleting function
vadi2 May 29, 2017
79cf983
Applied clang-format over KeyUnit.cpp
vadi2 Jun 4, 2017
e7a24bd
Applied feedback on enableKey
vadi2 Jun 4, 2017
f5c635d
Applied clang-format over XMLexport.cpp
vadi2 Jun 4, 2017
2b508dc
Added newline
vadi2 Jun 4, 2017
b3b5748
Added file to src.pro
vadi2 Jun 4, 2017
dd52f00
Re-applied clang-format
vadi2 Jun 4, 2017
22c0002
Improved other functions to be up to the standard
vadi2 Jun 4, 2017
832c65a
Formatting improvements
vadi2 Jun 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 112 additions & 2 deletions src/KeyUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ void KeyUnit::compileAll()
}
}

TKey* KeyUnit::findKey(QString& name)
{
QMap<QString, TKey*>::const_iterator it = mLookupTable.find(name);
while (it != mLookupTable.end() && it.key() == name) {
TKey* pT = it.value();
return pT;
}
return 0;
}

bool KeyUnit::enableKey(const QString& name)
{
bool found = false;
Expand All @@ -99,6 +109,24 @@ bool KeyUnit::disableKey(const QString& name)
return found;
}

bool KeyUnit::killKey(QString& name)
{
for (auto it = mKeyRootNodeList.begin(); it != mKeyRootNodeList.end(); it++) {
TKey* pChild = *it;
if (pChild->getName() == name) {
// only temporary Keys can be killed
if (!pChild->isTempKey()) {
return false;
} else {
pChild->setIsActive(false);
markCleanup(pChild);
return true;
}
}
}
return false;
}

void KeyUnit::addKeyRootNode(TKey* pT, int parentPosition, int childPosition)
{
if (!pT) {
Expand Down Expand Up @@ -158,9 +186,14 @@ void KeyUnit::reParentKey(int childID, int oldParentID, int newParentID, int par

void KeyUnit::removeKeyRootNode(TKey* pT)
{
if (!pT) {
if (!pT)
return;
if (!pT->isTempKey()) {
mLookupTable.remove(pT->getName(), pT);
} else {
mLookupTable.remove(pT->getName());
}
mKeyMap.remove(pT->getID());
mKeyRootNodeList.remove(pT);
}

Expand Down Expand Up @@ -227,8 +260,12 @@ void KeyUnit::addKey(TKey* pT)

void KeyUnit::removeKey(TKey* pT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 This is functionally very similar to (void) KeyUnit::removeKeyRootNode(TKey*) so that could just call this one and then do the one extra line of code - but that does not matter for this PR, :shipit:

{
if (!pT) {
if (!pT)
return;
if (!pT->isTempKey()) {
mLookupTable.remove(pT->getName(), pT);
} else {
mLookupTable.remove(pT->getName());
}
mKeyMap.remove(pT->getID());
}
Expand Down Expand Up @@ -280,6 +317,79 @@ QString KeyUnit::getKeyName(int keyCode, int modifierCode)
}
}

void KeyUnit::initStats()
{
statsKeyTotal = 0;
statsTempKeys = 0;
statsActiveKeys = 0;
statsActiveKeysMax = 0;
statsActiveKeysMin = 0;
statsActiveKeysAverage = 0;
statsTempKeysCreated = 0;
statsTempKeysKilled = 0;
}

void KeyUnit::_assembleReport(TKey* pChild)
{
list<TKey*>* childrenList = pChild->mpMyChildrenList;
for (auto it2 = childrenList->begin(); it2 != childrenList->end(); it2++) {
TKey* pT = *it2;
_assembleReport(pT);
if (pT->isActive())
statsActiveKeys++;
if (pT->isTempKey())
statsTempKeys++;
statsKeyTotal++;
}
}

QString KeyUnit::assembleReport()
{
statsActiveKeys = 0;
statsKeyTotal = 0;
statsTempKeys = 0;
for (auto it = mKeyRootNodeList.begin(); it != mKeyRootNodeList.end(); it++) {
TKey* pChild = *it;
if (pChild->isActive())
statsActiveKeys++;
if (pChild->isTempKey())
statsTempKeys++;
statsKeyTotal++;
list<TKey*>* childrenList = pChild->mpMyChildrenList;
for (auto it2 = childrenList->begin(); it2 != childrenList->end(); it2++) {
TKey* pT = *it2;
_assembleReport(pT);
if (pT->isActive())
statsActiveKeys++;
if (pT->isTempKey())
statsTempKeys++;
statsKeyTotal++;
}
}
QStringList msg;
msg << "Keys current total: " << QString::number(statsKeyTotal) << "\n"
<< "tempKeys current total: " << QString::number(statsTempKeys) << "\n"
<< "active Keys: " << QString::number(statsActiveKeys) << "\n";
return msg.join("");
}

void KeyUnit::markCleanup(TKey* pT)
{
for (auto it = mCleanupList.begin(); it != mCleanupList.end(); it++) {
if (*it == pT) {
return;
}
}
mCleanupList.push_back(pT);
}

void KeyUnit::doCleanup()
{
for (auto it = mCleanupList.begin(); it != mCleanupList.end(); it++) {
delete *it;
}
mCleanupList.clear();
}

void KeyUnit::setupKeyNames()
{
Expand Down
18 changes: 18 additions & 0 deletions src/KeyUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,41 @@ class KeyUnit

TKey* getKey(int id);
void compileAll();
TKey* findKey(QString & name);
bool enableKey(const QString& name);
bool disableKey(const QString& name);
bool killKey(QString& name);
bool registerKey(TKey* pT);
void unregisterKey(TKey* pT);
void reParentKey(int childID, int oldParentID, int newParentID, int parentPosition = -1, int childPosition = -1);
QString assembleReport();
int getNewID();
QString getKeyName(int keyCode, int modifier);
void setupKeyNames();
void uninstall(const QString&);
void _uninstall(TKey* pChild, const QString& packageName);
bool processDataStream(int, int);
void markCleanup( TKey * pT );
void doCleanup();

QMultiMap<QString, TKey*> mLookupTable;
std::list<TKey*> mCleanupList;
QMutex mKeyUnitLock;
int statsKeyTotal;
int statsTempKeys;
int statsActiveKeys;
int statsActiveKeysMax;
int statsActiveKeysMin;
int statsActiveKeysAverage;
int statsTempKeysCreated;
int statsTempKeysKilled;
QList<TKey*> uninstallList;

private:
KeyUnit() {}
TKey* getKeyPrivate(int id);
void initStats();
void _assembleReport(TKey*);
void addKeyRootNode(TKey* pT, int parentPosition = -1, int childPosition = -1);
void addKey(TKey* pT);
void removeKeyRootNode(TKey* pT);
Expand Down
10 changes: 8 additions & 2 deletions src/TConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,16 +2727,22 @@ void TConsole::showStatistics()

script = "setFgColor(190,150,0); setUnderline(true); echo([[\n\nTrigger Report:\n\n]]); setBold(false);setUnderline(false);setFgColor(150,120,0)";
mpHost->mLuaInterpreter.compileAndExecuteScript( script );

QString r1 = mpHost->getTriggerUnit()->assembleReport();
msg = r1;
print( msg, QColor(150, 120, 0), Qt::black );
script = "setFgColor(190,150,0); setUnderline(true);echo([[\n\nTimer Report:\n\n]]);setBold(false);setUnderline(false);setFgColor(150,120,0)";
mpHost->mLuaInterpreter.compileAndExecuteScript( script );
QString r2 = mpHost->getTimerUnit()->assembleReport();
QString footer = QString("\n+--------------------------------------------------------------+\n" );
msg = r2;
print( msg, QColor(150, 120, 0), Qt::black );

script = "setFgColor(190,150,0); setUnderline(true);echo([[\n\nKeybinding Report:\n\n]]);setBold(false);setUnderline(false);setFgColor(150,120,0)";
mpHost->mLuaInterpreter.compileAndExecuteScript( script );
QString r3 = mpHost->getKeyUnit()->assembleReport();
msg = r3;
print( msg, QColor(150, 120, 0), Qt::black );

QString footer = QString("\n+--------------------------------------------------------------+\n" );
mpHost->mpConsole->print( footer, QColor(150, 120, 0), Qt::black );
script = "resetFormat();";
mpHost->mLuaInterpreter.compileAndExecuteScript( script );
Expand Down
17 changes: 14 additions & 3 deletions src/TKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TKey::TKey( TKey * parent, Host * pHost )
: Tree<TKey>( parent )
, exportItem(true)
, mModuleMasterFolder(false)
, mIsTempKey( false )
, mpHost( pHost )
, mNeedsToBeCompiled( true )
, mModuleMember(false)
Expand All @@ -43,9 +44,10 @@ TKey::TKey( TKey * parent, Host * pHost )
}

TKey::TKey( QString name, Host * pHost )
: Tree<TKey>(0)
, exportItem(true)
, mModuleMasterFolder(false)
: Tree<TKey>( 0 )
, exportItem( true )
, mModuleMasterFolder( false )
, mIsTempKey( false )
, mName( name )
, mpHost( pHost )
, mNeedsToBeCompiled( true )
Expand All @@ -64,6 +66,15 @@ TKey::~TKey()
mpHost->getKeyUnit()->unregisterKey(this);
}

void TKey::setName( const QString& name )
{
if( ! mIsTempKey )
{
mpHost->getKeyUnit()->mLookupTable.remove( mName, this );
}
mName = name;
mpHost->getKeyUnit()->mLookupTable.insertMulti( name, this );
}

bool TKey::match(int key, int modifier)
{
Expand Down
5 changes: 4 additions & 1 deletion src/TKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TKey : public Tree<TKey>
TKey(QString name, Host* pHost);
void compileAll();
QString getName() { return mName; }
void setName(QString name) { mName = name; }
void setName(const QString & name);
int getKeyCode() { return mKeyCode; }
void setKeyCode(int code) { mKeyCode = code; }
int getKeyModifiers() { return mKeyModifier; }
Expand All @@ -61,6 +61,8 @@ class TKey : public Tree<TKey>
void setIsFolder(bool b) { mIsFolder = b; }
bool match(int, int);
bool registerKey();
bool isTempKey() { return mIsTempKey; }
void setIsTempKey(bool b) { mIsTempKey = b; }
//bool serialize( QDataStream & );
//bool restore( QDataStream & fs, bool );
bool exportItem;
Expand Down Expand Up @@ -88,6 +90,7 @@ class TKey : public Tree<TKey>
bool mIsFolder;
QPointer<Host> mpHost;
bool mNeedsToBeCompiled;
bool mIsTempKey;
bool mModuleMember;
};

Expand Down
Loading