snippetssettingspage.cpp 19.7 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30 31

#include "snippetssettingspage.h"
#include "snippeteditor.h"
32
#include "isnippetprovider.h"
33 34 35 36 37 38
#include "snippet.h"
#include "snippetscollection.h"
#include "snippetssettings.h"
#include "ui_snippetssettingspage.h"

#include <coreplugin/icore.h>
39
#include <texteditor/texteditorsettings.h>
40 41
#include <extensionsystem/pluginmanager.h>

42 43 44 45 46
#include <QModelIndex>
#include <QAbstractTableModel>
#include <QList>
#include <QTextStream>
#include <QMessageBox>
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

namespace TextEditor {
namespace Internal {

// SnippetsTableModel
class SnippetsTableModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    SnippetsTableModel(QObject *parent);
    virtual ~SnippetsTableModel() {}

    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
    virtual Qt::ItemFlags flags(const QModelIndex &modelIndex) const;
    virtual QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const;
    virtual bool setData(const QModelIndex &modelIndex, const QVariant &value,
                         int role = Qt::EditRole);
    virtual QVariant headerData(int section, Qt::Orientation orientation,
                                int role = Qt::DisplayRole) const;

68 69
    QList<QString> groupIds() const;
    void load(const QString &groupId);
70 71 72 73 74 75

    QModelIndex createSnippet();
    QModelIndex insertSnippet(const Snippet &snippet);
    void removeSnippet(const QModelIndex &modelIndex);
    const Snippet &snippetAt(const QModelIndex &modelIndex) const;
    void setSnippetContent(const QModelIndex &modelIndex, const QString &content);
Leandro Melo's avatar
Leandro Melo committed
76 77 78
    void revertBuitInSnippet(const QModelIndex &modelIndex);
    void restoreRemovedBuiltInSnippets();
    void resetSnippets();
79 80

private:
Leandro Melo's avatar
Leandro Melo committed
81
    void replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex);
82 83
    static bool isValidTrigger(const QString &s);

84
    SnippetsCollection* m_collection;
85
    QString m_activeGroupId;
86 87 88 89
};

SnippetsTableModel::SnippetsTableModel(QObject *parent) :
    QAbstractTableModel(parent),
90
    m_collection(SnippetsCollection::instance())
91 92 93 94
{}

int SnippetsTableModel::rowCount(const QModelIndex &) const
{
95
    return m_collection->totalActiveSnippets(m_activeGroupId);
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
}

int SnippetsTableModel::columnCount(const QModelIndex &) const
{
    return 2;
}

Qt::ItemFlags SnippetsTableModel::flags(const QModelIndex &index) const
{
    Qt::ItemFlags itemFlags = QAbstractTableModel::flags(index);
    if (index.isValid())
        itemFlags |= Qt::ItemIsEditable;
    return itemFlags;
}

QVariant SnippetsTableModel::data(const QModelIndex &modelIndex, int role) const
{
    if (!modelIndex.isValid())
        return QVariant();

    if (role == Qt::DisplayRole || role == Qt::EditRole) {
117
        const Snippet &snippet = m_collection->snippet(modelIndex.row(), m_activeGroupId);
118 119 120 121 122 123 124 125 126 127 128 129
        if (modelIndex.column() == 0)
            return snippet.trigger();
        else
            return snippet.complement();
    } else {
        return QVariant();
    }
}

bool SnippetsTableModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
{
    if (modelIndex.isValid() && role == Qt::EditRole) {
130
        Snippet snippet(m_collection->snippet(modelIndex.row(), m_activeGroupId));
131 132 133 134 135 136 137 138 139 140 141 142 143
        if (modelIndex.column() == 0) {
            const QString &s = value.toString();
            if (!isValidTrigger(s)) {
                QMessageBox::critical(0, tr("Error"), tr("Not a valid trigger."));
                if (snippet.trigger().isEmpty())
                    removeSnippet(modelIndex);
                return false;
            }
            snippet.setTrigger(s);
        } else {
            snippet.setComplement(value.toString());
        }

Leandro Melo's avatar
Leandro Melo committed
144
        replaceSnippet(snippet, modelIndex);
145 146 147 148 149 150 151 152 153 154 155 156 157
        return true;
    }
    return false;
}

QVariant SnippetsTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
        return QVariant();

    if (section == 0)
        return tr("Trigger");
    else
158
        return tr("Trigger Variant");
159 160
}

161
void SnippetsTableModel::load(const QString &groupId)
162
{
163
    beginResetModel();
164
    m_activeGroupId = groupId;
165
    endResetModel();
166 167
}

