Move debugger kit settings into a separate dialog.

Change the DebuggerKitConfigWidget to contain a display label
only. Add a Button with a menu for "Autodetect" and
"Edit...".

Change-Id: I8ec17966ef220c81fb8b145a61df4408d5950da9
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Friedemann Kleint
2012-09-11 14:03:08 +02:00
parent d02d67d58c
commit d339637701
5 changed files with 153 additions and 71 deletions

View File

@@ -137,7 +137,7 @@ bool DebuggerKitChooser::kitMatches(const ProjectExplorer::Kit *k) const
QString DebuggerKitChooser::kitToolTip(Kit *k) const QString DebuggerKitChooser::kitToolTip(Kit *k) const
{ {
return DebuggerKitInformation::userOutput(k); return DebuggerKitInformation::userOutput(DebuggerKitInformation::debuggerItem(k));
} }
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////

View File

@@ -45,10 +45,14 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel> #include <QLabel>
#include <QComboBox> #include <QComboBox>
#include <QMenu>
#include <QAction>
#include <QPushButton>
#include <QDialogButtonBox>
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
@@ -67,44 +71,30 @@ DebuggerKitConfigWidget::DebuggerKitConfigWidget(ProjectExplorer::Kit *k,
ProjectExplorer::KitConfigWidget(parent), ProjectExplorer::KitConfigWidget(parent),
m_kit(k), m_kit(k),
m_info(ki), m_info(ki),
m_comboBox(new QComboBox(this)), m_dirty(false),
m_label(new QLabel(this)), m_label(new QLabel(this)),
m_chooser(new Utils::PathChooser(this)) m_button(new QPushButton(tr("Manage..."), this))
{ {
setToolTip(tr("The debugger to use for this kit.")); setToolTip(tr("The debugger to use for this kit."));
QVBoxLayout *layout = new QVBoxLayout(this); QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0); layout->setMargin(0);
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(GdbEngineType), QVariant(int(GdbEngineType)));
if (ProjectExplorer::Abi::hostAbi().os() == ProjectExplorer::Abi::WindowsOS) {
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(CdbEngineType), QVariant(int(CdbEngineType)));
} else {
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(LldbEngineType), QVariant(int(LldbEngineType)));
}
layout->addWidget(m_comboBox);
m_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
m_label->setOpenExternalLinks(true);
layout->addWidget(m_label); layout->addWidget(m_label);
m_chooser->setContentsMargins(0, 0, 0, 0); // ToolButton with Menu, defaulting to 'Autodetect'.
m_chooser->setExpectedKind(Utils::PathChooser::ExistingCommand); QMenu *buttonMenu = new QMenu(m_button);
m_chooser->insertButton(0, tr("Auto detect"), this, SLOT(autoDetectDebugger())); QAction *autoDetectAction = buttonMenu->addAction(tr("Auto-detect"));
connect(autoDetectAction, SIGNAL(triggered()), this, SLOT(autoDetectDebugger()));
layout->addWidget(m_chooser); QAction *changeAction = buttonMenu->addAction(tr("Edit..."));
connect(changeAction, SIGNAL(triggered()), this, SLOT(showDialog()));
m_button->setMenu(buttonMenu);
discard(); discard();
connect(m_chooser, SIGNAL(changed(QString)), this, SIGNAL(dirty()));
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dirty()));
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshLabel()));
} }
void DebuggerKitConfigWidget::addToLayout(QGridLayout *layout, int row) QWidget *DebuggerKitConfigWidget::buttonWidget() const
{ {
addLabel(layout, row); return m_button;
layout->addWidget(this, row, WidgetColumn, 3 , 1);
addButtonWidget(layout, row + 2);
} }
QString DebuggerKitConfigWidget::displayName() const QString DebuggerKitConfigWidget::displayName() const
@@ -114,47 +104,99 @@ QString DebuggerKitConfigWidget::displayName() const
void DebuggerKitConfigWidget::makeReadOnly() void DebuggerKitConfigWidget::makeReadOnly()
{ {
m_comboBox->setEnabled(false); m_button->setEnabled(false);
m_chooser->setEnabled(false);
} }
void DebuggerKitConfigWidget::apply() void DebuggerKitConfigWidget::apply()
{ {
DebuggerKitInformation::setDebuggerItem(m_kit, DebuggerKitInformation::DebuggerItem(engineType(), fileName())); DebuggerKitInformation::setDebuggerItem(m_kit, m_item);
m_dirty = false;
} }
void DebuggerKitConfigWidget::discard() void DebuggerKitConfigWidget::discard()
{ {
const DebuggerKitInformation::DebuggerItem item = DebuggerKitInformation::debuggerItem(m_kit); doSetItem(DebuggerKitInformation::debuggerItem(m_kit));
setEngineType(item.engineType); m_dirty = false;
setFileName(item.binary);
}
bool DebuggerKitConfigWidget::isDirty() const
{
const DebuggerKitInformation::DebuggerItem item = DebuggerKitInformation::debuggerItem(m_kit);
return item.engineType != engineType() || item.binary != fileName();
}
QWidget *DebuggerKitConfigWidget::buttonWidget() const
{
return m_chooser->buttonAtIndex(1);
} }
void DebuggerKitConfigWidget::autoDetectDebugger() void DebuggerKitConfigWidget::autoDetectDebugger()
{ {
const DebuggerKitInformation::DebuggerItem item = DebuggerKitInformation::autoDetectItem(m_kit); setItem(DebuggerKitInformation::autoDetectItem(m_kit));
setEngineType(item.engineType);
setFileName(item.binary);
} }
DebuggerEngineType DebuggerKitConfigWidget::engineType() const void DebuggerKitConfigWidget::doSetItem(const DebuggerKitInformation::DebuggerItem &item)
{
m_item = item;
m_label->setText(DebuggerKitInformation::userOutput(m_item));
}
void DebuggerKitConfigWidget::setItem(const DebuggerKitInformation::DebuggerItem &item)
{
if (m_item != item) {
m_dirty = true;
doSetItem(item);
emit dirty();
}
}
void DebuggerKitConfigWidget::showDialog()
{
DebuggerKitConfigDialog dialog;
dialog.setWindowTitle(tr("Debugger for \"%1\"").arg(m_kit->displayName()));
dialog.setDebuggerItem(m_item);
if (dialog.exec() == QDialog::Accepted)
setItem(dialog.item());
}
// -----------------------------------------------------------------------
// DebuggerKitConfigDialog:
// -----------------------------------------------------------------------
DebuggerKitConfigDialog::DebuggerKitConfigDialog(QWidget *parent)
: QDialog(parent)
, m_comboBox(new QComboBox(this))
, m_label(new QLabel(this))
, m_chooser(new Utils::PathChooser(this))
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *layout = new QVBoxLayout(this);
QFormLayout *formLayout = new QFormLayout;
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(GdbEngineType), QVariant(int(GdbEngineType)));
if (ProjectExplorer::Abi::hostAbi().os() == ProjectExplorer::Abi::WindowsOS) {
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(CdbEngineType), QVariant(int(CdbEngineType)));
} else {
m_comboBox->addItem(DebuggerKitInformation::debuggerEngineName(LldbEngineType), QVariant(int(LldbEngineType)));
}
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(refreshLabel()));
QLabel *engineTypeLabel = new QLabel(tr("&Engine:"));
engineTypeLabel->setBuddy(m_comboBox);
formLayout->addRow(engineTypeLabel, m_comboBox);
m_label->setTextInteractionFlags(Qt::TextBrowserInteraction);
m_label->setOpenExternalLinks(true);
formLayout->addRow(m_label);
QLabel *binaryLabel = new QLabel(tr("&Binary:"));
m_chooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
binaryLabel->setBuddy(m_chooser);
formLayout->addRow(binaryLabel, m_chooser);
layout->addLayout(formLayout);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
layout->addWidget(buttonBox);
}
DebuggerEngineType DebuggerKitConfigDialog::engineType() const
{ {
const int index = m_comboBox->currentIndex(); const int index = m_comboBox->currentIndex();
return static_cast<DebuggerEngineType>(m_comboBox->itemData(index).toInt()); return static_cast<DebuggerEngineType>(m_comboBox->itemData(index).toInt());
} }
void DebuggerKitConfigWidget::setEngineType(DebuggerEngineType et) void DebuggerKitConfigDialog::setEngineType(DebuggerEngineType et)
{ {
const int size = m_comboBox->count(); const int size = m_comboBox->count();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
@@ -166,17 +208,17 @@ void DebuggerKitConfigWidget::setEngineType(DebuggerEngineType et)
} }
} }
Utils::FileName DebuggerKitConfigWidget::fileName() const Utils::FileName DebuggerKitConfigDialog::fileName() const
{ {
return m_chooser->fileName(); return m_chooser->fileName();
} }
void DebuggerKitConfigWidget::setFileName(const Utils::FileName &fn) void DebuggerKitConfigDialog::setFileName(const Utils::FileName &fn)
{ {
m_chooser->setFileName(fn); m_chooser->setFileName(fn);
} }
void DebuggerKitConfigWidget::refreshLabel() void DebuggerKitConfigDialog::refreshLabel()
{ {
QString text; QString text;
const DebuggerEngineType type = engineType(); const DebuggerEngineType type = engineType();
@@ -205,5 +247,11 @@ void DebuggerKitConfigWidget::refreshLabel()
QStringList(QLatin1String("--version"))); QStringList(QLatin1String("--version")));
} }
void DebuggerKitConfigDialog::setDebuggerItem(const DebuggerKitInformation::DebuggerItem &item)
{
setEngineType(item.engineType);
setFileName(item.binary);
}
} // namespace Internal } // namespace Internal
} // namespace Debugger } // namespace Debugger

