editortoolbar.cpp 15.2 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Lasse Holmstedt's avatar
Lasse Holmstedt committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Lasse Holmstedt's avatar
Lasse Holmstedt committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Lasse Holmstedt's avatar
Lasse Holmstedt 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.
Lasse Holmstedt's avatar
Lasse Holmstedt committed
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
****************************************************************************/
Lasse Holmstedt's avatar
Lasse Holmstedt committed
29

30
#include "editortoolbar.h"
Lasse Holmstedt's avatar
Lasse Holmstedt committed
31 32 33 34

#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
35

Lasse Holmstedt's avatar
Lasse Holmstedt committed
36
#include <coreplugin/editormanager/editormanager.h>
37
#include <coreplugin/editormanager/documentmodel.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
38 39
#include <coreplugin/actionmanager/actionmanager.h>

40
#include <utils/hostosinfo.h>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
41 42
#include <utils/qtcassert.h>

43 44 45 46 47 48 49
#include <QDir>
#include <QApplication>
#include <QComboBox>
#include <QVBoxLayout>
#include <QToolButton>
#include <QMenu>
#include <QClipboard>
Lasse Holmstedt's avatar
Lasse Holmstedt committed
50 51 52 53 54

enum {
    debug = false
};

55
namespace Core {
Lasse Holmstedt's avatar
Lasse Holmstedt committed
56

hjk's avatar
hjk committed
57 58
struct EditorToolBarPrivate
{
59 60 61
    explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q);

    QComboBox *m_editorList;
62
    QToolButton *m_closeEditorButton;
63 64 65 66 67
    QToolButton *m_lockButton;
    QAction *m_goBackAction;
    QAction *m_goForwardAction;
    QToolButton *m_backButton;
    QToolButton *m_forwardButton;
68 69 70
    QToolButton *m_splitButton;
    QAction *m_horizontalSplitAction;
    QAction *m_verticalSplitAction;
71
    QAction *m_splitNewWindowAction;
72
    QToolButton *m_closeSplitButton;
73 74 75 76 77 78 79 80 81 82

    QWidget *m_activeToolBar;
    QWidget *m_toolBarPlaceholder;
    QWidget *m_defaultToolBar;

    bool m_isStandalone;
};

EditorToolBarPrivate::EditorToolBarPrivate(QWidget *parent, EditorToolBar *q) :
    m_editorList(new QComboBox(q)),
83
    m_closeEditorButton(new QToolButton),
84 85 86
    m_lockButton(new QToolButton),
    m_goBackAction(new QAction(QIcon(QLatin1String(Constants::ICON_PREV)), EditorManager::tr("Go Back"), parent)),
    m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), parent)),
87 88
    m_splitButton(new QToolButton),
    m_horizontalSplitAction(new QAction(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)), EditorManager::tr("Split"), parent)),
Eike Ziller's avatar
Eike Ziller committed
89
    m_verticalSplitAction(new QAction(QIcon(QLatin1String(Constants::ICON_SPLIT_VERTICAL)), EditorManager::tr("Split Side by Side"), parent)),
90
    m_splitNewWindowAction(new QAction(EditorManager::tr("Open in New Window"), parent)),
91
    m_closeSplitButton(new QToolButton),
92 93 94 95 96 97 98
    m_activeToolBar(0),
    m_toolBarPlaceholder(new QWidget),
    m_defaultToolBar(new QWidget(q)),
    m_isStandalone(false)
{
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
99 100 101
/*!
  Mimic the look of the text editor toolbar as defined in e.g. EditorView::EditorView
  */
Lasse Holmstedt's avatar
Lasse Holmstedt committed
102
EditorToolBar::EditorToolBar(QWidget *parent) :
103
        Utils::StyledBar(parent), d(new EditorToolBarPrivate(parent, this))
Lasse Holmstedt's avatar
Lasse Holmstedt committed
104
{
Lasse Holmstedt's avatar
Lasse Holmstedt committed
105 106 107
    QHBoxLayout *toolBarLayout = new QHBoxLayout(this);
    toolBarLayout->setMargin(0);
    toolBarLayout->setSpacing(0);
108 109 110
    toolBarLayout->addWidget(d->m_defaultToolBar);
    d->m_toolBarPlaceholder->setLayout(toolBarLayout);
    d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
111

112 113
    d->m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    d->m_activeToolBar = d->m_defaultToolBar;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
114

115 116 117
    d->m_lockButton->setAutoRaise(true);
    d->m_lockButton->setEnabled(false);

118 119
    connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
    connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
120

121
    d->m_editorList->setProperty("hideicon", true);
122
    d->m_editorList->setProperty("notelideasterisk", true);
123 124
    d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    d->m_editorList->setMinimumContentsLength(20);
hjk's avatar
hjk committed
125
    d->m_editorList->setModel(DocumentModel::model());
126 127
    d->m_editorList->setMaxVisibleItems(40);
    d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
128

129
    d->m_closeEditorButton->setAutoRaise(true);
Eike Ziller's avatar
Eike Ziller committed
130
    d->m_closeEditorButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_DOCUMENT)));
