2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-02-26 11:08:17 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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
|
|
|
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2014-07-18 17:11:57 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager_p.h>
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <utils/fileutils.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2010-02-26 11:08:17 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QComboBox>
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDrag>
|
|
|
|
|
#include <QLabel>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMenu>
|
2014-09-04 20:43:09 +02:00
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
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
|
|
|
|
2014-05-07 16:25:04 +02:00
|
|
|
struct EditorToolBarPrivate
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
explicit EditorToolBarPrivate(QWidget *parent, EditorToolBar *q);
|
|
|
|
|
|
|
|
|
|
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;
|
2014-09-04 20:43:09 +02:00
|
|
|
QToolButton *m_dragHandle;
|
2014-09-10 17:03:13 +02:00
|
|
|
QMenu *m_dragHandleMenu;
|
|
|
|
|
EditorToolBar::MenuProvider m_menuProvider;
|
2010-09-16 12:26:28 +02:00
|
|
|
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;
|
2013-04-15 12:53:34 +02:00
|
|
|
QAction *m_splitNewWindowAction;
|
2011-12-05 13:28:56 +01:00
|
|
|
QToolButton *m_closeSplitButton;
|
2010-09-16 12:26:28 +02:00
|
|
|
|
|
|
|
|
QWidget *m_activeToolBar;
|
|
|
|
|
QWidget *m_toolBarPlaceholder;
|
|
|
|
|
QWidget *m_defaultToolBar;
|
|
|
|
|
|
2014-09-04 20:43:09 +02:00
|
|
|
QPoint m_dragStartPosition;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
bool m_isStandalone;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
EditorToolBarPrivate::EditorToolBarPrivate(QWidget *parent, EditorToolBar *q) :
|
|
|
|
|
m_editorList(new QComboBox(q)),
|
2014-09-04 20:43:09 +02:00
|
|
|
m_closeEditorButton(new QToolButton(q)),
|
|
|
|
|
m_lockButton(new QToolButton(q)),
|
|
|
|
|
m_dragHandle(new QToolButton(q)),
|
2015-02-25 12:45:15 +03:00
|
|
|
m_dragHandleMenu(0),
|
2010-09-16 12:26:28 +02:00
|
|
|
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)),
|
2015-02-25 12:45:15 +03:00
|
|
|
m_backButton(new QToolButton(q)),
|
|
|
|
|
m_forwardButton(new QToolButton(q)),
|
2014-09-04 20:43:09 +02:00
|
|
|
m_splitButton(new QToolButton(q)),
|
2011-12-05 13:28:56 +01:00
|
|
|
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)),
|
2013-06-03 14:53:56 +02:00
|
|
|
m_splitNewWindowAction(new QAction(EditorManager::tr("Open in New Window"), parent)),
|
2014-09-04 20:43:09 +02:00
|
|
|
m_closeSplitButton(new QToolButton(q)),
|
2010-09-16 12:26:28 +02:00
|
|
|
m_activeToolBar(0),
|
2014-09-04 20:43:09 +02:00
|
|
|
m_toolBarPlaceholder(new QWidget(q)),
|
2010-09-16 12:26:28 +02:00
|
|
|
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);
|
|
|
|
|
|
2014-09-10 17:03:13 +02:00
|
|
|
d->m_dragHandle->setProperty("noArrow", true);
|
2014-09-04 20:43:09 +02:00
|
|
|
d->m_dragHandle->setToolTip(tr("Drag to drag documents between splits"));
|
|
|
|
|
d->m_dragHandle->installEventFilter(this);
|
2014-09-10 17:03:13 +02:00
|
|
|
d->m_dragHandleMenu = new QMenu(d->m_dragHandle);
|
|
|
|
|
d->m_dragHandle->setMenu(d->m_dragHandleMenu);
|
2014-09-04 20:43:09 +02:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
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);
|
2012-10-11 11:18:26 +04:00
|
|
|
d->m_editorList->setProperty("notelideasterisk", true);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
d->m_editorList->setMinimumContentsLength(20);
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_editorList->setModel(DocumentModel::model());
|
2010-09-16 12:26:28 +02:00
|
|
|
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);
|
2014-08-01 15:14:15 +02:00
|
|
|
d->m_closeEditorButton->setIcon(QIcon(QLatin1String(Constants::ICON_BUTTON_CLOSE)));
|
2011-12-05 13:28:56 +01:00
|
|
|
d->m_closeEditorButton->setEnabled(false);
|
2014-07-07 19:05:39 +02:00
|
|
|
d->m_closeEditorButton->setProperty("showborder", true);
|
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->setDefaultAction(d->m_goBackAction);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_forwardButton->setDefaultAction(d->m_goForwardAction);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
if (Utils::HostOsInfo::isMacHost()) {
|
|
|
|
|
d->m_horizontalSplitAction->setIconVisibleInMenu(false);
|
|
|
|
|
d->m_verticalSplitAction->setIconVisibleInMenu(false);
|
2013-04-15 12:53:34 +02:00
|
|
|
d->m_splitNewWindowAction->setIconVisibleInMenu(false);
|
2012-08-23 15:53:58 +02:00
|
|
|
}
|
2011-12-05 13:28:56 +01:00
|
|
|
|
|
|
|
|
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);
|
2013-04-15 12:53:34 +02:00
|
|
|
splitMenu->addAction(d->m_splitNewWindowAction);
|
2011-12-05 13:28:56 +01:00
|
|
|
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);
|
2014-09-04 20:43:09 +02:00
|
|
|
toplayout->addWidget(d->m_dragHandle);
|
2010-09-16 12:26:28 +02:00
|
|
|
toplayout->addWidget(d->m_editorList);
|
2014-07-07 19:05:39 +02:00
|
|
|
toplayout->addWidget(d->m_closeEditorButton);
|
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);
|
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
|
|
|
|
2014-09-10 17:03:13 +02:00
|
|
|
connect(d->m_editorList, &QComboBox::customContextMenuRequested, [this](QPoint p) {
|
|
|
|
|
QMenu menu;
|
|
|
|
|
fillListContextMenu(&menu);
|
|
|
|
|
menu.exec(d->m_editorList->mapToGlobal(p));
|
|
|
|
|
});
|
|
|
|
|
connect(d->m_dragHandleMenu, &QMenu::aboutToShow, [this]() {
|
|
|
|
|
d->m_dragHandleMenu->clear();
|
|
|
|
|
fillListContextMenu(d->m_dragHandleMenu);
|
|
|
|
|
});
|
2010-09-16 12:26:28 +02:00
|
|
|
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);
|
2013-04-15 12:53:34 +02:00
|
|
|
connect(d->m_splitNewWindowAction, SIGNAL(triggered()),
|
|
|
|
|
this, SIGNAL(splitNewWindowClicked()), Qt::QueuedConnection);
|
2011-12-05 13:28:56 +01:00
|
|
|
connect(d->m_closeSplitButton, SIGNAL(clicked()),
|
|
|
|
|
this, SIGNAL(closeSplitClicked()), Qt::QueuedConnection);
|
|
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2012-05-24 13:49:06 +02:00
|
|
|
connect(ActionManager::command(Constants::CLOSE), SIGNAL(keySequenceChanged()),
|
2010-03-09 17:40:55 +01:00
|
|
|
this, SLOT(updateActionShortcuts()));
|
2012-05-24 13:49:06 +02:00
|
|
|
connect(ActionManager::command(Constants::GO_BACK), SIGNAL(keySequenceChanged()),
|
2010-03-09 17:40:55 +01:00
|
|
|
this, SLOT(updateActionShortcuts()));
|
2012-05-24 13:49:06 +02:00
|
|
|
connect(ActionManager::command(Constants::GO_FORWARD), SIGNAL(keySequenceChanged()),
|
2010-03-09 17:40:55 +01:00
|
|
|
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);
|
2013-07-19 17:19:04 +02:00
|
|
|
disconnect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
|
2010-03-09 17:40:55 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
if (d->m_isStandalone)
|
2014-08-19 16:15:57 +02:00
|
|
|
EditorManager::slotCloseCurrentEditorOrDocument();
|
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);
|
2013-07-19 17:19:04 +02:00
|
|
|
connect(editor->document(), SIGNAL(changed()), this, SLOT(checkDocumentStatus()));
|
2010-03-09 17:40:55 +01:00
|
|
|
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
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
updateDocumentStatus(editor->document());
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2014-11-16 10:52:41 +02:00
|
|
|
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
|
|
|
|
this, &EditorToolBar::updateEditorListSelection);
|
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
|
|
|
|
2014-09-10 17:03:13 +02:00
|
|
|
void EditorToolBar::setMenuProvider(const EditorToolBar::MenuProvider &provider)
|
|
|
|
|
{
|
|
|
|
|
d->m_menuProvider = provider;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2013-07-05 16:00:19 +02:00
|
|
|
IDocument *document = editor ? editor->document() : 0;
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
|
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)
|
2013-07-03 17:18:06 +02:00
|
|
|
updateToolBar(editor ? editor->toolBar() : 0);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
updateDocumentStatus(document);
|
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)
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(newSelection->document()));
|
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
|
|
|
{
|
2014-06-13 16:21:25 +02:00
|
|
|
EditorManager::activateEditorForEntry(DocumentModel::entryAtRow(row));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-10 17:03:13 +02:00
|
|
|
void EditorToolBar::fillListContextMenu(QMenu *menu)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2014-09-10 17:03:13 +02:00
|
|
|
if (d->m_menuProvider) {
|
|
|
|
|
d->m_menuProvider(menu);
|
2014-08-19 16:15:57 +02:00
|
|
|
} else {
|
2014-09-10 17:03:13 +02:00
|
|
|
IEditor *editor = EditorManager::currentEditor();
|
|
|
|
|
DocumentModel::Entry *entry = editor ? DocumentModel::entryForDocument(editor->document())
|
|
|
|
|
: 0;
|
|
|
|
|
EditorManager::addSaveAndCloseEditorActions(menu, entry, editor);
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
EditorManager::addNativeDirAndOpenWithActions(menu, entry);
|
2014-08-19 16:15:57 +02:00
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 17:40:55 +01:00
|
|
|
void EditorToolBar::makeEditorWritable()
|
|
|
|
|
{
|
2013-07-09 11:52:44 +02:00
|
|
|
if (IDocument *current = EditorManager::currentDocument())
|
2014-07-18 17:11:57 +02:00
|
|
|
Internal::EditorManagerPrivate::makeFileWritable(current);
|
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-05-24 13:49:06 +02:00
|
|
|
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")));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
void EditorToolBar::checkDocumentStatus()
|
2010-03-09 17:40:55 +01:00
|
|
|
{
|
2013-07-19 17:19:04 +02:00
|
|
|
IDocument *document = qobject_cast<IDocument *>(sender());
|
|
|
|
|
QTC_ASSERT(document, return);
|
2014-06-13 16:21:25 +02:00
|
|
|
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
|
2013-07-19 17:19:04 +02:00
|
|
|
d->m_editorList->currentIndex());
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
if (entry && entry->document && entry->document == document)
|
|
|
|
|
updateDocumentStatus(document);
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
void EditorToolBar::updateDocumentStatus(IDocument *document)
|
2010-03-09 17:40:55 +01:00
|
|
|
{
|
2013-07-19 17:19:04 +02:00
|
|
|
d->m_closeEditorButton->setEnabled(document != 0);
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
if (!document) {
|
2011-12-06 11:40:16 +01:00
|
|
|
d->m_lockButton->setIcon(QIcon());
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(QString());
|
2014-09-04 20:43:09 +02:00
|
|
|
d->m_dragHandle->setIcon(QIcon());
|
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
|
|
|
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document));
|
2010-03-09 17:40:55 +01:00
|
|
|
|
2013-07-19 17:19:04 +02:00
|
|
|
if (document->filePath().isEmpty()) {
|
2012-02-14 12:10:29 +01:00
|
|
|
d->m_lockButton->setIcon(QIcon());
|
|
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(QString());
|
2013-07-19 17:19:04 +02:00
|
|
|
} else if (document->isFileReadOnly()) {
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_lockButton->setIcon(DocumentModel::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 {
|
2014-05-07 16:25:04 +02:00
|
|
|
d->m_lockButton->setIcon(DocumentModel::unlockedIcon());
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_lockButton->setEnabled(false);
|
|
|
|
|
d->m_lockButton->setToolTip(tr("File is writable"));
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
2014-09-04 20:43:09 +02:00
|
|
|
|
|
|
|
|
if (document->filePath().isEmpty())
|
|
|
|
|
d->m_dragHandle->setIcon(QIcon());
|
|
|
|
|
else
|
2014-12-21 21:54:30 +02:00
|
|
|
d->m_dragHandle->setIcon(FileIconProvider::icon(document->filePath().toFileInfo()));
|
2014-09-04 20:43:09 +02:00
|
|
|
|
2014-12-21 21:54:30 +02:00
|
|
|
d->m_editorList->setToolTip(document->filePath().isEmpty()
|
|
|
|
|
? document->displayName()
|
|
|
|
|
: document->filePath().toUserOutput());
|
2010-03-09 17:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 20:43:09 +02:00
|
|
|
bool EditorToolBar::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (obj == d->m_dragHandle) {
|
|
|
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
auto me = static_cast<QMouseEvent *>(event);
|
2014-09-10 17:03:13 +02:00
|
|
|
if (me->buttons() == Qt::LeftButton)
|
2014-09-04 20:43:09 +02:00
|
|
|
d->m_dragStartPosition = me->pos();
|
2014-09-10 17:03:13 +02:00
|
|
|
return true; // do not pop up menu already on press
|
|
|
|
|
} else if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
d->m_dragHandle->showMenu();
|
|
|
|
|
return true;
|
2014-09-04 20:43:09 +02:00
|
|
|
} else if (event->type() == QEvent::MouseMove) {
|
|
|
|
|
auto me = static_cast<QMouseEvent *>(event);
|
|
|
|
|
if (me->buttons() != Qt::LeftButton)
|
|
|
|
|
return Utils::StyledBar::eventFilter(obj, event);
|
|
|
|
|
if ((me->pos() - d->m_dragStartPosition).manhattanLength()
|
|
|
|
|
< QApplication::startDragDistance())
|
|
|
|
|
return Utils::StyledBar::eventFilter(obj, event);
|
|
|
|
|
DocumentModel::Entry *entry = DocumentModel::entryAtRow(
|
|
|
|
|
d->m_editorList->currentIndex());
|
|
|
|
|
if (!entry) // no document
|
|
|
|
|
return Utils::StyledBar::eventFilter(obj, event);
|
2014-09-12 12:52:34 +02:00
|
|
|
auto drag = new QDrag(this);
|
|
|
|
|
auto data = new Utils::FileDropMimeData;
|
2015-02-15 15:57:21 +02:00
|
|
|
data->addFile(entry->fileName().toString());
|
2014-09-12 12:52:34 +02:00
|
|
|
drag->setMimeData(data);
|
2014-09-04 20:43:09 +02:00
|
|
|
Qt::DropAction action = drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction);
|
|
|
|
|
if (action == Qt::MoveAction)
|
|
|
|
|
emit currentDocumentMoved();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Utils::StyledBar::eventFilter(obj, event);
|
|
|
|
|
}
|
|
|
|
|
|
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
|