mainwindow.cpp 46.7 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
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
12
13
14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
con's avatar
con committed
29
30

#include "mainwindow.h"
31
#include "actioncontainer.h"
32
#include "command.h"
Eike Ziller's avatar
Eike Ziller committed
33
#include "actionmanager.h"
34
#include "actionmanager_p.h"
hjk's avatar
hjk committed
35
#include "icore.h"
con's avatar
con committed
36
37
#include "coreconstants.h"
#include "editormanager.h"
38
#include "externaltool.h"
39
#include "toolsettings.h"
40
#include "mimetypesettings.h"
con's avatar
con committed
41
#include "fancytabwidget.h"
42
#include "documentmanager.h"
con's avatar
con committed
43
#include "generalsettings.h"
kh1's avatar
kh1 committed
44
#include "helpmanager.h"
45
#include "ieditor.h"
46
#include "idocumentfactory.h"
con's avatar
con committed
47
48
49
50
#include "messagemanager.h"
#include "modemanager.h"
#include "mimedatabase.h"
#include "newdialog.h"
51
#include "outputpanemanager.h"
con's avatar
con committed
52
53
#include "outputpane.h"
#include "plugindialog.h"
54
#include "progressmanager_p.h"
con's avatar
con committed
55
56
57
#include "progressview.h"
#include "shortcutsettings.h"
#include "vcsmanager.h"
con's avatar
con committed
58
#include "variablechooser.h"
59
#include "scriptmanager_p.h"
con's avatar
con committed
60
61
62
#include "settingsdialog.h"
#include "variablemanager.h"
#include "versiondialog.h"
con's avatar
con committed
63
#include "statusbarmanager.h"
64
#include "id.h"
con's avatar
con committed
65
66
67
68
#include "manhattanstyle.h"
#include "navigationwidget.h"
#include "rightpane.h"
#include "editormanager/ieditorfactory.h"
69
#include "statusbarwidget.h"
con's avatar
con committed
70
#include "basefilewizard.h"
71
#include "ioutputpane.h"
72
#include "externaltoolmanager.h"
73
#include "editormanager/systemeditor.h"
con's avatar
con committed
74

75
76
77
78
#if defined(Q_OS_MAC)
#include "macfullscreen.h"
#endif

79
#include <app/app_version.h>
con's avatar
con committed
80
#include <coreplugin/findplaceholder.h>
81
#include <coreplugin/icorelistener.h>
82
#include <coreplugin/inavigationwidgetfactory.h>
83
#include <coreplugin/settingsdatabase.h>
hjk's avatar
hjk committed
84
#include <utils/historycompleter.h>
85
#include <utils/pathchooser.h>
86
#include <utils/stylehelper.h>
87
#include <utils/stringutils.h>
88
#include <extensionsystem/pluginmanager.h>
con's avatar
con committed
89

90
91
92
93
94
95
96
97
98
#include <QDebug>
#include <QFileInfo>
#include <QSettings>
#include <QTimer>
#include <QtPlugin>
#include <QUrl>
#include <QDir>
#include <QFile>
#include <QMimeData>
con's avatar
con committed
99

100
101
102
103
104
105
106
107
108
109
110
111
#include <QApplication>
#include <QCloseEvent>
#include <QMenu>
#include <QPixmap>
#include <QPrinter>
#include <QShortcut>
#include <QStatusBar>
#include <QWizard>
#include <QToolButton>
#include <QMessageBox>
#include <QMenuBar>
#include <QPushButton>
Thomas Hartmann's avatar
Thomas Hartmann committed
112
#include <QStyleFactory>
con's avatar
con committed
113
114
115
116
117
118

/*
#ifdef Q_OS_UNIX
#include <signal.h>
extern "C" void handleSigInt(int sig)
{
119
    Q_UNUSED(sig)
hjk's avatar
hjk committed
120
    Core::ICore::exit();
con's avatar
con committed
121
122
123
124
125
126
127
128
    qDebug() << "SIGINT caught. Shutting down.";
}
#endif
*/

using namespace Core;
using namespace Core::Internal;

129
enum { debugMainWindow = 0 };
con's avatar
con committed
130
131

MainWindow::MainWindow() :
132
    Utils::AppMainWindow(),
hjk's avatar
hjk committed
133
    m_coreImpl(new ICore(this)),
134
    m_additionalContexts(Constants::C_GLOBAL),
135
136
    m_settings(ExtensionSystem::PluginManager::settings()),
    m_globalSettings(ExtensionSystem::PluginManager::globalSettings()),
137
138
139
    m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
                                            QLatin1String("QtCreator"),
                                            this)),
con's avatar
con committed
140
    m_printer(0),
Eike Ziller's avatar
Eike Ziller committed
141
    m_actionManager(new ActionManager(this)),
con's avatar
con committed
142
    m_editorManager(0),
143
    m_externalToolManager(0),
144
    m_progressManager(new ProgressManagerPrivate()),
145
    m_scriptManager(new ScriptManagerPrivate(this)),
Friedemann Kleint's avatar
Friedemann Kleint committed
146
    m_variableManager(new VariableManager),
hjk's avatar
hjk committed
147
    m_vcsManager(new VcsManager),
con's avatar
con committed
148
    m_statusBarManager(0),
con's avatar
con committed
149
150
    m_modeManager(0),
    m_mimeDatabase(new MimeDatabase),
kh1's avatar
kh1 committed
151
    m_helpManager(new HelpManager),
con's avatar
con committed
152
153
    m_navigationWidget(0),
    m_rightPaneWidget(0),
