summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin/editormanager/openeditorsview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/editormanager/openeditorsview.cpp')
-rw-r--r--src/plugins/coreplugin/editormanager/openeditorsview.cpp87
1 files changed, 50 insertions, 37 deletions
diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp
index c30ace1f86..b65fe1c25f 100644
--- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp
+++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp
@@ -41,6 +41,8 @@
#include <coreplugin/actionmanager/command.h>
#include <utils/qtcassert.h>
+#include <QApplication>
+#include <QGridLayout>
#include <QTimer>
#include <QMenu>
#include <QPainter>
@@ -48,6 +50,7 @@
#include <QStyleOption>
#include <QHeaderView>
#include <QKeyEvent>
+#include <QTreeView>
using namespace Core;
using namespace Core::Internal;
@@ -93,36 +96,36 @@ void OpenEditorsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
OpenEditorsWidget::OpenEditorsWidget()
{
- m_ui.setupUi(this);
setWindowTitle(tr("Open Documents"));
setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR)));
- setFocusProxy(m_ui.editorList);
- m_ui.editorList->viewport()->setAttribute(Qt::WA_Hover);
- m_ui.editorList->setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
- m_ui.editorList->header()->hide();
- m_ui.editorList->setIndentation(0);
- m_ui.editorList->setTextElideMode(Qt::ElideMiddle);
- m_ui.editorList->setFrameStyle(QFrame::NoFrame);
- m_ui.editorList->setAttribute(Qt::WA_MacShowFocusRect, false);
+ setUniformRowHeights(true);
+ viewport()->setAttribute(Qt::WA_Hover);
+ setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
+ header()->hide();
+ setIndentation(0);
+ setTextElideMode(Qt::ElideMiddle);
+ setFrameStyle(QFrame::NoFrame);
+ setAttribute(Qt::WA_MacShowFocusRect, false);
EditorManager *em = EditorManager::instance();
- m_ui.editorList->setModel(em->openedEditorsModel());
- m_ui.editorList->setSelectionMode(QAbstractItemView::SingleSelection);
- m_ui.editorList->setSelectionBehavior(QAbstractItemView::SelectRows);
- m_ui.editorList->header()->setStretchLastSection(false);
- m_ui.editorList->header()->setResizeMode(0, QHeaderView::Stretch);
- m_ui.editorList->header()->setResizeMode(1, QHeaderView::Fixed);
- m_ui.editorList->header()->resizeSection(1, 16);
- m_ui.editorList->setContextMenuPolicy(Qt::CustomContextMenu);
- m_ui.editorList->installEventFilter(this);
+ setModel(em->openedEditorsModel());
+ setSelectionMode(QAbstractItemView::SingleSelection);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ header()->setStretchLastSection(false);
+ header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(1, QHeaderView::Fixed);
+ header()->resizeSection(1, 16);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+ installEventFilter(this);
+ viewport()->installEventFilter(this);
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentItem(Core::IEditor*)));
- connect(m_ui.editorList, SIGNAL(clicked(QModelIndex)),
+ connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(handleClicked(QModelIndex)));
- connect(m_ui.editorList, SIGNAL(pressed(QModelIndex)),
+ connect(this, SIGNAL(pressed(QModelIndex)),
this, SLOT(handlePressed(QModelIndex)));
- connect(m_ui.editorList, SIGNAL(customContextMenuRequested(QPoint)),
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(contextMenuRequested(QPoint)));
}
@@ -133,30 +136,41 @@ OpenEditorsWidget::~OpenEditorsWidget()
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
{
if (!editor) {
- m_ui.editorList->clearSelection();
+ clearSelection();
return;
}
EditorManager *em = EditorManager::instance();
- m_ui.editorList->setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
- m_ui.editorList->selectionModel()->select(m_ui.editorList->currentIndex(),
+ setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
+ selectionModel()->select(currentIndex(),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
- m_ui.editorList->scrollTo(m_ui.editorList->currentIndex());
+ scrollTo(currentIndex());
}
bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event)
{
- if (obj == m_ui.editorList && event->type() == QEvent::KeyPress
- && m_ui.editorList->currentIndex().isValid()) {
+ if (obj == this && event->type() == QEvent::KeyPress
+ && currentIndex().isValid()) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if ((ke->key() == Qt::Key_Return
|| ke->key() == Qt::Key_Enter)
&& ke->modifiers() == 0) {
- activateEditor(m_ui.editorList->currentIndex());
+ activateEditor(currentIndex());
return true;
} else if ((ke->key() == Qt::Key_Delete
|| ke->key() == Qt::Key_Backspace)
&& ke->modifiers() == 0) {
- closeEditor(m_ui.editorList->currentIndex());
+ closeEditor(currentIndex());
+ }
+ } else if (obj == viewport()
+ && event->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent * me = static_cast<QMouseEvent*>(event);
+ if (me->button() == Qt::MiddleButton
+ && me->modifiers() == Qt::NoModifier) {
+ QModelIndex index = indexAt(me->pos());
+ if (index.isValid()) {
+ closeEditor(index);
+ return true;
+ }
}
}
return false;
@@ -164,11 +178,10 @@ bool OpenEditorsWidget::eventFilter(QObject *obj, QEvent *event)
void OpenEditorsWidget::handlePressed(const QModelIndex &index)
{
- if (index.column() == 0) {
+ if (index.column() == 0)
activateEditor(index);
- } else if (index.column() == 1) {
+ else if (index.column() == 1)
m_delegate->pressedIndex = index;
- }
}
void OpenEditorsWidget::handleClicked(const QModelIndex &index)
@@ -178,7 +191,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
// work around a bug in itemviews where the delegate wouldn't get the QStyle::State_MouseOver
QPoint cursorPos = QCursor::pos();
- QWidget *vp = m_ui.editorList->viewport();
+ QWidget *vp = viewport();
QMouseEvent e(QEvent::MouseMove, vp->mapFromGlobal(cursorPos), cursorPos, Qt::NoButton, 0, 0);
QCoreApplication::sendEvent(vp, &e);
}
@@ -186,7 +199,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{
- m_ui.editorList->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::instance()->activateEditorForIndex(index, EditorManager::ModeSwitch);
}
@@ -200,11 +213,11 @@ void OpenEditorsWidget::closeEditor(const QModelIndex &index)
void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{
QMenu contextMenu;
- QModelIndex editorIndex = m_ui.editorList->indexAt(pos);
- EditorManager::instance()->addCloseEditorActions(&contextMenu, editorIndex);
+ QModelIndex editorIndex = indexAt(pos);
+ EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, editorIndex);
contextMenu.addSeparator();
EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex);
- contextMenu.exec(m_ui.editorList->mapToGlobal(pos));
+ contextMenu.exec(mapToGlobal(pos));
}
///