168 169 170 171 172
QList<QString> SnippetsTableModel::groupIds() const
{
    return m_collection->groupIds();
}

173 174
QModelIndex SnippetsTableModel::createSnippet()
{
175
    Snippet snippet(m_activeGroupId);
176 177 178 179 180
    return insertSnippet(snippet);
}

QModelIndex SnippetsTableModel::insertSnippet(const Snippet &snippet)
{
181
    const SnippetsCollection::Hint &hint = m_collection->computeInsertionHint(snippet);
182
    beginInsertRows(QModelIndex(), hint.index(), hint.index());
183
    m_collection->insertSnippet(snippet, hint);
184 185 186 187 188 189 190 191
    endInsertRows();

    return index(hint.index(), 0);
}

void SnippetsTableModel::removeSnippet(const QModelIndex &modelIndex)
{
    beginRemoveRows(QModelIndex(), modelIndex.row(), modelIndex.row());
192
    m_collection->removeSnippet(modelIndex.row(), m_activeGroupId);
193 194 195 196 197
    endRemoveRows();
}

const Snippet &SnippetsTableModel::snippetAt(const QModelIndex &modelIndex) const
{
198
    return m_collection->snippet(modelIndex.row(), m_activeGroupId);
199 200 201 202
}

void SnippetsTableModel::setSnippetContent(const QModelIndex &modelIndex, const QString &content)
{
203
    m_collection->setSnippetContent(modelIndex.row(), m_activeGroupId, content);
204 205
}

Leandro Melo's avatar
Leandro Melo committed
206 207
void SnippetsTableModel::revertBuitInSnippet(const QModelIndex &modelIndex)
{
208
    const Snippet &snippet = m_collection->revertedSnippet(modelIndex.row(), m_activeGroupId);
Leandro Melo's avatar
Leandro Melo committed
209 210 211 212 213 214 215 216 217
    if (snippet.id().isEmpty()) {
        QMessageBox::critical(0, tr("Error"), tr("Error reverting snippet."));
        return;
    }
    replaceSnippet(snippet, modelIndex);
}

void SnippetsTableModel::restoreRemovedBuiltInSnippets()
{
218
    beginResetModel();
219
    m_collection->restoreRemovedSnippets(m_activeGroupId);
220
    endResetModel();
Leandro Melo's avatar
Leandro Melo committed
221 222 223 224
}

void SnippetsTableModel::resetSnippets()
{
225
    beginResetModel();
226
    m_collection->reset(m_activeGroupId);
227
    endResetModel();
Leandro Melo's avatar
Leandro Melo committed
228 229 230 231 232 233
}

void SnippetsTableModel::replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex)
{
    const int row = modelIndex.row();
    const SnippetsCollection::Hint &hint =
234
        m_collection->computeReplacementHint(row, snippet);
Leandro Melo's avatar
Leandro Melo committed
235
    if (modelIndex.row() == hint.index()) {
236
        m_collection->replaceSnippet(row, snippet, hint);
237 238 239 240
        if (modelIndex.column() == 0)
            emit dataChanged(modelIndex, modelIndex.sibling(row, 1));
        else
            emit dataChanged(modelIndex.sibling(row, 0), modelIndex);
Leandro Melo's avatar
Leandro Melo committed
241 242 243 244 245 246
    } else {
        if (row < hint.index())
            // Rows will be moved down.
            beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index() + 1);
        else
            beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index());
247
        m_collection->replaceSnippet(row, snippet, hint);
Leandro Melo's avatar
Leandro Melo committed
248 249 250 251
        endMoveRows();
    }
}

252 253 254 255 256
bool SnippetsTableModel::isValidTrigger(const QString &s)
{
    if (s.isEmpty())
        return false;
    for (int i = 0; i < s.length(); ++i)
257
        if (!s.at(i).isLetter() && s.at(i) != QLatin1Char('_') && (!s.at(i).isDigit() || i == 0))
258 259 260 261 262 263 264 265 266
            return false;
    return true;
}

// SnippetsSettingsPagePrivate
class SnippetsSettingsPagePrivate : public QObject
{
    Q_OBJECT
public:
hjk's avatar
hjk committed
267
    SnippetsSettingsPagePrivate(Core::Id id);
268 269
    ~SnippetsSettingsPagePrivate() { delete m_model; }

hjk's avatar
hjk committed
270
    Core::Id id() const { return m_id; }
271 272 273 274 275 276 277 278 279 280 281 282
    const QString &displayName() const { return m_displayName; }
    bool isKeyword(const QString &s) const { return m_keywords.contains(s, Qt::CaseInsensitive); }
    void configureUi(QWidget *parent);