154
    m_versionDialog(0),
con's avatar
con committed
155
156
157
    m_activeContext(0),
    m_generalSettings(new GeneralSettings),
    m_shortcutSettings(new ShortcutSettings),
158
    m_toolSettings(new ToolSettings),
159
    m_mimeTypeSettings(new MimeTypeSettings),
160
    m_systemEditor(new SystemEditor),
con's avatar
con committed
161
162
163
164
165
166
167
168
    m_focusToEditor(0),
    m_newAction(0),
    m_openAction(0),
    m_openWithAction(0),
    m_saveAllAction(0),
    m_exitAction(0),
    m_optionsAction(0),
    m_toggleSideBarAction(0),
hjk's avatar
hjk committed
169
    m_toggleFullScreenAction(0),
170
#ifdef Q_OS_MAC
con's avatar
con committed
171
172
173
174
175
    m_minimizeAction(0),
    m_zoomAction(0),
#endif
    m_toggleSideBarButton(new QToolButton)
{
176
    (void) new DocumentManager(this);
177
178
    OutputPaneManager::create();

hjk's avatar
hjk committed
179
180
    Utils::HistoryCompleter::setSettings(m_settings);

con's avatar
con committed
181
    setWindowTitle(tr("Qt Creator"));
182
#ifndef Q_OS_MAC
183
    QApplication::setWindowIcon(QIcon(QLatin1String(Constants::ICON_QTLOGO_128)));
184
#endif
185
186
    QCoreApplication::setApplicationName(QLatin1String("QtCreator"));
    QCoreApplication::setApplicationVersion(QLatin1String(Core::Constants::IDE_VERSION_LONG));
187
    QCoreApplication::setOrganizationName(QLatin1String(Constants::IDE_SETTINGSVARIANT_STR));
188
    QString baseName = QApplication::style()->objectName();
Nikolai Kosjar's avatar
Nikolai Kosjar committed
189
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
190
    if (baseName == QLatin1String("windows")) {
191
        // Sometimes we get the standard windows 95 style as a fallback
192
193
194
195
196
197
198
199
200
201
        if (QStyleFactory::keys().contains("Fusion"))
            baseName = QLatin1String("fusion"); // Qt5
        else { // Qt4
            // e.g. if we are running on a KDE4 desktop
            QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION");
            if (desktopEnvironment == "kde")
                baseName = QLatin1String("plastique");
            else
                baseName = QLatin1String("cleanlooks");
        }
202
203
204
205
    }
#endif
    qApp->setStyle(new ManhattanStyle(baseName));

con's avatar
con committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    setDockNestingEnabled(true);

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

    registerDefaultContainers();
    registerDefaultActions();

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

    m_modeStack = new FancyTabWidget(this);
    m_modeManager = new ModeManager(this, m_modeStack);
    m_modeManager->addWidget(m_progressManager->progressView());
con's avatar
con committed
220
    m_statusBarManager = new StatusBarManager(this);
con's avatar
con committed
221
    m_messageManager = new MessageManager;
hjk's avatar
hjk committed
222
    m_editorManager = new EditorManager(this);
con's avatar
con committed
223
    m_editorManager->hide();
hjk's avatar
hjk committed
224
    m_externalToolManager = new ExternalToolManager();
con's avatar
con committed
225
226
227
228
229
230
231
232
233
234
235
236
237
    setCentralWidget(m_modeStack);

    connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*,QWidget*)),
            this, SLOT(updateFocusWidget(QWidget*,QWidget*)));
    // Add a small Toolbutton for toggling the navigation widget
    statusBar()->insertPermanentWidget(0, m_toggleSideBarButton);

//    setUnifiedTitleAndToolBarOnMac(true);
#ifdef Q_OS_UNIX
     //signal(SIGINT, handleSigInt);
#endif

    statusBar()->setProperty("p_styled", true);
238
    setAcceptDrops(true);
239
240
241
242

#if defined(Q_OS_MAC)
    MacFullScreen::addFullScreen(this);
#endif
con's avatar
con committed
243
244
}

245
void MainWindow::setSidebarVisible(bool visible)
con's avatar
con committed
246
247
{
    if (NavigationWidgetPlaceHolder::current()) {
248
        if (m_navigationWidget->isSuppressed() && visible) {
con's avatar
con committed
249
250
251
            m_navigationWidget->setShown(true);
            m_navigationWidget->setSuppressed(false);
        } else {
252
            m_navigationWidget->setShown(visible);
con's avatar
con committed
253
254
255
256
257
258
        }
    }
}

void MainWindow::setSuppressNavigationWidget(bool suppress)
{
hjk's avatar
hjk committed
259
    if (NavigationWidgetPlaceHolder::current())
con's avatar
con committed
260
261
262
        m_navigationWidget->setSuppressed(suppress);
}

263
264
265
266
267
void MainWindow::setOverrideColor(const QColor &color)
{
    m_overrideColor = color;
}

268
269
270
271
272
273
274
275
276
277
#ifdef Q_OS_MAC
void MainWindow::setIsFullScreen(bool fullScreen)
{
    if (fullScreen)
        m_toggleFullScreenAction->setText(tr("Exit Full Screen"));
    else
        m_toggleFullScreenAction->setText(tr("Enter Full Screen"));
}
#endif

