mainwindow.cpp 42.2 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
con's avatar
con committed
25 26

#include "mainwindow.h"
hjk's avatar
hjk committed
27
#include "icore.h"
28
#include "coreicons.h"
29
#include "jsexpander.h"
30
#include "toolsettings.h"
31
#include "mimetypesettings.h"
con's avatar
con committed
32
#include "fancytabwidget.h"
33
#include "documentmanager.h"
con's avatar
con committed
34
#include "generalsettings.h"
kh1's avatar
kh1 committed
35
#include "helpmanager.h"
36
#include "idocumentfactory.h"
con's avatar
con committed
37 38
#include "messagemanager.h"
#include "modemanager.h"
39
#include "outputpanemanager.h"
con's avatar
con committed
40 41 42
#include "plugindialog.h"
#include "vcsmanager.h"
#include "versiondialog.h"
con's avatar
con committed
43
#include "statusbarmanager.h"
44
#include "id.h"
con's avatar
con committed
45 46 47 48
#include "manhattanstyle.h"
#include "navigationwidget.h"
#include "rightpane.h"
#include "editormanager/ieditorfactory.h"
49
#include "statusbarwidget.h"
50
#include "systemsettings.h"
51
#include "externaltoolmanager.h"
52
#include "editormanager/systemeditor.h"
53
#include "windowsupport.h"
con's avatar
con committed
54

55
#include <app/app_version.h>
56 57 58 59 60 61 62 63
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actionmanager_p.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/dialogs/newdialog.h>
#include <coreplugin/dialogs/settingsdialog.h>
#include <coreplugin/dialogs/shortcutsettings.h>
#include <coreplugin/editormanager/editormanager.h>
64
#include <coreplugin/editormanager/editormanager_p.h>
65
#include <coreplugin/editormanager/ieditor.h>
66
#include <coreplugin/inavigationwidgetfactory.h>
67 68
#include <coreplugin/progressmanager/progressmanager_p.h>
#include <coreplugin/progressmanager/progressview.h>
69
#include <coreplugin/settingsdatabase.h>
hjk's avatar
hjk committed
70
#include <extensionsystem/pluginmanager.h>
71
#include <utils/algorithm.h>
hjk's avatar
hjk committed
72
#include <utils/historycompleter.h>
73
#include <utils/hostosinfo.h>
Eike Ziller's avatar
Eike Ziller committed
74
#include <utils/mimetypes/mimedatabase.h>
75
#include <utils/qtcassert.h>
76
#include <utils/stylehelper.h>
77
#include <utils/theme/theme.h>
78
#include <utils/stringutils.h>
con's avatar
con committed
79

80 81
#include <QApplication>
#include <QCloseEvent>
82
#include <QColorDialog>
hjk's avatar
hjk committed
83 84 85
#include <QDebug>
#include <QDir>
#include <QFileInfo>
86 87
#include <QMenu>
#include <QMenuBar>
hjk's avatar
hjk committed
88 89
#include <QMessageBox>
#include <QPrinter>
90
#include <QPushButton>
hjk's avatar
hjk committed
91 92
#include <QSettings>
#include <QStatusBar>
93
#include <QStyleFactory>
hjk's avatar
hjk committed
94 95 96
#include <QTimer>
#include <QToolButton>
#include <QUrl>
con's avatar
con committed
97

98
using namespace ExtensionSystem;
hjk's avatar
hjk committed
99
using namespace Utils;
100 101 102

namespace Core {
namespace Internal {
con's avatar
con committed
103

104
enum { debugMainWindow = 0 };
con's avatar
con committed
105 106

MainWindow::MainWindow() :
hjk's avatar
hjk committed
107
    AppMainWindow(),
hjk's avatar
hjk committed
108
    m_coreImpl(new ICore(this)),
109
    m_lowPrioAdditionalContexts(Constants::C_GLOBAL),
110
    m_settingsDatabase(new SettingsDatabase(QFileInfo(PluginManager::settings()->fileName()).path(),
111 112
                                            QLatin1String("QtCreator"),
                                            this)),
con's avatar
con committed
113
    m_printer(0),
114
    m_windowSupport(0),
con's avatar
con committed
115
    m_editorManager(0),
116
    m_externalToolManager(0),
117
    m_progressManager(new ProgressManagerPrivate),
118
    m_jsExpander(new JsExpander),
hjk's avatar
hjk committed
119
    m_vcsManager(new VcsManager),
con's avatar
con committed
120
    m_statusBarManager(0),
con's avatar
con committed
121
    m_modeManager(0),
kh1's avatar
kh1 committed
122
    m_helpManager(new HelpManager),
123
    m_modeStack(new FancyTabWidget(this)),
con's avatar
con committed
124 125
    m_navigationWidget(0),
    m_rightPaneWidget(0),
126
    m_versionDialog(0),
con's avatar
con committed
127
    m_generalSettings(new GeneralSettings),
128
    m_systemSettings(new SystemSettings),
con's avatar
con committed
129
    m_shortcutSettings(new ShortcutSettings),
130
    m_toolSettings(new ToolSettings),
131
    m_mimeTypeSettings(new MimeTypeSettings),
132
    m_systemEditor(new SystemEditor),
con's avatar
con committed
133 134 135 136 137 138 139 140 141 142
    m_focusToEditor(0),
    m_newAction(0),
    m_openAction(0),
    m_openWithAction(0),
    m_saveAllAction(0),
    m_exitAction(0),
    m_optionsAction(0),
    m_toggleSideBarAction(0),
    m_toggleSideBarButton(new QToolButton)
{
143
    (void) new DocumentManager(this);
144 145
    OutputPaneManager::create();

hjk's avatar
hjk committed
146
    HistoryCompleter::setSettings(PluginManager::settings());
hjk's avatar
hjk committed
147

con's avatar
con committed
148
    setWindowTitle(tr("Qt Creator"));
hjk's avatar
hjk committed
149
    if (HostOsInfo::isLinuxHost())
150
        QApplication::setWindowIcon(Icons::QTCREATORLOGO_BIG.icon());
151
    QCoreApplication::setApplicationName(QLatin1String("QtCreator"));
Orgad Shaneh's avatar
Orgad Shaneh committed
152
    QCoreApplication::setApplicationVersion(QLatin1String(Constants::IDE_VERSION_LONG));
153
    QCoreApplication::setOrganizationName(QLatin1String(Constants::IDE_SETTINGSVARIANT_STR));
154
    QString baseName = QApplication::style()->objectName();
155
    // Sometimes we get the standard windows 95 style as a fallback
hjk's avatar
hjk committed
156
    if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()
157 158
            && baseName == QLatin1String("windows")) {
        baseName = QLatin1String("fusion");
159
    }
160 161 162 163 164 165 166 167 168 169 170 171

    // if the user has specified as base style in the theme settings,
    // prefer that
    const QStringList available = QStyleFactory::keys();
    foreach (const QString &s, Utils::creatorTheme()->preferredStyles()) {
        if (available.contains(s, Qt::CaseInsensitive)) {
            baseName = s;
            break;
        }
    }

    QApplication::setStyle(new ManhattanStyle(baseName));
172

con's avatar
con committed
173 174 175 176 177
    setDockNestingEnabled(true);

    setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
    setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);

178
    m_modeManager = new ModeManager(this, m_modeStack);
179 180 181 182 183 184 185
    connect(m_modeStack, &FancyTabWidget::topAreaClicked, this, [](Qt::MouseButton, Qt::KeyboardModifiers modifiers) {
        if (modifiers & Qt::ShiftModifier) {
            QColor color = QColorDialog::getColor(StyleHelper::requestedBaseColor(), ICore::dialogParent());
            if (color.isValid())
                StyleHelper::setBaseColor(color);
        }
    });
186

con's avatar
con committed
187 188 189 190 191 192
    registerDefaultContainers();
    registerDefaultActions();

    m_navigationWidget = new NavigationWidget(m_toggleSideBarAction);
    m_rightPaneWidget = new RightPaneWidget();

con's avatar
con committed
193
    m_statusBarManager = new StatusBarManager(this);
con's avatar
con committed
194
    m_messageManager = new MessageManager;
hjk's avatar
hjk committed
195 196
    m_editorManager = new EditorManager(this);
    m_externalToolManager = new ExternalToolManager();
con's avatar
con committed
197 198
    setCentralWidget(m_modeStack);

199 200 201
    m_progressManager->progressView()->setParent(this);
    m_progressManager->progressView()->setReferenceWidget(m_modeStack->statusBar());

Orgad Shaneh's avatar
Orgad Shaneh committed
202
    connect(qApp, &QApplication::focusChanged, this, &MainWindow::updateFocusWidget);
con's avatar
con committed
203 204 205 206
    // Add a small Toolbutton for toggling the navigation widget
    statusBar()->insertPermanentWidget(0, m_toggleSideBarButton);

//    setUnifiedTitleAndToolBarOnMac(true);
hjk's avatar
hjk committed
207
    //if (HostOsInfo::isAnyUnixHost())
208
        //signal(SIGINT, handleSigInt);
con's avatar
con committed
209 210

    statusBar()->setProperty("p_styled", true);
211

212
    auto dropSupport = new DropSupport(this, [](QDropEvent *event, DropSupport *) {
213 214
        return event->source() == 0; // only accept drops from the "outside" (e.g. file manager)
    });
215
    connect(dropSupport, &DropSupport::filesDropped,
216
            this, &MainWindow::openDroppedFiles);
con's avatar
con committed
217 218
}

219
void MainWindow::setSidebarVisible(bool visible)
con's avatar
con committed
220 221
{
    if (NavigationWidgetPlaceHolder::current()) {
222
        if (m_navigationWidget->isSuppressed() && visible) {
con's avatar
con committed
223 224 225
            m_navigationWidget->setShown(true);
            m_navigationWidget->setSuppressed(false);
        } else {
226
            m_navigationWidget->setShown(visible);
con's avatar
con committed
227 228 229 230 231 232
        }
    }
}

void MainWindow::setSuppressNavigationWidget(bool suppress)
{
hjk's avatar
hjk committed
233
    if (NavigationWidgetPlaceHolder::current())
con's avatar
con committed
234 235 236
        m_navigationWidget->setSuppressed(suppress);
}

237 238 239 240 241
void MainWindow::setOverrideColor(const QColor &color)
{
    m_overrideColor = color;
}

242 243 244 245 246 247 248 249 250 251
QStringList MainWindow::additionalAboutInformation() const
{
    return m_aboutInformation;
}

void MainWindow::appendAboutInformation(const QString &line)
{
    m_aboutInformation.append(line);
}

252 253 254 255 256
void MainWindow::addPreCloseListener(const std::function<bool ()> &listener)
{
    m_preCloseListeners.append(listener);
}

con's avatar
con committed
257 258
MainWindow::~MainWindow()
{
259 260 261 262 263
    // explicitly delete window support, because that calls methods from ICore that call methods
    // from mainwindow, so mainwindow still needs to be alive
    delete m_windowSupport;
    m_windowSupport = 0;

264 265
    PluginManager::removeObject(m_shortcutSettings);
    PluginManager::removeObject(m_generalSettings);
266
    PluginManager::removeObject(m_systemSettings);
267 268 269
    PluginManager::removeObject(m_toolSettings);
    PluginManager::removeObject(m_mimeTypeSettings);
    PluginManager::removeObject(m_systemEditor);
270 271
    delete m_externalToolManager;
    m_externalToolManager = 0;
con's avatar
con committed
272 273 274 275 276 277
    delete m_messageManager;
    m_messageManager = 0;
    delete m_shortcutSettings;
    m_shortcutSettings = 0;
    delete m_generalSettings;
    m_generalSettings = 0;
278 279
    delete m_systemSettings;
    m_systemSettings = 0;
280 281
    delete m_toolSettings;
    m_toolSettings = 0;
282 283
    delete m_mimeTypeSettings;
    m_mimeTypeSettings = 0;
284 285
    delete m_systemEditor;
    m_systemEditor = 0;
con's avatar
con committed
286 287 288 289
    delete m_printer;
    m_printer = 0;
    delete m_vcsManager;
    m_vcsManager = 0;
con's avatar
con committed
290
    //we need to delete editormanager and statusbarmanager explicitly before the end of the destructor,
con's avatar
con committed
291 292 293
    //because they might trigger stuff that tries to access data from editorwindow, like removeContextWidget

    // All modes are now gone
294
    OutputPaneManager::destroy();
con's avatar
con committed
295

296
    // Now that the OutputPaneManager is gone, is a good time to delete the view
297
    PluginManager::removeObject(m_outputView);
con's avatar
con committed
298 299 300 301 302 303
    delete m_outputView;

    delete m_editorManager;
    m_editorManager = 0;
    delete m_progressManager;
    m_progressManager = 0;
304 305
    delete m_statusBarManager;
    m_statusBarManager = 0;
306
    PluginManager::removeObject(m_coreImpl);
con's avatar
con committed
307 308 309 310 311 312 313 314
    delete m_coreImpl;
    m_coreImpl = 0;

    delete m_rightPaneWidget;
    m_rightPaneWidget = 0;

    delete m_modeManager;
    m_modeManager = 0;
kh1's avatar
kh1 committed
315 316 317

    delete m_helpManager;
    m_helpManager = 0;
318 319
    delete m_jsExpander;
    m_jsExpander = 0;
con's avatar
con committed
320 321
}

322
bool MainWindow::init(QString *errorMessage)
con's avatar
con committed
323
{
324
    Q_UNUSED(errorMessage)
325

326
    PluginManager::addObject(m_coreImpl);
con's avatar
con committed
327
    m_statusBarManager->init();
con's avatar
con committed
328
    m_modeManager->init();
329
    m_progressManager->init(); // needs the status bar manager
con's avatar
con committed
330

331
    PluginManager::addObject(m_generalSettings);
332
    PluginManager::addObject(m_systemSettings);
333 334 335 336
    PluginManager::addObject(m_shortcutSettings);
    PluginManager::addObject(m_toolSettings);
    PluginManager::addObject(m_mimeTypeSettings);
    PluginManager::addObject(m_systemEditor);
337

338
    // Add widget to the bottom, we create the view here instead of inside the
Tobias Hunger's avatar
Tobias Hunger committed
339
    // OutputPaneManager, since the StatusBarManager needs to be initialized before
Orgad Shaneh's avatar
Orgad Shaneh committed
340
    m_outputView = new StatusBarWidget;
341
    m_outputView->setWidget(OutputPaneManager::instance()->buttonsWidget());
Orgad Shaneh's avatar
Orgad Shaneh committed
342
    m_outputView->setPosition(StatusBarWidget::Second);
343
    PluginManager::addObject(m_outputView);
hjk's avatar
hjk committed
344
    MessageManager::init();
con's avatar
con committed
345 346 347 348 349
    return true;
}

void MainWindow::extensionsInitialized()
{
350
    EditorManagerPrivate::extensionsInitialized();
351
    MimeTypeSettings::restoreSettings();
352
    m_windowSupport = new WindowSupport(this, Context("Core.MainWindow"));
353
    m_windowSupport->setCloseActionEnabled(false);
con's avatar
con committed
354
    m_statusBarManager->extensionsInitalized();
355
    OutputPaneManager::instance()->init();
356
    m_vcsManager->extensionsInitialized();
357
    m_navigationWidget->setFactories(PluginManager::getObjects<INavigationWidgetFactory>());
358

con's avatar
con committed
359 360 361
    readSettings();
    updateContext();

362
    emit m_coreImpl->coreAboutToOpen();
363
    // Delay restoreWindowState, since it is overridden by LayoutRequest event
Orgad Shaneh's avatar
Orgad Shaneh committed
364 365
    QTimer::singleShot(0, this, &MainWindow::restoreWindowState);
    QTimer::singleShot(0, m_coreImpl, &ICore::coreOpened);
con's avatar
con committed
366 367 368 369
}

void MainWindow::closeEvent(QCloseEvent *event)
{
Tobias Hunger's avatar
Tobias Hunger committed
370
    ICore::saveSettings();
con's avatar
con committed
371 372

    // Save opened files
373
    if (!DocumentManager::saveAllModifiedDocuments()) {
con's avatar
con committed
374 375 376 377
        event->ignore();
        return;
    }

378 379
    foreach (const std::function<bool()> &listener, m_preCloseListeners) {
        if (!listener()) {
con's avatar
con committed
380 381 382 383 384 385
            event->ignore();
            return;
        }
    }

    emit m_coreImpl->coreAboutToClose();
386

con's avatar
con committed
387
    writeSettings();
388 389 390

    m_navigationWidget->closeSubWidgets();

con's avatar
con committed
391 392 393
    event->accept();
}

394
void MainWindow::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
395
{
396
    raiseWindow();
397
    QStringList filePaths = Utils::transform(files,
398
                                             [](const DropSupport::FileSpec &spec) -> QString {
399 400 401
                                                 return spec.filePath;
                                             });
    openFiles(filePaths, ICore::SwitchMode);
402 403
}

con's avatar
con committed
404 405
IContext *MainWindow::currentContextObject() const
{
406
    return m_activeContext.isEmpty() ? 0 : m_activeContext.first();
con's avatar
con committed
407 408 409 410 411 412 413 414 415
}

QStatusBar *MainWindow::statusBar() const
{
    return m_modeStack->statusBar();
}

void MainWindow::registerDefaultContainers()
{
Eike Ziller's avatar
Eike Ziller committed
416
    ActionContainer *menubar = ActionManager::createMenuBar(Constants::MENU_BAR);
con's avatar
con committed
417

hjk's avatar
hjk committed
418
    if (!HostOsInfo::isMacHost()) // System menu bar on Mac
419
        setMenuBar(menubar->menuBar());
con's avatar
con committed
420 421 422 423 424 425 426
    menubar->appendGroup(Constants::G_FILE);
    menubar->appendGroup(Constants::G_EDIT);
    menubar->appendGroup(Constants::G_VIEW);
    menubar->appendGroup(Constants::G_TOOLS);
    menubar->appendGroup(Constants::G_WINDOW);
    menubar->appendGroup(Constants::G_HELP);

427
    // File Menu
Eike Ziller's avatar
Eike Ziller committed
428
    ActionContainer *filemenu = ActionManager::createMenu(Constants::M_FILE);
con's avatar
con committed
429 430 431 432 433 434 435 436 437
    menubar->addMenu(filemenu, Constants::G_FILE);
    filemenu->menu()->setTitle(tr("&File"));
    filemenu->appendGroup(Constants::G_FILE_NEW);
    filemenu->appendGroup(Constants::G_FILE_OPEN);
    filemenu->appendGroup(Constants::G_FILE_PROJECT);
    filemenu->appendGroup(Constants::G_FILE_SAVE);
    filemenu->appendGroup(Constants::G_FILE_CLOSE);
    filemenu->appendGroup(Constants::G_FILE_PRINT);
    filemenu->appendGroup(Constants::G_FILE_OTHER);
hjk's avatar
hjk committed
438
    connect(filemenu->menu(), &QMenu::aboutToShow, this, &MainWindow::aboutToShowRecentFiles);
con's avatar
con committed
439 440


441
    // Edit Menu
Eike Ziller's avatar
Eike Ziller committed
442
    ActionContainer *medit = ActionManager::createMenu(Constants::M_EDIT);
con's avatar
con committed
443 444 445 446 447
    menubar->addMenu(medit, Constants::G_EDIT);
    medit->menu()->setTitle(tr("&Edit"));
    medit->appendGroup(Constants::G_EDIT_UNDOREDO);
    medit->appendGroup(Constants::G_EDIT_COPYPASTE);
    medit->appendGroup(Constants::G_EDIT_SELECTALL);
448
    medit->appendGroup(Constants::G_EDIT_ADVANCED);
449
    medit->appendGroup(Constants::G_EDIT_FIND);
con's avatar
con committed
450 451
    medit->appendGroup(Constants::G_EDIT_OTHER);

452
    // Tools Menu
Eike Ziller's avatar
Eike Ziller committed
453
    ActionContainer *ac = ActionManager::createMenu(Constants::M_TOOLS);
con's avatar
con committed
454 455 456
    menubar->addMenu(ac, Constants::G_TOOLS);
    ac->menu()->setTitle(tr("&Tools"));

457
    // Window Menu
Eike Ziller's avatar
Eike Ziller committed
458
    ActionContainer *mwindow = ActionManager::createMenu(Constants::M_WINDOW);
con's avatar
con committed
459 460 461
    menubar->addMenu(mwindow, Constants::G_WINDOW);
    mwindow->menu()->setTitle(tr("&Window"));
    mwindow->appendGroup(Constants::G_WINDOW_SIZE);
462
    mwindow->appendGroup(Constants::G_WINDOW_VIEWS);
con's avatar
con committed
463 464 465
    mwindow->appendGroup(Constants::G_WINDOW_PANES);
    mwindow->appendGroup(Constants::G_WINDOW_SPLIT);
    mwindow->appendGroup(Constants::G_WINDOW_NAVIGATE);
466
    mwindow->appendGroup(Constants::G_WINDOW_LIST);
con's avatar
con committed
467 468
    mwindow->appendGroup(Constants::G_WINDOW_OTHER);

469
    // Help Menu
Eike Ziller's avatar
Eike Ziller committed
470
    ac = ActionManager::createMenu(Constants::M_HELP);
con's avatar
con committed
471 472
    menubar->addMenu(ac, Constants::G_HELP);
    ac->menu()->setTitle(tr("&Help"));
473
    ac->appendGroup(Constants::G_HELP_HELP);
474
    ac->appendGroup(Constants::G_HELP_SUPPORT);
475
    ac->appendGroup(Constants::G_HELP_ABOUT);
Jarek Kobus's avatar
Jarek Kobus committed
476
    ac->appendGroup(Constants::G_HELP_UPDATES);
con's avatar
con committed
477 478 479 480
}

