1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nicolas Arnaud-Cormos.
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "macrosplugin.h"
36 #include "macrosconstants.h"
37 #include "macromanager.h"
38 #include "macrooptionspage.h"
39 #include "macrolocatorfilter.h"
41 #include <texteditor/texteditorconstants.h>
43 #include <coreplugin/coreconstants.h>
44 #include <coreplugin/actionmanager/actionmanager.h>
45 #include <coreplugin/actionmanager/actioncontainer.h>
46 #include <coreplugin/actionmanager/command.h>
47 #include <coreplugin/icore.h>
48 #include <coreplugin/uniqueidmanager.h>
49 #include <coreplugin/icontext.h>
51 #include <QtCore/QtPlugin>
52 #include <QtCore/QSettings>
53 #include <QtGui/QAction>
54 #include <QtGui/QKeySequence>
55 #include <QtGui/QMenu>
57 using namespace Macros;
58 using namespace Macros::Internal;
60 MacrosPlugin::MacrosPlugin()
64 MacrosPlugin::~MacrosPlugin()
68 bool MacrosPlugin::initialize(const QStringList &arguments, QString *error_message)
71 Q_UNUSED(error_message);
73 addAutoReleasedObject(new MacroOptionsPage);
74 addAutoReleasedObject(new MacroLocatorFilter);
76 Core::ICore *core = Core::ICore::instance();
77 Core::ActionManager *am = core->actionManager();
79 Core::Context globalcontext(Core::Constants::C_GLOBAL);
80 Core::Context textContext(TextEditor::Constants::C_TEXTEDITOR);
81 m_macroManager = new MacroManager(this);
84 Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
85 Core::ActionContainer *mmacrotools = am->createMenu(Constants::M_TOOLS_MACRO);
86 QMenu *menu = mmacrotools->menu();
87 menu->setTitle(tr("&Macros"));
88 menu->setEnabled(true);
89 mtools->addMenu(mmacrotools);
91 QAction *startMacro = new QAction(tr("Record Macro"), this);
92 Core::Command *command = am->registerAction(startMacro, Constants::START_MACRO, textContext);
94 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+(")));
96 command->setDefaultKeySequence(QKeySequence(tr("Alt+(")));
98 mmacrotools->addAction(command);
99 connect(startMacro, SIGNAL(triggered()), m_macroManager, SLOT(startMacro()));
101 QAction *endMacro = new QAction(tr("Stop Recording Macro"), this);
102 endMacro->setEnabled(false);
103 command = am->registerAction(endMacro, Constants::END_MACRO, globalcontext);
105 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+)")));
107 command->setDefaultKeySequence(QKeySequence(tr("Alt+)")));
109 mmacrotools->addAction(command);
110 connect(endMacro, SIGNAL(triggered()), m_macroManager, SLOT(endMacro()));
112 QAction *executeLastMacro = new QAction(tr("Play Last Macro"), this);
113 command = am->registerAction(executeLastMacro, Constants::EXECUTE_LAST_MACRO, textContext);
114 command->setDefaultKeySequence(QKeySequence(tr("Alt+R")));
115 mmacrotools->addAction(command);
116 connect(executeLastMacro, SIGNAL(triggered()), m_macroManager, SLOT(executeLastMacro()));
118 QAction *saveLastMacro = new QAction(tr("Save Last Macro"), this);
119 saveLastMacro->setEnabled(false);
120 command = am->registerAction(saveLastMacro, Constants::SAVE_LAST_MACRO, textContext);
121 mmacrotools->addAction(command);
122 connect(saveLastMacro, SIGNAL(triggered()), m_macroManager, SLOT(saveLastMacro()));
127 void MacrosPlugin::extensionsInitialized()
131 Q_EXPORT_PLUGIN(MacrosPlugin)