con's avatar
con committed
278
279
MainWindow::~MainWindow()
{
280
281
282
283
284
    ExtensionSystem::PluginManager::removeObject(m_shortcutSettings);
    ExtensionSystem::PluginManager::removeObject(m_generalSettings);
    ExtensionSystem::PluginManager::removeObject(m_toolSettings);
    ExtensionSystem::PluginManager::removeObject(m_mimeTypeSettings);
    ExtensionSystem::PluginManager::removeObject(m_systemEditor);
285
286
    delete m_externalToolManager;
    m_externalToolManager = 0;
con's avatar
con committed
287
288
289
290
291
292
    delete m_messageManager;
    m_messageManager = 0;
    delete m_shortcutSettings;
    m_shortcutSettings = 0;
    delete m_generalSettings;
    m_generalSettings = 0;
293
294
    delete m_toolSettings;
    m_toolSettings = 0;
295
296
    delete m_mimeTypeSettings;
    m_mimeTypeSettings = 0;
297
298
    delete m_systemEditor;
    m_systemEditor = 0;
con's avatar
con committed
299
300
301
302
303
304
    delete m_settings;
    m_settings = 0;
    delete m_printer;
    m_printer = 0;
    delete m_vcsManager;
    m_vcsManager = 0;
con's avatar
con committed
305
    //we need to delete editormanager and statusbarmanager explicitly before the end of the destructor,
con's avatar
con committed
306
307
308
    //because they might trigger stuff that tries to access data from editorwindow, like removeContextWidget

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

311
    // Now that the OutputPaneManager is gone, is a good time to delete the view
312
    ExtensionSystem::PluginManager::removeObject(m_outputView);
con's avatar
con committed
313
314
315
316
    delete m_outputView;

    delete m_editorManager;
    m_editorManager = 0;
con's avatar
con committed
317
318
    delete m_statusBarManager;
    m_statusBarManager = 0;
con's avatar
con committed
319
320
    delete m_progressManager;
    m_progressManager = 0;
321
    ExtensionSystem::PluginManager::removeObject(m_coreImpl);
con's avatar
con committed
322
323
324
325
326
327
328
329
330
331
    delete m_coreImpl;
    m_coreImpl = 0;

    delete m_rightPaneWidget;
    m_rightPaneWidget = 0;

    delete m_modeManager;
    m_modeManager = 0;
    delete m_mimeDatabase;
    m_mimeDatabase = 0;
kh1's avatar
kh1 committed
332
333
334

    delete m_helpManager;
    m_helpManager = 0;
con's avatar
con committed
335
336
}

337
bool MainWindow::init(QString *errorMessage)
con's avatar
con committed
338
{
339
    Q_UNUSED(errorMessage)
340

341
342
343
    if (!mimeDatabase()->addMimeTypes(QLatin1String(":/core/editormanager/BinFiles.mimetypes.xml"), errorMessage))
        return false;

344
    ExtensionSystem::PluginManager::addObject(m_coreImpl);
con's avatar
con committed
345
    m_statusBarManager->init();
con's avatar
con committed
346
347
    m_modeManager->init();
    m_progressManager->init();
con's avatar
con committed
348

349
350
351
352
353
    ExtensionSystem::PluginManager::addObject(m_generalSettings);
    ExtensionSystem::PluginManager::addObject(m_shortcutSettings);
    ExtensionSystem::PluginManager::addObject(m_toolSettings);
    ExtensionSystem::PluginManager::addObject(m_mimeTypeSettings);
    ExtensionSystem::PluginManager::addObject(m_systemEditor);
354

355
    // Add widget to the bottom, we create the view here instead of inside the
Tobias Hunger's avatar
Tobias Hunger committed
356
    // OutputPaneManager, since the StatusBarManager needs to be initialized before
357
    m_outputView = new Core::StatusBarWidget;
358
    m_outputView->setWidget(OutputPaneManager::instance()->buttonsWidget());
359
    m_outputView->setPosition(Core::StatusBarWidget::Second);
360
    ExtensionSystem::PluginManager::addObject(m_outputView);
361
    m_messageManager->init();
con's avatar
con committed
362
363
364
365
366
367
    return true;
}

void MainWindow::extensionsInitialized()
{
    m_editorManager->init();
con's avatar
con committed
368
    m_statusBarManager->extensionsInitalized();
369
    OutputPaneManager::instance()->init();
370
    m_vcsManager->extensionsInitialized();
371
    m_navigationWidget->setFactories(ExtensionSystem::PluginManager::getObjects<INavigationWidgetFactory>());
372

373
    // reading the shortcut settings must be done after all shortcuts have been registered
Eike Ziller's avatar
Eike Ziller committed
374
    m_actionManager->d->initialize();
375

con's avatar
con committed
376
377
378
    readSettings();
    updateContext();

379
380
    emit m_coreImpl->coreAboutToOpen();
    show();
con's avatar
con committed
381
382
383
384
385
    emit m_coreImpl->coreOpened();
}

void MainWindow::closeEvent(QCloseEvent *event)
{
Tobias Hunger's avatar
Tobias Hunger committed
386
    ICore::saveSettings();
con's avatar
con committed
387
388
389

    // Save opened files
    bool cancelled;
390
    QList<IDocument*> notSaved = DocumentManager::saveModifiedDocuments(DocumentManager::modifiedDocuments(), &cancelled);
391
    if (cancelled || !notSaved.isEmpty()) {
con's avatar
con committed
392
393
394
395
396
        event->ignore();
        return;
    }

    const QList<ICoreListener *> listeners =
397
        ExtensionSystem::PluginManager::getObjects<ICoreListener>();
con's avatar
con committed
398
399
400
401
402
403
404
405
    foreach (ICoreListener *listener, listeners) {
        if (!listener->coreAboutToClose()) {
            event->ignore();
            return;
        }
    }

    emit m_coreImpl->coreAboutToClose();
406

con's avatar
con committed
407
    writeSettings();
408
409
410

    m_navigationWidget->closeSubWidgets();

con's avatar
con committed
411
412
413
    event->accept();
}

414
415
416
417
418
419
420
// Check for desktop file manager file drop events

static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
{
    if (files)
        files->clear();
    // Extract dropped files from Mime data.
421
    if (!d->hasUrls())
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
        return false;
    const QList<QUrl> urls = d->urls();
    if (urls.empty())
        return false;
    // Try to find local files
    bool hasFiles = false;
    const QList<QUrl>::const_iterator cend = urls.constEnd();
    for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) {
        const QString fileName = it->toLocalFile();
        if (!fileName.isEmpty()) {
            hasFiles = true;
            if (files) {
                files->push_back(fileName);
            } else {
                break; // No result list, sufficient for checking
            }
        }
    }
    return hasFiles;
}

void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
445
    if (isDesktopFileManagerDrop(event->mimeData()) && m_filesToOpenDelayed.isEmpty()) {
446
447
448
449
450
451
452
453
454
455
456
        event->accept();
    } else {
        event->ignore();
    }
}

void MainWindow::dropEvent(QDropEvent *event)
{
    QStringList files;
    if (isDesktopFileManagerDrop(event->mimeData(), &files)) {
        event->accept();
457
458
        m_filesToOpenDelayed.append(files);
        QTimer::singleShot(50, this, SLOT(openDelayedFiles()));
459
460
461
462
463
    } else {
        event->ignore();
    }
}

464
465
466
467
468
469
470
471
472
473
void MainWindow::openDelayedFiles()
{
    if (m_filesToOpenDelayed.isEmpty())
        return;
    activateWindow();
    raise();
    openFiles(m_filesToOpenDelayed, ICore::SwitchMode);
    m_filesToOpenDelayed.clear();
}

con's avatar
con committed
474
475
476
477
478
479
480
481
482
483
484
485
IContext *MainWindow::currentContextObject() const
{
    return m_activeContext;
}

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

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

488
#ifndef Q_OS_MAC // System menu bar on Mac
con's avatar
con committed
489
490
491
492
493
494
495
496
497
    setMenuBar(menubar->menuBar());
#endif
    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);

498
    // File Menu
Eike Ziller's avatar
Eike Ziller committed
499
    ActionContainer *filemenu = ActionManager::createMenu(Constants::M_FILE);
con's avatar
con committed
500
501
502
503
504
505
506
507
508
509
510
511
    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);
    connect(filemenu->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowRecentFiles()));


512
    // Edit Menu
Eike Ziller's avatar
Eike Ziller committed
513
    ActionContainer *medit = ActionManager::createMenu(Constants::M_EDIT);
con's avatar
con committed
514
515
516
517
518
    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);
519
    medit->appendGroup(Constants::G_EDIT_ADVANCED);
520
    medit->appendGroup(Constants::G_EDIT_FIND);
con's avatar
con committed
521
522
    medit->appendGroup(Constants::G_EDIT_OTHER);

523
    // Tools Menu
Eike Ziller's avatar
Eike Ziller committed
524
    ActionContainer *ac = ActionManager::createMenu(Constants::M_TOOLS);
con's avatar
con committed
525
526
527
    menubar->addMenu(ac, Constants::G_TOOLS);
    ac->menu()->setTitle(tr("&Tools"));

528
    // Window Menu
Eike Ziller's avatar
Eike Ziller committed
529
    ActionContainer *mwindow = ActionManager::createMenu(Constants::M_WINDOW);
con's avatar
con committed
530
531
532
    menubar->addMenu(mwindow, Constants::G_WINDOW);
    mwindow->menu()->setTitle(tr("&Window"));
    mwindow->appendGroup(Constants::G_WINDOW_SIZE);
533
    mwindow->appendGroup(Constants::G_WINDOW_VIEWS);
con's avatar
con committed
534
535
536
537
538
    mwindow->appendGroup(Constants::G_WINDOW_PANES);
    mwindow->appendGroup(Constants::G_WINDOW_SPLIT);
    mwindow->appendGroup(Constants::G_WINDOW_NAVIGATE);
    mwindow->appendGroup(Constants::G_WINDOW_OTHER);

539
    // Help Menu
Eike Ziller's avatar
Eike Ziller committed
540
    ac = ActionManager::createMenu(Constants::M_HELP);
con's avatar
con committed
541
542
    menubar->addMenu(ac, Constants::G_HELP);
    ac->menu()->setTitle(tr("&Help"));
543
544
    ac->appendGroup(Constants::G_HELP_HELP);
    ac->appendGroup(Constants::G_HELP_ABOUT);
con's avatar
con committed
545
546
547
548
}