void MainWindow::registerDefaultActions()
{
Eike Ziller's avatar
Eike Ziller committed
481 482 483 484 485
    ActionContainer *mfile = ActionManager::actionContainer(Constants::M_FILE);
    ActionContainer *medit = ActionManager::actionContainer(Constants::M_EDIT);
    ActionContainer *mtools = ActionManager::actionContainer(Constants::M_TOOLS);
    ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
    ActionContainer *mhelp = ActionManager::actionContainer(Constants::M_HELP);
con's avatar
con committed
486 487

    // File menu separators
488 489 490 491
    mfile->addSeparator(Constants::G_FILE_SAVE);
    mfile->addSeparator(Constants::G_FILE_PRINT);
    mfile->addSeparator(Constants::G_FILE_CLOSE);
    mfile->addSeparator(Constants::G_FILE_OTHER);
con's avatar
con committed
492
    // Edit menu separators
493 494 495 496
    medit->addSeparator(Constants::G_EDIT_COPYPASTE);
    medit->addSeparator(Constants::G_EDIT_SELECTALL);
    medit->addSeparator(Constants::G_EDIT_FIND);
    medit->addSeparator(Constants::G_EDIT_ADVANCED);
con's avatar
con committed
497

498
    // Return to editor shortcut: Note this requires Qt to fix up
con's avatar
con committed
499
    // handling of shortcut overrides in menus, item views, combos....
500
    m_focusToEditor = new QAction(tr("Return to Editor"), this);
501
    Command *cmd = ActionManager::registerAction(m_focusToEditor, Constants::S_RETURNTOEDITOR);
con's avatar
con committed
502
    cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
Orgad Shaneh's avatar
Orgad Shaneh committed
503
    connect(m_focusToEditor, &QAction::triggered, this, &MainWindow::setFocusToEditor);
con's avatar
con committed
504

505
    // New File Action
506
    QIcon icon = QIcon::fromTheme(QLatin1String("document-new"), Icons::NEWFILE.icon());
507
    m_newAction = new QAction(icon, tr("&New File or Project..."), this);
508
    cmd = ActionManager::registerAction(m_newAction, Constants::NEW);
con's avatar
con committed
509 510
    cmd->setDefaultKeySequence(QKeySequence::New);
    mfile->addAction(cmd, Constants::G_FILE_NEW);
511
    connect(m_newAction, &QAction::triggered, this, [this]() {
512 513 514 515 516 517
        ICore::showNewItemDialog(tr("New File or Project", "Title of dialog"),
                                 IWizardFactory::allWizardFactories(), QString());
    });
    connect(ICore::instance(), &ICore::newItemDialogRunningChanged, m_newAction, [this]() {
        m_newAction->setEnabled(!ICore::isNewItemDialogRunning());
    });
con's avatar
con committed
518

519
    // Open Action
520
    icon = QIcon::fromTheme(QLatin1String("document-open"), Icons::OPENFILE.icon());
521
    m_openAction = new QAction(icon, tr("&Open File or Project..."), this);
522
    cmd = ActionManager::registerAction(m_openAction, Constants::OPEN);
con's avatar
con committed
523 524
    cmd->setDefaultKeySequence(QKeySequence::Open);
    mfile->addAction(cmd, Constants::G_FILE_OPEN);
Orgad Shaneh's avatar
Orgad Shaneh committed
525
    connect(m_openAction, &QAction::triggered, this, &MainWindow::openFile);
con's avatar
con committed
526

527
    // Open With Action
528
    m_openWithAction = new QAction(tr("Open File &With..."), this);
529
    cmd = ActionManager::registerAction(m_openWithAction, Constants::OPEN_WITH);
con's avatar
con committed
530
    mfile->addAction(cmd, Constants::G_FILE_OPEN);
Orgad Shaneh's avatar
Orgad Shaneh committed
531
    connect(m_openWithAction, &QAction::triggered, this, &MainWindow::openFileWith);
con's avatar
con committed
532

533
    // File->Recent Files Menu
Eike Ziller's avatar
Eike Ziller committed
534
    ActionContainer *ac = ActionManager::createMenu(Constants::M_FILE_RECENTFILES);
con's avatar
con committed
535
    mfile->addMenu(ac, Constants::G_FILE_OPEN);
536
    ac->menu()->setTitle(tr("Recent &Files"));
537
    ac->setOnAllDisabledBehavior(ActionContainer::Show);
con's avatar
con committed
538

539
    // Save Action
540
    icon = QIcon::fromTheme(QLatin1String("document-save"), Icons::SAVEFILE.icon());
541
    QAction *tmpaction = new QAction(icon, EditorManager::tr("&Save"), this);
542
    tmpaction->setEnabled(false);
543
    cmd = ActionManager::registerAction(tmpaction, Constants::SAVE);
con's avatar
con committed
544
    cmd->setDefaultKeySequence(QKeySequence::Save);
con's avatar
con committed
545
    cmd->setAttribute(Command::CA_UpdateText);
546
    cmd->setDescription(tr("Save"));
con's avatar
con committed
547 548
    mfile->addAction(cmd, Constants::G_FILE_SAVE);

549
    // Save As Action
550
    icon = QIcon::fromTheme(QLatin1String("document-save-as"));
551
    tmpaction = new QAction(icon, EditorManager::tr("Save &As..."), this);
552
    tmpaction->setEnabled(false);
553
    cmd = ActionManager::registerAction(tmpaction, Constants::SAVEAS);
554
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+Shift+S") : QString()));
con's avatar
con committed
555
    cmd->setAttribute(Command::CA_UpdateText);
556
    cmd->setDescription(tr("Save As..."));
con's avatar
con committed
557 558
    mfile->addAction(cmd, Constants::G_FILE_SAVE);

559
    // SaveAll Action
con's avatar
con committed
560
    m_saveAllAction = new QAction(tr("Save A&ll"), this);
561
    cmd = ActionManager::registerAction(m_saveAllAction, Constants::SAVEALL);
562
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? QString() : tr("Ctrl+Shift+S")));
con's avatar
con committed
563
    mfile->addAction(cmd, Constants::G_FILE_SAVE);