    void apply();
    void finish();

private slots:
    void loadSnippetGroup(int index);
    void markSnippetsCollection();
    void addSnippet();
    void removeSnippet();
Leandro Melo's avatar
Leandro Melo committed
283 284 285
    void revertBuiltInSnippet();
    void restoreRemovedBuiltInSnippets();
    void resetAllSnippets();
286 287
    void selectSnippet(const QModelIndex &parent, int row);
    void selectMovedSnippet(const QModelIndex &, int, int, const QModelIndex &, int row);
Leandro Melo's avatar
Leandro Melo committed
288 289
    void setSnippetContent();
    void updateCurrentSnippetDependent(const QModelIndex &modelIndex = QModelIndex());
290
    void decorateEditors(const TextEditor::FontSettings &fontSettings);
291 292

private:
293 294
    SnippetEditorWidget *currentEditor() const;
    SnippetEditorWidget *editorAt(int i) const;
295 296 297 298 299

    void loadSettings();
    bool settingsChanged() const;
    void writeSettings();

hjk's avatar
hjk committed
300
    const Core::Id m_id;
301 302 303 304 305 306 307 308 309
    const QString m_displayName;
    const QString m_settingsPrefix;
    SnippetsTableModel *m_model;
    bool m_snippetsCollectionChanged;
    QString m_keywords;
    SnippetsSettings m_settings;
    Ui::SnippetsSettingsPage m_ui;
};

hjk's avatar
hjk committed
310
SnippetsSettingsPagePrivate::SnippetsSettingsPagePrivate(Core::Id id) :
311 312 313 314 315 316 317
    m_id(id),
    m_displayName(tr("Snippets")),
    m_settingsPrefix(QLatin1String("Text")),
    m_model(new SnippetsTableModel(0)),
    m_snippetsCollectionChanged(false)
{}

318
SnippetEditorWidget *SnippetsSettingsPagePrivate::currentEditor() const
319 320 321 322
{
    return editorAt(m_ui.snippetsEditorStack->currentIndex());
}

323
SnippetEditorWidget *SnippetsSettingsPagePrivate::editorAt(int i) const
324
{
325
    return static_cast<SnippetEditorWidget *>(m_ui.snippetsEditorStack->widget(i));
326 327 328 329 330 331
}

void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
{
    m_ui.setupUi(w);

332
    const QList<ISnippetProvider *> &providers =
333
        ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
334 335
    foreach (ISnippetProvider *provider, providers) {
        m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
336
        SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
337
        snippetEditor->setFontSettings(TextEditorSettings::fontSettings());
338 339 340 341
        provider->decorateEditor(snippetEditor);
        m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
        connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
    }
342 343 344 345 346 347 348 349 350

    m_ui.snippetsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    m_ui.snippetsTable->setSelectionMode(QAbstractItemView::SingleSelection);
    m_ui.snippetsTable->horizontalHeader()->setStretchLastSection(true);
    m_ui.snippetsTable->horizontalHeader()->setHighlightSections(false);
    m_ui.snippetsTable->verticalHeader()->setVisible(false);
    m_ui.snippetsTable->verticalHeader()->setDefaultSectionSize(20);
    m_ui.snippetsTable->setModel(m_model);

Leandro Melo's avatar
Leandro Melo committed
351 352
    m_ui.revertButton->setEnabled(false);

353 354 355 356 357
    QTextStream(&m_keywords) << m_displayName;

    loadSettings();
    loadSnippetGroup(m_ui.groupCombo->currentIndex());

Robert Loehning's avatar
Robert Loehning committed
358
    connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)),
359
            this, SLOT(selectSnippet(QModelIndex,int)));
Robert Loehning's avatar
Robert Loehning committed
360
    connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)),
361
            this, SLOT(markSnippetsCollection()));
Robert Loehning's avatar
Robert Loehning committed
362
    connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
363
            this, SLOT(markSnippetsCollection()));
Robert Loehning's avatar
Robert Loehning committed
364
    connect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
365
            this, SLOT(selectMovedSnippet(QModelIndex,int,int,QModelIndex,int)));
Robert Loehning's avatar
Robert Loehning committed
366
    connect(m_model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
367 368 369
            this, SLOT(markSnippetsCollection()));
    connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SLOT(markSnippetsCollection()));
Leandro Melo's avatar
Leandro Melo committed
370 371
    connect(m_model, SIGNAL(modelReset()), this, SLOT(updateCurrentSnippetDependent()));
    connect(m_model, SIGNAL(modelReset()), this, SLOT(markSnippetsCollection()));
