summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor/qmloutlinemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmljseditor/qmloutlinemodel.cpp')
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.cpp33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index 9cd7a900a1..d5fb914063 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -38,6 +38,7 @@
#include <qmljs/qmljsrewriter.h>
#include <qmljstools/qmljsrefactoringchanges.h>
+#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
@@ -54,6 +55,8 @@ enum {
debug = false
};
+static const char INTERNAL_MIMETYPE[] = "application/x-qtcreator-qmloutlinemodel";
+
namespace QmlJSEditor {
namespace Internal {
@@ -307,15 +310,14 @@ QmlOutlineModel::QmlOutlineModel(QmlJSEditorDocument *document) :
const QString resourcePath = Core::ICore::resourcePath();
Icons::instance()->setIconFilesPath(resourcePath + QLatin1String("/qmlicons"));
- // TODO: Maybe add a Copy Action?
- setSupportedDragActions(Qt::MoveAction);
setItemPrototype(new QmlOutlineItem(this));
}
QStringList QmlOutlineModel::mimeTypes() const
{
QStringList types;
- types << QLatin1String("application/x-qtcreator-qmloutlinemodel");
+ types << QLatin1String(INTERNAL_MIMETYPE);
+ types << Utils::FileDropSupport::mimeTypesForFilePaths();
return types;
}
@@ -324,9 +326,8 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
{
if (indexes.count() <= 0)
return 0;
- QStringList types = mimeTypes();
- QMimeData *data = new QMimeData();
- QString format = types.at(0);
+ auto data = new Utils::FileDropMimeData;
+ data->setOverrideFileDropAction(Qt::CopyAction);
QByteArray encoded;
QDataStream stream(&encoded, QIODevice::WriteOnly);
stream << indexes.size();
@@ -334,6 +335,10 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
for (int i = 0; i < indexes.size(); ++i) {
QModelIndex index = indexes.at(i);
+ AST::SourceLocation location = sourceLocation(index);
+ data->addFile(m_editorDocument->filePath(), location.startLine,
+ location.startColumn - 1 /*editors have 0-based column*/);
+
QList<int> rowPath;
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
rowPath.prepend(i.row());
@@ -341,7 +346,7 @@ QMimeData *QmlOutlineModel::mimeData(const QModelIndexList &indexes) const
stream << rowPath;
}
- data->setData(format, encoded);
+ data->setData(QLatin1String(INTERNAL_MIMETYPE), encoded);
return data;
}
@@ -411,6 +416,12 @@ Qt::ItemFlags QmlOutlineModel::flags(const QModelIndex &index) const
return flags;
}
+Qt::DropActions QmlOutlineModel::supportedDragActions() const
+{
+ // copy action used for dragging onto editor splits
+ return Qt::MoveAction | Qt::CopyAction;
+}
+
Document::Ptr QmlOutlineModel::document() const
{
@@ -912,7 +923,7 @@ QString QmlOutlineModel::asString(AST::UiQualifiedId *id)
AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember) {
AST::SourceLocation location;
- location.offset = objMember->firstSourceLocation().offset;
+ location = objMember->firstSourceLocation();
location.length = objMember->lastSourceLocation().offset
- objMember->firstSourceLocation().offset
+ objMember->lastSourceLocation().length;
@@ -921,7 +932,7 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember)
AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode) {
AST::SourceLocation location;
- location.offset = exprNode->firstSourceLocation().offset;
+ location = exprNode->firstSourceLocation();
location.length = exprNode->lastSourceLocation().offset
- exprNode->firstSourceLocation().offset
+ exprNode->lastSourceLocation().length;
@@ -938,7 +949,7 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyAssignmentList *pr
AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyNameAndValue *propertyNode) {
AST::SourceLocation location;
- location.offset = propertyNode->name->propertyNameToken.offset;
+ location = propertyNode->name->propertyNameToken;
location.length = propertyNode->value->lastSourceLocation().end() - location.offset;
return location;
@@ -946,7 +957,7 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyNameAndValue *prop
AST::SourceLocation QmlOutlineModel::getLocation(AST::PropertyGetterSetter *propertyNode) {
AST::SourceLocation location;
- location.offset = propertyNode->name->propertyNameToken.offset;
+ location = propertyNode->name->propertyNameToken;
location.length = propertyNode->rbraceToken.end() - location.offset;
return location;