Changeset View
Changeset View
Standalone View
Standalone View
addons/filetree/katefiletreemodel.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "katefiletreemodel.h" | 20 | #include "katefiletreemodel.h" | ||
21 | 21 | | |||
22 | #include <QDir> | 22 | #include <QDir> | ||
23 | #include <QFileInfo> | 23 | #include <QFileInfo> | ||
24 | #include <QList> | 24 | #include <QList> | ||
25 | #include <QMimeData> | ||||
25 | #include <QMimeDatabase> | 26 | #include <QMimeDatabase> | ||
26 | #include <QIcon> | 27 | #include <QIcon> | ||
27 | #include <QStack> | 28 | #include <QStack> | ||
28 | 29 | | |||
29 | #include <KColorScheme> | 30 | #include <KColorScheme> | ||
30 | #include <KColorUtils> | 31 | #include <KColorUtils> | ||
31 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
32 | #include <KIconUtils> | 33 | #include <KIconUtils> | ||
▲ Show 20 Lines • Show All 450 Lines • ▼ Show 20 Line(s) | |||||
483 | { | 484 | { | ||
484 | Qt::ItemFlags flags = Qt::ItemIsEnabled; | 485 | Qt::ItemFlags flags = Qt::ItemIsEnabled; | ||
485 | 486 | | |||
486 | if (!index.isValid()) { | 487 | if (!index.isValid()) { | ||
487 | return 0; | 488 | return 0; | ||
488 | } | 489 | } | ||
489 | 490 | | |||
490 | const ProxyItem *item = static_cast<ProxyItem *>(index.internalPointer()); | 491 | const ProxyItem *item = static_cast<ProxyItem *>(index.internalPointer()); | ||
491 | if (item && !item->childCount()) { | 492 | if (item) { | ||
493 | if (!item->childCount()) { | ||||
492 | flags |= Qt::ItemIsSelectable; | 494 | flags |= Qt::ItemIsSelectable; | ||
493 | } | 495 | } | ||
494 | 496 | | |||
497 | if (item->doc() && item->doc()->url().isValid()) { | ||||
498 | flags |= Qt::ItemIsDragEnabled; | ||||
499 | } | ||||
500 | } | ||||
501 | | ||||
495 | return flags; | 502 | return flags; | ||
496 | } | 503 | } | ||
497 | 504 | | |||
498 | Q_DECLARE_METATYPE(QList<KTextEditor::Document *>) | 505 | Q_DECLARE_METATYPE(QList<KTextEditor::Document *>) | ||
499 | 506 | | |||
500 | QVariant KateFileTreeModel::data(const QModelIndex &index, int role) const | 507 | QVariant KateFileTreeModel::data(const QModelIndex &index, int role) const | ||
501 | { | 508 | { | ||
502 | if (!index.isValid()) { | 509 | if (!index.isValid()) { | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 562 | if (m_shadingEnabled && m_brushes.contains(item)) { | |||
556 | return m_brushes[item]; | 563 | return m_brushes[item]; | ||
557 | } | 564 | } | ||
558 | break; | 565 | break; | ||
559 | } | 566 | } | ||
560 | 567 | | |||
561 | return QVariant(); | 568 | return QVariant(); | ||
562 | } | 569 | } | ||
563 | 570 | | |||
571 | QMimeData *KateFileTreeModel::mimeData(const QModelIndexList &indexes) const | ||||
572 | { | ||||
573 | QList<QUrl> urls; | ||||
574 | | ||||
575 | for (const auto &index : indexes) { | ||||
576 | ProxyItem *item = static_cast<ProxyItem *>(index.internalPointer()); | ||||
577 | if (!item || !item->doc() || !item->doc()->url().isValid()) { | ||||
578 | continue; | ||||
579 | } | ||||
580 | | ||||
581 | urls.append(item->doc()->url()); | ||||
582 | } | ||||
583 | | ||||
584 | if (urls.isEmpty()) { | ||||
585 | return nullptr; | ||||
586 | } | ||||
587 | | ||||
588 | QMimeData *mimeData = new QMimeData(); | ||||
589 | mimeData->setUrls(urls); | ||||
590 | return mimeData; | ||||
591 | } | ||||
592 | | ||||
564 | QVariant KateFileTreeModel::headerData(int section, Qt::Orientation orientation, int role) const | 593 | QVariant KateFileTreeModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
565 | { | 594 | { | ||
566 | Q_UNUSED(orientation); | 595 | Q_UNUSED(orientation); | ||
567 | Q_UNUSED(role); | 596 | Q_UNUSED(role); | ||
568 | 597 | | |||
569 | if (section == 0) { | 598 | if (section == 0) { | ||
570 | return QLatin1String("name"); | 599 | return QLatin1String("name"); | ||
571 | } | 600 | } | ||
▲ Show 20 Lines • Show All 735 Lines • Show Last 20 Lines |