diff options
| author | 2016-11-10 00:49:59 -0500 | |
|---|---|---|
| committer | 2016-11-10 00:49:59 -0500 | |
| commit | 48dacdbf2e6ccf885d1069bb4b3ef78d18d93671 (patch) | |
| tree | 788b39de87df66e1e226d82bb29ad6a54353711b | |
| parent | KviKvsEventManager: Fix memory leak in addRawHandler (diff) | |
| download | KVIrc-48dacdbf2e6ccf885d1069bb4b3ef78d18d93671.tar.gz KVIrc-48dacdbf2e6ccf885d1069bb4b3ef78d18d93671.tar.bz2 KVIrc-48dacdbf2e6ccf885d1069bb4b3ef78d18d93671.zip | |
Input History: Added skipping of input lines if consecutive lines are the same
* Skips adding line to the Input History if the previous line in the history
is the exact same as the new line.
* Added disabling of global input history button when boolEnableInputHistory
is set to false.
* Fixes KviInput::applyOptions() where previously it was adding additional
signal connections every time new settings were applied to KVIrc, causing
multiple of the same signal to be called for historyButtonClicked().
* Fixes issue where global input history was reversed upon being loaded from
config file.
| -rw-r--r-- | src/kvirc/ui/KviInput.cpp | 31 | ||||
| -rw-r--r-- | src/kvirc/ui/KviInputEditor.cpp | 32 | ||||
| -rw-r--r-- | src/kvirc/ui/KviInputEditor.h | 5 | ||||
| -rw-r--r-- | src/kvirc/ui/KviInputHistory.cpp | 13 | ||||
| -rw-r--r-- | src/kvirc/ui/KviInputHistory.h | 2 |
5 files changed, 48 insertions, 35 deletions
diff --git a/src/kvirc/ui/KviInput.cpp b/src/kvirc/ui/KviInput.cpp index eab5cd9e5..f08d46fda 100644 --- a/src/kvirc/ui/KviInput.cpp +++ b/src/kvirc/ui/KviInput.cpp @@ -114,6 +114,7 @@ KviInput::KviInput(KviWindow * pPar, KviUserListView * pView) { is1.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::HistoryOff))); m_pHistoryButton->setIcon(is1); + m_pHistoryButton->setEnabled(false); KviTalToolTip::add(m_pHistoryButton, __tr2qs("Input history disabled")); } @@ -137,7 +138,7 @@ KviInput::KviInput(KviWindow * pPar, KviUserListView * pView) is0.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::SayKvs)), QIcon::Normal, QIcon::Off); m_pCommandlineModeButton->setIcon(is0); KviTalToolTip::add(m_pCommandlineModeButton, __tr2qs("User friendly command-line mode Ctrl+Y<br>See also /help commandline")); - + if(KVI_OPTION_BOOL(KviOption_boolCommandlineInUserFriendlyModeByDefault)) m_pCommandlineModeButton->setChecked(true); @@ -405,19 +406,27 @@ void KviInput::applyOptions() { if(KVI_OPTION_BOOL(KviOption_boolEnableInputHistory)) { - QIcon is1; - is1.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::History))); - m_pHistoryButton->setIcon(is1); - KviTalToolTip::add(m_pHistoryButton, __tr2qs("Show history Ctrl+PageUp")); - connect(m_pHistoryButton, SIGNAL(clicked()), this, SLOT(historyButtonClicked())); + if(!m_pHistoryButton->isEnabled()) + { + QIcon is1; + is1.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::History))); + m_pHistoryButton->setIcon(is1); + m_pHistoryButton->setEnabled(true); + KviTalToolTip::add(m_pHistoryButton, __tr2qs("Show history Ctrl+PageUp")); + connect(m_pHistoryButton, SIGNAL(clicked()), this, SLOT(historyButtonClicked())); + } } else { - QIcon is1; - is1.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::HistoryOff))); - m_pHistoryButton->setIcon(is1); - KviTalToolTip::add(m_pHistoryButton, __tr2qs("Input history disabled")); - m_pHistoryButton->disconnect(SIGNAL(clicked())); + if(m_pHistoryButton->isEnabled()) + { + QIcon is1; + is1.addPixmap(*(g_pIconManager->getSmallIcon(KviIconManager::HistoryOff))); + m_pHistoryButton->setIcon(is1); + m_pHistoryButton->setEnabled(false); + KviTalToolTip::add(m_pHistoryButton, __tr2qs("Input history disabled")); + m_pHistoryButton->disconnect(SIGNAL(clicked())); + } } m_pInputEditor->applyOptions(); diff --git a/src/kvirc/ui/KviInputEditor.cpp b/src/kvirc/ui/KviInputEditor.cpp index 14931ae31..80ac826f1 100644 --- a/src/kvirc/ui/KviInputEditor.cpp +++ b/src/kvirc/ui/KviInputEditor.cpp @@ -1692,22 +1692,18 @@ void KviInputEditor::handleDragSelection() void KviInputEditor::finishInput() { - if(!m_szTextBuffer.isEmpty() /* && (!m_History->current() || m_szTextBuffer.compare(*(m_History->current())))*/) + if(!m_szTextBuffer.isEmpty()) { if(m_pInputParent->inherits("KviInput")) KviInputHistory::instance()->add(m_szTextBuffer); - m_History.insert(m_History.begin(), m_szTextBuffer); + addToHistory(m_szTextBuffer); } //ensure the color window is hidden (bug #835) if(g_pColorWindow && g_pColorWindow->isVisible()) g_pColorWindow->hide(); - KVI_ASSERT(KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES > 1); //ABSOLUTELY NEEDED, if not, pHist will be destroyed... - if(m_History.size() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES) - m_History.pop_back(); - m_iCurHistoryIdx = -1; } @@ -3145,14 +3141,9 @@ void KviInputEditor::sendPlain() if(!szBuffer.isEmpty()) { KviInputHistory::instance()->add(szBuffer); - m_History.insert(m_History.begin(), szBuffer); + addToHistory(szBuffer); } - KVI_ASSERT(KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES > 1); //ABSOLUTELY NEEDED, if not, pHist will be destroyed... - - if(m_History.size() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES) - m_History.pop_back(); - m_iCurHistoryIdx = -1; } @@ -3181,14 +3172,9 @@ void KviInputEditor::sendKvs() if(!szBuffer.isEmpty()) { KviInputHistory::instance()->add(szBuffer); - m_History.insert(m_History.begin(), szBuffer); + addToHistory(szBuffer); } - KVI_ASSERT(KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES > 1); //ABSOLUTELY NEEDED, if not, pHist will be destroyed... - - if(m_History.size() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES) - m_History.pop_back(); - m_iCurHistoryIdx = -1; } @@ -3392,3 +3378,13 @@ void KviInputEditor::dummy() { } // this function does nothing. check the header file for explanation +void KviInputEditor::addToHistory(const QString &szString) +{ + if(!m_History.empty() && m_History.front() == szString) + return; + + m_History.insert(m_History.begin(), szString); + + if(m_History.size() > KVI_INPUT_MAX_LOCAL_HISTORY_ENTRIES) + m_History.pop_back(); +} diff --git a/src/kvirc/ui/KviInputEditor.h b/src/kvirc/ui/KviInputEditor.h index 44b6df638..3e407cbe2 100644 --- a/src/kvirc/ui/KviInputEditor.h +++ b/src/kvirc/ui/KviInputEditor.h @@ -949,6 +949,11 @@ private slots: */ void spellCheckerPopupCorrectionActionTriggered(); + /** + * Adds line to input history + */ + void addToHistory(const QString & szString); + protected: void insertIconCode(const QString & szCode); void completionEscapeUnsafeToken(QString & szToken); diff --git a/src/kvirc/ui/KviInputHistory.cpp b/src/kvirc/ui/KviInputHistory.cpp index 3cc53ec34..5f46ad0d9 100644 --- a/src/kvirc/ui/KviInputHistory.cpp +++ b/src/kvirc/ui/KviInputHistory.cpp @@ -61,11 +61,14 @@ void KviInputHistory::delRef() m_uCount--; } -void KviInputHistory::add(QString szString) +void KviInputHistory::add(const QString & szString) { - m_StringList.insert(m_StringList.begin(), std::move(szString)); + if(!m_StringList.empty() && m_StringList.back() == szString) + return; + + m_StringList.push_back(szString); if(m_StringList.size() > KVI_INPUT_MAX_GLOBAL_HISTORY_ENTRIES) - m_StringList.pop_back(); + m_StringList.erase(m_StringList.begin()); } void KviInputHistory::load(const QString & szFileName) @@ -93,8 +96,6 @@ void KviInputHistory::save(const QString & szFileName) KviConfigurationFile c(szFileName, KviConfigurationFile::Write); c.clear(); - c.writeEntry("Count", static_cast<unsigned>(m_StringList.size())); - KviCString szTmp; int iIdx = 0; @@ -107,4 +108,6 @@ void KviInputHistory::save(const QString & szFileName) iIdx++; } } + + c.writeEntry("Count", iIdx); } diff --git a/src/kvirc/ui/KviInputHistory.h b/src/kvirc/ui/KviInputHistory.h index 7dd7255ca..068401a86 100644 --- a/src/kvirc/ui/KviInputHistory.h +++ b/src/kvirc/ui/KviInputHistory.h @@ -101,7 +101,7 @@ public: * \param szString The string to add * \return void */ - void add(QString szString); + void add(const QString & szString); /** * \brief Returns the list of string in the history |
