-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenuhideplugin.cpp
75 lines (62 loc) · 2.12 KB
/
menuhideplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "menuhideplugin.h"
#include "menuhideconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/coreconstants.h>
#include <QAction>
#include <QMessageBox>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
namespace menuhide {
namespace Internal {
menuhidePlugin::menuhidePlugin()
{
}
menuhidePlugin::~menuhidePlugin()
{
}
bool menuhidePlugin::initialize(const QStringList &arguments, QString *errorString)
{
Q_UNUSED(arguments)
Q_UNUSED(errorString)
auto action = new QAction(tr("Hide main menu"), this);
action->setCheckable(true);
action->setChecked(false);
Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
Core::Context(Core::Constants::C_GLOBAL));
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+M")));
connect(action, &QAction::triggered, this, &menuhidePlugin::triggerAction);
Core::ActionManager::actionContainer(Core::Constants::M_WINDOW)->addAction(cmd);
return true;
}
void menuhidePlugin::extensionsInitialized()
{
}
ExtensionSystem::IPlugin::ShutdownFlag menuhidePlugin::aboutToShutdown()
{
return SynchronousShutdown;
}
void menuhidePlugin::triggerAction()
{
Core::ActionContainer *menubar_ac = Core::ActionManager::actionContainer(Core::Constants::MENU_BAR);
if (menubar_ac) {
QMenuBar *mb = menubar_ac->menuBar();
if (mb) {
mb->setVisible(!mb->isVisible());
} else {
QMessageBox::critical(Core::ICore::mainWindow(),
tr("Hide main menu"),
tr("Failed to get QMenuBar from ActionContainer."));
}
} else {
QMessageBox::critical(Core::ICore::mainWindow(),
tr("Hide main menu"),
tr("Failed to get menubar ActionContainer."));
}
}
} // namespace Internal
} // namespace menuhide