void MainWindow::registerDefaultActions()
{
Eike Ziller's avatar
Eike Ziller committed
549
550
551
552
553
    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
554

555
556
    Context globalContext(Constants::C_GLOBAL);

con's avatar
con committed
557
    // File menu separators
558
559
560
561
    mfile->addSeparator(globalContext, Constants::G_FILE_SAVE);
    mfile->addSeparator(globalContext, Constants::G_FILE_PRINT);
    mfile->addSeparator(globalContext, Constants::G_FILE_CLOSE);
    mfile->addSeparator(globalContext, Constants::G_FILE_OTHER);
con's avatar
con committed
562
    // Edit menu separators
563
564
565
566
    medit->addSeparator(globalContext, Constants::G_EDIT_COPYPASTE);
    medit->addSeparator(globalContext, Constants::G_EDIT_SELECTALL);
    medit->addSeparator(globalContext, Constants::G_EDIT_FIND);
    medit->addSeparator(globalContext, Constants::G_EDIT_ADVANCED);
con's avatar
con committed
567

568
    // Return to editor shortcut: Note this requires Qt to fix up
con's avatar
con committed
569
570
    // handling of shortcut overrides in menus, item views, combos....
    m_focusToEditor = new QShortcut(this);
571
    Command *cmd = ActionManager::registerShortcut(m_focusToEditor, Constants::S_RETURNTOEDITOR, globalContext);
con's avatar
con committed
572
573
574
    cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
    connect(m_focusToEditor, SIGNAL(activated()), this, SLOT(setFocusToEditor()));

575
    // New File Action
576
    QIcon icon = QIcon::fromTheme(QLatin1String("document-new"), QIcon(QLatin1String(Constants::ICON_NEWFILE)));
577
    m_newAction = new QAction(icon, tr("&New File or Project..."), this);
Eike Ziller's avatar
Eike Ziller committed
578
    cmd = ActionManager::registerAction(m_newAction, Constants::NEW, globalContext);
con's avatar
con committed
579
580
581
582
    cmd->setDefaultKeySequence(QKeySequence::New);
    mfile->addAction(cmd, Constants::G_FILE_NEW);
    connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile()));

583
    // Open Action
584
    icon = QIcon::fromTheme(QLatin1String("document-open"), QIcon(QLatin1String(Constants::ICON_OPENFILE)));
585
    m_openAction = new QAction(icon, tr("&Open File or Project..."), this);
Eike Ziller's avatar
Eike Ziller committed
586
    cmd = ActionManager::registerAction(m_openAction, Constants::OPEN, globalContext);
con's avatar
con committed
587
588
589
590
    cmd->setDefaultKeySequence(QKeySequence::Open);
    mfile->addAction(cmd, Constants::G_FILE_OPEN);
    connect(m_openAction, SIGNAL(triggered()), this, SLOT(openFile()));

591
    // Open With Action
592
    m_openWithAction = new QAction(tr("Open File &With..."), this);
Eike Ziller's avatar
Eike Ziller committed
593
    cmd = ActionManager::registerAction(m_openWithAction, Constants::OPEN_WITH, globalContext);
con's avatar
con committed
594
595
596
    mfile->addAction(cmd, Constants::G_FILE_OPEN);
    connect(m_openWithAction, SIGNAL(triggered()), this, SLOT(openFileWith()));

597
    // File->Recent Files Menu
Eike Ziller's avatar
Eike Ziller committed
598
    ActionContainer *ac = ActionManager::createMenu(Constants::M_FILE_RECENTFILES);
con's avatar
con committed
599
    mfile->addMenu(ac, Constants::G_FILE_OPEN);
600
    ac->menu()->setTitle(tr("Recent &Files"));
601
    ac->setOnAllDisabledBehavior(ActionContainer::Show);
con's avatar
con committed
602

603
    // Save Action
604
    icon = QIcon::fromTheme(QLatin1String("document-save"), QIcon(QLatin1String(Constants::ICON_SAVEFILE)));
605
    QAction *tmpaction = new QAction(icon, tr("&Save"), this);
606
    tmpaction->setEnabled(false);
Eike Ziller's avatar
Eike Ziller committed
607
    cmd = ActionManager::registerAction(tmpaction, Constants::SAVE, globalContext);
con's avatar
con committed
608
    cmd->setDefaultKeySequence(QKeySequence::Save);
con's avatar
con committed
609
    cmd->setAttribute(Command::CA_UpdateText);
610
    cmd->setDescription(tr("Save"));
con's avatar
con committed
611
612
    mfile->addAction(cmd, Constants::G_FILE_SAVE);

613
    // Save As Action
614
615
    icon = QIcon::fromTheme(QLatin1String("document-save-as"));
    tmpaction = new QAction(icon, tr("Save &As..."), this);
616
    tmpaction->setEnabled(false);
Eike Ziller's avatar
Eike Ziller committed
617
    cmd = ActionManager::registerAction(tmpaction, Constants::SAVEAS, globalContext);
618
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+Shift+S") : QString()));
con's avatar
con committed
619
    cmd->setAttribute(Command::CA_UpdateText);
620
    cmd->setDescription(tr("Save As..."));
con's avatar
con committed
621
622
    mfile->addAction(cmd, Constants::G_FILE_SAVE);

623
    // SaveAll Action
con's avatar
con committed
624
    m_saveAllAction = new QAction(tr("Save A&ll"), this);
Eike Ziller's avatar
Eike Ziller committed
625
    cmd = ActionManager::registerAction(m_saveAllAction, Constants::SAVEALL, globalContext);
626
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? QString() : tr("Ctrl+Shift+S")));
con's avatar
con committed
627
628
629
    mfile->addAction(cmd, Constants::G_FILE_SAVE);
    connect(m_saveAllAction, SIGNAL(triggered()), this, SLOT(saveAll()));

630
    // Print Action
631
632
    icon = QIcon::fromTheme(QLatin1String("document-print"));
    tmpaction = new QAction(icon, tr("&Print..."), this);
633
    tmpaction->setEnabled(false);
Eike Ziller's avatar
Eike Ziller committed
634
    cmd = ActionManager::registerAction(tmpaction, Constants::PRINT, globalContext);
