//----------------------------------------------------------------------------- // Purpose: auto completes current text //----------------------------------------------------------------------------- void CConsolePanel::OnAutoComplete(bool reverse) { if (!m_bAutoCompleteMode) { // we're not in auto-complete mode, Start m_iNextCompletion = 0; m_bAutoCompleteMode = true; } // if we're in reverse, move back to before the current if (reverse) { m_iNextCompletion -= 2; if (m_iNextCompletion < 0) { // loop around in reverse m_iNextCompletion = m_CompletionList.Size() - 1; } } // get the next completion if (!m_CompletionList.IsValidIndex(m_iNextCompletion)) { // loop completion list m_iNextCompletion = 0; } // make sure everything is still valid if (!m_CompletionList.IsValidIndex(m_iNextCompletion)) return; // match found, set text char completedText[256]; CompletionItem *item = m_CompletionList[m_iNextCompletion]; Assert( item ); if ( !item->m_bIsCommand && item->m_pCommand ) { Q_strncpy(completedText, item->GetCommand(), sizeof(completedText) - 2 ); } else { Q_strncpy(completedText, item->GetItemText(), sizeof(completedText) - 2 ); } if ( !Q_strstr( completedText, " " ) ) { Q_strncat(completedText, " ", sizeof(completedText), COPY_ALL_CHARACTERS ); } m_pEntry->SetText(completedText); m_pEntry->GotoTextEnd(); m_pEntry->SelectNone(); m_iNextCompletion++; }
void CConsolePanel::OnAutoComplete(bool reverse) { if (!m_bAutoCompleteMode) { m_iNextCompletion = 0; m_bAutoCompleteMode = true; } if (reverse) { m_iNextCompletion -= 2; if (m_iNextCompletion < 0) { m_iNextCompletion = m_CompletionList.Size() - 1; } } if (!m_CompletionList.IsValidIndex(m_iNextCompletion)) { m_iNextCompletion = 0; } if (!m_CompletionList.IsValidIndex(m_iNextCompletion)) return; char completedText[256]; CompletionItem *item = m_CompletionList[m_iNextCompletion]; Assert( item ); Q_strncpy(completedText, item->GetItemText(), sizeof(completedText) - 2 ); if ( !Q_strstr( completedText, " " ) ) { Q_strncat(completedText, " ", sizeof(completedText), COPY_ALL_CHARACTERS ); } m_pEntry->SetText(completedText); m_pEntry->SelectNone(); m_pEntry->GotoTextEnd(); m_iNextCompletion++; }