OSDN Git Service

fad8a3cd66df9603e1598a943d1419982fe58cf0
[qt-creator-jp/qt-creator-jp.git] / src / plugins / macros / macrosplugin.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nicolas Arnaud-Cormos.
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "macrosplugin.h"
35
36 #include "macrosconstants.h"
37 #include "macromanager.h"
38 #include "macrooptionspage.h"
39 #include "macrolocatorfilter.h"
40
41 #include <texteditor/texteditorconstants.h>
42
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>
50
51 #include <QtCore/QtPlugin>
52 #include <QtCore/QSettings>
53 #include <QtGui/QAction>
54 #include <QtGui/QKeySequence>
55 #include <QtGui/QMenu>
56
57 using namespace Macros;
58 using namespace Macros::Internal;
59
60 MacrosPlugin::MacrosPlugin()
61 {
62 }
63
64 MacrosPlugin::~MacrosPlugin()
65 {
66 }
67
68 bool MacrosPlugin::initialize(const QStringList &arguments, QString *error_message)
69 {
70     Q_UNUSED(arguments);
71     Q_UNUSED(error_message);
72
73     addAutoReleasedObject(new MacroOptionsPage);
74     addAutoReleasedObject(new MacroLocatorFilter);
75
76     Core::ICore *core = Core::ICore::instance();
77     Core::ActionManager *am = core->actionManager();
78
79     Core::Context globalcontext(Core::Constants::C_GLOBAL);
80     Core::Context textContext(TextEditor::Constants::C_TEXTEDITOR);
81     m_macroManager = new MacroManager(this);
82
83     // Menus
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);
90
91     QAction *startMacro = new QAction(tr("Record Macro"),  this);
92     Core::Command *command = am->registerAction(startMacro, Constants::START_MACRO, textContext);
93 #ifdef Q_WS_MAC
94     command->setDefaultKeySequence(QKeySequence(tr("Ctrl+(")));
95 #else
96     command->setDefaultKeySequence(QKeySequence(tr("Alt+(")));
97 #endif
98     mmacrotools->addAction(command);
99     connect(startMacro, SIGNAL(triggered()), m_macroManager, SLOT(startMacro()));
100
101     QAction *endMacro = new QAction(tr("Stop Recording Macro"),  this);
102     endMacro->setEnabled(false);
103     command = am->registerAction(endMacro, Constants::END_MACRO, globalcontext);
104 #ifdef Q_WS_MAC
105     command->setDefaultKeySequence(QKeySequence(tr("Ctrl+)")));
106 #else
107     command->setDefaultKeySequence(QKeySequence(tr("Alt+)")));
108 #endif
109     mmacrotools->addAction(command);
110     connect(endMacro, SIGNAL(triggered()), m_macroManager, SLOT(endMacro()));
111
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()));
117
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()));
123
124     return true;
125 }
126
127 void MacrosPlugin::extensionsInitialized()
128 {
129 }
130
131 Q_EXPORT_PLUGIN(MacrosPlugin)