Skip to content

Commit

Permalink
Revert "Add an option to order nick completion by last action time. R…
Browse files Browse the repository at this point in the history
…esolves #2216."

This reverts commit 446bff0.
  • Loading branch information
pragmaware committed Dec 29, 2017
1 parent 6ef18f9 commit ce3c901
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 112 deletions.
3 changes: 1 addition & 2 deletions src/kvirc/kernel/KviOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ KviUIntOption g_uintOptionsTable[KVI_NUM_UINT_OPTIONS] = {
UINT_OPTION("ToolBarButtonStyle", 0, KviOption_groupTheme), // 0 = Qt::ToolButtonIconOnly
UINT_OPTION("MaximumBlowFishKeySize", 56, KviOption_sectFlagNone),
UINT_OPTION("CustomCursorWidth", 1, KviOption_resetUpdateGui),
UINT_OPTION("UserListMinimumWidth", 100, KviOption_sectFlagUserListView | KviOption_resetUpdateGui | KviOption_groupTheme),
UINT_OPTION("NickCompletionOrder", 2, KviOption_sectFlagNone)
UINT_OPTION("UserListMinimumWidth", 100, KviOption_sectFlagUserListView | KviOption_resetUpdateGui | KviOption_groupTheme)
};

#define FONT_OPTION(_name, _face, _size, _flags) \
Expand Down
3 changes: 1 addition & 2 deletions src/kvirc/kernel/KviOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,8 @@ DECLARE_OPTION_STRUCT(KviStringListOption, QStringList)
#define KviOption_uintMaximumBlowFishKeySize 80
#define KviOption_uintCustomCursorWidth 81 /* Interface */
#define KviOption_uintUserListMinimumWidth 82
#define KviOption_uintNickCompletionOrder 83

#define KVI_NUM_UINT_OPTIONS 84
#define KVI_NUM_UINT_OPTIONS 83

