From 0bcc8094022b9d50c8db5f1b9c09692aa04c55a0 Mon Sep 17 00:00:00 2001 From: con Date: Wed, 2 Feb 2011 17:04:51 +0100 Subject: [PATCH] Use the add button for adding categories. --- .../coreplugin/dialogs/externaltoolconfig.cpp | 34 +++++++++++++++++-- .../coreplugin/dialogs/externaltoolconfig.h | 1 + .../coreplugin/dialogs/externaltoolconfig.ui | 15 +++----- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index 61768f674aa..a7d2361dd0f 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using namespace Core; using namespace Core::Internal; @@ -73,6 +74,12 @@ ExternalToolConfig::ExternalToolConfig(QWidget *parent) : connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addTool())); connect(ui->removeButton, SIGNAL(clicked()), this, SLOT(removeTool())); + QMenu *menu = new QMenu(ui->addButton); + ui->addButton->setMenu(menu); + QAction *addCategory = new QAction(tr("Add Category"), this); + menu->addAction(addCategory); + connect(addCategory, SIGNAL(triggered()), this, SLOT(addCategory())); + showInfoForItem(0); updateButtons(ui->toolTree->currentItem()); } @@ -143,7 +150,6 @@ void ExternalToolConfig::handleCurrentItemChanged(QTreeWidgetItem *now, QTreeWid void ExternalToolConfig::updateButtons(QTreeWidgetItem *item) { ExternalTool *tool = 0; - ui->addButton->setEnabled(item != 0); if (item) tool = item->data(0, Qt::UserRole).value(); if (!tool) { @@ -313,7 +319,10 @@ void ExternalToolConfig::addTool() { // find category to use QTreeWidgetItem *currentItem = ui->toolTree->currentItem(); - QTC_ASSERT(currentItem, return); + if (!currentItem) { + addCategory(); + return; + } QString category; QTreeWidgetItem *parent; if (currentItem->parent()) { @@ -361,3 +370,24 @@ void ExternalToolConfig::removeTool() delete currentItem; delete tool; } + +void ExternalToolConfig::addCategory() +{ + const QString &categoryBase = tr("New category"); + QString category = categoryBase; + int count = 0; + while (m_tools.contains(category)) { + ++count; + category = categoryBase + QString::number(count); + } + bool blocked = ui->toolTree->blockSignals(true); // block itemChanged + QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << category); + item->setFlags(TOOL_ITEM_FLAGS); + item->setData(0, Qt::UserRole, category); // save name for the renaming stuff + m_tools.insert(category, QList()); + int newIndex = m_tools.keys().indexOf(category); + ui->toolTree->insertTopLevelItem(newIndex, item); + ui->toolTree->blockSignals(blocked); // unblock itemChanged + ui->toolTree->setCurrentItem(item); + ui->toolTree->editItem(item); +} diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.h b/src/plugins/coreplugin/dialogs/externaltoolconfig.h index d9db9c80b1b..e412e3c2928 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.h +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.h @@ -70,6 +70,7 @@ private slots: void updateCurrentItem(); void addTool(); void removeTool(); + void addCategory(); private: Ui::ExternalToolConfig *ui; diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.ui b/src/plugins/coreplugin/dialogs/externaltoolconfig.ui index 9e8495e9b73..09261d8aca0 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.ui +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.ui @@ -42,6 +42,9 @@ p, li { white-space: pre-wrap; } + + + QToolButton::MenuButtonPopup + @@ -122,11 +125,7 @@ p, li { white-space: pre-wrap; } - - - Utils::PathChooser::Command - - + @@ -146,11 +145,7 @@ p, li { white-space: pre-wrap; } - - - Utils::PathChooser::Command - - +