View File

@@ -33,10 +33,15 @@
#include <projectexplorer/kitconfigwidget.h> #include <projectexplorer/kitconfigwidget.h>
#include "debuggerconstants.h" #include "debuggerkitinformation.h"
QT_FORWARD_DECLARE_CLASS(QLabel) #include <QDialog>
QT_FORWARD_DECLARE_CLASS(QComboBox)
QT_BEGIN_NAMESPACE
class QLabel;
class QComboBox;
class QPushButton;
QT_END_NAMESPACE
namespace ProjectExplorer { class Kit; } namespace ProjectExplorer { class Kit; }
namespace Utils { namespace Utils {
@@ -67,23 +72,45 @@ public:
void apply(); void apply();
void discard(); void discard();
bool isDirty() const; bool isDirty() const { return m_dirty; }
QWidget *buttonWidget() const; QWidget *buttonWidget() const;
void addToLayout(QGridLayout *layout, int row);
private slots:
void autoDetectDebugger();
void showDialog();
private:
void setItem(const DebuggerKitInformation::DebuggerItem &item);
void doSetItem(const DebuggerKitInformation::DebuggerItem &item);
ProjectExplorer::Kit *m_kit;
const DebuggerKitInformation *m_info;
DebuggerKitInformation::DebuggerItem m_item;
bool m_dirty;
QLabel *m_label;
QPushButton *m_button;
};
class DebuggerKitConfigDialog : public QDialog
{
Q_OBJECT
public:
explicit DebuggerKitConfigDialog(QWidget *parent = 0);
void setDebuggerItem(const DebuggerKitInformation::DebuggerItem &item);
DebuggerKitInformation::DebuggerItem item() const
{ return DebuggerKitInformation::DebuggerItem(engineType(), fileName()); }
private slots:
void refreshLabel();
private:
DebuggerEngineType engineType() const; DebuggerEngineType engineType() const;
void setEngineType(DebuggerEngineType et); void setEngineType(DebuggerEngineType et);
Utils::FileName fileName() const; Utils::FileName fileName() const;
void setFileName(const Utils::FileName &fn); void setFileName(const Utils::FileName &fn);
private slots:
void autoDetectDebugger();
void refreshLabel();
private:
ProjectExplorer::Kit *m_kit;
const DebuggerKitInformation *m_info;
QComboBox *m_comboBox; QComboBox *m_comboBox;
QLabel *m_label; QLabel *m_label;
Utils::PathChooser *m_chooser; Utils::PathChooser *m_chooser;

View File

@@ -269,16 +269,17 @@ KitConfigWidget *DebuggerKitInformation::createConfigWidget(Kit *k) const
return new Internal::DebuggerKitConfigWidget(k, this); return new Internal::DebuggerKitConfigWidget(k, this);
} }
QString DebuggerKitInformation::userOutput(const ProjectExplorer::Kit *k) QString DebuggerKitInformation::userOutput(const DebuggerItem &item)
{ {
const DebuggerItem item = DebuggerKitInformation::debuggerItem(k); const QString binary = item.binary.toUserOutput();
return tr("%1 using '%2'").arg(debuggerEngineName(item.engineType), return binary.isEmpty() ?
item.binary.toUserOutput()); tr("%1 <None>").arg(debuggerEngineName(item.engineType)) :
tr("%1 using '%2'").arg(debuggerEngineName(item.engineType), binary);
} }
KitInformation::ItemList DebuggerKitInformation::toUserOutput(Kit *k) const KitInformation::ItemList DebuggerKitInformation::toUserOutput(Kit *k) const
{ {
return ItemList() << qMakePair(tr("Debugger"), DebuggerKitInformation::userOutput(k)); return ItemList() << qMakePair(tr("Debugger"), DebuggerKitInformation::userOutput(DebuggerKitInformation::debuggerItem(k)));
} }
static const char engineTypeKeyC[] = "EngineType"; static const char engineTypeKeyC[] = "EngineType";

