Initial import

This commit is contained in:
con
2008-12-02 12:01:29 +01:00
commit 05c35356ab
1675 changed files with 229938 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<plugin name="RegExp" version="0.9.1" compatVersion="0.9.1">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2008 Nokia Corporation</copyright>
<license>Nokia Technology Preview License Agreement</license>
<description>Regular Expression test widget.</description>
<url>http://www.trolltech.com/</url>
<dependencyList>
<dependency name="Core" version="0.9.1"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,10 @@
TEMPLATE = lib
TARGET = RegExp
include(../../qworkbenchplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
QT += xml
HEADERS += regexpwindow.h regexpplugin.h settings.h
SOURCES += regexpwindow.cpp regexpplugin.cpp settings.cpp

View File

@@ -0,0 +1,77 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "regexpplugin.h"
#include "settings.h"
#include "regexpwindow.h"
#include <coreplugin/baseview.h>
#include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h>
#include <QtCore/qplugin.h>
using namespace RegExp::Internal;
RegExpPlugin::RegExpPlugin()
{
}
RegExpPlugin::~RegExpPlugin()
{
if (m_regexpWindow) {
m_regexpWindow->settings().toQSettings(m_core->settings());
}
}
void RegExpPlugin::extensionsInitialized()
{
}
bool RegExpPlugin::initialize(const QStringList & /*arguments*/, QString *error_message)
{
Q_UNUSED(error_message)
m_core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
m_regexpWindow = new RegExpWindow;
Settings settings;
settings.fromQSettings(m_core->settings());
m_regexpWindow->setSettings(settings);
const int plugId = m_core->uniqueIDManager()->uniqueIdentifier(QLatin1String("RegExpPlugin"));
addAutoReleasedObject(new Core::BaseView("TextEditor.RegExpWindow",
m_regexpWindow,
QList<int>() << plugId,
Qt::RightDockWidgetArea));
return true;
}
Q_EXPORT_PLUGIN(RegExpPlugin)

View File

@@ -0,0 +1,69 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef REGEXPPLUGIN_H
#define REGEXPPLUGIN_H
#include <extensionsystem/iplugin.h>
#include <QtCore/QObject>
#include <QtCore/QPointer>
namespace Core {
class ICore;
}
namespace RegExp {
namespace Internal {
class RegExpWindow;
class RegExpPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
RegExpPlugin();
virtual ~RegExpPlugin();
bool initialize(const QStringList &arguments, QString *error_message);
void extensionsInitialized();
private:
Core::ICore *m_core;
QPointer<RegExpWindow> m_regexpWindow;
};
} //namespace Internal
} //namespace RegExp
#endif

View File

