2010-12-20 10:35:30 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nicolas Arnaud-Cormos.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
2010-12-20 11:10:30 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-20 11:10:30 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-20 11:10:30 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-12-20 10:35:30 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "macrooptionswidget.h"
|
|
|
|
|
#include "ui_macrooptionswidget.h"
|
|
|
|
|
#include "macrosconstants.h"
|
|
|
|
|
#include "macromanager.h"
|
|
|
|
|
#include "macro.h"
|
|
|
|
|
#include "macrosconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2011-02-07 11:34:02 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-12-20 10:35:30 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
|
2011-01-20 14:03:07 +01:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
|
2011-01-24 12:29:48 +01:00
|
|
|
#include <QtGui/QShortcut>
|
2011-01-20 14:03:07 +01:00
|
|
|
#include <QtGui/QButtonGroup>
|
|
|
|
|
#include <QtGui/QTreeWidget>
|
|
|
|
|
#include <QtGui/QTreeWidgetItem>
|
|
|
|
|
#include <QtGui/QCheckBox>
|
|
|
|
|
#include <QtGui/QGroupBox>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QRegExpValidator>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
int NAME_ROLE = Qt::UserRole;
|
|
|
|
|
int WRITE_ROLE = Qt::UserRole+1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using namespace Macros;
|
|
|
|
|
using namespace Macros::Internal;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MacroOptionsWidget::MacroOptionsWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui(new Ui::MacroOptionsWidget),
|
|
|
|
|
m_changingCurrent(false)
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui->setupUi(this);
|
2010-12-20 10:35:30 +01:00
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
connect(m_ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
|
2010-12-20 10:35:30 +01:00
|
|
|
this, SLOT(changeCurrentItem(QTreeWidgetItem*)));
|
2011-02-07 11:34:02 +01:00
|
|
|
connect(m_ui->removeButton, SIGNAL(clicked()),
|
2010-12-20 10:35:30 +01:00
|
|
|
this, SLOT(remove()));
|
2011-02-07 11:34:02 +01:00
|
|
|
connect(m_ui->description, SIGNAL(textChanged(QString)),
|
2010-12-20 10:35:30 +01:00
|
|
|
this, SLOT(changeDescription(QString)));
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui->treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
|
|
initialize();
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MacroOptionsWidget::~MacroOptionsWidget()
|
|
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
delete m_ui;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
void MacroOptionsWidget::initialize()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
|
|
|
|
m_macroToRemove.clear();
|
|
|
|
|
m_macroToChange.clear();
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui->treeWidget->clear();
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
// Create the treeview
|
2011-02-07 11:34:02 +01:00
|
|
|
createTable();
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-07 11:34:02 +01:00
|
|
|
void MacroOptionsWidget::createTable()
|
2010-12-20 10:35:30 +01:00
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
QDir dir(MacroManager::instance()->macrosDirectory());
|
2010-12-20 10:35:30 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
Core::ActionManager *am = core->actionManager();
|
2011-01-24 11:39:42 +01:00
|
|
|
|
2010-12-20 10:35:30 +01:00
|
|
|
QMapIterator<QString, Macro *> it(MacroManager::instance()->macros());
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
QFileInfo fileInfo(it.value()->fileName());
|
|
|
|
|
if (fileInfo.absoluteDir() == dir.absolutePath()) {
|
2011-02-07 11:34:02 +01:00
|
|
|
QTreeWidgetItem *macroItem = new QTreeWidgetItem(m_ui->treeWidget);
|
2010-12-20 10:35:30 +01:00
|
|
|
macroItem->setText(0, it.value()->displayName());
|
|
|
|
|
macroItem->setText(1, it.value()->description());
|
|
|
|
|
macroItem->setData(0, NAME_ROLE, it.value()->displayName());
|
|
|
|
|
macroItem->setData(0, WRITE_ROLE, it.value()->isWritable());
|
2011-01-24 11:39:42 +01:00
|
|
|
|
|
|
|
|
Core::Command *command = am->command(Core::Id(Constants::PREFIX_MACRO+it.value()->displayName()));
|
|
|
|
|
if (command && command->shortcut())
|
|
|
|
|
macroItem->setText(2, command->shortcut()->key().toString());
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroOptionsWidget::changeCurrentItem(QTreeWidgetItem *current)
|
|
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
m_changingCurrent = true;
|
2010-12-20 10:35:30 +01:00
|
|
|
if (!current) {
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui->removeButton->setEnabled(false);
|
|
|
|
|
m_ui->description->clear();
|
|
|
|
|
m_ui->macroGroup->setEnabled(false);
|
2010-12-20 10:35:30 +01:00
|
|
|
} else {
|
2011-02-07 11:34:02 +01:00
|
|
|
m_ui->removeButton->setEnabled(true);
|
|
|
|
|
m_ui->description->setText(current->text(1));
|
|
|
|
|
m_ui->description->setEnabled(current->data(0, WRITE_ROLE).toBool());
|
|
|
|
|
m_ui->macroGroup->setEnabled(true);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
2011-02-07 11:34:02 +01:00
|
|
|
m_changingCurrent = false;
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroOptionsWidget::remove()
|
|
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
|
|
|
|
m_macroToRemove.append(current->data(0, NAME_ROLE).toString());
|
2010-12-20 10:35:30 +01:00
|
|
|
delete current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroOptionsWidget::apply()
|
|
|
|
|
{
|
|
|
|
|
// Remove macro
|
2011-02-07 11:34:02 +01:00
|
|
|
foreach (const QString &name, m_macroToRemove) {
|
2010-12-20 10:35:30 +01:00
|
|
|
MacroManager::instance()->deleteMacro(name);
|
2011-02-07 11:34:02 +01:00
|
|
|
m_macroToChange.remove(name);
|
|
|
|
|
}
|
2010-12-20 10:35:30 +01:00
|
|
|
|
|
|
|
|
// Change macro
|
2011-02-07 11:34:02 +01:00
|
|
|
QMapIterator<QString, QString> it(m_macroToChange);
|
2010-12-20 10:35:30 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2011-02-07 11:34:02 +01:00
|
|
|
MacroManager::instance()->changeMacro(it.key(), it.value());
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reinitialize the page
|
2011-02-07 11:34:02 +01:00
|
|
|
initialize();
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MacroOptionsWidget::changeDescription(const QString &description)
|
|
|
|
|
{
|
2011-02-07 11:34:02 +01:00
|
|
|
QTreeWidgetItem *current = m_ui->treeWidget->currentItem();
|
|
|
|
|
if (m_changingCurrent || !current)
|
2010-12-20 10:35:30 +01:00
|
|
|
return;
|
2011-02-07 11:34:02 +01:00
|
|
|
|
|
|
|
|
QString macroName = current->data(0, NAME_ROLE).toString();
|
|
|
|
|
m_macroToChange[macroName] = description;
|
|
|
|
|
current->setText(1, description);
|
|
|
|
|
QFont font = current->font(1);
|
|
|
|
|
font.setItalic(true);
|
|
|
|
|
current->setFont(1, font);
|
2010-12-20 10:35:30 +01:00
|
|
|
}
|