Commit 6669e8ea authored by hjk's avatar hjk

KitChooser: Add a 'Manage' button for quick setting access

Change-Id: I0f90075ed6549b1e5093d8cc81975bc46acf38fb
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 242ad7e5
......@@ -43,6 +43,7 @@
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
#include <QDebug>
#include <QDialogButtonBox>
#include <QDir>
......
......@@ -109,6 +109,7 @@
# include <utils/winutils.h>
#endif
#include <QComboBox>
#include <QDockWidget>
#include <QFileDialog>
#include <QInputDialog>
......
......@@ -316,7 +316,7 @@ bool AttachCoreDialog::useLocalCoreFile() const
void AttachCoreDialog::changed()
{
bool isValid = d->kitChooser->currentIndex() >= 0 && d->localExecFileName->isValid();
bool isValid = d->kitChooser->currentKit() && d->localExecFileName->isValid();
bool isKitLocal = isLocalKit();
d->forceLocalLabel->setVisible(!isKitLocal);
......
......@@ -47,6 +47,7 @@
#include <QDebug>
#include <QProcess>
#include <QtAlgorithms>
#include <QTabWidget>
#include <QTextEdit>
#include <ctype.h>
......
......@@ -33,6 +33,11 @@
#include "kitmanager.h"
#include <coreplugin/icore.h>
#include <projectexplorerconstants.h>
#include <QComboBox>
#include <QHBoxLayout>
#include <QPushButton>
#include <QSettings>
namespace ProjectExplorer {
......@@ -40,9 +45,25 @@ namespace ProjectExplorer {
const char lastKitKey[] = "LastSelectedKit";
KitChooser::KitChooser(QWidget *parent) :
QComboBox(parent)
QWidget(parent)
{
m_chooser = new QComboBox(this);
m_manageButton = new QPushButton(tr("Manage..."), this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_chooser);
layout->addWidget(m_manageButton);
connect(m_chooser, SIGNAL(currentIndexChanged(int)), SLOT(onCurrentIndexChanged(int)));
connect(m_manageButton, SIGNAL(clicked()), SLOT(onManageButtonClicked()));
connect(KitManager::instance(), SIGNAL(kitsChanged()), SLOT(populate()));
}
void KitChooser::onManageButtonClicked()
{
connect(this, SIGNAL(currentIndexChanged(int)), SLOT(onCurrentIndexChanged(int)));
Core::ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID, this);
}
void KitChooser::onCurrentIndexChanged(int index)
......@@ -51,6 +72,7 @@ void KitChooser::onCurrentIndexChanged(int index)
setToolTip(kitToolTip(kit));
else
setToolTip(QString());
emit currentIndexChanged(index);
}
bool KitChooser::kitMatches(const Kit *k) const
......@@ -70,31 +92,31 @@ QString KitChooser::kitToolTip(Kit *k) const
void KitChooser::populate()
{
clear();
m_chooser->clear();
foreach (Kit *kit, KitManager::kits()) {
if (kitMatches(kit)) {
addItem(kitText(kit), qVariantFromValue(kit->id()));
setItemData(count() - 1, kitToolTip(kit), Qt::ToolTipRole);
m_chooser->addItem(kitText(kit), qVariantFromValue(kit->id()));
m_chooser->setItemData(m_chooser->count() - 1, kitToolTip(kit), Qt::ToolTipRole);
}
}
setEnabled(count() > 1);
m_chooser->setEnabled(m_chooser->count() > 1);
const int index = Core::ICore::settings()->value(QLatin1String(lastKitKey)).toInt();
setCurrentIndex(qMin(index, count()));
m_chooser->setCurrentIndex(qMin(index, m_chooser->count()));
}
Kit *KitChooser::currentKit() const
{
const int index = currentIndex();
const int index = m_chooser->currentIndex();
Core::ICore::settings()->setValue(QLatin1String(lastKitKey), index);
return index == -1 ? 0 : kitAt(index);
}
void KitChooser::setCurrentKitId(Core::Id id)
{
for (int i = 0, n = count(); i != n; ++i) {
for (int i = 0, n = m_chooser->count(); i != n; ++i) {
if (kitAt(i)->id() == id) {
setCurrentIndex(i);
m_chooser->setCurrentIndex(i);
break;
}
}
......@@ -108,7 +130,7 @@ Core::Id KitChooser::currentKitId() const
Kit *KitChooser::kitAt(int index) const
{
Core::Id id = qvariant_cast<Core::Id>(itemData(index));
Core::Id id = qvariant_cast<Core::Id>(m_chooser->itemData(index));
return KitManager::find(id);
}
......
......@@ -32,7 +32,12 @@
#include "projectexplorer_export.h"
#include <QComboBox>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace Core { class Id; }
......@@ -41,7 +46,7 @@ namespace ProjectExplorer {
class Kit;
// Let the user pick a kit.
class PROJECTEXPLORER_EXPORT KitChooser : public QComboBox
class PROJECTEXPLORER_EXPORT KitChooser : public QWidget
{
Q_OBJECT
......@@ -53,11 +58,15 @@ public:
Kit *currentKit() const;
signals:
void currentIndexChanged(int);
public slots:
void populate();
private slots:
void onCurrentIndexChanged(int index);
void onManageButtonClicked();
protected:
virtual bool kitMatches(const Kit *k) const;
......@@ -66,6 +75,8 @@ protected:
private:
Kit *kitAt(int index) const;
QComboBox *m_chooser;
QPushButton *m_manageButton;
};
} // namespace ProjectExplorer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment