Commit d768008d authored by con's avatar con

Add a tools settings page and show the tools there.

No editing possible yet.
parent b9f9cf3d
......@@ -88,7 +88,9 @@ SOURCES += mainwindow.cpp \
navigationsubwidget.cpp \
sidebarwidget.cpp \
rssfetcher.cpp \
externaltool.cpp
externaltool.cpp \
dialogs/externaltoolconfig.cpp \
toolsettings.cpp
HEADERS += mainwindow.h \
editmode.h \
......@@ -174,14 +176,17 @@ HEADERS += mainwindow.h \
navigationsubwidget.h \
sidebarwidget.h \
rssfetcher.h \
externaltool.h
externaltool.h \
dialogs/externaltoolconfig.h \
toolsettings.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \
dialogs/saveitemsdialog.ui \
dialogs/openwithdialog.ui \
editormanager/openeditorsview.ui \
generalsettings.ui
generalsettings.ui \
dialogs/externaltoolconfig.ui
RESOURCES += core.qrc \
fancyactionbar.qrc
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "externaltoolconfig.h"
#include "ui_externaltoolconfig.h"
#include <QtCore/QTextStream>
using namespace Core::Internal;
ExternalToolConfig::ExternalToolConfig(QWidget *parent) :
QWidget(parent),
ui(new Ui::ExternalToolConfig)
{
ui->setupUi(this);
connect(ui->toolTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
this, SLOT(showInfoForItem(QTreeWidgetItem*)));
showInfoForItem(0);
}
ExternalToolConfig::~ExternalToolConfig()
{
delete ui;
}
QString ExternalToolConfig::searchKeywords() const
{
QString keywords;
QTextStream(&keywords)
<< ui->descriptionLabel->text()
<< ui->executableLabel->text()
<< ui->argumentsLabel->text()
<< ui->workingDirectoryLabel->text()
<< ui->outputLabel->text()
<< ui->errorOutputLabel->text()
<< ui->inputCheckbox->text();
return keywords;
}
void ExternalToolConfig::setTools(const QMap<QString, QList<ExternalTool *> > &tools)
{
// TODO make copy of tools
QMapIterator<QString, QList<ExternalTool *> > categories(tools);
while (categories.hasNext()) {
categories.next();
QString name = (categories.key().isEmpty() ? tr("External Tools Menu") : categories.key());
QTreeWidgetItem *category = new QTreeWidgetItem(ui->toolTree, QStringList() << name);
foreach (ExternalTool *tool, categories.value()) {
QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList() << tool->displayName());
item->setData(0, Qt::UserRole, qVariantFromValue(tool));
}
}
ui->toolTree->expandAll();
}
void ExternalToolConfig::showInfoForItem(QTreeWidgetItem *item)
{
ExternalTool *tool = 0;
if (item)
tool = item->data(0, Qt::UserRole).value<ExternalTool *>();
if (!tool) {
ui->description->setText(QString());
ui->executable->setPath(QString());
ui->arguments->setText(QString());
ui->workingDirectory->setPath(QString());
ui->inputText->setPlainText(QString());
ui->infoWidget->setEnabled(false);
return;
}
ui->infoWidget->setEnabled(true);
ui->description->setText(tool->description());
ui->executable->setPath(tool->executables().isEmpty() ? QString() : tool->executables().first());
ui->arguments->setText(tool->arguments());
ui->workingDirectory->setPath(tool->workingDirectory());
ui->outputBehavior->setCurrentIndex((int)tool->outputHandling());
ui->errorOutputBehavior->setCurrentIndex((int)tool->errorHandling());
ui->inputCheckbox->setChecked(!tool->input().isEmpty());
ui->inputText->setPlainText(tool->input());
ui->description->setCursorPosition(0);
ui->arguments->setCursorPosition(0);
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef EXTERNALTOOLCONFIG_H
#define EXTERNALTOOLCONFIG_H
#include "coreplugin/externaltool.h"
#include <QtGui/QWidget>
#include <QtGui/QTreeWidgetItem>
namespace Core {
namespace Internal {
namespace Ui {
class ExternalToolConfig;
}
class ExternalToolConfig : public QWidget
{
Q_OBJECT
public:
explicit ExternalToolConfig(QWidget *parent = 0);
~ExternalToolConfig();
void setTools(const QMap<QString, QList<ExternalTool *> > &tools);
QString searchKeywords() const;
private slots:
void showInfoForItem(QTreeWidgetItem *item);
private:
Ui::ExternalToolConfig *ui;
};
} // Internal
} // Core
#endif // EXTERNALTOOLCONFIG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Core::Internal::ExternalToolConfig</class>
<widget class="QWidget" name="Core::Internal::ExternalToolConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>725</width>
<height>468</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="toolTree">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QWidget" name="infoWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="description"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="executableLabel">
<property name="text">
<string>Executable:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="executable">
<property name="expectedKind">
<enum>Utils::PathChooser::ExistingCommand</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="argumentsLabel">
<property name="text">
<string>Arguments:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="arguments"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="workingDirectoryLabel">
<property name="text">
<string>Working directory:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Utils::PathChooser" name="workingDirectory"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="outputLabel">
<property name="text">
<string>Output:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="outputBehavior">
<item>
<property name="text">
<string>Ignore</string>
</property>
</item>
<item>
<property name="text">
<string>Show in pane</string>
</property>
</item>
<item>
<property name="text">
<string>Replace selection</string>
</property>
</item>
<item>
<property name="text">
<string>Reload document</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="errorOutputLabel">
<property name="text">
<string>Error output:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="errorOutputBehavior">
<item>
<property name="text">
<string>Ignore</string>
</property>
</item>
<item>
<property name="text">
<string>Show in pane</string>
</property>
</item>
<item>
<property name="text">
<string>Replace selection</string>
</property>
</item>
<item>
<property name="text">
<string>Reload document</string>
</property>
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="inputCheckbox">
<property name="text">
<string>Input:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPlainTextEdit" name="inputText">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -446,6 +446,15 @@ void SettingsDialog::ensureAllCategoryWidgets()
ensureCategoryWidget(category);
}
void SettingsDialog::disconnectTabWidgets()
{
foreach (Category *category, m_model->categories()) {
if (category->tabWidget)
disconnect(category->tabWidget, SIGNAL(currentChanged(int)),
this, SLOT(currentTabChanged(int)));
}
}
void SettingsDialog::updateEnabledTabs(Category *category, const QString &searchText)
{
for (int i = 0; i < category->pages.size(); ++i) {
......@@ -497,6 +506,7 @@ void SettingsDialog::filter(const QString &text)
void SettingsDialog::accept()
{
disconnectTabWidgets();
m_applied = true;
foreach (IOptionsPage *page, m_visitedPages)
page->apply();
......@@ -507,6 +517,7 @@ void SettingsDialog::accept()
void SettingsDialog::reject()
{
disconnectTabWidgets();
foreach (IOptionsPage *page, m_pages)
page->finish();
done(QDialog::Rejected);
......
......@@ -99,6 +99,7 @@ private:
void updateEnabledTabs(Category *category, const QString &searchText);
void ensureCategoryWidget(Category *category);
void ensureAllCategoryWidgets();
void disconnectTabWidgets();
const QList<Core::IOptionsPage*> m_pages;
......
......@@ -84,6 +84,21 @@ ExternalTool::ExternalTool() :
{
}
ExternalTool::ExternalTool(const ExternalTool *other)
: m_id(other->m_id),
m_description(other->m_description),
m_displayName(other->m_displayName),
m_displayCategory(other->m_displayCategory),
m_order(other->m_order),
m_executables(other->m_executables),
m_arguments(other->m_arguments),
m_input(other->m_input),
m_workingDirectory(other->m_workingDirectory),
m_outputHandling(other->m_outputHandling),
m_errorHandling(other->m_errorHandling)
{
}
ExternalTool::~ExternalTool()
{
}
......@@ -448,14 +463,20 @@ void ExternalToolManager::initialize()
mtools->addMenu(mexternaltools, Constants::G_DEFAULT_THREE);
QMap<QString, QMultiMap<int, Command*> > categoryMenus;
QMap<QString, QMultiMap<int, ExternalTool*> > categoryMap;
parseDirectory(m_core->userResourcePath() + QLatin1String("/externaltools"),
&categoryMenus);
&categoryMap);
parseDirectory(m_core->resourcePath() + QLatin1String("/externaltools"),
&categoryMenus, true);
&categoryMap, true);
QMapIterator<QString, QMultiMap<int, ExternalTool*> > it(categoryMap);
while (it.hasNext()) {
it.next();
m_categoryMap.insert(it.key(), it.value().values());
}
// add all the category menus, QMap is nicely sorted
QMapIterator<QString, QMultiMap<int, Command*> > it(categoryMenus);
it.toFront();
while (it.hasNext()) {
it.next();
ActionContainer *container = 0;
......@@ -466,18 +487,23 @@ void ExternalToolManager::initialize()
mexternaltools->addMenu(container, Constants::G_DEFAULT_ONE);
container->menu()->setTitle(it.key());
}
foreach (Command *cmd, it.value().values()) {
foreach (ExternalTool *tool, it.value().values()) {
// tool action and command
QAction *action = new QAction(tool->displayName(), this);
action->setToolTip(tool->description());
action->setWhatsThis(tool->description());
action->setData(tool->id());
Command *cmd = am->registerAction(action, Id("Tools.External." + tool->id()), Context(Constants::C_GLOBAL));
connect(action, SIGNAL(triggered()), this, SLOT(menuActivated()));
container->addAction(cmd, Constants::G_DEFAULT_TWO);
}
}
}
void ExternalToolManager::parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Command*> > *categoryMenus,
void ExternalToolManager::parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, ExternalTool*> > *categoryMenus,
bool ignoreDuplicates)
{
QTC_ASSERT(categoryMenus, return);
ActionManager *am = m_core->actionManager();
Command *cmd;
QDir dir(directory, QLatin1String("*.xml"), QDir::Unsorted, QDir::Files | QDir::Readable);
foreach (const QFileInfo &info, dir.entryInfoList()) {
QFile file(info.absoluteFilePath());
......@@ -499,15 +525,7 @@ void ExternalToolManager::parseDirectory(const QString &directory, QMap<QString,
continue;
}
m_tools.insert(tool->id(), tool);
// tool action and command
QAction *action = new QAction(tool->displayName(), this);
action->setToolTip(tool->description());
action->setWhatsThis(tool->description());
action->setData(tool->id());
cmd = am->registerAction(action, Id("Tools.External." + tool->id()), Context(Constants::C_GLOBAL));
connect(action, SIGNAL(triggered()), this, SLOT(menuActivated()));
(*categoryMenus)[tool->displayCategory()].insert(tool->order(), cmd);
(*categoryMenus)[tool->displayCategory()].insert(tool->order(), tool);
}
}
}
......@@ -520,3 +538,9 @@ void ExternalToolManager::menuActivated()
QTC_ASSERT(tool, return);
new ExternalToolRunner(tool);
}
QMap<QString, QList<Internal::ExternalTool *> > ExternalToolManager::tools() const
{
return m_categoryMap;
}
......@@ -58,6 +58,7 @@ public:
};
ExternalTool();
ExternalTool(const ExternalTool *other);
~ExternalTool();
QString id() const;
......@@ -131,6 +132,8 @@ public:
ExternalToolManager(Core::ICore *core);
~ExternalToolManager();
QMap<QString, QList<Internal::ExternalTool *> > tools() const;
signals:
void replaceSelectionRequested(const QString &text);
......@@ -139,12 +142,13 @@ private slots:
private:
void initialize();
void parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Command*> > *categoryMenus,
void parseDirectory(const QString &directory, QMap<QString, QMultiMap<int, Internal::ExternalTool*> > *categoryMenus,
bool ignoreDuplicates = false);
static ExternalToolManager *m_instance;
Core::ICore *m_core;
QMap<QString, Internal::ExternalTool *> m_tools;
QMap<QString, QList<Internal::ExternalTool *> > m_categoryMap;
// for sending the replaceSelectionRequested signal
friend class Core::Internal::ExternalToolRunner;
......@@ -152,4 +156,6 @@ private:
} // Core
Q_DECLARE_METATYPE(Core::Internal::ExternalTool *)
#endif // EXTERNALTOOL_H
......@@ -39,6 +39,7 @@
#include "coreconstants.h"
#include "editormanager.h"
#include "externaltool.h"
#include "toolsettings.h"
#include "fancytabwidget.h"
#include "filemanager.h"
#include "generalsettings.h"
......@@ -148,6 +149,7 @@ MainWindow::MainWindow() :
m_activeContext(0),
m_generalSettings(new GeneralSettings),
m_shortcutSettings(new ShortcutSettings),
m_toolSettings(new ToolSettings),
m_systemEditor(new SystemEditor),
m_focusToEditor(0),
m_newAction(0),
......@@ -251,6 +253,7 @@ MainWindow::~MainWindow()
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
pm->removeObject(m_shortcutSettings);
pm->removeObject(m_generalSettings);
pm->removeObject(m_toolSettings);
pm->removeObject(m_systemEditor);
delete m_messageManager;
m_messageManager = 0;
......@@ -258,6 +261,8 @@ MainWindow::~MainWindow()
m_shortcutSettings = 0;
delete m_generalSettings;