2010-02-26 11:08:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-03-10 12:48:17 +01:00
|
|
|
#include "editortoolbar.h"
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-03-09 09:42:22 +01:00
|
|
|
#include <coreplugin/minisplitter.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/sidebar.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-03-12 16:47:46 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editorview.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/openeditorsmodel.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/parameteraction.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2010-03-09 17:40:55 +01:00
|
|
|
#include <utils/styledbar.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QToolBar>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
namespace Core {
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
struct EditorToolBarPrivate {
|
|
|
|
|
explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q);
|
|
|
|
|
|
|
|
|
|
Core::OpenEditorsModel *m_editorsListModel;
|
|
|
|
|
QComboBox *m_editorList;
|
2011-12-05 13:28:56 +01:00
|
|
|
QToolButton *m_closeEditorButton;
|
2010-09-16 12:26:28 +02:00
|
|
|
QToolButton *m_lockButton;
|
|
|
|
|
QAction *m_goBackAction;
|
|
|
|
|
QAction *m_goForwardAction;
|
|
|
|
|
QToolButton *m_backButton;
|
|
|
|
|
QToolButton *m_forwardButton;
|
2011-12-05 13:28:56 +01:00
|
|
|
QToolButton *m_splitButton;
|
|
|
|
|
QAction *m_horizontalSplitAction;
|
|
|
|
|
QAction *m_verticalSplitAction;
|
|
|
|
|
QToolButton *m_closeSplitButton;
|
2010-09-16 12:26:28 +02:00
|
|
|
|
|
|
|
|
QWidget *m_activeToolBar;
|
|
|
|
|
QWidget *m_toolBarPlaceholder;
|
|
|
|
|
QWidget *m_defaultToolBar;
|
|
|
|
|
|
|
|
|
|
bool m_isStandalone;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EditorToolBarPrivate::EditorToolBarPrivate(QWidget *parent, EditorToolBar *q) :
|
|
|
|
|
m_editorList(new QComboBox(q)),
|
2011-12-05 13:28:56 +01:00
|
|
|
m_closeEditorButton(new QToolButton),
|
2010-09-16 12:26:28 +02:00
|
|
|
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)),
|
2011-12-05 13:28:56 +01:00
|
|
|
m_splitButton(new QToolButton),
|
|
|
|
|
m_horizontalSplitAction(new QAction(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)), EditorManager::tr("Split"), parent)),
|
2012-02-01 21:39:05 +01:00
|
|
|
m_verticalSplitAction(new QAction(QIcon(QLatin1String(Constants::ICON_SPLIT_VERTICAL)), EditorManager::tr("Split Side by Side"), parent)),
|
2011-12-05 13:28:56 +01:00
|
|
|
m_closeSplitButton(new QToolButton),
|
2010-09-16 12:26:28 +02:00
|
|
|
m_activeToolBar(0),
|
|
|
|
|
m_toolBarPlaceholder(new QWidget),
|
|
|
|
|
m_defaultToolBar(new QWidget(q)),
|
|
|
|
|
m_isStandalone(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
/*!
|
|
|
|
|
Mimic the look of the text editor toolbar as defined in e.g. EditorView::EditorView
|
|
|
|
|
*/
|
2010-03-09 17:40:55 +01:00
|
|
|
EditorToolBar::EditorToolBar(QWidget *parent) :
|
2010-09-16 12:26:28 +02:00
|
|
|
Utils::StyledBar(parent), d(new EditorToolBarPrivate(parent, this))
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 17:40:55 +01:00
|
|
|
QHBoxLayout *toolBarLayout = new QHBoxLayout(this);
|
|
|
|
|
toolBarLayout->setMargin(0);
|
|
|
|
|
toolBarLayout->setSpacing(0);
|
2010-09-16 12:26:28 +02:00
|
|
|
toolBarLayout->addWidget(d->m_defaultToolBar);
|
|
|
|
|
d->m_toolBarPlaceholder->setLayout(toolBarLayout);
|
|
|
|
|
d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
|
d->m_activeToolBar = d->m_defaultToolBar;
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2011-12-06 11:40:16 +01:00
|
|
|
d->m_lockButton->setAutoRaise(true);
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorsListModel = EditorManager::instance()->openedEditorsModel();
|
|
|
|
|
connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
|
|
|
|
|
connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2011-12-09 16:45:49 +01:00
|
|
|
d->m_editorList->setProperty("hideicon", true);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
d->m_editorList->setMinimumContentsLength(20);
|
|
|
|
|
d->m_editorList->setModel(d->m_editorsListModel);
|
|
|
|
|
d->m_editorList->setMaxVisibleItems(40);
|
|
|
|
|
d->m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_closeEditorButton->setAutoRaise(true);
|
2012-02-01 21:39:05 +01:00
|
|
|
d->m_closeEditorButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_DOCUMENT)));
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_closeEditorButton->setEnabled(false);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_backButton = new QToolButton(this);
|
|
|
|
|
d->m_backButton->setDefaultAction(d->m_goBackAction);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_forwardButton= new QToolButton(this);
|
|
|
|
|
d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-01-25 10:25:05 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_horizontalSplitAction->setIconVisibleInMenu(false);
|
|
|
|
|
d->m_verticalSplitAction->setIconVisibleInMenu(false);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
d->m_splitButton->setIcon(QIcon(QLatin1String(Constants::ICON_SPLIT_HORIZONTAL)));
|
|
|
|
|
d->m_splitButton->setToolTip(tr("Split"));
|
|
|
|
|
d->m_splitButton->setPopupMode(QToolButton::InstantPopup);
|
2012-02-01 21:39:05 +01:00
|
|
|
d->m_splitButton->setProperty("noArrow", true);
|
2011-12-05 13:28:56 +01:00
|
|
|
QMenu *splitMenu = new QMenu(d->m_splitButton);
|
|
|
|
|
splitMenu->addAction(d->m_horizontalSplitAction);
|
|
|
|
|
splitMenu->addAction(d->m_verticalSplitAction);
|
|
|
|
|
d->m_splitButton->setMenu(splitMenu);
|
|
|
|
|
|
|
|
|
|
d->m_closeSplitButton->setAutoRaise(true);
|
2012-02-01 21:39:05 +01:00
|
|
|
d->m_closeSplitButton->setIcon(QIcon(QLatin1String(Constants::ICON_CLOSE_SPLIT_BOTTOM)));
|
2011-12-05 13:28:56 +01:00
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
QHBoxLayout *toplayout = new QHBoxLayout(this);
|
|
|
|
|
toplayout->setSpacing(0);
|
|
|
|
|
toplayout->setMargin(0);
|
2010-09-16 12:26:28 +02:00
|
|
|
toplayout->addWidget(d->m_backButton);
|
|
|
|
|
toplayout->addWidget(d->m_forwardButton);
|
2011-12-06 11:40:16 +01:00
|
|
|
toplayout->addWidget(d->m_lockButton);
|
2010-09-16 12:26:28 +02:00
|
|
|
toplayout->addWidget(d->m_editorList);
|
2011-12-05 13:28:56 +01:00
|
|
|
toplayout->addWidget(d->m_toolBarPlaceholder, 1); // Custom toolbar stretches
|
|
|
|
|
toplayout->addWidget(d->m_splitButton);
|
|
|
|
|
toplayout->addWidget(d->m_closeSplitButton);
|
2012-02-01 21:39:05 +01:00
|
|
|
toplayout->addWidget(d->m_closeEditorButton);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
setLayout(toplayout);
|
|
|
|
|
|
2010-03-15 16:02:38 +01:00
|
|
|
// this signal is disconnected for standalone toolbars and replaced with
|
|
|
|
|
// a private slot connection
|
2010-09-16 12:26:28 +02:00
|
|
|
connect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
|
2010-03-15 16:02:38 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
connect(d->m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
|
|
|
|
|
connect(d->m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
|
2011-12-05 13:28:56 +01:00
|
|
|
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);
|
|
|
|
|
connect(d->m_closeSplitButton, SIGNAL(clicked()),
|
|
|
|
|
this, SIGNAL(closeSplitClicked()), Qt::QueuedConnection);
|
|
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
ActionManager *am = ICore::actionManager();
|
2010-03-09 17:40:55 +01:00
|
|
|
connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
|
|
|
|
|
this, SLOT(updateActionShortcuts()));
|
|
|
|
|
connect(am->command(Constants::GO_BACK), SIGNAL(keySequenceChanged()),
|
|
|
|
|
this, SLOT(updateActionShortcuts()));
|
|
|
|
|
connect(am->command(Constants::GO_FORWARD), SIGNAL(keySequenceChanged()),
|
|
|
|
|
this, SLOT(updateActionShortcuts()));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-02-17 14:00:45 +01:00
|
|
|
updateActionShortcuts();
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
EditorToolBar::~EditorToolBar()
|
|
|
|
|
{
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2010-09-16 12:26:28 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::removeToolbarForEditor(IEditor *editor)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(editor, return);
|
2010-03-09 17:40:55 +01:00
|
|
|
disconnect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
|
|
|
|
|
|
|
|
|
QWidget *toolBar = editor->toolBar();
|
|
|
|
|
if (toolBar != 0) {
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_activeToolBar == toolBar) {
|
|
|
|
|
d->m_activeToolBar = d->m_defaultToolBar;
|
|
|
|
|
d->m_activeToolBar->setVisible(true);
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toolBarPlaceholder->layout()->removeWidget(toolBar);
|
2010-03-09 17:40:55 +01:00
|
|
|
toolBar->setVisible(false);
|
|
|
|
|
toolBar->setParent(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-05 13:28:56 +01:00
|
|
|
void EditorToolBar::setCloseSplitEnabled(bool enable)
|
|
|
|
|
{
|
|
|
|
|
d->m_closeSplitButton->setVisible(enable);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 21:39:05 +01:00
|
|
|
void EditorToolBar::setCloseSplitIcon(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
d->m_closeSplitButton->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-05 13:28:56 +01:00
|
|
|
void EditorToolBar::closeEditor()
|
2010-03-09 17:40:55 +01:00
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
IEditor *current = EditorManager::currentEditor();
|
|
|
|
|
if (!current)
|
2010-03-09 17:40:55 +01:00
|
|
|
return;
|
|
|
|
|
|
2012-05-08 09:43:14 +02:00
|
|
|
if (d->m_isStandalone)
|
|
|
|
|
EditorManager::instance()->closeEditor(current);
|
2010-03-09 17:40:55 +01:00
|
|
|
emit closeClicked();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 10:50:11 +01:00
|
|
|
void EditorToolBar::addEditor(IEditor *editor)
|
2010-03-09 17:40:55 +01:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(editor, return);
|
2010-03-09 17:40:55 +01:00
|
|
|
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
|
|
|
|
QWidget *toolBar = editor->toolBar();
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
if (toolBar && !d->m_isStandalone)
|
2010-03-09 17:40:55 +01:00
|
|
|
addCenterToolBar(toolBar);
|
2010-03-09 09:42:22 +01:00
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
updateEditorStatus(editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::addCenterToolBar(QWidget *toolBar)
|
|
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(toolBar, return);
|
2010-03-09 17:40:55 +01:00
|
|
|
toolBar->setVisible(false); // will be made visible in setCurrentEditor
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_toolBarPlaceholder->layout()->addWidget(toolBar);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
|
|
|
|
updateToolBar(toolBar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::updateToolBar(QWidget *toolBar)
|
|
|
|
|
{
|
|
|
|
|
if (!toolBar)
|
2010-09-16 12:26:28 +02:00
|
|
|
toolBar = d->m_defaultToolBar;
|
|
|
|
|
if (d->m_activeToolBar == toolBar)
|
2010-03-09 17:40:55 +01:00
|
|
|
return;
|
|
|
|
|
toolBar->setVisible(true);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_activeToolBar->setVisible(false);
|
|
|
|
|
d->m_activeToolBar = toolBar;
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 10:50:11 +01:00
|
|
|
void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_isStandalone = flags & FlagsStandalone;
|
|
|
|
|
if (d->m_isStandalone) {
|
2010-03-12 16:47:46 +01:00
|
|
|
EditorManager *em = EditorManager::instance();
|
|
|
|
|
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*)));
|
2010-03-15 16:02:38 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
disconnect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
|
|
|
|
|
connect(d->m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int)));
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_splitButton->setVisible(false);
|
|
|
|
|
d->m_closeSplitButton->setVisible(false);
|
2010-03-12 16:47:46 +01:00
|
|
|
}
|
2010-03-10 10:50:11 +01:00
|
|
|
}
|
2010-03-09 17:40:55 +01:00
|
|
|
|
|
|
|
|
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(editor, return);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
|
2010-03-09 17:40:55 +01:00
|
|
|
|
|
|
|
|
// 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.
|
2010-09-16 12:26:28 +02:00
|
|
|
if (!d->m_isStandalone)
|
2010-03-09 17:40:55 +01:00
|
|
|
updateToolBar(editor->toolBar());
|
|
|
|
|
|
|
|
|
|
updateEditorStatus(editor);
|
2010-03-09 09:42:22 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
|
2010-03-09 09:42:22 +01:00
|
|
|
{
|
2010-03-12 16:47:46 +01:00
|
|
|
if (newSelection)
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(newSelection).row());
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-15 16:02:38 +01:00
|
|
|
void EditorToolBar::changeActiveEditor(int row)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
EditorManager *em = ICore::editorManager();
|
2010-09-16 12:26:28 +02:00
|
|
|
QAbstractItemModel *model = d->m_editorList->model();
|
2010-12-17 13:14:01 +01:00
|
|
|
em->activateEditorForIndex(model->index(row, 0), EditorManager::ModeSwitch);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::listContextMenu(QPoint pos)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
QModelIndex index = d->m_editorsListModel->index(d->m_editorList->currentIndex(), 0);
|
|
|
|
|
QString fileName = d->m_editorsListModel->data(index, Qt::UserRole + 1).toString();
|
2010-02-26 11:08:17 +01:00
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
QMenu menu;
|
2011-08-15 15:21:02 +02:00
|
|
|
QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
|
2011-08-16 18:55:23 +02:00
|
|
|
menu.addSeparator();
|
2011-08-15 15:21:02 +02:00
|
|
|
EditorManager::instance()->addCloseEditorActions(&menu, index);
|
2011-08-16 18:55:23 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
|
EditorManager::instance()->addNativeDirActions(&menu, index);
|
2011-08-15 15:21:02 +02:00
|
|
|
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
|
|
|
|
|
if (result == copyPath) {
|
2010-06-25 20:05:41 +02:00
|
|
|
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::makeEditorWritable()
|
|
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
if (IEditor *current = EditorManager::currentEditor())
|
|
|
|
|
EditorManager::instance()->makeFileWritable(current->document());
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::setCanGoBack(bool canGoBack)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_goBackAction->setEnabled(canGoBack);
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::setCanGoForward(bool canGoForward)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_goForwardAction->setEnabled(canGoForward);
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::updateActionShortcuts()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
ActionManager *am = ICore::actionManager();
|
2012-02-17 14:00:45 +01:00
|
|
|
d->m_closeEditorButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close Document")));
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_goBackAction->setToolTip(am->command(Constants::GO_BACK)->action()->toolTip());
|
|
|
|
|
d->m_goForwardAction->setToolTip(am->command(Constants::GO_FORWARD)->action()->toolTip());
|
2012-02-17 14:00:45 +01:00
|
|
|
d->m_closeSplitButton->setToolTip(am->command(Constants::REMOVE_CURRENT_SPLIT)->stringWithAppendedShortcut(tr("Remove Split")));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::checkEditorStatus()
|
|
|
|
|
{
|
|
|
|
|
IEditor *editor = qobject_cast<IEditor *>(sender());
|
2012-05-08 09:43:14 +02:00
|
|
|
IEditor *current = EditorManager::currentEditor();
|
2010-03-09 17:40:55 +01:00
|
|
|
|
|
|
|
|
if (current == editor)
|
|
|
|
|
updateEditorStatus(editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::updateEditorStatus(IEditor *editor)
|
|
|
|
|
{
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_closeEditorButton->setEnabled(editor != 0);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
if (!editor || !editor->document()) {
|
2011-12-06 11:40:16 +01:00
|
|
|
d->m_lockButton->setIcon(QIcon());
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(QString());
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setToolTip(QString());
|
2010-02-26 11:08:17 +01:00
|
|
|
return;
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
if (editor->document()->fileName().isEmpty()) {
|
2012-02-14 12:10:29 +01:00
|
|
|
d->m_lockButton->setIcon(QIcon());
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(QString());
|
2012-02-14 16:43:51 +01:00
|
|
|
} else if (editor->document()->isFileReadOnly()) {
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->lockedIcon()));
|
2012-02-14 12:10:29 +01:00
|
|
|
d->m_lockButton->setEnabled(true);
|
2012-01-02 12:18:04 +01:00
|
|
|
d->m_lockButton->setToolTip(tr("Make Writable"));
|
2010-02-26 11:08:17 +01:00
|
|
|
} else {
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_lockButton->setIcon(QIcon(d->m_editorsListModel->unlockedIcon()));
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(tr("File is writable"));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
2012-05-08 09:43:14 +02:00
|
|
|
IEditor *current = EditorManager::currentEditor();
|
|
|
|
|
if (editor == current)
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setToolTip(
|
2012-05-08 09:43:14 +02:00
|
|
|
current->document()->fileName().isEmpty()
|
|
|
|
|
? current->displayName()
|
2012-02-14 16:43:51 +01:00
|
|
|
: QDir::toNativeSeparators(editor->document()->fileName())
|
2010-03-09 17:40:55 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorToolBar::setNavigationVisible(bool isVisible)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_goBackAction->setVisible(isVisible);
|
|
|
|
|
d->m_goForwardAction->setVisible(isVisible);
|
|
|
|
|
d->m_backButton->setVisible(isVisible);
|
|
|
|
|
d->m_forwardButton->setVisible(isVisible);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
} // Core
|