131
    d->m_closeEditorButton->setEnabled(false);
132
    d->m_closeEditorButton->setProperty("showborder", true);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
133

134
    d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
135

136 137
    d->m_backButton = new QToolButton(this);
    d->m_backButton->setDefaultAction(d->m_goBackAction);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
138

139 140
    d->m_forwardButton= new QToolButton(this);
    d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
141

142 143 144
    if (Utils::HostOsInfo::isMacHost()) {
        d->m_horizontalSplitAction->setIconVisibleInMenu(false);
        d->m_verticalSplitAction->setIconVisibleInMenu(false);
145
        d->m_splitNewWindowAction->setIconVisibleInMenu(false);
146
    }
147 148 149 150

    d->m_splitButton->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
    d->m_splitButton->setToolTip(tr("Split"));
    d->m_splitButton->setPopupMode(QToolButton::InstantPopup);
Eike Ziller's avatar
Eike Ziller committed
151
    d->m_splitButton->setProperty("noArrow", true);
152 153 154
    QMenu *splitMenu = new QMenu(d->m_splitButton);
    splitMenu->addAction(d->m_horizontalSplitAction);
    splitMenu->addAction(d->m_verticalSplitAction);
155
    splitMenu->addAction(d->m_splitNewWindowAction);
156 157 158
    d->m_splitButton->setMenu(splitMenu);

    d->m_closeSplitButton->setAutoRaise(true);
Eike Ziller's avatar
Eike Ziller committed
159
    d->m_closeSplitButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_SPLIT_BOTTOM)));
160

Lasse Holmstedt's avatar
Lasse Holmstedt committed
161 162 163
    QHBoxLayout *toplayout = new QHBoxLayout(this);
    toplayout->setSpacing(0);
    toplayout->setMargin(0);
164 165
    toplayout->addWidget(d->m_backButton);
    toplayout->addWidget(d->m_forwardButton);
166
    toplayout->addWidget(d->m_lockButton);
167
    toplayout->addWidget(d->m_editorList);
168
    toplayout->addWidget(d->m_closeEditorButton);
169 170 171
    toplayout->addWidget(d->m_toolBarPlaceholder, 1); // Custom toolbar stretches
    toplayout->addWidget(d->m_splitButton);
    toplayout->addWidget(d->m_closeSplitButton);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
172

Lasse Holmstedt's avatar
Lasse Holmstedt committed
173 174
    setLayout(toplayout);

175 176
    // this signal is disconnected for standalone toolbars and replaced with
    // a private slot connection
177
    connect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
178