@@ -0,0 +1,294 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "regexpwindow.h"
#include "settings.h"
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QLabel>
#include <QtGui/QLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QContextMenuEvent>
#include <QtGui/QMenu>
#include <QtGui/QInputDialog>
using namespace RegExp::Internal;
RegExpWindow::RegExpWindow(QWidget *parent) :
QWidget(parent),
patternLabel(new QLabel(tr("&Pattern:"))),
escapedPatternLabel(new QLabel(tr("&Escaped Pattern:"))),
syntaxLabel(new QLabel(tr("&Pattern Syntax:"))),
textLabel(new QLabel(tr("&Text:"))),
patternComboBox (new QComboBox),
escapedPatternLineEdit(new QLineEdit),
textComboBox(new QComboBox),
caseSensitiveCheckBox(new QCheckBox(tr("Case &Sensitive"))),
minimalCheckBox(new QCheckBox(tr("&Minimal"))),
syntaxComboBox(new QComboBox),
indexLabel(new QLabel(tr("Index of Match:"))),
matchedLengthLabel(new QLabel(tr("Matched Length:"))),
indexEdit(new QLineEdit),
matchedLengthEdit(new QLineEdit)
{
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
QGridLayout *mainLayout = new QGridLayout;
patternComboBox->setEditable(true);
patternComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
patternLabel->setBuddy(patternComboBox);
mainLayout->addWidget(patternLabel, 0, 0);
mainLayout->addWidget(patternComboBox, 0, 1);
escapedPatternLineEdit->setReadOnly(true);
QPalette palette = escapedPatternLineEdit->palette();
palette.setBrush(QPalette::Base, palette.brush(QPalette::Disabled, QPalette::Base));
escapedPatternLineEdit->setPalette(palette);
escapedPatternLabel->setBuddy(escapedPatternLineEdit);
mainLayout->addWidget(escapedPatternLabel, 1, 0);
mainLayout->addWidget(escapedPatternLineEdit, 1, 1);
syntaxComboBox->addItem(tr("Regular expression v1"), QRegExp::RegExp);
syntaxComboBox->addItem(tr("Regular expression v2"), QRegExp::RegExp2);
syntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
syntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
syntaxLabel->setBuddy(syntaxComboBox);
mainLayout->addWidget(syntaxLabel, 2, 0);
mainLayout->addWidget(syntaxComboBox, 2, 1);
QHBoxLayout *checkBoxLayout = new QHBoxLayout;
caseSensitiveCheckBox->setChecked(true);
checkBoxLayout->addWidget(caseSensitiveCheckBox);
checkBoxLayout->addWidget(minimalCheckBox);
checkBoxLayout->addStretch(1);
mainLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
textComboBox->setEditable(true);
textComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
textLabel->setBuddy(textComboBox);
mainLayout->addWidget(textLabel, 4, 0);
mainLayout->addWidget(textComboBox, 4, 1);
indexEdit->setReadOnly(true);
mainLayout->addWidget(indexLabel, 5, 0);
mainLayout->addWidget(indexEdit, 5, 1);
matchedLengthEdit->setReadOnly(true);
mainLayout->addWidget(matchedLengthLabel, 6, 0);
mainLayout->addWidget(matchedLengthEdit, 6, 1);
vboxLayout->addLayout(mainLayout);
vboxLayout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
for (int i = 0; i < MaxCaptures; ++i) {
captureLabels[i] = new QLabel(tr("Capture %1:").arg(i));
captureEdits[i] = new QLineEdit;
captureEdits[i]->setReadOnly(true);
}
captureLabels[0]->setText(tr("Match:"));
for (int j = 0; j < MaxCaptures; ++j) {
mainLayout->addWidget(captureLabels[j], 7 + j, 0);
mainLayout->addWidget(captureEdits[j], 7 + j, 1);
}
connect(patternComboBox, SIGNAL(editTextChanged(const QString &)), this, SLOT(refresh()));
connect(textComboBox, SIGNAL(editTextChanged(const QString &)), this, SLOT(refresh()));
connect(caseSensitiveCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh()));
connect(minimalCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh()));
connect(syntaxComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(refresh()));
setWindowTitle(tr("Regular Expression"));
refresh();
}
static const char *escapedBackSlash = "\\\\";
static const char *escapedDoubleQuote = "\\\"";
static QString escapePattern(const QString &pattern)
{
QString escaped = pattern;
escaped.replace(QString(QLatin1Char('\\')) , QLatin1String(escapedBackSlash));
const QChar doubleQuote(QLatin1Char('"'));
escaped.replace(doubleQuote, QString(QLatin1String(escapedDoubleQuote)));
escaped.prepend(doubleQuote);
escaped.append(doubleQuote);
return escaped;
}
static QString unescapePattern(QString escaped)
{
// remove quotes
const QChar doubleQuote(QLatin1Char('"'));
if (escaped.endsWith(doubleQuote))
escaped.truncate(escaped.size() - 1);
if (escaped.startsWith(doubleQuote))
escaped.remove(0, 1);
const int size = escaped.size();
if (!size)
return QString();
// parse out escapes. Do not just replace.
QString pattern;
const QChar backSlash = QLatin1Char('\\');
bool escapeSeen = false;
for (int i = 0; i < size; i++) {
const QChar c = escaped.at(i);
if (c == backSlash && !escapeSeen)
escapeSeen = true;
else {
pattern.push_back(c);
escapeSeen = false;
}
}
return pattern;
}
void RegExpWindow::refresh()
{
setUpdatesEnabled(false);
const QString pattern = patternComboBox->currentText();
const QString text = textComboBox->currentText();
escapedPatternLineEdit->setText(escapePattern(pattern));
QRegExp rx(pattern);
const Qt::CaseSensitivity cs = caseSensitiveCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
rx.setCaseSensitivity(cs);
rx.setMinimal(minimalCheckBox->isChecked());
const QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(
syntaxComboBox->itemData(syntaxComboBox->currentIndex()).toInt());
rx.setPatternSyntax(syntax);
QPalette palette = patternComboBox->palette();
if (rx.isValid()) {
palette.setColor(QPalette::Text,
textComboBox->palette().color(QPalette::Text));
} else {
palette.setColor(QPalette::Text, Qt::red);
}
patternComboBox->setPalette(palette);
indexEdit->setText(QString::number(rx.indexIn(text)));
matchedLengthEdit->setText(QString::number(rx.matchedLength()));
for (int i = 0; i < MaxCaptures; ++i) {
const bool enabled = i <= rx.numCaptures();
captureLabels[i]->setEnabled(enabled);
captureEdits[i]->setEnabled(enabled);
captureEdits[i]->setText(rx.cap(i));
}
setUpdatesEnabled(true);
}
static void saveTextCombo(const QComboBox *cb, QString &current, QStringList &items)
{
current = cb->currentText();
items.clear();
if (const int count = cb->count())
for (int i = 0;i < count; i++) {
const QString text = cb->itemText(i);
if (items.indexOf(text) == -1)
items += text;
}
}
Settings RegExpWindow::settings() const
{
Settings rc;
rc.m_patternSyntax = static_cast<QRegExp::PatternSyntax>(syntaxComboBox->itemData(syntaxComboBox->currentIndex()).toInt());
rc.m_minimal = minimalCheckBox->checkState() == Qt::Checked;
rc.m_caseSensitive = caseSensitiveCheckBox->checkState() == Qt::Checked;
saveTextCombo(patternComboBox, rc.m_currentPattern, rc.m_patterns);
saveTextCombo(textComboBox, rc.m_currentMatch, rc.m_matches);
return rc;
}
static void restoreTextCombo(const QString &current, const QStringList &items, QComboBox *cb)
{
cb->clear();
cb->addItems(items);
cb->lineEdit()->setText(current);
}
void RegExpWindow::setSettings(const Settings &s)
{
const int patternIndex = syntaxComboBox->findData(QVariant(s.m_patternSyntax));
syntaxComboBox->setCurrentIndex(patternIndex);
minimalCheckBox->setCheckState(s.m_minimal ? Qt::Checked : Qt::Unchecked);
caseSensitiveCheckBox->setCheckState(s.m_caseSensitive ? Qt::Checked : Qt::Unchecked);
restoreTextCombo(s.m_currentPattern, s.m_patterns, patternComboBox);
restoreTextCombo(s.m_currentMatch, s.m_matches, textComboBox);
}
void RegExpWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
QAction *enterQuotedAction = menu.addAction(tr("Enter pattern from code..."));
connect(enterQuotedAction, SIGNAL(triggered()), this, SLOT(enterEscaped()));
menu.addSeparator();
QAction *clearPatternsAction = menu.addAction(tr("Clear patterns"));
connect(clearPatternsAction, SIGNAL(triggered()), patternComboBox, SLOT(clear()));
QAction *clearTextsAction = menu.addAction(tr("Clear texts"));
connect(clearTextsAction, SIGNAL(triggered()), textComboBox, SLOT(clear()));
event->accept();
menu.exec(event->globalPos());
}
void RegExpWindow::enterEscaped()
{
const QString escapedPattern = QInputDialog::getText (this, tr("Enter pattern from code"), tr("Pattern"));
if ( escapedPattern.isEmpty())
return;
patternComboBox->lineEdit()->setText(unescapePattern(escapedPattern));
}