372 373 374 375

    connect(m_ui.groupCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSnippetGroup(int)));
    connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addSnippet()));
    connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeSnippet()));
Leandro Melo's avatar
Leandro Melo committed
376 377 378 379
    connect(m_ui.resetAllButton, SIGNAL(clicked()), this, SLOT(resetAllSnippets()));
    connect(m_ui.restoreRemovedButton, SIGNAL(clicked()),
            this, SLOT(restoreRemovedBuiltInSnippets()));
    connect(m_ui.revertButton, SIGNAL(clicked()), this, SLOT(revertBuiltInSnippet()));
380
    connect(m_ui.snippetsTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
Leandro Melo's avatar
Leandro Melo committed
381
            this, SLOT(updateCurrentSnippetDependent(QModelIndex)));
382 383 384

    connect(TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
            this, SLOT(decorateEditors(TextEditor::FontSettings)));
385 386 387 388 389 390 391
}

void SnippetsSettingsPagePrivate::apply()
{
    if (settingsChanged())
        writeSettings();

392 393 394
    if (currentEditor()->document()->isModified())
        setSnippetContent();

395
    if (m_snippetsCollectionChanged) {
396 397 398 399
        QString errorString;
        if (SnippetsCollection::instance()->synchronize(&errorString))
            m_snippetsCollectionChanged = false;
        else
hjk's avatar
hjk committed
400
            QMessageBox::critical(Core::ICore::mainWindow(),
401
                    tr("Error While Saving Snippet Collection"), errorString);
402
    }
403 404 405 406 407
}

void SnippetsSettingsPagePrivate::finish()
{
    if (m_snippetsCollectionChanged) {
408
        SnippetsCollection::instance()->reload();
409 410
        m_snippetsCollectionChanged = false;
    }
411 412

    disconnect(TextEditorSettings::instance(), 0, this, 0);
413 414 415 416
}

void SnippetsSettingsPagePrivate::loadSettings()
{
417 418 419
    if (m_ui.groupCombo->count() == 0)
        return;

420 421 422 423 424 425 426
    m_settings.fromSettings(m_settingsPrefix, Core::ICore::settings());
    const QString &lastGroupName = m_settings.lastUsedSnippetGroup();
    const int index = m_ui.groupCombo->findText(lastGroupName);
    if (index != -1)
        m_ui.groupCombo->setCurrentIndex(index);
    else
        m_ui.groupCombo->setCurrentIndex(0);
427 428 429 430
}

void SnippetsSettingsPagePrivate::writeSettings()
{
431 432 433
    if (m_ui.groupCombo->count() == 0)
        return;

434 435
    m_settings.setLastUsedSnippetGroup(m_ui.groupCombo->currentText());
    m_settings.toSettings(m_settingsPrefix, Core::ICore::settings());
436 437 438 439 440 441 442 443 444 445 446
}

bool SnippetsSettingsPagePrivate::settingsChanged() const
{
    if (m_settings.lastUsedSnippetGroup() != m_ui.groupCombo->currentText())
        return true;
    return false;
}

void SnippetsSettingsPagePrivate::loadSnippetGroup(int index)
{
447 448 449
    if (index == -1)
        return;

450 451
    m_ui.snippetsEditorStack->setCurrentIndex(index);
    currentEditor()->clear();
452
    m_model->load(m_ui.groupCombo->itemData(index).toString());
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
}

void SnippetsSettingsPagePrivate::markSnippetsCollection()
{
    if (!m_snippetsCollectionChanged)
        m_snippetsCollectionChanged = true;
}

void SnippetsSettingsPagePrivate::addSnippet()
{
    const QModelIndex &modelIndex = m_model->createSnippet();
    selectSnippet(QModelIndex(), modelIndex.row());
    m_ui.snippetsTable->edit(modelIndex);
}

void SnippetsSettingsPagePrivate::removeSnippet()
{
    const QModelIndex &modelIndex = m_ui.snippetsTable->selectionModel()->currentIndex();
    if (!modelIndex.isValid()) {
        QMessageBox::critical(0, tr("Error"), tr("No snippet selected."));
        return;
    }
    m_model->removeSnippet(modelIndex);
}

Leandro Melo's avatar
Leandro Melo committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
void SnippetsSettingsPagePrivate::restoreRemovedBuiltInSnippets()
{
    m_model->restoreRemovedBuiltInSnippets();
}