namespace KviIdentdOutputMode
{
Expand Down
9 changes: 4 additions & 5 deletions src/kvirc/ui/KviInputEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,12 +2368,10 @@ void KviInputEditor::standardNickCompletion(bool bAddMask, QString & szWord, boo

if(m_pUserListView->completeNickStandard(szWord, m_szLastCompletedNick, szBuffer, bAddMask))
{
// Because szBuffer does not necessarily equal the completed nickname,
// completeNickStandard will update m_szLastCompletedNick with the nickname.

// completed: save the buffer
m_szLastCompletionBuffer = m_szTextBuffer;
m_iLastCompletionCursorPosition = m_iCursorPosition;
m_szLastCompletedNick = szBuffer;
standardNickCompletionInsertCompletedText(szWord, szBuffer, bFirstWordInLine, bInCommand);
m_bLastCompletionFinished = 0;
// REPAINT CALLED FROM OUTSIDE!
Expand All @@ -2399,6 +2397,7 @@ void KviInputEditor::standardNickCompletion(bool bAddMask, QString & szWord, boo
if(m_pUserListView->completeNickStandard(szWord, m_szLastCompletedNick, szBuffer, bAddMask))
{
// completed
m_szLastCompletedNick = szBuffer;
standardNickCompletionInsertCompletedText(szWord, szBuffer, bFirstWordInLine, bInCommand);
m_bLastCompletionFinished = 0;
// REPAINT CALLED FROM OUTSIDE!
Expand All @@ -2418,12 +2417,12 @@ void KviInputEditor::standardNickCompletion(bool bAddMask, QString & szWord, boo
//getWordBeforeCursor(word,&bFirstWordInLine);
if(szWord.isEmpty())
return;
m_szLastCompletedNick = "";
if(m_pUserListView->completeNickStandard(szWord, m_szLastCompletedNick, szBuffer, bAddMask))
if(m_pUserListView->completeNickStandard(szWord, "", szBuffer, bAddMask))
{
// completed
m_szLastCompletionBuffer = m_szTextBuffer;
m_iLastCompletionCursorPosition = m_iCursorPosition;
m_szLastCompletedNick = szBuffer;
standardNickCompletionInsertCompletedText(szWord, szBuffer, bFirstWordInLine, bInCommand);
m_bLastCompletionFinished = 0;
// REPAINT CALLED FROM OUTSIDE!
Expand Down
125 changes: 34 additions & 91 deletions src/kvirc/ui/KviUserListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ KviUserListView::KviUserListView(QWidget * pParent, KviWindowToolPageButton * pB
m_ieEntries = 0;
m_iIEntries = 0;
m_iSelectedCount = 0;
m_CompletionList = nullptr;

applyOptions();
}
Expand All @@ -257,7 +256,6 @@ KviUserListView::~KviUserListView()
delete m_pToolTip;
delete m_pViewArea;
delete m_pUsersLabel;
delete m_CompletionList;
}

void KviUserListView::emitRightClick()
Expand Down Expand Up @@ -487,115 +485,60 @@ void KviUserListView::completeNickBashLike(const QString & szBegin, std::vector<
}
}

bool KviUserListView::completeNickStandard(const QString & szBegin, QString & szSkipAfter, QString & szBuffer, bool bAppendMask)
bool KviUserListView::completeNickStandard(const QString & szBegin, const QString & szSkipAfter, QString & szBuffer, bool bAppendMask)
{
// For normal nickname completion, we'll build a list of matching nicknames in order,
// then look through it to the next nickname each time Tab is pressed.
if (m_CompletionList == nullptr)
{
// No list; build it.
m_CompletionList = new std::list<QString>();

KviUserListEntry * pEntry = m_pHeadItem;

for(KviUserListEntry * pEntry = m_pHeadItem; pEntry; pEntry = pEntry->m_pNext)
{
// FIXME: completion should skip my own nick or place it as last entry in the chain (?)

// if(KviConsoleWindow * c = m_pKviWindow->console())
// {
// if(kvi_strEqualCI(entry->m_szNick.ptr(),c->currentNickName())
// }

if(pEntry->m_szNick.length() >= szBegin.length())
{
bool bEqual = KviQString::equalCIN(szBegin, pEntry->m_szNick, szBegin.length());
if(!bEqual && KVI_OPTION_BOOL(KviOption_boolIgnoreSpecialCharactersInNickCompletion))
{
QString szTmp = pEntry->m_szNick;
szTmp.remove(QRegExp("[^a-zA-Z0-9]"));
bEqual = KviQString::equalCIN(szBegin, szTmp, szBegin.length());
}

if(bEqual)
{
// Matching entry; insert it into the list.
std::list<QString>::iterator it;
switch (KVI_OPTION_UINT(KviOption_uintNickCompletionOrder))
{
case 0: // As listed
m_CompletionList->push_back(pEntry->m_szNick);
break;
case 1: // Alphabetical
for (it = m_CompletionList->begin(); it != m_CompletionList->end(); ++it)
{
if ((KviQString::cmpCI(pEntry->m_szNick, *it,
KVI_OPTION_BOOL(KviOption_boolPlaceNickWithNonAlphaCharsAtEnd)) < 0))
{
break;
}
}
m_CompletionList->insert(it, pEntry->m_szNick);
break;
default: // Last action time
for (it = m_CompletionList->begin(); it != m_CompletionList->end(); ++it)
{
if (pEntry->m_lastActionTime > (*m_pEntryDict->find(*it)).m_lastActionTime)
{
break;
}
}
m_CompletionList->insert(it, pEntry->m_szNick);
break;
}

}
}
}
}

// The list exists; find the next match.
std::list<QString>::iterator it = m_CompletionList->begin();
KviUserListEntry * pEntry = m_pHeadItem;

if(!szSkipAfter.isEmpty())
{
while(it != m_CompletionList->end())
while(pEntry)
{
if(KviQString::equalCI(szSkipAfter, *it))
if(KviQString::equalCI(szSkipAfter, pEntry->m_szNick))
{
++it;
pEntry = pEntry->m_pNext;
break;
}
++it;
pEntry = pEntry->m_pNext;
}
}

if(it != m_CompletionList->end())
// FIXME: completion should skip my own nick or place it as last entry in the chain (?)

// if(KviConsoleWindow * c = m_pKviWindow->console())
// {
// if(kvi_strEqualCI(entry->m_szNick.ptr(),c->currentNickName())
// }

// Ok...now the real completion
while(pEntry)
{
szSkipAfter = *it;
szBuffer = *it;
if(bAppendMask)
if(pEntry->m_szNick.length() >= szBegin.length())
{
KviUserListEntry * entry = m_pEntryDict->find(*it);
if (entry)
bool bEqual = KviQString::equalCIN(szBegin, pEntry->m_szNick, szBegin.length());
if(!bEqual && KVI_OPTION_BOOL(KviOption_boolIgnoreSpecialCharactersInNickCompletion))
{
szBuffer += "!";
szBuffer += entry->m_pGlobalData->user();
szBuffer += "@";
szBuffer += entry->m_pGlobalData->host();
QString szTmp = pEntry->m_szNick;
szTmp.remove(QRegExp("[^a-zA-Z0-9]"));
bEqual = KviQString::equalCIN(szBegin, szTmp, szBegin.length());
}
else

if(bEqual)
{
// They left the user list during the completion session.
szBuffer += "!*@*";
// This is ok.
szBuffer = pEntry->m_szNick;
if(bAppendMask)
{
szBuffer += "!";
szBuffer += pEntry->m_pGlobalData->user();
szBuffer += "@";
szBuffer += pEntry->m_pGlobalData->host();
}
return true;
}
}
return true;
pEntry = pEntry->m_pNext;
}

// No more matches; delete the list.
delete m_CompletionList;
m_CompletionList = nullptr;
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions src/kvirc/ui/KviUserListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ class KVIRC_API KviUserListView : public KviWindowToolWidget
int m_iIEntries;
KviWindow * m_pKviWindow;

std::list<QString> * m_CompletionList;

public:
/**
* \brief Updates the list view area
Expand Down Expand Up @@ -722,12 +720,12 @@ class KVIRC_API KviUserListView : public KviWindowToolWidget
* It looks for the letters typed, if it found at least a result, it
* cycles through the completed nicknames
* \param szBegin The starting of the nick
* \param szSkipAfter The string to skip after the nick is completed. Will be updated with the completed nickname.
* \param szSkipAfter The string to skip after the nick is completed
* \param szBuffer The buffer where to store the data
* \param bAppendMask Whether to append the complete mask
* \return bool
*/
bool completeNickStandard(const QString & szBegin, QString & szSkipAfter, QString & szBuffer, bool bAppendMask);
bool completeNickStandard(const QString & szBegin, const QString & szSkipAfter, QString & szBuffer, bool bAppendMask);

/**
* \brief Completes the nick in Bash-like behaviour
Expand Down
5 changes: 0 additions & 5 deletions src/modules/options/OptionsWidget_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ OptionsWidget_inputFeatures::OptionsWidget_inputFeatures(QWidget * parent)

addBoolSelector(g, __tr2qs_ctx("Ignore special characters in nick completion", "options"), KviOption_boolIgnoreSpecialCharactersInNickCompletion);

// TODO: Add a combo box for KviOption_uintNickCompletionOrder
// 0: as listed
// 1: alphabetical
// 2: by last action time

KviBoolSelector * d = addBoolSelector(0, 7, 0, 7, __tr2qs_ctx("Use a custom cursor width", "options"), KviOption_boolEnableCustomCursorWidth);
KviUIntSelector * f = addUIntSelector(0, 8, 0, 8, __tr2qs_ctx("Custom cursor width:", "options"), KviOption_uintCustomCursorWidth, 1, 24, 8, KVI_OPTION_BOOL(KviOption_boolEnableCustomCursorWidth));
f->setSuffix(__tr2qs_ctx(" pixels", "options"));
Expand Down
3 changes: 0 additions & 3 deletions src/modules/options/OptionsWidget_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class OptionsWidget_inputLook : public KviOptionsWidget
class OptionsWidget_inputFeatures : public KviOptionsWidget
{
Q_OBJECT
private:
QComboBox * m_pNickCompletionOrder;

public:
OptionsWidget_inputFeatures(QWidget * parent);
~OptionsWidget_inputFeatures();
Expand Down

0 comments on commit ce3c901

Please sign in to comment.