View File

@@ -0,0 +1,92 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef REGEXPWINDOW_H
#define REGEXPWINDOW_H
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QLabel;
class QComboBox;
class QCheckBox;
class QLineEdit;
QT_END_NAMESPACE
namespace RegExp {
namespace Internal {
struct Settings;
class RegExpWindow : public QWidget
{
Q_OBJECT
public:
RegExpWindow(QWidget *parent = 0);
Settings settings() const;
void setSettings(const Settings &s);
protected:
void contextMenuEvent(QContextMenuEvent *);
private slots:
void refresh();
void enterEscaped();
private:
QLabel *patternLabel;
QLabel *escapedPatternLabel;
QLabel *syntaxLabel;
QLabel *textLabel;
QComboBox *patternComboBox;
QLineEdit *escapedPatternLineEdit;
QComboBox *textComboBox;
QCheckBox *caseSensitiveCheckBox;
QCheckBox *minimalCheckBox;
QComboBox *syntaxComboBox;
QLabel *indexLabel;
QLabel *matchedLengthLabel;
QLineEdit *indexEdit;
QLineEdit *matchedLengthEdit;
enum { MaxCaptures = 6 };
QLabel *captureLabels[MaxCaptures];
QLineEdit *captureEdits[MaxCaptures];
};
} //namespace Internal
} //namespace RegExp
#endif