179 180
    connect(d->m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
    connect(d->m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
181 182 183 184 185
    connect(d->m_closeEditorButton, SIGNAL(clicked()), this, SLOT(closeEditor()), Qt::QueuedConnection);
    connect(d->m_horizontalSplitAction, SIGNAL(triggered()),
            this, SIGNAL(horizontalSplitClicked()), Qt::QueuedConnection);
    connect(d->m_verticalSplitAction, SIGNAL(triggered()),
            this, SIGNAL(verticalSplitClicked()), Qt::QueuedConnection);
186 187
    connect(d->m_splitNewWindowAction, SIGNAL(triggered()),
            this, SIGNAL(splitNewWindowClicked()), Qt::QueuedConnection);
188 189 190
    connect(d->m_closeSplitButton, SIGNAL(clicked()),
            this, SIGNAL(closeSplitClicked()), Qt::QueuedConnection);

Lasse Holmstedt's avatar
Lasse Holmstedt committed
191

Eike Ziller's avatar
Eike Ziller committed
192
    connect(ActionManager::command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
193
            this, SLOT(updateActionShortcuts()));
Eike Ziller's avatar
Eike Ziller committed
194
    connect(ActionManager::command(Constants::GO_BACK), SIGNAL(keySequenceChanged()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
195
            this, SLOT(updateActionShortcuts()));
Eike Ziller's avatar
Eike Ziller committed
196
    connect(ActionManager::command(Constants::GO_FORWARD), SIGNAL(keySequenceChanged()),
Lasse Holmstedt's avatar
Lasse Holmstedt committed
197
            this, SLOT(updateActionShortcuts()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
198

199
    updateActionShortcuts();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
200 201
}

202 203
EditorToolBar::~EditorToolBar()
{
hjk's avatar
hjk committed
204
    delete d;
205 206
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
207
void EditorToolBar::removeToolbarForEditor(IEditor *editor)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
208
{
209
    QTC_ASSERT(editor, return);
210
    disconnect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
211 212 213

    QWidget *toolBar = editor->toolBar();
    if (toolBar != 0) {
214 215 216
        if (d->m_activeToolBar == toolBar) {
            d->m_activeToolBar = d->m_defaultToolBar;
            d->m_activeToolBar->setVisible(true);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
217
        }
218
        d->m_toolBarPlaceholder->layout()->removeWidget(toolBar);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
219 220 221 222 223
        toolBar->setVisible(false);
        toolBar->setParent(0);
    }
}

224 225 226 227 228
void EditorToolBar::setCloseSplitEnabled(bool enable)
{
    d->m_closeSplitButton->setVisible(enable);
}

Eike Ziller's avatar
Eike Ziller committed
229 230 231 232 233
void EditorToolBar::setCloseSplitIcon(const QIcon &icon)
{
    d->m_closeSplitButton->setIcon(icon);
}

234
void EditorToolBar::closeEditor()
Lasse Holmstedt's avatar
Lasse Holmstedt committed
235
{
hjk's avatar
hjk committed
236 237
    IEditor *current = EditorManager::currentEditor();
    if (!current)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
238 239
        return;

hjk's avatar
hjk committed
240
    if (d->m_isStandalone)
241
        EditorManager::closeEditor(current);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
242 243 244
    emit closeClicked();
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
245
void EditorToolBar::addEditor(IEditor *editor)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
246
{
247
    QTC_ASSERT(editor, return);
248
    connect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
249 250
    QWidget *toolBar = editor->toolBar();

251
    if (toolBar && !d->m_isStandalone)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
252
        addCenterToolBar(toolBar);
253

254
    updateDocumentStatus(editor->document());
Lasse Holmstedt's avatar
Lasse Holmstedt committed
255 256 257 258
}

void EditorToolBar::addCenterToolBar(QWidget *toolBar)
{
259
    QTC_ASSERT(toolBar, return);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
260
    toolBar->setVisible(false); // will be made visible in setCurrentEditor
261
    d->m_toolBarPlaceholder->layout()->addWidget(toolBar);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
262 263 264 265 266 267 268

    updateToolBar(toolBar);
}

void EditorToolBar::updateToolBar(QWidget *toolBar)
{
    if (!toolBar)
269 270
        toolBar = d->m_defaultToolBar;
    if (d->m_activeToolBar == toolBar)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
271 272
        return;
    toolBar->setVisible(true);
273 274
    d->m_activeToolBar->setVisible(false);
    d->m_activeToolBar = toolBar;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
275 276
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
277 278
void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
{
279 280
    d->m_isStandalone = flags & FlagsStandalone;
    if (d->m_isStandalone) {
281
        EditorManager *em = EditorManager::instance();
282
        connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*)));
283

284 285
        disconnect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
        connect(d->m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int)));
286 287
        d->m_splitButton->setVisible(false);
        d->m_closeSplitButton->setVisible(false);
288
    }
Lasse Holmstedt's avatar
Lasse Holmstedt committed
289
}
Lasse Holmstedt's avatar
Lasse Holmstedt committed
290 291

void EditorToolBar::setCurrentEditor(IEditor *editor)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
292
{
293
    IDocument *document = editor ? editor->document() : 0;
hjk's avatar
hjk committed
294
    d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
295 296 297

    // If we never added the toolbar from the editor,  we will never change
    // the editor, so there's no need to update the toolbar either.
298
    if (!d->m_isStandalone)
299
        updateToolBar(editor ? editor->toolBar() : 0);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
300

301
    updateDocumentStatus(document);
302
}
Lasse Holmstedt's avatar
Lasse Holmstedt committed
303

Lasse Holmstedt's avatar
Lasse Holmstedt committed
304
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
305
{
306
    if (newSelection)
hjk's avatar
hjk committed
307
        d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(newSelection->document()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
308 309
}

310
void EditorToolBar::changeActiveEditor(int row)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
311
{
312
    EditorManager::activateEditorForEntry(DocumentModel::entryAtRow(row));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
313 314
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
315
void EditorToolBar::listContextMenu(QPoint pos)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
316
{
317
    DocumentModel::Entry *entry = DocumentModel::entryAtRow(
318
                d->m_editorList->currentIndex());
319
    QString fileName = entry ? entry->fileName() : QString();
320
    QString shortFileName = entry ? QFileInfo(fileName).fileName() : QString();
Lasse Holmstedt's avatar
Lasse Holmstedt committed
321
    QMenu menu;
322
    QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
323
    QAction *copyFileName = menu.addAction(tr("Copy File Name to Clipboard"));
Robert Loehning's avatar
Robert Loehning committed
324
    menu.addSeparator();
325 326 327 328
    if (fileName.isEmpty() || shortFileName.isEmpty()) {
        copyPath->setEnabled(false);
        copyFileName->setEnabled(false);
    }
329
    EditorManager::addSaveAndCloseEditorActions(&menu, entry);
Robert Loehning's avatar
Robert Loehning committed
330
    menu.addSeparator();
331
    EditorManager::addNativeDirAndOpenWithActions(&menu, entry);
332
    QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
333
    if (result == copyPath)
334
        QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
335 336
    if (result == copyFileName)
        QApplication::clipboard()->setText(shortFileName);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
337 338
}

Lasse Holmstedt's avatar
Lasse Holmstedt committed
339 340
void EditorToolBar::makeEditorWritable()
{
341
    if (IDocument *current = EditorManager::currentDocument())
342
        EditorManager::makeFileWritable(current);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
343 344 345 346
}

void EditorToolBar::setCanGoBack(bool canGoBack)
{
347
    d->m_goBackAction->setEnabled(canGoBack);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
348 349 350 351
}

void EditorToolBar::setCanGoForward(bool canGoForward)
{
352
    d->m_goForwardAction->setEnabled(canGoForward);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
353 354 355
}

void EditorToolBar::updateActionShortcuts()
Lasse Holmstedt's avatar
Lasse Holmstedt committed
356
{
Eike Ziller's avatar
Eike Ziller committed
357 358 359 360
    d->m_closeEditorButton->setToolTip(ActionManager::command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close Document")));
    d->m_goBackAction->setToolTip(ActionManager::command(Constants::GO_BACK)->action()->toolTip());
    d->m_goForwardAction->setToolTip(ActionManager::command(Constants::GO_FORWARD)->action()->toolTip());
    d->m_closeSplitButton->setToolTip(ActionManager::command(Constants::REMOVE_CURRENT_SPLIT)->stringWithAppendedShortcut(tr("Remove Split")));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
361 362
}

363
void EditorToolBar::checkDocumentStatus()
Lasse Holmstedt's avatar
Lasse Holmstedt committed
364
{
365 366
    IDocument *document = qobject_cast<IDocument *>(sender());
    QTC_ASSERT(document, return);
367
    DocumentModel::Entry *entry = DocumentModel::entryAtRow(
368
                d->m_editorList->currentIndex());
Lasse Holmstedt's avatar
Lasse Holmstedt committed
369

370 371
    if (entry && entry->document && entry->document == document)
        updateDocumentStatus(document);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
372 373
}

374
void EditorToolBar::updateDocumentStatus(IDocument *document)
Lasse Holmstedt's avatar
Lasse Holmstedt committed
375
{
376
    d->m_closeEditorButton->setEnabled(document != 0);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
377

378
    if (!document) {
379 380 381
        d->m_lockButton->setIcon(QIcon());
        d->m_lockButton->setEnabled(false);
        d->m_lockButton->setToolTip(QString());
382
        d->m_editorList->setToolTip(QString());
Lasse Holmstedt's avatar
Lasse Holmstedt committed
383
        return;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
384
    }
Lasse Holmstedt's avatar
Lasse Holmstedt committed
385

hjk's avatar
hjk committed
386
    d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
387

388
    if (document->filePath().isEmpty()) {
389 390 391
        d->m_lockButton->setIcon(QIcon());
        d->m_lockButton->setEnabled(false);
        d->m_lockButton->setToolTip(QString());
392
    } else if (document->isFileReadOnly()) {
hjk's avatar
hjk committed
393
        d->m_lockButton->setIcon(DocumentModel::lockedIcon());
394
        d->m_lockButton->setEnabled(true);
Leena Miettinen's avatar
Leena Miettinen committed
395
        d->m_lockButton->setToolTip(tr("Make Writable"));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
396
    } else {
hjk's avatar
hjk committed
397
        d->m_lockButton->setIcon(DocumentModel::unlockedIcon());
398 399
        d->m_lockButton->setEnabled(false);
        d->m_lockButton->setToolTip(tr("File is writable"));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
400
    }
401 402 403 404
    d->m_editorList->setToolTip(
            document->filePath().isEmpty()
            ? document->displayName()
            : QDir::toNativeSeparators(document->filePath()));
Lasse Holmstedt's avatar
Lasse Holmstedt committed
405 406 407 408
}

void EditorToolBar::setNavigationVisible(bool isVisible)
{
409 410 411 412
    d->m_goBackAction->setVisible(isVisible);
    d->m_goForwardAction->setVisible(isVisible);
    d->m_backButton->setVisible(isVisible);
    d->m_forwardButton->setVisible(isVisible);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
413 414
}

415
} // Core