2008-12-02 12:01:29 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-01-13 19:21:51 +01:00
|
|
|
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
|
** Non-Open Source Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** 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
|
2008-12-02 14:17:16 +01:00
|
|
|
** agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** 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
|
2008-12-02 14:17:16 +01:00
|
|
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
2008-12-16 17:20:00 +01:00
|
|
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
|
***************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "snippetswindow.h"
|
|
|
|
|
#include "snippetscompletion.h"
|
|
|
|
|
#include "snippetsplugin.h"
|
|
|
|
|
#include "snippetspec.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2009-01-28 13:23:45 +01:00
|
|
|
#include <QtCore/QtPlugin>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QApplication>
|
2009-01-28 13:23:45 +01:00
|
|
|
#include <QtGui/QShortcut>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2009-01-28 13:23:45 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-01-28 13:23:45 +01:00
|
|
|
#include <coreplugin/baseview.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/iview.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <texteditor/itexteditable.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
|
|
|
|
|
using namespace Snippets::Internal;
|
|
|
|
|
|
|
|
|
|
SnippetsPlugin *SnippetsPlugin::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
SnippetsPlugin::SnippetsPlugin()
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
2009-01-28 13:23:45 +01:00
|
|
|
m_snippetsCompletion = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SnippetsPlugin::~SnippetsPlugin()
|
|
|
|
|
{
|
|
|
|
|
removeObject(m_snippetsCompletion);
|
|
|
|
|
delete m_snippetsCompletion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnippetsPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
bool SnippetsPlugin::initialize(const QStringList &arguments, QString *)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Q_UNUSED(arguments);
|
|
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
Core::ActionManager *am = core->actionManager();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QList<int> context;
|
2009-01-20 11:52:04 +01:00
|
|
|
context << core->uniqueIDManager()->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_snippetWnd = new SnippetsWindow();
|
2009-01-28 13:23:45 +01:00
|
|
|
Core::BaseView *view = new Core::BaseView;
|
2009-02-20 17:22:16 +01:00
|
|
|
view->setUniqueViewName("Snippets");
|
2009-01-28 13:23:45 +01:00
|
|
|
view->setWidget(m_snippetWnd);
|
|
|
|
|
view->setContext(QList<int>()
|
|
|
|
|
<< core->uniqueIDManager()->uniqueIdentifier(QLatin1String("Snippets Window"))
|
|
|
|
|
<< core->uniqueIDManager()->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR));
|
|
|
|
|
//view->setDefaultPosition(Qt::RightDockWidgetArea));
|
|
|
|
|
addAutoReleasedObject(view);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_snippetsCompletion = new SnippetsCompletion(this);
|
|
|
|
|
addObject(m_snippetsCompletion);
|
|
|
|
|
|
|
|
|
|
foreach (SnippetSpec *snippet, m_snippetWnd->snippets()) {
|
|
|
|
|
QShortcut *sc = new QShortcut(m_snippetWnd);
|
2009-01-28 13:23:45 +01:00
|
|
|
Core::Command *cmd = am->registerShortcut(sc, simplifySnippetName(snippet), context);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd->setCategory(tr("Snippets"));
|
|
|
|
|
connect(sc, SIGNAL(activated()), this, SLOT(snippetActivated()));
|
|
|
|
|
m_shortcuts.insert(sc, snippet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SnippetsPlugin::simplifySnippetName(SnippetSpec *snippet) const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Snippets.")
|
|
|
|
|
+ snippet->category().simplified().replace(QLatin1String(" "), QLatin1String(""))
|
|
|
|
|
+ QLatin1Char('.')
|
|
|
|
|
+ snippet->name().simplified().replace(QLatin1String(" "), QLatin1String(""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SnippetsPlugin::snippetActivated()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
SnippetSpec *snippet = m_shortcuts.value(sender());
|
2009-01-20 11:52:04 +01:00
|
|
|
if (snippet && core->editorManager()->currentEditor()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
TextEditor::ITextEditable *te =
|
|
|
|
|
qobject_cast<TextEditor::ITextEditable *>(
|
2009-01-20 11:52:04 +01:00
|
|
|
core->editorManager()->currentEditor());
|
2008-12-02 12:01:29 +01:00
|
|
|
m_snippetWnd->insertSnippet(te, snippet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(SnippetsPlugin)
|