forked from qt-creator/qt-creator
Editors: Support drag and drop from open editors pane to splits
Change-Id: I6f8685319f0afe2a326a66e36a1e6b671e317614 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -33,10 +33,13 @@
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -50,10 +53,15 @@ public:
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
QModelIndex parent(const QModelIndex &/*index*/) const { return QModelIndex(); }
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
QStringList mimeTypes() const;
|
||||
|
||||
void addEntry(DocumentModel::Entry *entry);
|
||||
void removeDocument(int idx);
|
||||
|
||||
@@ -341,6 +349,16 @@ QModelIndex DocumentModelPrivate::index(int row, int column, const QModelIndex &
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
Qt::DropActions DocumentModelPrivate::supportedDragActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList DocumentModelPrivate::mimeTypes() const
|
||||
{
|
||||
return Utils::FileDropSupport::mimeTypesForFilePaths();
|
||||
}
|
||||
|
||||
DocumentModel::Entry *DocumentModel::entryAtRow(int row)
|
||||
{
|
||||
int entryIndex = row - 1/*<no document>*/;
|
||||
@@ -398,6 +416,26 @@ QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const
|
||||
{
|
||||
const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
|
||||
if (!e || e->fileName().isEmpty())
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QMimeData *DocumentModelPrivate::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QStringList filePaths;
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
|
||||
if (!e || e->fileName().isEmpty())
|
||||
continue;
|
||||
filePaths.append(e->fileName());
|
||||
}
|
||||
return Utils::FileDropSupport::mimeDataForFilePaths(filePaths);
|
||||
}
|
||||
|
||||
int DocumentModel::rowOfDocument(IDocument *document)
|
||||
{
|
||||
if (!document)
|
||||
|
@@ -88,6 +88,8 @@ OpenEditorsWidget::OpenEditorsWidget()
|
||||
{
|
||||
setWindowTitle(tr("Open Documents"));
|
||||
setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR)));
|
||||
setDragEnabled(true);
|
||||
setDragDropMode(QAbstractItemView::DragOnly);
|
||||
setUniformRowHeights(true);
|
||||
viewport()->setAttribute(Qt::WA_Hover);
|
||||
setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
|
||||
@@ -314,6 +316,11 @@ QModelIndex ProxyModel::sibling(int row, int column, const QModelIndex &idx) con
|
||||
return QAbstractItemModel::sibling(row, column, idx);
|
||||
}
|
||||
|
||||
Qt::DropActions ProxyModel::supportedDragActions() const
|
||||
{
|
||||
return sourceModel()->supportedDragActions();
|
||||
}
|
||||
|
||||
void ProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
QModelIndex topLeftIndex = mapFromSource(topLeft);
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
|
||||
// QAbstractProxyModel::sibling is broken in Qt 5
|
||||
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
|
||||
// QAbstractProxyModel::supportedDragActions delegation is missing in Qt 5
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
|
||||
private slots:
|
||||
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
|
Reference in New Issue
Block a user