Orgad Shaneh's avatar
Orgad Shaneh committed
564
    connect(m_saveAllAction, &QAction::triggered, this, &MainWindow::saveAll);
con's avatar
con committed
565

566
    // Print Action
567 568
    icon = QIcon::fromTheme(QLatin1String("document-print"));
    tmpaction = new QAction(icon, tr("&Print..."), this);
569
    tmpaction->setEnabled(false);
570
    cmd = ActionManager::registerAction(tmpaction, Constants::PRINT);
571
    cmd->setDefaultKeySequence(QKeySequence::Print);
con's avatar
con committed
572 573
    mfile->addAction(cmd, Constants::G_FILE_PRINT);

574
    // Exit Action
575 576
    icon = QIcon::fromTheme(QLatin1String("application-exit"));
    m_exitAction = new QAction(icon, tr("E&xit"), this);
Eike Ziller's avatar
Eike Ziller committed
577
    m_exitAction->setMenuRole(QAction::QuitRole);
578
    cmd = ActionManager::registerAction(m_exitAction, Constants::EXIT);
con's avatar
con committed
579 580
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Q")));
    mfile->addAction(cmd, Constants::G_FILE_OTHER);
Orgad Shaneh's avatar
Orgad Shaneh committed
581
    connect(m_exitAction, &QAction::triggered, this, &MainWindow::exit);
con's avatar
con committed
582

583
    // Undo Action
584
    icon = QIcon::fromTheme(QLatin1String("edit-undo"), Icons::UNDO.icon());
585
    tmpaction = new QAction(icon, tr("&Undo"), this);