635
    cmd->setDefaultKeySequence(QKeySequence::Print);
con's avatar
con committed
636
637
    mfile->addAction(cmd, Constants::G_FILE_PRINT);

638
    // Exit Action
639
640
    icon = QIcon::fromTheme(QLatin1String("application-exit"));
    m_exitAction = new QAction(icon, tr("E&xit"), this);
Eike Ziller's avatar
Eike Ziller committed
641
    cmd = ActionManager::registerAction(m_exitAction, Constants::EXIT, globalContext);
con's avatar
con committed
642
643
644
645
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Q")));
    mfile->addAction(cmd, Constants::G_FILE_OTHER);
    connect(m_exitAction, SIGNAL(triggered()), this, SLOT(exit()));

646
    // Undo Action
647
    icon = QIcon::fromTheme(QLatin1String("edit-undo"), QIcon(QLatin1String(Constants::ICON_UNDO)));
648
    tmpaction = new QAction(icon, tr("&Undo"), this);
Eike Ziller's avatar
Eike Ziller committed
649
    cmd = ActionManager::registerAction(tmpaction, Constants::UNDO, globalContext);
con's avatar
con committed
650
    cmd->setDefaultKeySequence(QKeySequence::Undo);
con's avatar
con committed
651
    cmd->setAttribute(Command::CA_UpdateText);
652
    cmd->setDescription(tr("Undo"));
con's avatar
con committed
653
    medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
654
    tmpaction->setEnabled(false);
con's avatar
con committed
655

656
    // Redo Action
657
    icon = QIcon::fromTheme(QLatin1String("edit-redo"), QIcon(QLatin1String(Constants::ICON_REDO)));
658
    tmpaction = new QAction(icon, tr("&Redo"), this);
Eike Ziller's avatar
Eike Ziller committed
659
    cmd = ActionManager::registerAction(tmpaction, Constants::REDO, globalContext);
con's avatar
con committed
660
    cmd->setDefaultKeySequence(QKeySequence::Redo);
con's avatar
con committed
661
    cmd->setAttribute(Command::CA_UpdateText);
662
    cmd->setDescription(tr("Redo"));
con's avatar
con committed
663
    medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
664
    tmpaction->setEnabled(false);
con's avatar
con committed
665

666
    // Cut Action
667
    icon = QIcon::fromTheme(QLatin1String("edit-cut"), QIcon(QLatin1String(Constants::ICON_CUT)));
668
    tmpaction = new QAction(icon, tr("Cu&t"), this);
Eike Ziller's avatar
Eike Ziller committed
669
    cmd = ActionManager::registerAction(tmpaction, Constants::CUT, globalContext);
con's avatar
con committed
670
671
    cmd->setDefaultKeySequence(QKeySequence::Cut);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
672
    tmpaction->setEnabled(false);
con's avatar
con committed
673

674
    // Copy Action
675
    icon = QIcon::fromTheme(QLatin1String("edit-copy"), QIcon(QLatin1String(Constants::ICON_COPY)));
676
    tmpaction = new QAction(icon, tr("&Copy"), this);
Eike Ziller's avatar
Eike Ziller committed
677
    cmd = ActionManager::registerAction(tmpaction, Constants::COPY, globalContext);
con's avatar
con committed
678
679
    cmd->setDefaultKeySequence(QKeySequence::Copy);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
680
    tmpaction->setEnabled(false);
con's avatar
con committed
681

682
    // Paste Action
683
    icon = QIcon::fromTheme(QLatin1String("edit-paste"), QIcon(QLatin1String(Constants::ICON_PASTE)));
684
    tmpaction = new QAction(icon, tr("&Paste"), this);
Eike Ziller's avatar
Eike Ziller committed
685
    cmd = ActionManager::registerAction(tmpaction, Constants::PASTE, globalContext);
con's avatar
con committed
686
687
    cmd->setDefaultKeySequence(QKeySequence::Paste);
    medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
688
    tmpaction->setEnabled(false);
con's avatar
con committed
689

690
    // Select All
691
    icon = QIcon::fromTheme(QLatin1String("edit-select-all"));
con's avatar
con committed
692
    tmpaction = new QAction(icon, tr("Select &All"), this);
Eike Ziller's avatar
Eike Ziller committed
693
    cmd = ActionManager::registerAction(tmpaction, Constants::SELECTALL, globalContext);
con's avatar
con committed
694
695
    cmd->setDefaultKeySequence(QKeySequence::SelectAll);
    medit->addAction(cmd, Constants::G_EDIT_SELECTALL);
696
    tmpaction->setEnabled(false);
con's avatar
con committed
697

698
    // Goto Action
699
    icon = QIcon::fromTheme(QLatin1String("go-jump"));
700
    tmpaction = new QAction(icon, tr("&Go to Line..."), this);
Eike Ziller's avatar
Eike Ziller committed
701
    cmd = ActionManager::registerAction(tmpaction, Constants::GOTO, globalContext);
con's avatar
con committed
702
703
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+L")));
    medit->addAction(cmd, Constants::G_EDIT_OTHER);
704
    tmpaction->setEnabled(false);
con's avatar
con committed
705

706
    // Options Action
con's avatar
con committed
707
    mtools->appendGroup(Constants::G_TOOLS_OPTIONS);
708
    mtools->addSeparator(globalContext, Constants::G_TOOLS_OPTIONS);
con's avatar
con committed
709
    m_optionsAction = new QAction(tr("&Options..."), this);
Eike Ziller's avatar
Eike Ziller committed
710
    cmd = ActionManager::registerAction(m_optionsAction, Constants::OPTIONS, globalContext);
