OSDN Git Service

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