diff --git a/src/plugins/git/changeselectiondialog.cpp b/src/plugins/git/changeselectiondialog.cpp index d260b356529..167d12ed039 100644 --- a/src/plugins/git/changeselectiondialog.cpp +++ b/src/plugins/git/changeselectiondialog.cpp @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include namespace Git { namespace Internal { @@ -60,8 +63,9 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co m_ui->changeNumberEdit->setFocus(); m_ui->changeNumberEdit->selectAll(); - connect(m_ui->changeNumberEdit, SIGNAL(textChanged(QString)), this, SLOT(recalculateDetails())); + connect(m_ui->changeNumberEdit, SIGNAL(textChanged(QString)), this, SLOT(changeTextChanged(QString))); connect(m_ui->workingDirectoryEdit, SIGNAL(textChanged(QString)), this, SLOT(recalculateDetails())); + connect(m_ui->workingDirectoryEdit, SIGNAL(textChanged(QString)), this, SLOT(recalculateCompletion())); connect(m_ui->selectDirectoryButton, SIGNAL(clicked()), this, SLOT(chooseWorkingDirectory())); connect(m_ui->selectFromHistoryButton, SIGNAL(clicked()), this, SLOT(selectCommitFromRecentHistory())); connect(m_ui->showButton, SIGNAL(clicked()), this, SLOT(acceptShow())); @@ -77,7 +81,13 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co m_ui->checkoutButton->setDefault(true); else m_ui->showButton->setDefault(true); + m_changeModel = new QStringListModel(this); + QCompleter *changeCompleter = new QCompleter(m_changeModel, this); + m_ui->changeNumberEdit->setCompleter(changeCompleter); + changeCompleter->setCaseSensitivity(Qt::CaseInsensitive); + recalculateDetails(); + recalculateCompletion(); } ChangeSelectionDialog::~ChangeSelectionDialog() @@ -188,6 +198,26 @@ void ChangeSelectionDialog::enableButtons(bool b) m_ui->checkoutButton->setEnabled(b); } +void ChangeSelectionDialog::recalculateCompletion() +{ + const QString workingDir = workingDirectory(); + if (workingDir == m_oldWorkingDir) + return; + m_oldWorkingDir = workingDir; + + if (!workingDir.isEmpty()) { + GitClient *client = GitPlugin::instance()->gitClient(); + QStringList args; + args << QLatin1String("--format=%(refname:short)"); + QString output; + if (client->synchronousForEachRefCmd(workingDir, args, &output)) { + m_changeModel->setStringList(output.split(QLatin1Char('\n'))); + return; + } + } + m_changeModel->setStringList(QStringList()); +} + void ChangeSelectionDialog::recalculateDetails() { if (m_process) { @@ -233,5 +263,16 @@ void ChangeSelectionDialog::recalculateDetails() m_ui->detailsText->setPlainText(tr("Fetching commit data...")); } +void ChangeSelectionDialog::changeTextChanged(const QString &text) +{ + if (QCompleter *comp = m_ui->changeNumberEdit->completer()) { + if (text.isEmpty() && !comp->popup()->isVisible()) { + comp->setCompletionPrefix(text); + QTimer::singleShot(0, comp, SLOT(complete())); + } + } + recalculateDetails(); +} + } // Internal } // Git diff --git a/src/plugins/git/changeselectiondialog.h b/src/plugins/git/changeselectiondialog.h index fe441f2ec3d..c1ab0b2b6a0 100644 --- a/src/plugins/git/changeselectiondialog.h +++ b/src/plugins/git/changeselectiondialog.h @@ -41,6 +41,7 @@ class QLabel; class QLineEdit; class QPlainTextEdit; class QProcess; +class QStringListModel; QT_END_NAMESPACE namespace Git { @@ -72,7 +73,9 @@ private slots: void chooseWorkingDirectory(); void selectCommitFromRecentHistory(); void setDetails(int exitCode); + void recalculateCompletion(); void recalculateDetails(); + void changeTextChanged(const QString &text); void acceptCheckout(); void acceptCherryPick(); void acceptRevert(); @@ -87,6 +90,8 @@ private: QString m_gitBinaryPath; QProcessEnvironment m_gitEnvironment; ChangeCommand m_command; + QStringListModel *m_changeModel; + QString m_oldWorkingDir; }; } // namespace Internal diff --git a/src/plugins/git/changeselectiondialog.ui b/src/plugins/git/changeselectiondialog.ui index 5fd084858c2..8fe291169fa 100644 --- a/src/plugins/git/changeselectiondialog.ui +++ b/src/plugins/git/changeselectiondialog.ui @@ -39,7 +39,7 @@ - + HEAD @@ -119,6 +119,13 @@ + + + Utils::CompletingLineEdit + QLineEdit +
utils/completinglineedit.h
+
+