1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nicolas Arnaud-Cormos.
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "macrosplugin.h"
35 #include "macrosconstants.h"
36 #include "macromanager.h"
37 #include "macrooptionspage.h"
38 #include "macrolocatorfilter.h"
40 #include <texteditor/texteditorconstants.h>
42 #include <coreplugin/coreconstants.h>
43 #include <coreplugin/actionmanager/actionmanager.h>
44 #include <coreplugin/actionmanager/actioncontainer.h>
45 #include <coreplugin/actionmanager/command.h>
46 #include <coreplugin/icore.h>
47 #include <coreplugin/uniqueidmanager.h>
48 #include <coreplugin/icontext.h>
50 #include <QtCore/QtPlugin>
51 #include <QtCore/QSettings>
52 #include <QtGui/QAction>
53 #include <QtGui/QKeySequence>
54 #include <QtGui/QMenu>
56 using namespace Macros;
57 using namespace Macros::Internal;
59 MacrosPlugin::MacrosPlugin()
63 MacrosPlugin::~MacrosPlugin()
67 bool MacrosPlugin::initialize(const QStringList &arguments, QString *error_message)
70 Q_UNUSED(error_message);
72 addAutoReleasedObject(new MacroOptionsPage);
73 addAutoReleasedObject(new MacroLocatorFilter);
75 Core::ICore *core = Core::ICore::instance();
76 Core::ActionManager *am = core->actionManager();
78 Core::Context globalcontext(Core::Constants::C_GLOBAL);
79 Core::Context textContext(TextEditor::Constants::C_TEXTEDITOR);
80 m_macroManager = new MacroManager(this);
83 Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
84 Core::ActionContainer *mmacrotools = am->createMenu(Constants::M_TOOLS_MACRO);
85 QMenu *menu = mmacrotools->menu();
86 menu->setTitle(tr("&Macros"));
87 menu->setEnabled(true);
88 mtools->addMenu(mmacrotools);
90 QAction *startMacro = new QAction(tr("Record Macro"), this);
91 Core::Command *command = am->registerAction(startMacro, Constants::START_MACRO, textContext);
93 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+(")));
95 command->setDefaultKeySequence(QKeySequence(tr("Alt+(")));
97 mmacrotools->addAction(command);
98 connect(startMacro, SIGNAL(triggered()), m_macroManager, SLOT(startMacro()));
100 QAction *endMacro = new QAction(tr("Stop Recording Macro"), this);
101 endMacro->setEnabled(false);
102 command = am->registerAction(endMacro, Constants::END_MACRO, globalcontext);
104 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+)")));
106 command->setDefaultKeySequence(QKeySequence(tr("Alt+)")));
108 mmacrotools->addAction(command);
109 connect(endMacro, SIGNAL(triggered()), m_macroManager, SLOT(endMacro()));
111 QAction *executeLastMacro = new QAction(tr("Play Last Macro"), this);
112 command = am->registerAction(executeLastMacro, Constants::EXECUTE_LAST_MACRO, textContext);
113 command->setDefaultKeySequence(QKeySequence(tr("Alt+R")));
114 mmacrotools->addAction(command);
115 connect(executeLastMacro, SIGNAL(triggered()), m_macroManager, SLOT(executeLastMacro()));
117 QAction *saveLastMacro = new QAction(tr("Save Last Macro"), this);
118 saveLastMacro->setEnabled(false);
119 command = am->registerAction(saveLastMacro, Constants::SAVE_LAST_MACRO, textContext);
120 mmacrotools->addAction(command);
121 connect(saveLastMacro, SIGNAL(triggered()), m_macroManager, SLOT(saveLastMacro()));
126 void MacrosPlugin::extensionsInitialized()
130 Q_EXPORT_PLUGIN(MacrosPlugin)