586
    cmd = ActionManager::registerAction(tmpaction, Constants::UNDO);
con's avatar
con committed
587
    cmd->setDefaultKeySequence(QKeySequence::Undo);
con's avatar
con committed
588
    cmd->setAttribute(Command::CA_UpdateText);
589
    cmd->setDescription(tr("Undo"));
con's avatar
con committed
590
    medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
591
    tmpaction->setEnabled(false);
con's avatar
con committed
592

593
    // Redo Action
594
    icon = QIcon::fromTheme(QLatin1String("edit-redo"), Icons::REDO.icon());
595
    tmpaction = new QAction(icon, tr("&Redo"), this);
596
    cmd = ActionManager::registerAction(tmpaction, Constants::REDO);
con's avatar
con committed
597
    cmd->setDefaultKeySequence(QKeySequence::Redo);
con's avatar
con committed
598
    cmd->setAttribute(Command::CA_UpdateText);
599
    cmd->setDescription(tr("Redo"));
con's avatar
con committed
600
    medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
601
    tmpaction->setEnabled(false);
con's avatar
con committed
602

603
    // Cut Action
604
    icon = QIcon::fromTheme(QLatin1String("edit-cut"), Icons::CUT.icon());
605
    tmpaction = new QAction(icon, tr("Cu&t"), this);
606
    cmd = ActionManager::registerAction(tmpaction, Constants::CUT);
con's avatar
con committed
607 608
    cmd->setDefaultKeySequence(QKeySequence::Cut);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
609
    tmpaction->setEnabled(false);
con's avatar
con committed
610

611
    // Copy Action
612
    icon = QIcon::fromTheme(QLatin1String("edit-copy"), Icons::COPY.icon());
613
    tmpaction = new QAction(icon, tr("&Copy"), this);
614
    cmd = ActionManager::registerAction(tmpaction, Constants::COPY);
con's avatar
con committed
615 616
    cmd->setDefaultKeySequence(QKeySequence::Copy);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
617
    tmpaction->setEnabled(false);
con's avatar
con committed
618

619
    // Paste Action
620
    icon = QIcon::fromTheme(QLatin1String("edit-paste"), Icons::PASTE.icon());
621
    tmpaction = new QAction(icon, tr("&Paste"), this);
622
    cmd = ActionManager::registerAction(tmpaction, Constants::PASTE);
con's avatar
con committed
623 624
    cmd->setDefaultKeySequence(QKeySequence::Paste);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
625
    tmpaction->setEnabled(false);
con's avatar
con committed
626

627
    // Select All
628
    icon = QIcon::fromTheme(QLatin1String("edit-select-all"));
con's avatar
con committed
629
    tmpaction = new QAction(icon, tr("Select &All"), this);
630
    cmd = ActionManager::registerAction(tmpaction, Constants::SELECTALL);
con's avatar
con committed
631 632
    cmd->setDefaultKeySequence(QKeySequence::SelectAll);
    medit->addAction(cmd, Constants::G_EDIT_SELECTALL);
633
    tmpaction->setEnabled(false);
con's avatar
con committed
634

635
    // Goto Action
636
    icon = QIcon::fromTheme(QLatin1String("go-jump"));
637
    tmpaction = new QAction(icon, tr("&Go to Line..."), this);
638
    cmd = ActionManager::registerAction(tmpaction, Constants::GOTO);
con's avatar
con committed
639 640
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+L")));
    medit->addAction(cmd, Constants::G_EDIT_OTHER);
641
    tmpaction->setEnabled(false);
con's avatar
con committed
642

643
    // Options Action
con's avatar
con committed
644
    mtools->appendGroup(Constants::G_TOOLS_OPTIONS);
645
    mtools->addSeparator(Constants::G_TOOLS_OPTIONS);
646

con's avatar
con committed
647
    m_optionsAction = new QAction(tr("&Options..."), this);
Eike Ziller's avatar
Eike Ziller committed
648
    m_optionsAction->setMenuRole(QAction::PreferencesRole);
649
    cmd = ActionManager::registerAction(m_optionsAction, Constants::OPTIONS);
Eike Ziller's avatar
Eike Ziller committed
650
    cmd->setDefaultKeySequence(QKeySequence::Preferences);
con's avatar
con committed
651
    mtools->addAction(cmd, Constants::G_TOOLS_OPTIONS);
Orgad Shaneh's avatar
Orgad Shaneh committed
652
    connect(m_optionsAction, &QAction::triggered, this, [this]() { showOptionsDialog(); });
con's avatar
con committed
653

654
    mwindow->addSeparator(Constants::G_WINDOW_LIST);
655

656 657
    if (UseMacShortcuts) {
        // Minimize Action
658 659
        QAction *minimizeAction = new QAction(tr("Minimize"), this);
        minimizeAction->setEnabled(false); // actual implementation in WindowSupport
660
        cmd = ActionManager::registerAction(minimizeAction, Constants::MINIMIZE_WINDOW);
661 662 663 664
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+M")));
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);

        // Zoom Action