711
712
713
714
    if (UseMacShortcuts) {
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+,")));
        cmd->action()->setMenuRole(QAction::PreferencesRole);
    }
con's avatar
con committed
715
    mtools->addAction(cmd, Constants::G_TOOLS_OPTIONS);
con's avatar
con committed
716
717
    connect(m_optionsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));

718
719
720
    if (UseMacShortcuts) {
        // Minimize Action
        m_minimizeAction = new QAction(tr("Minimize"), this);
Eike Ziller's avatar
Eike Ziller committed
721
        cmd = ActionManager::registerAction(m_minimizeAction, Constants::MINIMIZE_WINDOW, globalContext);
722
723
724
725
726
727
        cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+M")));
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
        connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(showMinimized()));

        // Zoom Action
        m_zoomAction = new QAction(tr("Zoom"), this);
Eike Ziller's avatar
Eike Ziller committed
728
        cmd = ActionManager::registerAction(m_zoomAction, Constants::ZOOM_WINDOW, globalContext);
729
730
731
732
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
        connect(m_zoomAction, SIGNAL(triggered()), this, SLOT(showMaximized()));

        // Window separator
733
        mwindow->addSeparator(globalContext, Constants::G_WINDOW_SIZE);
734
    }
con's avatar
con committed
735

736
    // Show Sidebar Action
737
    m_toggleSideBarAction = new QAction(QIcon(QLatin1String(Constants::ICON_TOGGLE_SIDEBAR)),
738
                                        tr("Show Sidebar"), this);
739
    m_toggleSideBarAction->setCheckable(true);
Eike Ziller's avatar
Eike Ziller committed
740
    cmd = ActionManager::registerAction(m_toggleSideBarAction, Constants::TOGGLE_SIDEBAR, globalContext);
741
    cmd->setAttribute(Command::CA_UpdateText);
742
    cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+0") : tr("Alt+0")));
743
    connect(m_toggleSideBarAction, SIGNAL(triggered(bool)), this, SLOT(setSidebarVisible(bool)));
con's avatar
con committed
744
    m_toggleSideBarButton->setDefaultAction(cmd->action());
745
    mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
con's avatar
con committed
746
747
    m_toggleSideBarAction->setEnabled(false);

748
749
750
#if defined(Q_OS_MAC)
    bool fullScreenCheckable = false;
    const QString fullScreenActionText(tr("Enter Full Screen"));
751
    bool supportsFullScreen = MacFullScreen::supportsFullScreen();
752
753
754
#else
    bool fullScreenCheckable = true;
    const QString fullScreenActionText(tr("Full Screen"));
755
    bool supportsFullScreen = true;
756
#endif
757
758
759
760
    if (supportsFullScreen) {
        // Full Screen Action
        m_toggleFullScreenAction = new QAction(fullScreenActionText, this);
        m_toggleFullScreenAction->setCheckable(fullScreenCheckable);
Eike Ziller's avatar
Eike Ziller committed
761
        cmd = ActionManager::registerAction(m_toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN, globalContext);
762
763
764
765
        cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+Meta+F") : tr("Ctrl+Shift+F11")));
        cmd->setAttribute(Command::CA_UpdateText); /* for Mac */
        mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
        connect(m_toggleFullScreenAction, SIGNAL(triggered(bool)), this, SLOT(setFullScreen(bool)));
766
    }
hjk's avatar
hjk committed
767

768
    // Window->Views
Eike Ziller's avatar
Eike Ziller committed
769
    ActionContainer *mviews = ActionManager::createMenu(Constants::M_WINDOW_VIEWS);
770
771
772
    mwindow->addMenu(mviews, Constants::G_WINDOW_VIEWS);
    mviews->menu()->setTitle(tr("&Views"));

773
    // About IDE Action
774
    icon = QIcon::fromTheme(QLatin1String("help-about"));
775
#ifdef Q_OS_MAC
776
    tmpaction = new QAction(icon, tr("About &Qt Creator"), this); // it's convention not to add dots to the about menu
con's avatar
con committed
777
#else
778
    tmpaction = new QAction(icon, tr("About &Qt Creator..."), this);
con's avatar
con committed
779
#endif
Eike Ziller's avatar
Eike Ziller committed
780
    cmd = ActionManager::registerAction(tmpaction, Constants::ABOUT_QTCREATOR, globalContext);
con's avatar
con committed
781
782
    mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
    tmpaction->setEnabled(true);
783
#ifdef Q_OS_MAC
con's avatar
con committed
784
785
    cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
#endif
con's avatar
con committed
786
    connect(tmpaction, SIGNAL(triggered()), this,  SLOT(aboutQtCreator()));
con's avatar
con committed
787

con's avatar
con committed
788
789
    //About Plugins Action
    tmpaction = new QAction(tr("About &Plugins..."), this);
Eike Ziller's avatar
Eike Ziller committed
790
    cmd = ActionManager::registerAction(tmpaction, Constants::ABOUT_PLUGINS, globalContext);
con's avatar
con committed
791
792
    mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
    tmpaction->setEnabled(true);
793
#ifdef Q_OS_MAC
con's avatar
con committed
794
795
796
    cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
#endif
    connect(tmpaction, SIGNAL(triggered()), this,  SLOT(aboutPlugins()));
797
    // About Qt Action