void SnippetsSettingsPagePrivate::revertBuiltInSnippet()
{
    m_model->revertBuitInSnippet(m_ui.snippetsTable->selectionModel()->currentIndex());
}

void SnippetsSettingsPagePrivate::resetAllSnippets()
{
    m_model->resetSnippets();
}

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
void SnippetsSettingsPagePrivate::selectSnippet(const QModelIndex &parent, int row)
{
    QModelIndex topLeft = m_model->index(row, 0, parent);
    QModelIndex bottomRight = m_model->index(row, 1, parent);
    QItemSelection selection(topLeft, bottomRight);
    m_ui.snippetsTable->selectionModel()->select(selection, QItemSelectionModel::SelectCurrent);
    m_ui.snippetsTable->setCurrentIndex(topLeft);
    m_ui.snippetsTable->scrollTo(topLeft);
}

void SnippetsSettingsPagePrivate::selectMovedSnippet(const QModelIndex &,
                                                     int sourceRow,
                                                     int,
                                                     const QModelIndex &destinationParent,
                                                     int destinationRow)
{
    QModelIndex modelIndex;
    if (sourceRow < destinationRow)
        modelIndex = m_model->index(destinationRow - 1, 0, destinationParent);
    else
        modelIndex = m_model->index(destinationRow, 0, destinationParent);
    m_ui.snippetsTable->scrollTo(modelIndex);
Leandro Melo's avatar
Leandro Melo committed
515
    currentEditor()->setPlainText(m_model->snippetAt(modelIndex).content());
516 517
}

Leandro Melo's avatar
Leandro Melo committed
518
void SnippetsSettingsPagePrivate::updateCurrentSnippetDependent(const QModelIndex &modelIndex)
519
{
Leandro Melo's avatar
Leandro Melo committed
520 521 522 523 524 525 526 527
    if (modelIndex.isValid()) {
        const Snippet &snippet = m_model->snippetAt(modelIndex);
        currentEditor()->setPlainText(snippet.content());
        m_ui.revertButton->setEnabled(snippet.isBuiltIn());
    } else {
        currentEditor()->clear();
        m_ui.revertButton->setEnabled(false);
    }
528 529
}

Leandro Melo's avatar
Leandro Melo committed
530
void SnippetsSettingsPagePrivate::setSnippetContent()
531 532 533 534 535 536 537 538
{
    const QModelIndex &modelIndex = m_ui.snippetsTable->selectionModel()->currentIndex();
    if (modelIndex.isValid()) {
        m_model->setSnippetContent(modelIndex, currentEditor()->toPlainText());
        markSnippetsCollection();
    }
}

539 540 541
void SnippetsSettingsPagePrivate::decorateEditors(const TextEditor::FontSettings &fontSettings)
{
    const QList<ISnippetProvider *> &providers =
542
        ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
543 544 545 546 547 548 549 550 551 552 553 554
    for (int i = 0; i < m_ui.groupCombo->count(); ++i) {
        SnippetEditorWidget *snippetEditor = editorAt(i);
        snippetEditor->setFontSettings(fontSettings);
        const QString &id = m_ui.groupCombo->itemData(i).toString();
        // This list should be quite short... Re-iterating over it is ok.
        foreach (const ISnippetProvider *provider, providers) {
            if (provider->groupId() == id)
                provider->decorateEditor(snippetEditor);
        }
    }
}

555
// SnippetsSettingsPage
hjk's avatar
hjk committed
556
SnippetsSettingsPage::SnippetsSettingsPage(Core::Id id, QObject *parent) :
557
    TextEditorOptionsPage(parent),
hjk's avatar
hjk committed
558
    d(new SnippetsSettingsPagePrivate(id))
559
{
560 561
    setId(d->id());
    setDisplayName(d->displayName());
562 563
}

564
SnippetsSettingsPage::~SnippetsSettingsPage()
565
{
566
    delete d;
567 568 569 570
}

bool SnippetsSettingsPage::matches(const QString &s) const
{
hjk's avatar
hjk committed
571
    return d->isKeyword(s);
572 573 574 575 576
}

QWidget *SnippetsSettingsPage::createPage(QWidget *parent)
{
    QWidget *w = new QWidget(parent);
hjk's avatar
hjk committed
577
    d->configureUi(w);
578 579 580 581 582
    return w;
}

void SnippetsSettingsPage::apply()
{
hjk's avatar
hjk committed
583
    d->apply();
584 585 586 587
}

void SnippetsSettingsPage::finish()
{
hjk's avatar
hjk committed
588
    d->finish();
589 590 591 592 593 594
}

} // Internal
} // TextEditor

#include "snippetssettingspage.moc"