View File

@@ -0,0 +1,94 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "settings.h"
#include <QtCore/QSettings>
static const char *syntaxKey = "Syntax";
static const char *minimalKey = "Minimal";
static const char *caseSensitiveKey = "CaseSensitive";
static const char *patternKey = "Patterns";
static const char *currentPatternKey = "CurrentPattern";
static const char *matchKey = "Matches";
static const char *currentMatchKey = "CurrentMatch";
static const char *patternDefault = "[A-Za-z_]+([A-Za-z_0-9]*)";
static const char *matchDefault = "(10 + delta4) * 32";
static const char *settingsGroup = "RegExp";
namespace RegExp {
namespace Internal {
Settings::Settings() :
m_patternSyntax(QRegExp::RegExp),
m_minimal(false),
m_caseSensitive(true),
m_patterns(QLatin1String(patternDefault)),
m_currentPattern(m_patterns.front()),
m_matches(QLatin1String(matchDefault)),
m_currentMatch(m_matches.front())
{
}
void Settings::clear()
{
*this = Settings();
}
void Settings::fromQSettings(QSettings *s)
{
clear();
s->beginGroup(QLatin1String(settingsGroup));
m_patternSyntax = static_cast<QRegExp::PatternSyntax>(s->value(QLatin1String(syntaxKey), m_patternSyntax).toInt());
m_minimal = s->value(QLatin1String(minimalKey), m_minimal).toBool();
m_caseSensitive = s->value(QLatin1String(caseSensitiveKey), m_caseSensitive).toBool();
m_patterns = s->value(QLatin1String(patternKey), m_patterns).toStringList();
m_currentPattern = s->value(QLatin1String(currentPatternKey), m_currentPattern).toString();
m_matches = s->value(QLatin1String(matchKey), m_matches).toStringList();
m_currentMatch = s->value(QLatin1String(currentMatchKey), m_currentMatch).toString();
s->endGroup();
}
void Settings::toQSettings(QSettings *s) const
{
s->beginGroup(QLatin1String(settingsGroup));
s->setValue(QLatin1String(syntaxKey), m_patternSyntax);
s->setValue(QLatin1String(minimalKey), m_minimal);
s->setValue(QLatin1String(caseSensitiveKey), m_caseSensitive);
s->setValue(QLatin1String(patternKey), m_patterns);
s->setValue(QLatin1String(currentPatternKey), m_currentPattern);
s->setValue(QLatin1String(matchKey), m_matches);
s->setValue(QLatin1String(currentMatchKey), m_currentMatch);
s->endGroup();
}
}
}

View File

@@ -0,0 +1,69 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef REGEXP_SETTINGS_H
#define REGEXP_SETTINGS_H
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QRegExp>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace RegExp {
namespace Internal {
// Settings of the Regexp plugin.
// Provides methods to serialize into QSettings.
struct Settings {
Settings();
void clear();
void fromQSettings(QSettings *s);
void toQSettings(QSettings *s) const;
QRegExp::PatternSyntax m_patternSyntax;
bool m_minimal;
bool m_caseSensitive;
QStringList m_patterns;
QString m_currentPattern;
QStringList m_matches;
QString m_currentMatch;
};
} // namespace Internal
} // namespace RegExp
#endif // REGEXP_SETTINGS_H