con's avatar
con committed
798
//    tmpaction = new QAction(tr("About &Qt..."), this);
Eike Ziller's avatar
Eike Ziller committed
799
//    cmd = ActionManager::registerAction(tmpaction, Constants:: ABOUT_QT, globalContext);
con's avatar
con committed
800
801
802
803
//    mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
//    tmpaction->setEnabled(true);
//    connect(tmpaction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    // About sep
804
#ifndef Q_OS_MAC // doesn't have the "About" actions in the Help menu
con's avatar
con committed
805
806
    tmpaction = new QAction(this);
    tmpaction->setSeparator(true);
Eike Ziller's avatar
Eike Ziller committed
807
    cmd = ActionManager::registerAction(tmpaction, "QtCreator.Help.Sep.About", globalContext);
con's avatar
con committed
808
    mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
con's avatar
con committed
809
#endif
con's avatar
con committed
810
811
812
813
}

void MainWindow::newFile()
{
814
    showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards(), QString());
con's avatar
con committed
815
816
817
818
}

void MainWindow::openFile()
{
819
    openFiles(editorManager()->getOpenFileNames(), ICore::SwitchMode);
con's avatar
con committed
820
821
}

822
static QList<IDocumentFactory*> getNonEditorDocumentFactories()
con's avatar
con committed
823
{
824
    const QList<IDocumentFactory*> allFileFactories =
825
        ExtensionSystem::PluginManager::getObjects<IDocumentFactory>();
826
827
    QList<IDocumentFactory*> nonEditorFileFactories;
    foreach (IDocumentFactory *factory, allFileFactories) {
con's avatar
con committed
828
829
830
831
832
833
        if (!qobject_cast<IEditorFactory *>(factory))
            nonEditorFileFactories.append(factory);
    }
    return nonEditorFileFactories;
}

834
static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories,
con's avatar
con committed
835
836
837
838
839
                                     const MimeDatabase *db,
                                     const QFileInfo &fi)
{
    if (const MimeType mt = db->findByFile(fi)) {
        const QString type = mt.type();
840
        foreach (IDocumentFactory *factory, fileFactories) {
con's avatar
con committed
841
842
843
844
845
846
847
848
            if (factory->mimeTypes().contains(type))
                return factory;
        }
    }
    return 0;
}

// opens either an editor or loads a project
849
void MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags)
con's avatar
con committed
850
{
851
    QList<IDocumentFactory*> nonEditorFileFactories = getNonEditorDocumentFactories();
con's avatar
con committed
852
853
854
855

    foreach (const QString &fileName, fileNames) {
        const QFileInfo fi(fileName);
        const QString absoluteFilePath = fi.absoluteFilePath();
856
857
858
        if (IDocumentFactory *documentFactory = findDocumentFactory(nonEditorFileFactories, mimeDatabase(), fi)) {
            Core::IDocument *document = documentFactory->open(absoluteFilePath);
            if (!document && (flags & ICore::StopOnLoadFail))
859
                return;
860
            if (document && (flags & ICore::SwitchMode))
861
                ModeManager::activateMode(Id(Core::Constants::MODE_EDIT));
con's avatar
con committed
862
        } else {
863
            QFlags<EditorManager::OpenEditorFlag> emFlags;
864
            if (flags & ICore::SwitchMode)
865
                emFlags = EditorManager::ModeSwitch;
866
            if (flags & ICore::CanContainLineNumbers)
867
                emFlags |=  EditorManager::CanContainLineNumber;
hjk's avatar
hjk committed
868
            Core::IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
869
870
            if (!editor && (flags & ICore::StopOnLoadFail))
                return;
con's avatar
con committed
871
872
873
874
875
876
        }
    }
}

void MainWindow::setFocusToEditor()
{
mae's avatar
mae committed
877
    bool focusWasMovedToEditor = false;
con's avatar
con committed
878

mae's avatar
mae committed
879
    // give focus to the editor if we have one
hjk's avatar
hjk committed
880
    if (IEditor *editor = EditorManager::currentEditor()) {
Yuchen Deng's avatar
Yuchen Deng committed
881
        if (qApp->focusWidget() != editor->widget()->focusWidget()) {
Eike Ziller's avatar
Eike Ziller committed
882
883
884
885
886
            QWidget *w = editor->widget()->focusWidget();
            if (!w)
                w = editor->widget();
            w->setFocus();
            focusWasMovedToEditor = w->hasFocus();
887
        }
con's avatar
con committed
888
    }
mae's avatar
mae committed
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

    // check for some maximized pane which we want to unmaximize
    if (OutputPanePlaceHolder::getCurrent()
        && OutputPanePlaceHolder::getCurrent()->isVisible()
        && OutputPanePlaceHolder::getCurrent()->isMaximized()) {
        OutputPanePlaceHolder::getCurrent()->unmaximize();
        return;
    }

    if (focusWasMovedToEditor)
        return;

    // check for some visible bar which we want to hide
    bool stuffVisible =
            (FindToolBarPlaceHolder::getCurrent() &&
             FindToolBarPlaceHolder::getCurrent()->isVisible())
            || (OutputPanePlaceHolder::getCurrent() &&
                OutputPanePlaceHolder::getCurrent()->isVisible())
            || (RightPanePlaceHolder::current() &&
                RightPanePlaceHolder::current()->isVisible());
    if (stuffVisible) {
        if (FindToolBarPlaceHolder::getCurrent())
            FindToolBarPlaceHolder::getCurrent()->hide();
        OutputPaneManager::instance()->slotHide();
        RightPaneWidget::instance()->setShown(false);
        return;
    }

    // switch to edit mode if necessary
918
    ModeManager::activateMode(Id(Constants::MODE_EDIT));