665 666
        QAction *zoomAction = new QAction(tr("Zoom"), this);
        zoomAction->setEnabled(false); // actual implementation in WindowSupport
667
        cmd = ActionManager::registerAction(zoomAction, Constants::ZOOM_WINDOW);
668
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
669
    }
670

671
    // Full Screen Action
672
    QAction *toggleFullScreenAction = new QAction(tr("Full Screen"), this);
hjk's avatar
hjk committed
673
    toggleFullScreenAction->setCheckable(!HostOsInfo::isMacHost());
674
    toggleFullScreenAction->setEnabled(false); // actual implementation in WindowSupport
675
    cmd = ActionManager::registerAction(toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN);
676
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+Meta+F") : tr("Ctrl+Shift+F11")));
hjk's avatar
hjk committed
677
    if (HostOsInfo::isMacHost())
678 679 680
        cmd->setAttribute(Command::CA_UpdateText);
    mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);

681
    if (UseMacShortcuts) {
682
        mwindow->addSeparator(Constants::G_WINDOW_SIZE);
con's avatar
con committed
683

684 685
        QAction *closeAction = new QAction(tr("Close Window"), this);
        closeAction->setEnabled(false);
686
        cmd = ActionManager::registerAction(closeAction, Constants::CLOSE_WINDOW);
687 688 689
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Meta+W")));
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);

690
        mwindow->addSeparator(Constants::G_WINDOW_SIZE);
691
    }
con's avatar
con committed
692

693
    // Show Sidebar Action
694
    m_toggleSideBarAction = new QAction(Icons::TOGGLE_SIDEBAR.icon(),
Sergey Belyashov's avatar
Sergey Belyashov committed
695 696
                                        QCoreApplication::translate("Core", Constants::TR_SHOW_SIDEBAR),
                                        this);
697
    m_toggleSideBarAction->setCheckable(true);
698
    cmd = ActionManager::registerAction(m_toggleSideBarAction, Constants::TOGGLE_SIDEBAR);
699
    cmd->setAttribute(Command::CA_UpdateText);
700
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+0") : tr("Alt+0")));
hjk's avatar
hjk committed
701
    connect(m_toggleSideBarAction, &QAction::triggered, this, &MainWindow::setSidebarVisible);
702 703 704
    ProxyAction *toggleSideBarProxyAction =
            ProxyAction::proxyActionWithIcon(cmd->action(), Core::Icons::TOGGLE_SIDEBAR_TOOLBAR.icon());
    m_toggleSideBarButton->setDefaultAction(toggleSideBarProxyAction);
705
    mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
con's avatar
con committed
706 707
    m_toggleSideBarAction->setEnabled(false);

708 709 710
    // Show Mode Selector Action
    m_toggleModeSelectorAction = new QAction(tr("Show Mode Selector"), this);
    m_toggleModeSelectorAction->setCheckable(true);
711
    cmd = ActionManager::registerAction(m_toggleModeSelectorAction, Constants::TOGGLE_MODE_SELECTOR);
Orgad Shaneh's avatar
Orgad Shaneh committed
712 713
    connect(m_toggleModeSelectorAction, &QAction::triggered,
            ModeManager::instance(), &ModeManager::setModeSelectorVisible);
714
    mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
715

716
    // Window->Views
Eike Ziller's avatar
Eike Ziller committed
717
    ActionContainer *mviews = ActionManager::createMenu(Constants::M_WINDOW_VIEWS);
718 719 720
    mwindow->addMenu(mviews, Constants::G_WINDOW_VIEWS);
    mviews->menu()->setTitle(tr("&Views"));

721
    // "Help" separators
722
    mhelp->addSeparator(Constants::G_HELP_SUPPORT);
hjk's avatar
hjk committed
723
    if (!HostOsInfo::isMacHost())
724
        mhelp->addSeparator(Constants::G_HELP_ABOUT);
725

726
    // About IDE Action
727
    icon = QIcon::fromTheme(QLatin1String("help-about"));
hjk's avatar
hjk committed
728
    if (HostOsInfo::isMacHost())
729 730 731
        tmpaction = new QAction(icon, tr("About &Qt Creator"), this); // it's convention not to add dots to the about menu
    else
        tmpaction = new QAction(icon, tr("About &Qt Creator..."), this);
Eike Ziller's avatar
Eike Ziller committed
732
    tmpaction->setMenuRole(QAction::AboutRole);
733
    cmd = ActionManager::registerAction(tmpaction, Constants::ABOUT_QTCREATOR);
734 735
    mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
    tmpaction->setEnabled(true);
hjk's avatar
hjk committed
736
    connect(tmpaction, &QAction::triggered, this, &MainWindow::aboutQtCreator);
con's avatar
con committed
737

con's avatar
con committed
738 739
    //About Plugins Action
    tmpaction = new QAction(tr("About &Plugins..."), this);
Eike Ziller's avatar
Eike Ziller committed
740
    tmpaction->setMenuRole(QAction::ApplicationSpecificRole);