View File

@@ -47,6 +47,7 @@ public:
public: public:
DebuggerItem(); DebuggerItem();
DebuggerItem(DebuggerEngineType engineType, const Utils::FileName &fn); DebuggerItem(DebuggerEngineType engineType, const Utils::FileName &fn);
bool equals(const DebuggerItem &rhs) const { return engineType == rhs.engineType && binary == rhs.binary; }
DebuggerEngineType engineType; DebuggerEngineType engineType;
Utils::FileName binary; Utils::FileName binary;
@@ -71,7 +72,7 @@ public:
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const; ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const;
ItemList toUserOutput(ProjectExplorer::Kit *k) const; ItemList toUserOutput(ProjectExplorer::Kit *k) const;
static QString userOutput(const ProjectExplorer::Kit *k); static QString userOutput(const DebuggerItem &item);
static DebuggerItem debuggerItem(const ProjectExplorer::Kit *p); static DebuggerItem debuggerItem(const ProjectExplorer::Kit *p);
static void setDebuggerItem(ProjectExplorer::Kit *p, const DebuggerItem &item); static void setDebuggerItem(ProjectExplorer::Kit *p, const DebuggerItem &item);
@@ -93,6 +94,11 @@ private:
static QVariant itemToVariant(const DebuggerItem &i); static QVariant itemToVariant(const DebuggerItem &i);
}; };
inline bool operator==(const DebuggerKitInformation::DebuggerItem &i1, const DebuggerKitInformation::DebuggerItem &i2)
{ return i1.equals(i2); }
inline bool operator!=(const DebuggerKitInformation::DebuggerItem &i1, const DebuggerKitInformation::DebuggerItem &i2)
{ return !i1.equals(i2); }
} // namespace Debugger } // namespace Debugger
#endif // DEBUGGER_DEBUGGERKITINFORMATION_H #endif // DEBUGGER_DEBUGGERKITINFORMATION_H