2010-02-26 11:08:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
#include "designmodetoolbar.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>
|
|
|
|
|
#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 <coreplugin/modemanager.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/parameteraction.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QEvent>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QScrollArea>
|
|
|
|
|
#include <QtGui/QTabWidget>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QToolBar>
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::IEditor*)
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
namespace Core {
|
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 09:42:22 +01:00
|
|
|
DesignModeToolBar::DesignModeToolBar(QWidget *parent) :
|
2010-02-26 11:08:17 +01:00
|
|
|
QWidget(parent),
|
|
|
|
|
m_editorList(new QComboBox),
|
2010-03-09 09:42:22 +01:00
|
|
|
m_centerToolBar(0),
|
|
|
|
|
m_rightToolBar(new QToolBar),
|
2010-02-26 11:08:17 +01:00
|
|
|
m_closeButton(new QToolButton),
|
|
|
|
|
m_lockButton(new QToolButton),
|
|
|
|
|
m_goBackAction(new QAction(QIcon(QLatin1String(":/help/images/previous.png")), EditorManager::tr("Go Back"), parent)),
|
2010-03-09 09:42:22 +01:00
|
|
|
m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)),
|
|
|
|
|
m_editor(0)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 09:42:22 +01:00
|
|
|
ICore *core = ICore::instance();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
//setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
2010-02-26 11:08:17 +01:00
|
|
|
m_editorsListModel = core->editorManager()->openedEditorsModel();
|
|
|
|
|
|
|
|
|
|
// copied from EditorView::EditorView
|
|
|
|
|
m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
m_editorList->setMinimumContentsLength(20);
|
|
|
|
|
m_editorList->setModel(m_editorsListModel);
|
|
|
|
|
m_editorList->setMaxVisibleItems(40);
|
|
|
|
|
m_editorList->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
|
|
QToolBar *editorListToolBar = new QToolBar;
|
|
|
|
|
editorListToolBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
|
|
|
|
|
editorListToolBar->addWidget(m_editorList);
|
|
|
|
|
|
|
|
|
|
m_lockButton->setAutoRaise(true);
|
|
|
|
|
m_lockButton->setProperty("type", QLatin1String("dockbutton"));
|
|
|
|
|
|
|
|
|
|
m_closeButton->setAutoRaise(true);
|
|
|
|
|
m_closeButton->setIcon(QIcon(":/core/images/closebutton.png"));
|
|
|
|
|
m_closeButton->setProperty("type", QLatin1String("dockbutton"));
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
// ActionManager *am = core->actionManager();
|
|
|
|
|
// EditorManager *em = core->editorManager();
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
// TODO back/FW buttons disabled for the time being, as the implementation would require changing editormanager.
|
|
|
|
|
// QToolBar *backFwToolBar = new QToolBar;
|
|
|
|
|
// backFwToolBar->addAction(m_goBackAction);
|
|
|
|
|
// backFwToolBar->addAction(m_goForwardAction);
|
2010-03-09 09:42:22 +01:00
|
|
|
// Command *cmd = am->registerAction(m_goBackAction, Constants::GO_BACK, editor->context());
|
2010-02-26 11:08:17 +01:00
|
|
|
//#ifdef Q_WS_MAC
|
|
|
|
|
// cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Left")));
|
|
|
|
|
//#else
|
|
|
|
|
// cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Left")));
|
|
|
|
|
//#endif
|
|
|
|
|
// connect(m_goBackAction, SIGNAL(triggered()), em, SLOT(goBackInNavigationHistory()));
|
2010-03-09 09:42:22 +01:00
|
|
|
// cmd = am->registerAction(m_goForwardAction, Constants::GO_FORWARD, editor->context());
|
2010-02-26 11:08:17 +01:00
|
|
|
//#ifdef Q_WS_MAC
|
|
|
|
|
// cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Right")));
|
|
|
|
|
//#else
|
|
|
|
|
// cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Right")));
|
|
|
|
|
//#endif
|
|
|
|
|
// connect(m_goForwardAction, SIGNAL(triggered()), em, SLOT(goForwardInNavigationHistory()));
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
m_rightToolBar->setLayoutDirection(Qt::RightToLeft);
|
|
|
|
|
m_rightToolBar->addWidget(m_closeButton);
|
|
|
|
|
m_rightToolBar->addWidget(m_lockButton);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
QHBoxLayout *toplayout = new QHBoxLayout(this);
|
|
|
|
|
toplayout->setSpacing(0);
|
|
|
|
|
toplayout->setMargin(0);
|
|
|
|
|
toplayout->setContentsMargins(0,0,0,0);
|
|
|
|
|
toplayout->addWidget(editorListToolBar);
|
2010-03-09 09:42:22 +01:00
|
|
|
toplayout->addWidget(m_rightToolBar);
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
connect(m_editorList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int)));
|
|
|
|
|
connect(m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
|
|
|
|
|
connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
|
2010-03-09 09:42:22 +01:00
|
|
|
connect(m_closeButton, SIGNAL(clicked()), this, SIGNAL(closeClicked()));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
connect(core->editorManager(), SIGNAL(currentEditorChanged(IEditor*)), SLOT(updateEditorListSelection(IEditor*)));
|
2010-02-26 11:08:17 +01:00
|
|
|
|
|
|
|
|
updateEditorStatus();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::setCenterToolBar(QWidget *toolBar)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 09:42:22 +01:00
|
|
|
if (toolBar) {
|
|
|
|
|
layout()->removeWidget(m_rightToolBar);
|
|
|
|
|
layout()->addWidget(toolBar);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
2010-03-09 09:42:22 +01:00
|
|
|
|
|
|
|
|
layout()->addWidget(m_rightToolBar);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::setEditor(IEditor *editor)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 09:42:22 +01:00
|
|
|
m_editor = editor;
|
|
|
|
|
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(m_editor).row());
|
|
|
|
|
connect(m_editor, SIGNAL(changed()), this, SLOT(updateEditorStatus()));
|
|
|
|
|
}
|
2010-02-26 11:08:17 +01:00
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::updateEditorListSelection(IEditor *newSelection)
|
|
|
|
|
{
|
|
|
|
|
if (newSelection) {
|
|
|
|
|
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row());
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::listSelectionActivated(int row)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 09:42:22 +01:00
|
|
|
EditorManager *em = ICore::instance()->editorManager();
|
|
|
|
|
QAbstractItemModel *model = m_editorList->model();
|
|
|
|
|
|
2010-02-26 11:08:17 +01:00
|
|
|
const QModelIndex modelIndex = model->index(row, 0);
|
2010-03-09 09:42:22 +01:00
|
|
|
IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>();
|
2010-02-26 11:08:17 +01:00
|
|
|
if (editor) {
|
|
|
|
|
if (editor != em->currentEditor())
|
|
|
|
|
em->activateEditor(editor, EditorManager::NoModeSwitch);
|
|
|
|
|
} else {
|
|
|
|
|
QString fileName = model->data(modelIndex, Qt::UserRole + 1).toString();
|
|
|
|
|
QByteArray kind = model->data(modelIndex, Qt::UserRole + 2).toByteArray();
|
|
|
|
|
editor = em->openEditor(fileName, kind, EditorManager::NoModeSwitch);
|
|
|
|
|
}
|
|
|
|
|
if (editor) {
|
|
|
|
|
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::listContextMenu(QPoint pos)
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
|
|
|
|
QModelIndex index = m_editorsListModel->index(m_editorList->currentIndex(), 0);
|
|
|
|
|
QString fileName = m_editorsListModel->data(index, Qt::UserRole + 1).toString();
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
QMenu menu;
|
|
|
|
|
menu.addAction(tr("Copy full path to clipboard"));
|
|
|
|
|
if (menu.exec(m_editorList->mapToGlobal(pos))) {
|
|
|
|
|
QApplication::clipboard()->setText(fileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::makeEditorWritable()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 09:42:22 +01:00
|
|
|
if (m_editor)
|
|
|
|
|
ICore::instance()->editorManager()->makeEditorWritable(m_editor);
|
2010-02-26 11:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
void DesignModeToolBar::updateEditorStatus()
|
2010-02-26 11:08:17 +01:00
|
|
|
{
|
2010-03-09 10:26:20 +01:00
|
|
|
if (!m_editor || !m_editor->file())
|
2010-02-26 11:08:17 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_editor->file()->isReadOnly()) {
|
|
|
|
|
m_lockButton->setIcon(m_editorsListModel->lockedIcon());
|
|
|
|
|
m_lockButton->setEnabled(!m_editor->file()->fileName().isEmpty());
|
|
|
|
|
m_lockButton->setToolTip(tr("Make writable"));
|
|
|
|
|
} else {
|
|
|
|
|
m_lockButton->setIcon(m_editorsListModel->unlockedIcon());
|
|
|
|
|
m_lockButton->setEnabled(false);
|
|
|
|
|
m_lockButton->setToolTip(tr("File is writable"));
|
|
|
|
|
}
|
|
|
|
|
m_editorList->setToolTip(
|
|
|
|
|
m_editor->file()->fileName().isEmpty()
|
|
|
|
|
? m_editor->displayName()
|
|
|
|
|
: QDir::toNativeSeparators(m_editor->file()->fileName())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-09 09:42:22 +01:00
|
|
|
} // Core
|